summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManoj Srivastava <srivasta@debian.org>2018-02-12 11:03:58 -0800
committerManoj Srivastava <srivasta@debian.org>2018-02-12 11:03:58 -0800
commit5f64e38979e363319990d837d0b4b5df82b71cca (patch)
treee9e60b658648d29136146d6021c3934d376a374c /src
parent8852aa3f8eefeee4da27de0553b1653253b15619 (diff)
parent04687c439c4e99abd0bc29506ceaa293a6330d9c (diff)
Merge branch 'upstream'
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/ccl.c7
-rw-r--r--src/filter.c39
-rw-r--r--src/flex.skl14
-rw-r--r--src/flexdef.h13
-rw-r--r--src/gen.c42
-rw-r--r--src/gettext.h2
-rw-r--r--src/libfl.pc.in8
-rw-r--r--src/main.c28
-rw-r--r--src/misc.c49
-rwxr-xr-xsrc/mkskel.sh2
-rw-r--r--src/nfa.c2
-rw-r--r--src/options.c6
-rw-r--r--src/options.h3
-rw-r--r--src/regex.c4
-rw-r--r--src/scan.l9
-rw-r--r--src/scanopt.c105
-rw-r--r--src/tables.c8
-rw-r--r--src/tables_shared.h6
19 files changed, 182 insertions, 169 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index e379692..6e71893 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,7 @@
AM_YFLAGS = -d
AM_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\"
LIBS = @LIBS@
+pkgconfigdir = @pkgconfigdir@
m4 = @M4@
@@ -11,6 +12,7 @@ endif
if ENABLE_LIBFL
lib_LTLIBRARIES = libfl.la
+pkgconfig_DATA = libfl.pc
endif
libfl_la_SOURCES = \
libmain.c \
@@ -79,6 +81,8 @@ COMMON_SOURCES = \
LDADD = $(LIBOBJS) @LIBINTL@
+$(LIBOBJS): $(LIBOBJDIR)$(am__dirstamp)
+
include_HEADERS = \
FlexLexer.h
diff --git a/src/ccl.c b/src/ccl.c
index ff9a213..5c5af13 100644
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -73,6 +73,13 @@ void ccladd (int cclp, int ch)
newpos = ind + len;
+ /* For a non-last cclp, expanding the set will overflow and overwrite a
+ * char in the next cclp.
+ * FIXME: Need another allocation scheme for ccl's. */
+ if (cclp != lastccl) {
+ flexfatal(_("internal error: trying to add a char to a non-last ccl.\n"));
+ }
+
if (newpos >= current_max_ccl_tbl_size) {
current_max_ccl_tbl_size += MAX_CCL_TBL_SIZE_INCREMENT;
diff --git a/src/filter.c b/src/filter.c
index 71f3635..a7e69ec 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -47,10 +47,9 @@ struct filter *filter_create_ext (struct filter *chain, const char *cmd,
va_list ap;
/* allocate and initialize new filter */
- f = malloc(sizeof(struct filter));
+ f = calloc(sizeof(struct filter), 1);
if (!f)
- flexerror(_("malloc failed (f) in filter_create_ext"));
- memset (f, 0, sizeof (*f));
+ flexerror(_("calloc failed (f) in filter_create_ext"));
f->filter_func = NULL;
f->extra = NULL;
f->next = NULL;
@@ -100,10 +99,9 @@ struct filter *filter_create_int (struct filter *chain,
struct filter *f;
/* allocate and initialize new filter */
- f = malloc(sizeof(struct filter));
+ f = calloc(sizeof(struct filter), 1);
if (!f)
- flexerror(_("malloc failed in filter_create_int"));
- memset (f, 0, sizeof (*f));
+ flexerror(_("calloc failed in filter_create_int"));
f->next = NULL;
f->argc = 0;
f->argv = NULL;
@@ -230,8 +228,7 @@ int filter_tee_header (struct filter *chain)
* header file at the same time.
*/
- const int readsz = 512;
- char *buf;
+ char buf[512];
int to_cfd = -1;
FILE *to_c = NULL, *to_h = NULL;
bool write_header;
@@ -283,10 +280,7 @@ int filter_tee_header (struct filter *chain)
fprintf (to_c, "m4_define( [[M4_YY_OUTFILE_NAME]],[[%s]])m4_dnl\n",
outfilename ? outfilename : "<stdout>");
- buf = malloc((size_t) readsz);
- if (!buf)
- flexerror(_("malloc failed in filter_tee_header"));
- while (fgets (buf, readsz, stdin)) {
+ while (fgets (buf, sizeof buf, stdin)) {
fputs (buf, to_c);
if (write_header)
fputs (buf, to_h);
@@ -328,6 +322,13 @@ int filter_tee_header (struct filter *chain)
return 0;
}
+static bool is_blank_line (const char *str)
+{
+ while (isspace(*str))
+ str++;
+ return (*str == '\0');
+}
+
/** Adjust the line numbers in the #line directives of the generated scanner.
* After the m4 expansion, the line numbers are incorrect since the m4 macros
* can add or remove lines. This only adjusts line numbers for generated code,
@@ -336,8 +337,8 @@ int filter_tee_header (struct filter *chain)
*/
int filter_fix_linedirs (struct filter *chain)
{
- char *buf;
- const size_t readsz = 512;
+ char buf[512];
+ const size_t readsz = sizeof buf;
int lineno = 1;
bool in_gen = true; /* in generated code */
bool last_was_blank = false;
@@ -345,10 +346,6 @@ int filter_fix_linedirs (struct filter *chain)
if (!chain)
return 0;
- buf = malloc(readsz);
- if (!buf)
- flexerror(_("malloc failed in filter_fix_linedirs"));
-
while (fgets (buf, (int) readsz, stdin)) {
regmatch_t m[10];
@@ -391,7 +388,7 @@ int filter_fix_linedirs (struct filter *chain)
/* Adjust the line directives. */
in_gen = true;
snprintf (buf, readsz, "#line %d \"%s\"\n",
- lineno, filename);
+ lineno + 1, filename);
}
else {
/* it's a #line directive for code we didn't write */
@@ -403,9 +400,7 @@ int filter_fix_linedirs (struct filter *chain)
}
/* squeeze blank lines from generated code */
- else if (in_gen
- && regexec (&regex_blank_line, buf, 0, NULL,
- 0) == 0) {
+ else if (in_gen && is_blank_line(buf)) {
if (last_was_blank)
continue;
else
diff --git a/src/flex.skl b/src/flex.skl
index 786c977..f2da3a3 100644
--- a/src/flex.skl
+++ b/src/flex.skl
@@ -15,7 +15,7 @@
%# The quoting is "[[" and "]]" so we don't interfere with
%# user code.
%#
-%# All generate macros for the m4 stage contain the text "m4" or "M4"
+%# All generated macros for the m4 stage contain the text "m4" or "M4"
%# in them. This is to distinguish them from CPP macros.
%# The exception to this rule is YY_G, which is an m4 macro,
%# but it needs to be remain short because it is used everywhere.
@@ -218,6 +218,14 @@ m4_ifdef( [[M4_YY_TABLES_EXTERNAL]],
/* begin standard C headers. */
%if-c-only
+m4_ifdef( [[M4_YY_ALWAYS_INTERACTIVE]], ,
+[[m4_ifdef( [[M4_YY_NEVER_INTERACTIVE]], ,
+[[#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE 1 /* for fileno() */
+#ifndef _POSIX_SOURCE
+#define _POSIX_SOURCE 1
+#endif
+#endif]])]])
#include <stdio.h>
#include <string.h>
#include <errno.h>
@@ -3292,9 +3300,7 @@ static int yytbl_data_load YYFARGS2(struct yytbl_dmap *, dmap, struct yytbl_read
/* Now eat padding. */
{
- int pad;
- pad = yypad64(rd->bread);
- while(--pad >= 0){
+ while (rd->bread % (8 * sizeof(flex_uint8_t)) > 0) {
flex_int8_t t8;
if(yytbl_read8(&t8,rd) != 0)
return -1;
diff --git a/src/flexdef.h b/src/flexdef.h
index 9dac654..a48c64d 100644
--- a/src/flexdef.h
+++ b/src/flexdef.h
@@ -44,7 +44,6 @@
#include <stdarg.h>
#include <setjmp.h>
#include <ctype.h>
-#include <libgen.h> /* for XPG version of basename(3) */
#include <string.h>
#include <math.h>
@@ -77,8 +76,10 @@
#include <strings.h>
#include "flexint.h"
-/* We use gettext. So, when we write strings which should be translated, we mark them with _() */
-#ifdef ENABLE_NLS
+/* We use gettext. So, when we write strings which should be translated, we
+ * mark them with _()
+ */
+#if defined(ENABLE_NLS) && ENABLE_NLS
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif /* HAVE_LOCALE_H */
@@ -631,10 +632,6 @@ extern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
extern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
extern int num_backing_up, bol_needed;
-#ifndef HAVE_REALLOCARRAY
-void *reallocarray(void *, size_t, size_t);
-#endif
-
void *allocate_array(int, size_t);
void *reallocate_array(void *, int, size_t);
@@ -1131,7 +1128,7 @@ extern int filter_fix_linedirs(struct filter *chain);
* From "regex.c"
*/
-extern regex_t regex_linedir, regex_blank_line;
+extern regex_t regex_linedir;
bool flex_init_regex(void);
void flex_regcomp(regex_t *preg, const char *regex, int cflags);
char *regmatch_dup (regmatch_t * m, const char *src);
diff --git a/src/gen.c b/src/gen.c
index 590e5d8..c959f75 100644
--- a/src/gen.c
+++ b/src/gen.c
@@ -464,14 +464,14 @@ static struct yytbl_data *mkecstbl (void)
void genecs (void)
{
- int i, j;
+ int ch, row;
int numrows;
out_str_dec (get_yy_char_decl (), "yy_ec", csize);
- for (i = 1; i < csize; ++i) {
- ecgroup[i] = ABS (ecgroup[i]);
- mkdata (ecgroup[i]);
+ for (ch = 1; ch < csize; ++ch) {
+ ecgroup[ch] = ABS (ecgroup[ch]);
+ mkdata (ecgroup[ch]);
}
dataend ();
@@ -479,12 +479,13 @@ void genecs (void)
if (trace) {
fputs (_("\n\nEquivalence Classes:\n\n"), stderr);
+ /* Print in 8 columns */
numrows = csize / 8;
- for (j = 0; j < numrows; ++j) {
- for (i = j; i < csize; i = i + numrows) {
+ for (row = 0; row < numrows; ++row) {
+ for (ch = row; ch < csize; ch += numrows) {
fprintf (stderr, "%4s = %-2d",
- readable_form (i), ecgroup[i]);
+ readable_form (ch), ecgroup[ch]);
putc (' ', stderr);
}
@@ -1234,9 +1235,9 @@ void gentabs (void)
yytbl_data_compress (yyacc_tbl);
if (yytbl_data_fwrite (&tableswr, yyacc_tbl) < 0)
flexerror (_("Could not write yyacc_tbl"));
- yytbl_data_destroy (yyacc_tbl);
- yyacc_tbl = NULL;
}
+ yytbl_data_destroy (yyacc_tbl);
+ yyacc_tbl = NULL;
/* End generating yy_accept */
if (useecs) {
@@ -1289,11 +1290,10 @@ void gentabs (void)
if (tablesext) {
yytbl_data_compress (yymeta_tbl);
if (yytbl_data_fwrite (&tableswr, yymeta_tbl) < 0)
- flexerror (_
- ("Could not write yymeta_tbl"));
- yytbl_data_destroy (yymeta_tbl);
- yymeta_tbl = NULL;
+ flexerror (_("Could not write yymeta_tbl"));
}
+ yytbl_data_destroy (yymeta_tbl);
+ yymeta_tbl = NULL;
/* End generating yy_meta */
}
@@ -1350,9 +1350,9 @@ void gentabs (void)
yytbl_data_compress (yybase_tbl);
if (yytbl_data_fwrite (&tableswr, yybase_tbl) < 0)
flexerror (_("Could not write yybase_tbl"));
- yytbl_data_destroy (yybase_tbl);
- yybase_tbl = NULL;
}
+ yytbl_data_destroy (yybase_tbl);
+ yybase_tbl = NULL;
/* End generating yy_base */
@@ -1382,9 +1382,9 @@ void gentabs (void)
yytbl_data_compress (yydef_tbl);
if (yytbl_data_fwrite (&tableswr, yydef_tbl) < 0)
flexerror (_("Could not write yydef_tbl"));
- yytbl_data_destroy (yydef_tbl);
- yydef_tbl = NULL;
}
+ yytbl_data_destroy (yydef_tbl);
+ yydef_tbl = NULL;
/* End generating yy_def */
@@ -1420,9 +1420,9 @@ void gentabs (void)
yytbl_data_compress (yynxt_tbl);
if (yytbl_data_fwrite (&tableswr, yynxt_tbl) < 0)
flexerror (_("Could not write yynxt_tbl"));
- yytbl_data_destroy (yynxt_tbl);
- yynxt_tbl = NULL;
}
+ yytbl_data_destroy (yynxt_tbl);
+ yynxt_tbl = NULL;
/* End generating yy_nxt */
/* Begin generating yy_chk */
@@ -1454,9 +1454,9 @@ void gentabs (void)
yytbl_data_compress (yychk_tbl);
if (yytbl_data_fwrite (&tableswr, yychk_tbl) < 0)
flexerror (_("Could not write yychk_tbl"));
- yytbl_data_destroy (yychk_tbl);
- yychk_tbl = NULL;
}
+ yytbl_data_destroy (yychk_tbl);
+ yychk_tbl = NULL;
/* End generating yy_chk */
free(acc_array);
diff --git a/src/gettext.h b/src/gettext.h
index ea67f30..3f62961 100644
--- a/src/gettext.h
+++ b/src/gettext.h
@@ -20,7 +20,7 @@
#define _LIBGETTEXT_H 1
/* NLS can be disabled through the configure --disable-nls option. */
-#if ENABLE_NLS
+#ifdef ENABLE_NLS
/* Get declarations of GNU message catalog functions. */
# include <libintl.h>
diff --git a/src/libfl.pc.in b/src/libfl.pc.in
new file mode 100644
index 0000000..8d4240c
--- /dev/null
+++ b/src/libfl.pc.in
@@ -0,0 +1,8 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+
+Name: libfl
+Description: Flex (the fast lexical analyzer) support library
+Version: @PACKAGE_VERSION@
+Libs: -L${libdir} -lfl
diff --git a/src/main.c b/src/main.c
index e5eac44..a4047d7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -117,7 +117,7 @@ struct yytbl_writer tableswr;
char *program_name = "flex";
static const char outfile_template[] = "lex.%s.%s";
-static const char backing_name[] = "lex.backup";
+static const char *backing_name = "lex.backup";
static const char tablesfile_template[] = "lex.%s.tables";
/* From scan.l */
@@ -197,7 +197,7 @@ int flex_main (int argc, char *argv[])
/* Wrapper around flex_main, so flex_main can be built as a library. */
int main (int argc, char *argv[])
{
-#if ENABLE_NLS
+#if defined(ENABLE_NLS) && ENABLE_NLS
#if HAVE_LOCALE_H
setlocale (LC_MESSAGES, "");
setlocale (LC_CTYPE, "");
@@ -648,6 +648,7 @@ void flexend (int exit_status)
"yyget_extra",
"yyget_in",
"yyget_leng",
+ "yyget_column",
"yyget_lineno",
"yyget_lloc",
"yyget_lval",
@@ -670,6 +671,7 @@ void flexend (int exit_status)
"yyset_debug",
"yyset_extra",
"yyset_in",
+ "yyset_column",
"yyset_lineno",
"yyset_lloc",
"yyset_lval",
@@ -994,7 +996,7 @@ void flexinit (int argc, char **argv)
flex_init_regex();
/* Enable C++ if program name ends with '+'. */
- program_name = basename (argv[0]);
+ program_name = argv[0];
if (program_name != NULL &&
program_name[strlen (program_name) - 1] == '+')
@@ -1033,6 +1035,11 @@ void flexinit (int argc, char **argv)
backing_up_report = true;
break;
+ case OPT_BACKUP_FILE:
+ backing_up_report = true;
+ backing_name = arg;
+ break;
+
case OPT_DONOTHING:
break;
@@ -1201,7 +1208,7 @@ void flexinit (int argc, char **argv)
break;
case OPT_VERSION:
- printf (_("%s %s\n"), program_name, flex_version);
+ printf ("%s %s\n", (C_plus_plus ? "flex++" : "flex"), flex_version);
FLEX_EXIT (0);
case OPT_WARN:
@@ -1394,6 +1401,14 @@ void flexinit (int argc, char **argv)
//buf_strdefine (&userdef_buf, "YY_NO_SET_LINENO", "1");
buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LINENO",0);
break;
+ case OPT_NO_YYGET_COLUMN:
+ //buf_strdefine (&userdef_buf, "YY_NO_GET_COLUMN", "1");
+ buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_COLUMN",0);
+ break;
+ case OPT_NO_YYSET_COLUMN:
+ //buf_strdefine (&userdef_buf, "YY_NO_SET_COLUMN", "1");
+ buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_COLUMN",0);
+ break;
case OPT_NO_YYGET_IN:
//buf_strdefine (&userdef_buf, "YY_NO_GET_IN", "1");
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_IN",0);
@@ -1817,7 +1832,8 @@ void usage (void)
" -t, --stdout write scanner on stdout instead of %s\n"
" --yyclass=NAME name of C++ class\n"
" --header-file=FILE create a C header file in addition to the scanner\n"
- " --tables-file[=FILE] write tables to FILE\n" "\n"
+ " --tables-file[=FILE] write tables to FILE\n"
+ " --backup-file=FILE write backing-up information to FILE\n" "\n"
"Scanner behavior:\n"
" -7, --7bit generate 7-bit scanner\n"
" -8, --8bit generate 8-bit scanner\n"
@@ -1844,6 +1860,6 @@ void usage (void)
" -?\n"
" -h, --help produce this help message\n"
" -V, --version report %s version\n"),
- backing_name, program_name, outfile_path, program_name);
+ backing_name, "flex", outfile_path, "flex");
}
diff --git a/src/misc.c b/src/misc.c
index ef27833..745e6a8 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -116,15 +116,14 @@ void add_action (const char *new_text)
int len = (int) strlen (new_text);
while (len + action_index >= action_size - 10 /* slop */ ) {
- int new_size = action_size * 2;
- if (new_size <= 0)
+ if (action_size > INT_MAX / 2)
/* Increase just a little, to try to avoid overflow
* on 16-bit machines.
*/
action_size += action_size / 8;
else
- action_size = new_size;
+ action_size = action_size * 2;
action_array =
reallocate_character_array (action_array,
@@ -141,20 +140,24 @@ void add_action (const char *new_text)
void *allocate_array (int size, size_t element_size)
{
- void *mem;
-#if HAVE_REALLOCARRAY
- /* reallocarray has built-in overflow detection */
- mem = reallocarray(NULL, (size_t) size, element_size);
+ void *new_array;
+#if HAVE_REALLOCARR
+ new_array = NULL;
+ if (reallocarr(&new_array, (size_t) size, element_size))
+ flexfatal (_("memory allocation failed in allocate_array()"));
#else
+# if HAVE_REALLOCARRAY
+ new_array = reallocarray(NULL, (size_t) size, element_size);
+# else
+ /* Do manual overflow detection */
size_t num_bytes = (size_t) size * element_size;
- mem = (size && SIZE_MAX / (size_t) size < element_size) ? NULL :
+ new_array = (size && SIZE_MAX / (size_t) size < element_size) ? NULL :
malloc(num_bytes);
+# endif
+ if (!new_array)
+ flexfatal (_("memory allocation failed in allocate_array()"));
#endif
- if (!mem)
- flexfatal (_
- ("memory allocation failed in allocate_array()"));
-
- return mem;
+ return new_array;
}
@@ -659,17 +662,22 @@ char *readable_form (int c)
void *reallocate_array (void *array, int size, size_t element_size)
{
void *new_array;
-#if HAVE_REALLOCARRAY
- /* reallocarray has built-in overflow detection */
- new_array = reallocarray(array, (size_t) size, element_size);
+#if HAVE_REALLOCARR
+ new_array = array;
+ if (reallocarr(&new_array, (size_t) size, element_size))
+ flexfatal (_("attempt to increase array size failed"));
#else
+# if HAVE_REALLOCARRAY
+ new_array = reallocarray(array, (size_t) size, element_size);
+# else
+ /* Do manual overflow detection */
size_t num_bytes = (size_t) size * element_size;
new_array = (size && SIZE_MAX / (size_t) size < element_size) ? NULL :
realloc(array, num_bytes);
-#endif
+# endif
if (!new_array)
flexfatal (_("attempt to increase array size failed"));
-
+#endif
return new_array;
}
@@ -720,7 +728,10 @@ void skelout (void)
*/
#define cmd_match(s) (strncmp(buf,(s),strlen(s))==0)
- if (buf[1] == '%') {
+ if (buf[1] == '#') {
+ /* %# indicates comment line to be ignored */
+ }
+ else if (buf[1] == '%') {
/* %% is a break point for skelout() */
return;
}
diff --git a/src/mkskel.sh b/src/mkskel.sh
index 1aa59e1..2d6ae9f 100755
--- a/src/mkskel.sh
+++ b/src/mkskel.sh
@@ -48,7 +48,7 @@ sed '/^%#/d
s/m4_/m4preproc_/g
s/a4_/4_/g
s/[\\"]/\\&/g
-s/.*/ "&",/'
+s/[^\r]*/ "&",/'
echo ' 0
};'
diff --git a/src/nfa.c b/src/nfa.c
index 9143cf6..3d9bf24 100644
--- a/src/nfa.c
+++ b/src/nfa.c
@@ -499,6 +499,8 @@ int mkor (int first, int second)
}
}
+ firstst[first] = MIN(firstst[first], firstst[second]);
+
finalst[first] = orend;
return first;
}
diff --git a/src/options.c b/src/options.c
index 366bc2e..e98159c 100644
--- a/src/options.c
+++ b/src/options.c
@@ -62,6 +62,8 @@ optspec_t flexopts[] = {
,
{"--backup", OPT_BACKUP, 0}
, /* Generate backing-up information to lex.backup. */
+ {"--backup-file=FILE", OPT_BACKUP_FILE, 0}
+ , /* Generate backing-up information to FILE. */
{"-B", OPT_BATCH, 0}
,
{"--batch", OPT_BATCH, 0}
@@ -255,6 +257,10 @@ optspec_t flexopts[] = {
,
{"--noyyset_lineno", OPT_NO_YYSET_LINENO, 0}
,
+ {"--noyyget_column", OPT_NO_YYGET_COLUMN, 0}
+ ,
+ {"--noyyset_column", OPT_NO_YYSET_COLUMN, 0}
+ ,
{"--noyyget_in", OPT_NO_YYGET_IN, 0}
,
{"--noyyset_in", OPT_NO_YYSET_IN, 0}
diff --git a/src/options.h b/src/options.h
index 5b51c23..acee275 100644
--- a/src/options.h
+++ b/src/options.h
@@ -46,6 +46,7 @@ enum flexopt_flag_t {
OPT_ALWAYS_INTERACTIVE,
OPT_ARRAY,
OPT_BACKUP,
+ OPT_BACKUP_FILE,
OPT_BATCH,
OPT_BISON_BRIDGE,
OPT_BISON_BRIDGE_LOCATIONS,
@@ -83,6 +84,7 @@ enum flexopt_flag_t {
OPT_NO_YYGET_IN,
OPT_NO_YYGET_LENG,
OPT_NO_YYGET_LINENO,
+ OPT_NO_YYGET_COLUMN,
OPT_NO_YYGET_LLOC,
OPT_NO_YYGET_LVAL,
OPT_NO_YYGET_OUT,
@@ -92,6 +94,7 @@ enum flexopt_flag_t {
OPT_NO_YYSET_EXTRA,
OPT_NO_YYSET_IN,
OPT_NO_YYSET_LINENO,
+ OPT_NO_YYSET_COLUMN,
OPT_NO_YYSET_LLOC,
OPT_NO_YYSET_LVAL,
OPT_NO_YYSET_OUT,
diff --git a/src/regex.c b/src/regex.c
index 38e658b..f4c4163 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -25,10 +25,8 @@
static const char* REGEXP_LINEDIR = "^#line ([[:digit:]]+) \"(.*)\"";
-static const char* REGEXP_BLANK_LINE = "^[[:space:]]*$";
regex_t regex_linedir; /**< matches line directives */
-regex_t regex_blank_line; /**< matches blank lines */
/** Initialize the regular expressions.
@@ -37,8 +35,6 @@ regex_t regex_blank_line; /**< matches blank lines */
bool flex_init_regex(void)
{
flex_regcomp(&regex_linedir, REGEXP_LINEDIR, REG_EXTENDED);
- flex_regcomp(&regex_blank_line, REGEXP_BLANK_LINE, REG_EXTENDED);
-
return true;
}
diff --git a/src/scan.l b/src/scan.l
index 66db864..4f497ac 100644
--- a/src/scan.l
+++ b/src/scan.l
@@ -1,5 +1,11 @@
/* scan.l - scanner for flex input -*-C-*- */
+%top{
+/* flexdef.h includes config.h, which may contain macros that alter the API */
+/* of libc functions. Must include first before any libc header. */
+#include "flexdef.h"
+}
+
%{
/* Copyright (c) 1990 The Regents of the University of California. */
/* All rights reserved. */
@@ -32,7 +38,6 @@
/* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
/* PURPOSE. */
-#include "flexdef.h"
#include "parse.h"
extern bool tablesverify, tablesext;
extern int trlcontxt; /* Set in parse.y for each rule. */
@@ -433,6 +438,8 @@ M4QEND "]""]"
yyset_extra ACTION_M4_IFDEF("M4""_YY_NO_SET_EXTRA", ! option_sense);
yyget_leng ACTION_M4_IFDEF("M4""_YY_NO_GET_LENG", ! option_sense);
yyget_text ACTION_M4_IFDEF("M4""_YY_NO_GET_TEXT", ! option_sense);
+ yyget_column ACTION_M4_IFDEF("M4""_YY_NO_GET_COLUMN", ! option_sense);
+ yyset_column ACTION_M4_IFDEF("M4""_YY_NO_SET_COLUMN", ! option_sense);
yyget_lineno ACTION_M4_IFDEF("M4""_YY_NO_GET_LINENO", ! option_sense);
yyset_lineno ACTION_M4_IFDEF("M4""_YY_NO_SET_LINENO", ! option_sense);
yyget_in ACTION_M4_IFDEF("M4""_YY_NO_GET_IN", ! option_sense);
diff --git a/src/scanopt.c b/src/scanopt.c
index a475b6f..7a91178 100644
--- a/src/scanopt.c
+++ b/src/scanopt.c
@@ -68,7 +68,7 @@ static int PRINTLEN(struct _scanopt_t *, int);
static int RVAL(struct _scanopt_t *, int);
static int FLAGS(struct _scanopt_t *, int);
static const char *DESC(struct _scanopt_t *, int);
-static int scanopt_err(struct _scanopt_t *, int, int);
+static void scanopt_err(struct _scanopt_t *, int, int);
static int matchlongopt(char *, char **, int *, char **, int *);
static int find_opt(struct _scanopt_t *, int, char *, int, int *, int *opt_offset);
@@ -229,34 +229,23 @@ typedef struct usg_elem usg_elem;
int scanopt_usage (scanopt_t *scanner, FILE *fp, const char *usage)
{
struct _scanopt_t *s;
- int i, columns, indent = 2;
+ int i, columns;
+ const int indent = 2;
usg_elem *byr_val = NULL; /* option indices sorted by r_val */
usg_elem *store; /* array of preallocated elements. */
int store_idx = 0;
usg_elem *ue;
- int maxlen[2];
- int desccol = 0;
+ int opt_col_width = 0, desc_col_width = 0;
+ int desccol;
int print_run = 0;
- maxlen[0] = 0;
- maxlen[1] = 0;
-
s = (struct _scanopt_t *) scanner;
if (usage) {
fprintf (fp, "%s\n", usage);
}
else {
- /* Find the basename of argv[0] */
- const char *p;
-
- p = s->argv[0] + strlen (s->argv[0]);
- while (p != s->argv[0] && *p != '/')
- --p;
- if (*p == '/')
- p++;
-
- fprintf (fp, _("Usage: %s [OPTIONS]...\n"), p);
+ fprintf (fp, _("Usage: %s [OPTIONS]...\n"), s->argv[0]);
}
fprintf (fp, "\n");
@@ -324,65 +313,36 @@ int scanopt_usage (scanopt_t *scanner, FILE *fp, const char *usage)
/* first pass calculate how much room we need. */
for (ue = byr_val; ue; ue = ue->next) {
usg_elem *ap;
- int len = 0;
- int nshort = 0, nlong = 0;
-
+ int len;
-#define CALC_LEN(i) do {\
- if(FLAGS(s,i) & IS_LONG) \
- len += (nlong++||nshort) ? 2+PRINTLEN(s,i) : PRINTLEN(s,i);\
- else\
- len += (nshort++||nlong)? 2+PRINTLEN(s,i) : PRINTLEN(s,i);\
- }while(0)
+ len = PRINTLEN(s, ue->idx);
- if (!(FLAGS (s, ue->idx) & IS_LONG))
- CALC_LEN (ue->idx);
-
- /* do short aliases first. */
for (ap = ue->alias; ap; ap = ap->next) {
- if (FLAGS (s, ap->idx) & IS_LONG)
- continue;
- CALC_LEN (ap->idx);
+ len += PRINTLEN(s, ap->idx) + (int) strlen(", ");
}
- if (FLAGS (s, ue->idx) & IS_LONG)
- CALC_LEN (ue->idx);
-
- /* repeat the above loop, this time for long aliases. */
- for (ap = ue->alias; ap; ap = ap->next) {
- if (!(FLAGS (s, ap->idx) & IS_LONG))
- continue;
- CALC_LEN (ap->idx);
- }
-
- if (len > maxlen[0])
- maxlen[0] = len;
+ if (len > opt_col_width)
+ opt_col_width = len;
/* It's much easier to calculate length for description column! */
len = (int) strlen (DESC (s, ue->idx));
- if (len > maxlen[1])
- maxlen[1] = len;
+ if (len > desc_col_width)
+ desc_col_width = len;
}
/* Determine how much room we have, and how much we will allocate to each col.
* Do not address pathological cases. Output will just be ugly. */
columns = get_cols () - 1;
- if (maxlen[0] + maxlen[1] + indent * 2 > columns) {
- /* col 0 gets whatever it wants. we'll wrap the desc col. */
- maxlen[1] = columns - (maxlen[0] + indent * 2);
- if (maxlen[1] < 14) /* 14 is arbitrary lower limit on desc width. */
- maxlen[1] = INT_MAX;
+ if (opt_col_width + desc_col_width + indent * 2 > columns) {
+ /* opt col gets whatever it wants. we'll wrap the desc col. */
+ desc_col_width = columns - (opt_col_width + indent * 2);
+ if (desc_col_width < 14) /* 14 is arbitrary lower limit on desc width. */
+ desc_col_width = INT_MAX;
}
- desccol = maxlen[0] + indent * 2;
-
-#define PRINT_SPACES(fp,n)\
- do{\
- int _n;\
- _n=(n);\
- while(_n-- > 0)\
- fputc(' ',(fp));\
- }while(0)
+ desccol = opt_col_width + indent * 2;
+#define PRINT_SPACES(fp,n) \
+ fprintf((fp), "%*s", (n), "")
/* Second pass (same as above loop), this time we print. */
/* Sloppy hack: We iterate twice. The first time we print short and long options.
@@ -436,7 +396,7 @@ int scanopt_usage (scanopt_t *scanner, FILE *fp, const char *usage)
/* pad to desccol */
PRINT_SPACES (fp, desccol - nchars);
- /* Print description, wrapped to maxlen[1] columns. */
+ /* Print description, wrapped to desc_col_width columns. */
if (1) {
const char *pstart;
@@ -447,7 +407,7 @@ int scanopt_usage (scanopt_t *scanner, FILE *fp, const char *usage)
p = pstart;
- while (*p && n < maxlen[1]
+ while (*p && n < desc_col_width
&& *p != '\n') {
if (isspace ((unsigned char)(*p))
|| *p == '-') lastws =
@@ -497,7 +457,7 @@ int scanopt_usage (scanopt_t *scanner, FILE *fp, const char *usage)
#endif /* no scanopt_usage */
-static int scanopt_err (struct _scanopt_t *s, int is_short, int err)
+static void scanopt_err(struct _scanopt_t *s, int is_short, int err)
{
const char *optname = "";
char optchar[2];
@@ -542,7 +502,6 @@ static int scanopt_err (struct _scanopt_t *s, int is_short, int err)
break;
}
}
- return err;
}
@@ -729,7 +688,8 @@ int scanopt (scanopt_t *svoid, char **arg, int *optindex)
if (!find_opt
(s, 0, pstart, namelen, &errcode, &opt_offset)) {
- return scanopt_err (s, 1, errcode);
+ scanopt_err(s, 1, errcode);
+ return errcode;
}
optarg = pstart + 1;
@@ -748,8 +708,7 @@ int scanopt (scanopt_t *svoid, char **arg, int *optindex)
/* Look ahead in argv[] to see if there is something
* that we can use as an argument (if needed). */
- has_next = s->index + 1 < s->argc
- && strcmp ("--", s->argv[s->index + 1]) != 0;
+ has_next = s->index + 1 < s->argc;
optp = s->options + opt_offset;
auxp = s->aux + opt_offset;
@@ -757,9 +716,9 @@ int scanopt (scanopt_t *svoid, char **arg, int *optindex)
/* case: no args allowed */
if (auxp->flags & ARG_NONE) {
if (optarg && !is_short) {
- scanopt_err (s, is_short, errcode = SCANOPT_ERR_ARG_NOT_ALLOWED);
+ scanopt_err(s, is_short, SCANOPT_ERR_ARG_NOT_ALLOWED);
INC_INDEX (s, 1);
- return errcode;
+ return SCANOPT_ERR_ARG_NOT_ALLOWED;
}
else if (!optarg)
INC_INDEX (s, 1);
@@ -770,8 +729,10 @@ int scanopt (scanopt_t *svoid, char **arg, int *optindex)
/* case: required */
if (auxp->flags & ARG_REQ) {
- if (!optarg && !has_next)
- return scanopt_err (s, is_short, SCANOPT_ERR_ARG_NOT_FOUND);
+ if (!optarg && !has_next) {
+ scanopt_err(s, is_short, SCANOPT_ERR_ARG_NOT_FOUND);
+ return SCANOPT_ERR_ARG_NOT_FOUND;
+ }
if (!optarg) {
/* Let the next argv element become the argument. */
diff --git a/src/tables.c b/src/tables.c
index 980d2e9..182ab63 100644
--- a/src/tables.c
+++ b/src/tables.c
@@ -87,7 +87,7 @@ int yytbl_hdr_init (struct yytbl_hdr *th, const char *version_str,
th->th_magic = YYTBL_MAGIC;
th->th_hsize = (flex_uint32_t) (14 + strlen (version_str) + 1 + strlen (name) + 1);
- th->th_hsize += yypad64 (th->th_hsize);
+ th->th_hsize += (8 - (th->th_hsize % 8)) % 8; // Pad to 64-bit boundary
th->th_ssize = 0; // Not known at this point.
th->th_flags = 0;
th->th_version = xstrdup(version_str);
@@ -124,14 +124,14 @@ int yytbl_data_destroy (struct yytbl_data *td)
/** Write enough padding to bring the file pointer to a 64-bit boundary. */
static int yytbl_write_pad64 (struct yytbl_writer *wr)
{
- int pad, bwritten = 0;
+ int bwritten = 0;
- pad = yypad64 (wr->total_written);
- while (pad-- > 0)
+ while (wr->total_written % (8 * sizeof(flex_uint8_t)) > 0) {
if (yytbl_write8 (wr, 0) < 0)
return -1;
else
bwritten++;
+ }
return bwritten;
}
diff --git a/src/tables_shared.h b/src/tables_shared.h
index bbf9910..feca251 100644
--- a/src/tables_shared.h
+++ b/src/tables_shared.h
@@ -63,12 +63,6 @@ dnl flex code (hence the name "_shared").
#define YYTBL_MAGIC 0xF13C57B1
#endif
-/** Calculate (0-7) = number bytes needed to pad n to next 64-bit boundary. */
-#ifndef yypad64
-#define yypad64(n) ((8-((n)%8))%8)
-#endif
-
-
#ifndef YYTABLES_TYPES
#define YYTABLES_TYPES
/** Possible values for td_id field. Each one corresponds to a