diff options
author | millaway <millaway> | 2001-10-15 17:28:26 +0000 |
---|---|---|
committer | millaway <millaway> | 2001-10-15 17:28:26 +0000 |
commit | 63a4c4dba7aab03268d9732b4b2f8bc619bff2b0 (patch) | |
tree | 2d24957f38172282d0d049bde51966407a7968e7 | |
parent | e5b199ec2b48bb76c749ca1c5c19ac7f9242020c (diff) | |
download | flex-63a4c4dba7aab03268d9732b4b2f8bc619bff2b0.tar.gz |
Changed option processing to use buf.c instead of mingling with existing action_array code.
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | flexdef.h | 18 | ||||
-rw-r--r-- | main.c | 196 | ||||
-rw-r--r-- | misc.c | 3 | ||||
-rw-r--r-- | options.c | 8 |
5 files changed, 137 insertions, 92 deletions
diff --git a/Makefile.am b/Makefile.am index d9f9883..83484cc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -59,7 +59,8 @@ flex_SOURCES = \ tblcmp.c \ yylex.c \ options.c \ - scanopt.c + scanopt.c \ + buf.c libfl_a_SOURCES = \ libmain.c \ @@ -117,6 +118,7 @@ sym.o: sym.c flexdef.h config.h tblcmp.o: tblcmp.c flexdef.h config.h options.o: options.c options.h scanopt.h flexdef.h config.h scanopt.o: scanopt.c scanopt.h flexdef.h config.h +buf.o: buf.c flexdef.h #The below recipe for making the ChangeLog will only work if you have a copy of the cvs tree handy so let it fail gracefully. @@ -1027,4 +1027,22 @@ extern void stack1 PROTO((int, int, int, int)); extern int yylex PROTO((void)); +/* A growable array. See buf.c. */ +struct Buf { + void * elts; /* elements. */ + int nelts; /* number of elements. */ + size_t elt_size; /* in bytes. */ + int nmax; /* max capacity of elements. */ +}; + +extern void buf_init PROTO((struct Buf* buf, size_t elem_size)); +extern void buf_destroy PROTO((struct Buf* buf)); +extern struct Buf* buf_append PROTO((struct Buf* buf, const void* ptr, int n_elem)); +extern struct Buf* buf_strappend PROTO((struct Buf*, const char* str)); +extern struct Buf* buf_strnappend PROTO((struct Buf*, const char* str, int nchars)); +extern struct Buf* buf_strdefine PROTO((struct Buf* buf, const char* str, const char* def)); + +/* buffer for #define's generated by user-options on cmd line. */ +extern struct Buf userdef_buf; + #endif /* not defined FLEXDEF_H */ @@ -49,7 +49,7 @@ static char flex_version[] = FLEX_VERSION; void flexinit PROTO((int, char**)); void readin PROTO((void)); void set_up_initial_allocations PROTO((void)); - +static char * basename(char* path); /* these globals are all defined and commented in flexdef.h */ @@ -377,6 +377,10 @@ void check_options() if ( did_outfilename ) line_directive_out( stdout, 0 ); + /* Dump the user defined preproc directives. */ + if (userdef_buf.elts) + outn( (char*)(userdef_buf.elts) ); + skelout(); } @@ -656,8 +660,11 @@ char **argv; defs1_offset = prolog_offset = action_offset = action_index = 0; action_array[0] = '\0'; + /* Initialize any buffers. */ + buf_init(&userdef_buf, sizeof(char)); + /* Enable C++ if program name ends with '+'. */ - program_name = argv[0]; + program_name = basename(argv[0]); if ( program_name[0] != '\0' && program_name[strlen( program_name ) - 1] == '+' ) @@ -774,7 +781,7 @@ char **argv; break; case OPT_MAIN: - action_define( "YY_MAIN", 1); + buf_strdefine(&userdef_buf, "YY_MAIN", "1"); break; case OPT_NOLINE: @@ -857,11 +864,11 @@ char **argv; break; case OPT_ALWAYS_INTERACTIVE: - action_define("YY_ALWAYS_INTERACTIVE", 1); + buf_strdefine(&userdef_buf,"YY_ALWAYS_INTERACTIVE", "1"); break; case OPT_NEVER_INTERACTIVE: - action_define( "YY_NEVER_INTERACTIVE", 1 ); + buf_strdefine(&userdef_buf, "YY_NEVER_INTERACTIVE", "1" ); break; case OPT_ARRAY: @@ -885,20 +892,22 @@ char **argv; case OPT_PREPROCDEFINE: { - /* arg is "symbol" or "symbol=definition". - Replace the first '=' with ' '. - I'm not sure that argv[] is writable. So use a copy. */ - char *sym, *p; - sym = (char*)malloc(strlen("#define ")+strlen(arg)+1); - sprintf(sym,"#define %s\n",arg); - for(p=sym; *p != '\0'; ++p) - if (*p == '='){ - *p = ' '; - break; - } - - add_action(sym); - free(sym); + /* arg is "symbol" or "symbol=definition". */ + char *def; + + for(def=arg; *def != '\0' && *def!='='; ++def) + ; + + buf_strappend(&userdef_buf,"#define "); + if (*def=='\0'){ + buf_strappend(&userdef_buf,arg); + buf_strappend(&userdef_buf, " 1\n"); + }else{ + buf_strnappend(&userdef_buf, arg,def-arg); + buf_strappend(&userdef_buf, " "); + buf_strappend(&userdef_buf, def+1); + buf_strappend(&userdef_buf, "\n"); + } } break; @@ -907,7 +916,7 @@ char **argv; break; case OPT_STACK: - action_define( "YY_STACK_USED", 1 ); + buf_strdefine(&userdef_buf,"YY_STACK_USED","1"); break; case OPT_STDINIT: @@ -1235,73 +1244,88 @@ void set_up_initial_allocations() nultrans = (int *) 0; } +static char * basename(path) + char * path; +{ + char * p; + p = path; + for(p=path; *path; path++) + if( *path== '/') + p = path+1; + + return p; +} void usage() { - FILE *f = stdout; - - fprintf( f, -_( "%s [-bcdfhilnpstvwBFILTV78+? -R[b] -C[aefFmr] -ooutput -Pprefix -Sskeleton]\n" ), - program_name ); - fprintf( f, _( "\t[--help --version] [file ...]\n" ) ); - - fprintf( f, _( "\t-b generate backing-up information to %s\n" ), - backing_name ); - fprintf( f, _( "\t-c do-nothing POSIX option\n" ) ); - fprintf( f, _( "\t-d turn on debug mode in generated scanner\n" ) ); - fprintf( f, _( "\t-f generate fast, large scanner\n" ) ); - fprintf( f, _( "\t-h produce this help message\n" ) ); - fprintf( f, _( "\t-i generate case-insensitive scanner\n" ) ); - fprintf( f, _( "\t-l maximal compatibility with original lex\n" ) ); - fprintf( f, _( "\t-n do-nothing POSIX option\n" ) ); - fprintf( f, _( "\t-p generate performance report to stderr\n" ) ); - fprintf( f, - _( "\t-s suppress default rule to ECHO unmatched text\n" ) ); - - if ( ! did_outfilename ) - { - sprintf( outfile_path, outfile_template, - prefix, C_plus_plus ? "cc" : "c" ); - outfilename = outfile_path; - } + FILE *f = stdout; + if ( ! did_outfilename ) + { + sprintf( outfile_path, outfile_template, + prefix, C_plus_plus ? "cc" : "c" ); + outfilename = outfile_path; + } - fprintf( f, - _( "\t-t write generated scanner on stdout instead of %s\n" ), - outfilename ); - - fprintf( f, - _( "\t-v write summary of scanner statistics to stdout\n" ) ); - fprintf( f, _( "\t-w do not generate warnings\n" ) ); - fprintf( f, _( "\t-B generate batch scanner (opposite of -I)\n" ) ); - fprintf( f, - _( "\t-F use alternative fast scanner representation\n" ) ); - fprintf( f, - _( "\t-I generate interactive scanner (opposite of -B)\n" ) ); - fprintf( f, _( "\t-L suppress #line directives in scanner\n" ) ); - fprintf( f, _( "\t-R generate a reentrant C scanner\n" ) ); - fprintf( f, -_( "\t\t-Rb reentrant scanner is to be called by a bison pure parser.\n" ) ); - fprintf( f, _( "\t-T %s should run in trace mode\n" ), program_name ); - fprintf( f, _( "\t-V report %s version\n" ), program_name ); - fprintf( f, _( "\t-7 generate 7-bit scanner\n" ) ); - fprintf( f, _( "\t-8 generate 8-bit scanner\n" ) ); - fprintf( f, _( "\t-+ generate C++ scanner class\n" ) ); - fprintf( f, _( "\t-? produce this help message\n" ) ); - fprintf( f, -_( "\t-C specify degree of table compression (default is -Cem):\n" ) ); - fprintf( f, -_( "\t\t-Ca trade off larger tables for better memory alignment\n" ) ); - fprintf( f, _( "\t\t-Ce construct equivalence classes\n" ) ); - fprintf( f, -_( "\t\t-Cf do not compress scanner tables; use -f representation\n" ) ); - fprintf( f, -_( "\t\t-CF do not compress scanner tables; use -F representation\n" ) ); - fprintf( f, _( "\t\t-Cm construct meta-equivalence classes\n" ) ); - fprintf( f, - _( "\t\t-Cr use read() instead of stdio for scanner input\n" ) ); - fprintf( f, _( "\t-o specify output filename\n" ) ); - fprintf( f, _( "\t-P specify scanner prefix other than \"yy\"\n" ) ); - fprintf( f, _( "\t-S specify skeleton file\n" ) ); - fprintf( f, _( "\t--help produce this help message\n" ) ); - fprintf( f, _( "\t--version report %s version\n" ), program_name ); - } + fprintf(f,_( "%s [OPTIONS...] [file...]\n"), program_name); + fprintf(f, +_( +"Table Compression: (default is -Cem)\n" +" -Ca, --align trade off larger tables for better memory alignment\n" +" -Ce, --ecs construct equivalence classes\n" +" -Cf do not compress tables; use -f representation\n" +" -CF do not compress tables; use -F representation\n" +" -Cm, --meta-ecs construct meta-equivalence classes\n" +" -Cr, --read use read() instead of stdio for scanner input\n" +" -f, --full generate fast, large scanner. Same as -Cfr\n" +" -F, --fast use alternate table representation. Same as -CFr\n" + +"\n" +"Debugging:\n" +" -d, --debug enable debug mode in scanner\n" +" -b, --backup write backing-up information to %s\n" +" -p, --perf-report write performance report to stderr\n" +" -s, --nodefault suppress default rule to ECHO unmatched text\n" +" -T, --trace %s should run in trace mode\n" +" -w, --nowarn do not generate warnings\n" +" -v, --verbose write summary of scanner statistics to stdout\n" + +"\n" +"Files:\n" +" -o, --outfile=FILE specify output filename\n" +" -S, --skel=FILE specify skeleton file\n" +" -t, --stdout write scanner on stdout instead of %s\n" +" --yyclass=NAME name of C++ class\n" + +"\n" +"Scanner behavior:\n" +" -7, --7bit generate 7-bit scanner\n" +" -8, --8bit generate 8-bit scanner\n" +" -B, --batch generate batch scanner (opposite of -I)\n" +" -i, --case-insensitive ignore case in patterns\n" +" -l, --lex-compat maximal compatibility with original lex\n" +" -I, --interactive generate interactive scanner (opposite of -B)\n" +" --yylineno track line count in yylineno\n" + +"\n" +"Generated code:\n" +" -+, --c++ generate C++ scanner class\n" +" -Dmacro[=defn] #define macro defn (default defn is '1')\n" +" -L, --noline suppress #line directives in scanner\n" +" -P, --prefix=STRING use STRING as prefix instead of \"yy\"\n" +" -R, --reentrant generate a reentrant C scanner\n" +" -Rb, --reentrant-bison reentrant scanner for bison pure parser.\n" + +"\n" +"Functions:\n" +" --yywrap call yywrap on EOF\n" + +"\n" +"Miscellaneous:\n" +" -c do-nothing POSIX option\n" +" -n do-nothing POSIX option\n" +" -?\n" +" -h, --help produce this help message\n" +" -V, --version report %s version\n" +), backing_name, program_name, outfile_path, program_name); + +} @@ -34,7 +34,7 @@ #include "flexdef.h" - +/* Append "#define defname value\n" to the running buffer. */ void action_define( defname, value ) char *defname; int value; @@ -53,6 +53,7 @@ int value; } +/* Append "new_text" to the running buffer. */ void add_action( new_text ) char *new_text; { @@ -39,11 +39,11 @@ optspec_t flexopts[] = { {"--main", OPT_MAIN,0}, /* use built-in main() function. */ {"--meta-ecs", OPT_META_ECS,0},/* Construct meta-equivalence classes. */ {"--never-interactive", OPT_NEVER_INTERACTIVE,0}, -{"--no-default", OPT_NODEFAULT,0},/* Suppress default rule to ECHO unmatched text. */ +{"--nodefault", OPT_NODEFAULT,0},/* Suppress default rule to ECHO unmatched text. */ {"-s", OPT_NODEFAULT,0}, -{"--no-line", OPT_NOLINE,0},/* Suppress #line directives in scanner. */ +{"--noline", OPT_NOLINE,0},/* Suppress #line directives in scanner. */ {"-L", OPT_NOLINE,0},/* Suppress #line directives in scanner. */ -{"--no-warn", OPT_NOWARN,0},/* Suppress warning messages. */ +{"--nowarn", OPT_NOWARN,0},/* Suppress warning messages. */ {"-w", OPT_NOWARN,0}, {"--outfile=FILE", OPT_OUTFILE,0},/* Write to FILE (default is lex.yy.c) */ {"-o FILE", OPT_OUTFILE,0}, @@ -52,7 +52,7 @@ optspec_t flexopts[] = { {"--pointer", OPT_POINTER,0}, {"--prefix=PREFIX", OPT_PREFIX,0},/* Use PREFIX (default is yy) */ {"-P PREFIX", OPT_PREFIX,0}, -{"-D", OPT_PREPROCDEFINE,0},/* Define a preprocessor symbol. */ +{"-Dmacro", OPT_PREPROCDEFINE,0},/* Define a preprocessor symbol. */ {"--read", OPT_READ,0},/* Use read(2) instead of stdio. */ {"--reentrant", OPT_REENTRANT,0},/* Generate a reentrant C scanner. */ {"-R[b]", OPT_REENTRANT,0}, |