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.10 2000/05/08 20:49:51 xiphmont Exp $
17 ********************************************************************/
26 #include <sys/types.h>
32 utilname [-i] +|* input_book.vqh [+|* input_book.vqh]
33 input_data.vqd [input_data.vqd]
35 produces output data on stdout
36 (may also take input data from stdin)
40 extern void process_preprocess(codebook **b,char *basename);
41 extern void process_postprocess(codebook **b,char *basename);
42 extern void process_vector(codebook **b,int *addmul, int inter,double *a,int n);
43 extern void process_usage(void);
45 int main(int argc,char *argv[]){
47 codebook **b=calloc(1,sizeof(codebook *));
48 int *addmul=calloc(1,sizeof(int));
62 /* yes, this is evil. However, it's very convenient to parse file
70 if(sscanf(argv[1],"%d,%d",&start,&num)!=2){
72 if(sscanf(argv[1],"%d",&start)!=1){
73 fprintf(stderr,"Syntax error using -s\n");
85 /* input file. What kind? */
88 char *name=strdup(*argv++);
89 dot=strrchr(name,'.');
96 if(!strcmp(ext,"vqh")){
99 fprintf(stderr,"specify all input data (.vqd) files following\n"
100 "codebook header (.vqh) files\n");
103 /* is it additive or multiplicative? */
108 if(name[0]=='+')name++;
110 basename=strrchr(name,'/');
112 basename=strdup(basename)+1;
114 basename=strdup(name);
115 dot=strrchr(basename,'.');
118 b=realloc(b,sizeof(codebook *)*(books+2));
119 b[books]=codebook_load(name);
120 addmul=realloc(addmul,sizeof(int)*(books+1));
121 addmul[books++]=multp;
126 if(!strcmp(ext,"vqd")){
131 FILE *in=fopen(name,"r");
133 fprintf(stderr,"Could not open input file %s\n",name);
138 process_preprocess(b,basename);
144 /* count cols before we start reading */
147 while(*temp==' ')temp++;
148 for(cols=0;*temp;cols++){
149 while(*temp>32)temp++;
150 while(*temp==' ')temp++;
153 vec=alloca(cols*sizeof(double));
157 if(get_line_value(in,vec+j)){
158 fprintf(stderr,"Too few columns on line %ld in data file\n",lines);
161 /* ignores -s for now */
162 process_vector(b,addmul,interleave,vec,cols);
171 /* take any data from stdin */
174 if(fstat(STDIN_FILENO,&st)==-1){
175 fprintf(stderr,"Could not stat STDIN\n");
178 if((S_IFIFO|S_IFREG|S_IFSOCK)&st.st_mode){
184 process_preprocess(b,basename);
188 line=setup_line(stdin);
189 /* count cols before we start reading */
192 while(*temp==' ')temp++;
193 for(cols=0;*temp;cols++){
194 while(*temp>32)temp++;
195 while(*temp==' ')temp++;
198 vec=alloca(cols*sizeof(double));
202 if(get_line_value(stdin,vec+j)){
203 fprintf(stderr,"Too few columns on line %ld in data file\n",lines);
206 /* ignores -s for now */
207 process_vector(b,addmul,interleave,vec,cols);
209 line=setup_line(stdin);
214 process_postprocess(b,basename);