1 /********************************************************************
3 * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5 * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
6 * PLEASE READ THESE TERMS DISTRIBUTING. *
8 * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
9 * by Monty <monty@xiph.org> and The XIPHOPHORUS Company *
10 * http://www.xiph.org/ *
12 ********************************************************************
14 function: utility main for loading and operating on codebooks
15 last mod: $Id: run.c,v 1.6 2000/01/07 12:11:33 xiphmont Exp $
17 ********************************************************************/
26 #include <sys/types.h>
32 utilname input_book.vqh input_data.vqd [input_data.vqd]
34 produces output data on stdout
35 (may also take input data from stdin)
39 extern void process_preprocess(codebook **b,char *basename);
40 extern void process_postprocess(codebook **b,char *basename);
41 extern void process_vector(codebook **b,double *a);
42 extern void process_usage(void);
44 int main(int argc,char *argv[]){
48 codebook **b=calloc(1,sizeof(codebook *));
58 /* yes, this is evil. However, it's very convenient to parse file
68 /* input file. What kind? */
71 char *name=strdup(*argv++);
79 if(!strcmp(ext,"vqh")){
81 fprintf(stderr,"specify all input data (.vqd) files following\n"
82 "codebook header (.vqh) files\n");
86 basename=strrchr(name,'/');
88 basename=strdup(basename);
90 basename=strdup(name);
91 dot=strchr(basename,'.');
94 b=realloc(b,sizeof(codebook *)*(books+2));
95 b[books++]=codebook_load(name);
97 if(!a)a=malloc(sizeof(double)*b[books-1]->dim);
101 if(!strcmp(ext,"vqd")){
102 FILE *in=fopen(name,"r");
104 fprintf(stderr,"Could not open input file %s\n",name);
109 process_preprocess(b,basename);
115 while(get_vector(*b,in,a)!=-1)
123 /* take any data from stdin */
126 if(fstat(STDIN_FILENO,&st)==-1){
127 fprintf(stderr,"Could not stat STDIN\n");
130 if((S_IFIFO|S_IFREG|S_IFSOCK)&st.st_mode){
132 process_preprocess(b,basename);
137 while(get_vector(*b,stdin,a)!=-1)
142 process_postprocess(b,basename);