/* * Tue Apr 1 09:48:31 DST 2003 * spd@daphne.cps.unizar.es * s/$token/value/g filter * Max line length: 512 */ #include #include #include main( int argc, char **argv) { char s[512]; char *ifs=" \011"; char *argt,*os; extern char *optarg; extern int optind,opterr,optopt; int opcion; short i; unsigned char error=0; char *token[]={ "FOO", "BAR", "FOOBAR", NULL }; char *value[]={ "foo", "bar", "foobar", NULL }; while ( (opcion=getopt(argc,argv,"c:")) != EOF ) { switch(opcion) { case 'c': error += ( *optarg==0x00 ); ifs=optarg; break; default: error ++; break; } } if ( error != 0 ) { fprintf( stderr, "Usage: %s -c separator\n", argv[0]); exit(-1); } while ( gets(s) != NULL ) /* fixme: use fgets() */ { argt = strtok( s, ifs ); while( argt != NULL ) { if ( *argt == '$' ) { if ( argt[1] != NULL ) { argt++; for(i=0; token[i]!=NULL; i++) { if ( 0 == strcmp(argt, token[i] )) { argt = value[i]; break; } } if (token[i]==NULL) argt--; } } os=argt; argt=strtok( NULL, ifs ); printf( "%s%c", os, argt==NULL ? '\n' : *ifs); } } }