1 /*****************************************************************************
2 Major portions of this software are copyrighted by the Medical College
3 of Wisconsin, 1994-2000, and are released under the Gnu General Public
4 License, Version 2. See the file README.Copyright for details.
5 ******************************************************************************/
6
7 #include <stdio.h>
8 #include <string.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include "cs.h"
12
13 #define NBUF 256
14
main(int argc,char * argv[])15 int main( int argc , char * argv[] )
16 {
17 char buf[NBUF] , buf2[NBUF*2];
18 int ll , num=0 , ii , jj ;
19
20 if( argc < 2 || strcmp(argv[1],"-help") == 0 ){
21 printf("Usage: quotize name < input > output\n"
22 "Turns a text file into a C array of strings\n"
23 "initialized into an array 'char *name[]'.\n"
24 ) ;
25 exit(0) ;
26 }
27
28 printf("/** automatically generated by AFNI program quotize **/\n") ;
29 printf("static char *%s[] = {\n",argv[1]) ;
30 while( afni_fgets(buf,NBUF,stdin) != NULL ){
31 ll = strlen(buf) ; if( ll == 0 ) break ;
32 if( buf[ll-1] == '\n' ) buf[ll-1] = '\0' ;
33 for( ii=0,jj=0 ; buf[ii] != '\0' ; ){
34 if( buf[ii] == '"' || buf[ii] == '\\' ) buf2[jj++] = '\\' ;
35 buf2[jj++] = buf[ii++] ;
36 }
37 buf2[jj] = '\0' ;
38 printf(" \"%s\\n\" ,\n" , buf2 ) ;
39 num++ ;
40 }
41 printf(" NULL } ;\n") ;
42 printf("#define NUM_%s %d\n",argv[1],num) ;
43 exit(0) ;
44 }
45