#include "root.h" #include "file.h" #include "filter.h" typedef enum { strStart, strPrint, strNStates } strState; static filterRules *strTable[strNStates][NCHARS]; static filterRules strRules[] = { { "", "\t\"", strStart, strPrint, 0 }, { "\"", "\\\"", strPrint, strPrint, 0 }, { "\\", "\\\\", strPrint, strPrint, 0 }, { "\t", "\\t", strPrint, strPrint, 0 }, { "\n", "\",\n", strPrint, strStart, 0 }, { 0 } }; void fileToCStrings( const char *inputFile, const char *outputFile ) { FILE *fin, *fout; line *l; lineFilter filter; filterState state; initFilterTable( strTable, strRules, strNStates, YES ); filter.filt = stateFilter; filter.next = 0; filter.data = &state; state.table = strTable; state.state = strStart; state.filt = 0; fin = fileOpen( inputFile, "r", YES ); fout = fileOpen( outputFile, "w", YES ); l = fileRead( fin, &filter, 0 ); fprintf( fout, "{\n" ); fileWrite( fout, l, 0 ); fprintf( fout, "\t0\n};\n" ); fileClose( fin, YES ); fileClose( fout, YES ); lineListFree( l, markFree ); mallocCount(); } int main( int argc, const char *argv[] ) { if ( argc != 3 ) printf( "Usage: cstring input output\n" ); else fileToCStrings( argv[1], argv[2] ); return 0; }