Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
quotize.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include <stdio.h>
00008
00009 #define NBUF 256
00010
00011 int main( int argc , char * argv[] )
00012 {
00013 char buf[NBUF] , buf2[NBUF*2];
00014 int ll , num=0 , ii , jj ;
00015
00016 if( argc < 2 ){
00017 fprintf(stderr,"Usage: quotize name < input > output\n"
00018 "Turns a text file into a C array of strings\n"
00019 "initialized into an array 'char * name[]'.\n"
00020 ) ;
00021 exit(0) ;
00022 }
00023
00024 printf("static char * %s[] = {\n",argv[1]) ;
00025 while( fgets(buf,NBUF,stdin) != NULL ){
00026 ll = strlen(buf) ; if( ll == 0 ) break ;
00027 if( buf[ll-1] == '\n' ) buf[ll-1] = '\0' ;
00028 for( ii=0,jj=0 ; buf[ii] != '\0' ; ){
00029 if( buf[ii] == '"' || buf[ii] == '\\' ) buf2[jj++] = '\\' ;
00030 buf2[jj++] = buf[ii++] ;
00031 }
00032 buf2[jj] = '\0' ;
00033 printf(" \"%s\\n\" ,\n" , buf2 ) ;
00034 num++ ;
00035 }
00036 printf(" NULL } ;\n") ;
00037 printf("#define NUM_%s %d\n",argv[1],num) ;
00038 exit(0) ;
00039 }