1 /********************************************************************
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
11 ********************************************************************
13 function: utility main for loading and operating on codebooks
16 ********************************************************************/
25 #include <sys/types.h>
31 utilname [-i] +|* input_book.vqh [+|* input_book.vqh]
32 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,int *addmul, int inter,float *a,int n);
42 extern void process_usage(void);
44 int main(int argc,char *argv[]){
46 codebook **b=_ogg_calloc(1,sizeof(codebook *));
47 int *addmul=_ogg_calloc(1,sizeof(int));
61 /* yes, this is evil. However, it's very convenient to parse file
69 if(sscanf(argv[1],"%d,%d",&start,&num)!=2){
71 if(sscanf(argv[1],"%d",&start)!=1){
72 fprintf(stderr,"Syntax error using -s\n");
84 /* input file. What kind? */
87 char *name=strdup(*argv++);
88 dot=strrchr(name,'.');
95 if(!strcmp(ext,"vqh")){
98 fprintf(stderr,"specify all input data (.vqd) files following\n"
99 "codebook header (.vqh) files\n");
102 /* is it additive or multiplicative? */
107 if(name[0]=='+')name++;
109 basename=strrchr(name,'/');
111 basename=strdup(basename)+1;
113 basename=strdup(name);
114 dot=strrchr(basename,'.');
117 b=_ogg_realloc(b,sizeof(codebook *)*(books+2));
118 b[books]=codebook_load(name);
119 addmul=_ogg_realloc(addmul,sizeof(int)*(books+1));
120 addmul[books++]=multp;
125 if(!strcmp(ext,"vqd")){
130 FILE *in=fopen(name,"r");
132 fprintf(stderr,"Could not open input file %s\n",name);
137 process_preprocess(b,basename);
143 /* count cols before we start reading */
146 while(*temp==' ')temp++;
147 for(cols=0;*temp;cols++){
148 while(*temp>32)temp++;
149 while(*temp==' ')temp++;
152 vec=alloca(cols*sizeof(float));
156 if(get_line_value(in,vec+j)){
157 fprintf(stderr,"Too few columns on line %ld in data file\n",lines);
160 /* ignores -s for now */
161 process_vector(b,addmul,interleave,vec,cols);
170 /* take any data from stdin */
173 if(fstat(STDIN_FILENO,&st)==-1){
174 fprintf(stderr,"Could not stat STDIN\n");
177 if((S_IFIFO|S_IFREG|S_IFSOCK)&st.st_mode){
183 process_preprocess(b,basename);
187 line=setup_line(stdin);
188 /* count cols before we start reading */
191 while(*temp==' ')temp++;
192 for(cols=0;*temp;cols++){
193 while(*temp>32)temp++;
194 while(*temp==' ')temp++;
197 vec=alloca(cols*sizeof(float));
201 if(get_line_value(stdin,vec+j)){
202 fprintf(stderr,"Too few columns on line %ld in data file\n",lines);
205 /* ignores -s for now */
206 process_vector(b,addmul,interleave,vec,cols);
208 line=setup_line(stdin);
213 process_postprocess(b,basename);