diff options
author | Manoj Srivastava <srivasta@debian.org> | 2016-07-28 16:27:42 -0700 |
---|---|---|
committer | Manoj Srivastava <srivasta@debian.org> | 2016-07-28 16:27:42 -0700 |
commit | 6228bc837a1bfd806c6b6f92fea9f6a42f099e7e (patch) | |
tree | 8bd744e2835403d769bd59e69ffb98dd3698e890 /src/main.c | |
parent | 86ca4f322bbec8f52a76c1bf2a879bf464d9bb65 (diff) | |
parent | 609af5775f7277679dc3bd966b36f04cf7ccf2a8 (diff) |
merge tag v2.6.1
Signed-off-by: Manoj Srivastava <srivasta@debian.org>
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 133 |
1 files changed, 66 insertions, 67 deletions
@@ -36,15 +36,15 @@ #include "version.h" #include "options.h" #include "tables.h" +#include "parse.h" static char flex_version[] = FLEX_VERSION; /* declare functions that have forward references */ -void flexinit PROTO ((int, char **)); -void readin PROTO ((void)); -void set_up_initial_allocations PROTO ((void)); -static char *basename2 PROTO ((char *path, int should_strip_ext)); +void flexinit(int, char **); +void readin(void); +void set_up_initial_allocations(void); /* these globals are all defined and commented in flexdef.h */ @@ -94,7 +94,7 @@ int *accsiz, *dhash, numas; int numsnpairs, jambase, jamstate; int lastccl, *cclmap, *ccllen, *cclng, cclreuse; int current_maxccls, current_max_ccl_tbl_size; -Char *ccltbl; +unsigned char *ccltbl; char nmstr[MAXLINE]; int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs; int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave; @@ -117,19 +117,9 @@ struct yytbl_writer tableswr; */ char *program_name = "flex"; -#ifndef SHORT_FILE_NAMES static const char outfile_template[] = "lex.%s.%s"; static const char backing_name[] = "lex.backup"; static const char tablesfile_template[] = "lex.%s.tables"; -#else -static const char outfile_template[] = "lex%s.%s"; -static const char backing_name[] = "lex.bck"; -static const char tablesfile_template[] = "lex%s.tbl"; -#endif - -#ifdef MS_DOS -extern unsigned _stklen = 16384; -#endif /* From scan.l */ extern FILE* yyout; @@ -144,12 +134,9 @@ const char *escaped_qend = "[[]]M4_YY_NOOP]M4_YY_NOOP]M4_YY_NOOP[[]]"; /* For debugging. The max number of filters to apply to skeleton. */ static int preproc_level = 1000; -int flex_main PROTO ((int argc, char *argv[])); -int main PROTO ((int argc, char *argv[])); +int flex_main (int argc, char *argv[]); -int flex_main (argc, argv) - int argc; - char *argv[]; +int flex_main (int argc, char *argv[]) { int i, exit_status, child_status; @@ -209,9 +196,7 @@ int flex_main (argc, argv) } /* Wrapper around flex_main, so flex_main can be built as a library. */ -int main (argc, argv) - int argc; - char *argv[]; +int main (int argc, char *argv[]) { #if ENABLE_NLS #if HAVE_LOCALE_H @@ -227,7 +212,7 @@ int main (argc, argv) /* check_options - check user-specified options */ -void check_options () +void check_options (void) { int i; const char * m4 = NULL; @@ -363,8 +348,46 @@ void check_options () /* Setup the filter chain. */ output_chain = filter_create_int(NULL, filter_tee_header, headerfilename); - if ( !(m4 = getenv("M4"))) - m4 = M4; + if ( !(m4 = getenv("M4"))) { + char *slash; + m4 = M4; + if ((slash = strrchr(M4, '/')) != NULL) { + m4 = slash+1; + /* break up $PATH */ + const char *path = getenv("PATH"); + if (!path) { + m4 = M4; + } else { + do { + char m4_path[PATH_MAX]; + int length = strlen(path); + struct stat sbuf; + + const char *endOfDir = strchr(path, ':'); + if (!endOfDir) + endOfDir = path+length; + + if ((endOfDir-path+2) >= sizeof(m4_path)) { + path = endOfDir+1; + continue; + } + + strncpy(m4_path, path, sizeof(m4_path)); + m4_path[endOfDir-path] = '/'; + m4_path[endOfDir-path+1] = '\0'; + strncat(m4_path, m4, sizeof(m4_path)); + if (stat(m4_path, &sbuf) == 0 && + (S_ISREG(sbuf.st_mode)) && sbuf.st_mode & S_IXUSR) { + m4 = strdup(m4_path); + break; + } + path = endOfDir+1; + } while (path[0]); + if (!path[0]) + m4 = M4; + } + } + } filter_create_ext(output_chain, m4, "-P", 0); filter_create_int(output_chain, filter_fix_linedirs, NULL); @@ -396,20 +419,19 @@ void check_options () if (!tablesfilename) { nbytes = strlen (prefix) + strlen (tablesfile_template) + 2; - tablesfilename = pname = (char *) calloc (nbytes, 1); + tablesfilename = pname = calloc(nbytes, 1); snprintf (pname, nbytes, tablesfile_template, prefix); } if ((tablesout = fopen (tablesfilename, "w")) == NULL) lerr (_("could not create %s"), tablesfilename); - if (pname) - free (pname); + free(pname); tablesfilename = 0; yytbl_writer_init (&tableswr, tablesout); nbytes = strlen (prefix) + strlen ("tables") + 2; - tablesname = (char *) calloc (nbytes, 1); + tablesname = calloc(nbytes, 1); snprintf (tablesname, nbytes, "%stables", prefix); yytbl_hdr_init (&hdr, flex_version, tablesname); @@ -452,7 +474,8 @@ void check_options () char *str, *fmt = "#define %s %d\n"; size_t strsz; - str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(scname[i]) + (int)(1 + log10(i)) + 2); + strsz = strlen(fmt) + strlen(scname[i]) + (int)(1 + log10(i)) + 2; + str = malloc(strsz); if (!str) flexfatal(_("allocation of macro definition failed")); snprintf(str, strsz, fmt, scname[i], i - 1); @@ -474,7 +497,8 @@ void check_options () m4defs_buf.nelts = 0; /* memory leak here. */ /* Place a bogus line directive, it will be fixed in the filter. */ - outn("#line 0 \"M4_YY_OUTFILE_NAME\"\n"); + if (gen_line_dirs) + outn("#line 0 \"M4_YY_OUTFILE_NAME\"\n"); /* Dump the user defined preproc directives. */ if (userdef_buf.elts) @@ -490,9 +514,7 @@ void check_options () * This routine does not return. */ -void flexend (exit_status) - int exit_status; - +void flexend (int exit_status) { static int called_before = -1; /* prevent infinite recursion. */ int tblsiz; @@ -539,7 +561,6 @@ void flexend (exit_status) "EOB_ACT_END_OF_FILE", "EOB_ACT_LAST_MATCH", "FLEX_SCANNER", - "FLEX_STD", "REJECT", "YYFARGS0", "YYFARGS1", @@ -926,9 +947,7 @@ void flexend (exit_status) /* flexinit - initialize flex */ -void flexinit (argc, argv) - int argc; - char **argv; +void flexinit (int argc, char **argv) { int i, sawcmpflag, rv, optind; char *arg; @@ -982,9 +1001,9 @@ void flexinit (argc, argv) flex_init_regex(); /* Enable C++ if program name ends with '+'. */ - program_name = basename2 (argv[0], 0); + program_name = basename (argv[0]); - if (program_name[0] != '\0' && + if (program_name != NULL && program_name[strlen (program_name) - 1] == '+') C_plus_plus = true; @@ -1456,13 +1475,13 @@ void flexinit (argc, argv) /* readin - read in the rules section of the input file(s) */ -void readin () +void readin (void) { static char yy_stdinit[] = "FILE *yyin = stdin, *yyout = stdout;"; static char yy_nostdinit[] = - "FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;"; + "FILE *yyin = NULL, *yyout = NULL;"; - line_directive_out ((FILE *) 0, 1); + line_directive_out(NULL, 1); if (yyparse ()) { pinpoint_message (_("fatal parse error")); @@ -1715,7 +1734,7 @@ void readin () /* set_up_initial_allocations - allocate memory for internal tables */ -void set_up_initial_allocations () +void set_up_initial_allocations (void) { maximum_mns = (long_align ? MAXIMUM_MNS_LONG : MAXIMUM_MNS); current_mns = INITIAL_MNS; @@ -1769,31 +1788,11 @@ void set_up_initial_allocations () dss = allocate_int_ptr_array (current_max_dfas); dfaacc = allocate_dfaacc_union (current_max_dfas); - nultrans = (int *) 0; + nultrans = NULL; } -/* extracts basename from path, optionally stripping the extension "\.*" - * (same concept as /bin/sh `basename`, but different handling of extension). */ -static char *basename2 (path, strip_ext) - char *path; - int strip_ext; /* boolean */ -{ - char *b, *e = 0; - - b = path; - for (b = path; *path; path++) - if (*path == '/') - b = path + 1; - else if (*path == '.') - e = path; - - if (strip_ext && e && e > b) - *e = '\0'; - return b; -} - -void usage () +void usage (void) { FILE *f = stdout; |