summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c196
1 files changed, 110 insertions, 86 deletions
diff --git a/main.c b/main.c
index 5b771f0..2aaa419 100644
--- a/main.c
+++ b/main.c
@@ -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);
+
+}