]> granicus.if.org Git - flex/commitdiff
Replaced many CPP macros with m4 equivalents.
authorJohn Millaway <john43@users.sourceforge.net>
Tue, 11 Mar 2003 21:41:36 +0000 (21:41 +0000)
committerJohn Millaway <john43@users.sourceforge.net>
Tue, 11 Mar 2003 21:41:36 +0000 (21:41 +0000)
Makefile.am
buf.c
flex.skl
flexdef.h
gen.c
main.c
misc.c
scan.l

index bed7d74f48f11924269c8744ca0aab17cf0ce1c0..90a96aaa5550e44548a301bdfdcd336f19275925 100644 (file)
@@ -143,7 +143,7 @@ AM_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" -I@includedir@ -I$(top_srcdir)/intl
 LIBS = @LIBINTL@ @LIBS@
 
 skel.c: flex.skl mkskel.sh flexint.h tables_shared.h
-       $(m4) -P -DFLEX_MAJOR_VERSION=`echo $(VERSION)|cut -f 1 -d .` -DFLEX_MINOR_VERSION=`echo $(VERSION)|cut -f 2 -d .` -DFLEX_SUBMINOR_VERSION=`echo $(VERSION)|cut -f 3 -d .` $(srcdir)/flex.skl | $(SHELL) $(srcdir)/mkskel.sh  >skel.c
+       sed 's/m4_/m4postproc_/g; s/m4preproc_/m4_/g' $(srcdir)/flex.skl | $(m4) -P -DFLEX_MAJOR_VERSION=`echo $(VERSION)|cut -f 1 -d .` -DFLEX_MINOR_VERSION=`echo $(VERSION)|cut -f 2 -d .` -DFLEX_SUBMINOR_VERSION=`echo $(VERSION)|cut -f 3 -d .` | sed 's/m4postproc_/m4_/g' | $(SHELL) $(srcdir)/mkskel.sh  >skel.c
 
 # Explicitly describe dependencies.
 # You can recreate this with `gcc -I. -MM *.c'
diff --git a/buf.c b/buf.c
index c4d3fd13788187dfaa0101fa0167cbfeb7b7de4e..85d206d296f35abd30bdaf515533623b9a98b1ab 100644 (file)
--- a/buf.c
+++ b/buf.c
 
 /* global buffers. */
 struct Buf userdef_buf;                /* for user #definitions triggered by cmd-line. */
-struct Buf defs_buf;           /* for #define's autogenerated. */
+struct Buf defs_buf;           /* for #define's autogenerated. List of strings. */
 struct Buf yydmap_buf;         /* string buffer to hold yydmap elements */
+struct Buf m4defs_buf;          /**< Holds m4 definitions. List of strings. */
 
+struct Buf *buf_print_strings(struct Buf * buf, FILE* out)
+{
+    int i;
+
+    if(!buf || !out)
+        return buf;
+
+    for (i=0; i < buf->nelts; i++){
+        const char * s = ((char**)buf->elts)[i];
+        if(s)
+            fprintf(out, "%s", s);
+    }
+}
 
 /* Append a "%s" formatted string to a string buffer */
 struct Buf *buf_prints (struct Buf *buf, const char *fmt, const char *s)
@@ -89,6 +103,25 @@ struct Buf *buf_strdefine (buf, str, def)
        return buf;
 }
 
+/** Pushes "m4_define( [[def]], [[val]])m4_dnl" to end of buffer.
+ * @param buf A buffer as a list of strings.
+ * @param def The m4 symbol to define.
+ * @param val The definition; may be NULL.
+ * @return buf
+ */
+struct Buf *buf_m4_define (struct Buf *buf, const char* def, const char* val)
+{
+    const char * fmt = "m4_define( [[%s]], [[%s]])m4_dnl\n";
+    char * str;
+    int len;
+
+    val = val?val:"";
+    str = (char*)flex_alloc(strlen(fmt) + strlen(def) + strlen(val) + 2);
+    
+    sprintf(str, fmt, def, val);
+    buf_append(buf, str, 1);
+}
+
 /* create buf with 0 elements, each of size elem_size. */
 void buf_init (buf, elem_size)
      struct Buf *buf;
index c7bd5564a8b1773dbac944d2474aab3ddda0064e..2757fe29e3cb8b77c38f94a2dc8274a5ae5075ad 100644 (file)
--- a/flex.skl
+++ b/flex.skl
@@ -1,26 +1,30 @@
-m4_dnl -*-C-*- vi: set ft=c:
-m4_dnl This file is processed in several stages.
-m4_dnl Here are the stages, as best as I can describe:
-m4_dnl
-m4_dnl   1. flex.skl is processed through GNU m4 during the
-m4_dnl      pre-compilation stage of flex.
-m4_dnl   2. The preprocessed skeleton is translated verbatim into a
-m4_dnl      C array, saved as "skel.c" and compiled into the flex binary.
-m4_dnl   3. At runtime, the skeleton is generated and filtered (again)
-m4_dnl      through m4.
-m4_dnl
+%# -*-C-*- vi: set ft=c:
+%# This file is processed in several stages.
+%# Here are the stages, as best as I can describe:
+%#
+%#   1. flex.skl is processed through GNU m4 during the
+%#      pre-compilation stage of flex. Only macros starting
+%#      with `m4preproc_' are processed, and quoting is normal.
+%#
+%#   2. The preprocessed skeleton is translated verbatim into a
+%#      C array, saved as "skel.c" and compiled into the flex binary.
+%#
+%#   3. At runtime, the skeleton is generated and filtered (again)
+%#      through m4. Macros beginning with `m4_' will be processed.
+%#      The quoting is "[[" and "]]" so we don't interfere with
+%#      user code.
+%# 
 /* A lexical scanner generated by flex */
+
+%#  Macros for preproc stage.
+m4preproc_changecom
+
+%# Macros for runtime processing stage.
 m4_changecom
+m4_changequote([[, ]])
 
-m4_dnl 
-m4_dnl Create macros for the generation phase, not the preproc phase.
-m4_dnl
-`m4_changecom'
-m4_define(`YYDEFINE',``m4_define($@)'')
-m4_define(`YYIFDEF',``m4_ifdef($@)'')
 %# 
-
-%# Lines in this skeleton starting with a '%' character are "control lines"
+%# Lines in this skeleton starting with a "%" character are "control lines"
 %# and affect the generation of the scanner. The possible control codes are
 %# listed and processed in misc.c.
 %#
@@ -68,7 +72,7 @@ m4_define(`YYIFDEF',``m4_ifdef($@)'')
 /* end standard C headers. */
 
 %if-c-or-c++
-m4_include(`flexint.h')
+m4preproc_include(`flexint.h')
 %endif
 
 %if-c++-only
@@ -82,7 +86,7 @@ m4_include(`flexint.h')
 
 #ifdef __cplusplus
 
-/* C++ compilers don't understand traditional function definitions. */
+/* C++ compilers do not understand traditional function definitions. */
 #ifdef YY_TRADITIONAL_FUNC_DEFS
 #undef YY_TRADITIONAL_FUNC_DEFS
 #endif
@@ -92,7 +96,7 @@ m4_include(`flexint.h')
 
 #else  /* ! __cplusplus */
 
-/* We're not in a C++ compiler, so by default,
+/* We are not in a C++ compiler, so by default,
    we generate C99 function defs, unless you explicitly ask
    for traditional defs by defining YY_TRADITIONAL_FUNC_DEFS */
 
@@ -109,7 +113,7 @@ m4_include(`flexint.h')
 #define yyconst
 #endif
 
-/* For compilers that can't handle prototypes.
+/* For compilers that can not handle prototypes.
  * e.g.,
  * The function prototype
  *    int foo(int x, char* y);
@@ -145,26 +149,26 @@ m4_include(`flexint.h')
 typedef void* yyscan_t;
 #endif
 
-/* For use wherever a Global is accessed or assigned. */
-#define YY_G(var) (((struct yyguts_t*)yyscanner)->var)
+%# For use wherever a Global is accessed or assigned.
+m4_define( [[YY_G]], [[(((struct yyguts_t*)yyscanner)->$1)]])
 
-/* For use in function prototypes to append the additional argument. */
-#define YY_PROTO_LAST_ARG , yyscan_t yyscanner
-#define YY_PROTO_ONLY_ARG    yyscan_t yyscanner
+%# For use in function prototypes to append the additional argument.
+m4_define( [[YY_PROTO_LAST_ARG]],  [[, yyscan_t yyscanner]])
+m4_define( [[YY_PROTO_ONLY_ARG]],  [[yyscan_t yyscanner]])
 
-/* For use in function definitions to append the additional argument. */
-#ifdef YY_TRADITIONAL_FUNC_DEFS
-#define YY_DEF_LAST_ARG , yyscanner
-#define YY_DEF_ONLY_ARG    yyscanner
-#else
-#define YY_DEF_LAST_ARG , yyscan_t yyscanner
-#define YY_DEF_ONLY_ARG   yyscan_t yyscanner
-#endif
-#define YY_DECL_LAST_ARG yyscan_t yyscanner;
+%# For use in function definitions to append the additional argument.
+m4_ifdef( [[M4_YY_TRADITIONAL_FUNC_DEFS]],
+    m4_define( [[YY_DEF_LAST_ARG]], [[, yyscanner]])
+    m4_define( [[YY_DEF_ONLY_ARG]], [[yyscanner]])
+,
+    m4_define( [[YY_DEF_LAST_ARG]],  [[, yyscan_t yyscanner]])
+    m4_define( [[YY_DEF_ONLY_ARG]],  [[yyscan_t yyscanner]])
+)
+m4_define( [[YY_DECL_LAST_ARG]],  [[yyscan_t yyscanner;]])
 
-/* For use in function calls to pass the additional argument. */
-#define YY_CALL_LAST_ARG  , yyscanner
-#define YY_CALL_ONLY_ARG   yyscanner
+%# For use in function calls to pass the additional argument.
+m4_define( [[YY_CALL_LAST_ARG]], [[, yyscanner]])
+m4_define( [[YY_CALL_ONLY_ARG]], [[yyscanner]])
 
 /* For convenience, these vars (plus the bison vars far below)
    are macros in the reentrant scanner. */
@@ -181,19 +185,20 @@ int yylex_init YY_PARAMS((yyscan_t* scanner));
 
 %if-not-reentrant
 
-/* Define these macros to be no-ops. */
-#define YY_G(var) (var)
-#define YY_PROTO_LAST_ARG
-#define YY_PROTO_ONLY_ARG void
-#define YY_DEF_LAST_ARG
-#ifdef YY_TRADITIONAL_FUNC_DEFS
-#define YY_DEF_ONLY_ARG
-#else
-#define YY_DEF_ONLY_ARG void
-#endif
-#define YY_DECL_LAST_ARG
-#define YY_CALL_LAST_ARG
-#define YY_CALL_ONLY_ARG
+%# Define these macros to be no-ops.
+m4_define( [[YY_G]], [[($1)]])
+m4_define( [[YY_PROTO_LAST_ARG]])
+m4_define( [[YY_PROTO_ONLY_ARG]],  [[void]])
+m4_define( [[YY_DEF_LAST_ARG]])
+
+m4_ifdef( [[M4_YY_TRADITIONAL_FUNC_DEFS]],
+    m4_define( [[YY_DEF_ONLY_ARG]])
+,
+    m4_define( [[YY_DEF_ONLY_ARG]],  [[void]])
+)
+m4_define([[YY_DECL_LAST_ARG]])
+m4_define([[YY_CALL_LAST_ARG]])
+m4_define([[YY_CALL_ONLY_ARG]])
 
 %endif
 
@@ -212,19 +217,19 @@ int yylex_init YY_PARAMS((yyscan_t* scanner));
  *        char * y;
  *        yyscan_t yyscanner;
  */
-#ifdef YY_TRADITIONAL_FUNC_DEFS
-/* Generate traditional function defs */
-#define YYFARGS0(v) (YY_DEF_ONLY_ARG) YY_DECL_LAST_ARG
-#define YYFARGS1(t1,n1) (n1 YY_DEF_LAST_ARG) t1 n1; YY_DECL_LAST_ARG
-#define YYFARGS2(t1,n1,t2,n2) (n1,n2 YY_DEF_LAST_ARG) t1 n1; t2 n2; YY_DECL_LAST_ARG
-#define YYFARGS3(t1,n1,t2,n2,t3,n3) (n1,n2,n3 YY_DEF_LAST_ARG) t1 n1; t2 n2; t3 n3; YY_DECL_LAST_ARG
-#else
-/* Generate C99 function defs. */
-#define YYFARGS0(v) (YY_DEF_ONLY_ARG)
-#define YYFARGS1(t1,n1) (t1 n1 YY_DEF_LAST_ARG)
-#define YYFARGS2(t1,n1,t2,n2) (t1 n1,t2 n2 YY_DEF_LAST_ARG)
-#define YYFARGS3(t1,n1,t2,n2,t3,n3) (t1 n1,t2 n2,t3 n3 YY_DEF_LAST_ARG)
-#endif
+m4_ifdef( [[YY_TRADITIONAL_FUNC_DEFS]],
+%# Generate traditional function defs
+    #define YYFARGS0(v) (YY_DEF_ONLY_ARG) YY_DECL_LAST_ARG
+    #define YYFARGS1(t1,n1) (n1 YY_DEF_LAST_ARG) t1 n1; YY_DECL_LAST_ARG
+    #define YYFARGS2(t1,n1,t2,n2) (n1,n2 YY_DEF_LAST_ARG) t1 n1; t2 n2; YY_DECL_LAST_ARG
+    #define YYFARGS3(t1,n1,t2,n2,t3,n3) (n1,n2,n3 YY_DEF_LAST_ARG) t1 n1; t2 n2; t3 n3; YY_DECL_LAST_ARG
+,
+%# Generate C99 function defs.
+    m4_define( [[YYFARGS0]], [[(YY_DEF_ONLY_ARG)]])
+    m4_define( [[YYFARGS1]], [[($1 $2 YY_DEF_LAST_ARG)]])
+    m4_define( [[YYFARGS2]], [[($1 $2, $3 $4 YY_DEF_LAST_ARG)]])
+    m4_define( [[YYFARGS3]], [[($1 $2, $3 $4, $5 $6 YY_DEF_LAST_ARG)]])
+)
 
 /* Enter a start condition.  This macro really ought to take a parameter,
  * but we do it the disgusting crufty way forced on us by the ()-less
@@ -278,7 +283,7 @@ extern FILE *yyin, *yyout;
  *       existing scanners that call yyless() from OUTSIDE yylex. 
  *       One obvious solution it to make yy_act a global. I tried that, and saw
  *       a 5% performance hit in a non-yylineno scanner, because yy_act is
- *       normally declared as a register variable-- so it's not worth it.
+ *       normally declared as a register variable-- so it is not worth it.
  */
 #define  YY_LESS_LINENO(n) \
         do { \
@@ -302,10 +307,10 @@ extern FILE *yyin, *yyout;
  *
  * Prior to using the do-while the compiler would get upset at the
  * "else" because it interpreted the "if" statement as being all
- * done when it reached the ';' after the yyless() call.
+ * done when it reached the ";" after the yyless() call.
  */
 
-/* Return all but the first 'n' matched characters back to the input stream. */
+/* Return all but the first "n" matched characters back to the input stream. */
 
 #define yyless(n) \
        do \
@@ -531,14 +536,15 @@ static void yy_fatal_error YY_PARAMS(( yyconst char msg[] YY_PROTO_LAST_ARG ));
  * down here because we want the user's section 1 to have been scanned first.
  * The user has a chance to override it with an option.
  */
-#ifndef YY_NO_UNISTD_H
+m4_ifdef( [[M4_YY_NO_UNISTD_H]],,
+[[
 %if-c-only
 #include <unistd.h>
 %endif
 %if-c++-only
 #include <unistd.h>
 %endif
-#endif /* !YY_NO_UNISTD_H */
+]])
 
 #ifndef YY_EXTRA_TYPE
 #define YY_EXTRA_TYPE void *
@@ -576,12 +582,13 @@ struct yyguts_t
     int yylineno_r;
     int yy_flex_debug_r;
 
-#ifdef YY_USES_REJECT
+m4_ifdef( [[M4_YY_USES_REJECT]],
+[[
     yy_state_type *yy_state_buf;
     yy_state_type *yy_state_ptr;
     char *yy_full_match;
     int yy_lp;
-#endif
+]])
 
 #ifdef YY_TEXT_IS_ARRAY
     char yytext_r[YYLMAX];
@@ -627,70 +634,86 @@ static int yy_init_globals YY_PARAMS(( YY_PROTO_ONLY_ARG ));
 /* Accessor methods to globals.
    These are made visible to non-reentrant scanners for convenience. */
 
-#ifndef YY_NO_DESTROY
+m4_ifdef( [[M4_YY_NO_DESTROY]],,
+[[
 int yylex_destroy YY_PARAMS(( YY_PROTO_ONLY_ARG ));
-#endif
+]])
 
-#ifndef YY_NO_GET_DEBUG
+m4_ifdef( [[M4_YY_NO_GET_DEBUG]],,
+[[
 int yyget_debug YY_PARAMS(( YY_PROTO_ONLY_ARG ));
-#endif
+]])
 
-#ifndef YY_NO_SET_DEBUG
+m4_ifdef( [[M4_YY_NO_SET_DEBUG]],,
+[[
 void yyset_debug YY_PARAMS(( int debug_flag YY_PROTO_LAST_ARG ));
-#endif
+]])
 
-#ifndef YY_NO_GET_EXTRA
+m4_ifdef( [[M4_YY_NO_GET_EXTRA]],,
+[[
 YY_EXTRA_TYPE yyget_extra YY_PARAMS(( YY_PROTO_ONLY_ARG ));
-#endif
+]])
 
-#ifndef YY_NO_SET_EXTRA
+m4_ifdef( [[M4_YY_NO_SET_EXTRA]],,
+[[
 void yyset_extra YY_PARAMS(( YY_EXTRA_TYPE user_defined YY_PROTO_LAST_ARG ));
-#endif
+]])
 
-#ifndef YY_NO_GET_IN
+m4_ifdef( [[M4_YY_NO_GET_IN]],,
+[[
 FILE *yyget_in YY_PARAMS(( YY_PROTO_ONLY_ARG ));
-#endif
+]])
 
-#ifndef YY_NO_SET_IN
+m4_ifdef( [[M4_YY_NO_SET_IN]],,
+[[
 void yyset_in  YY_PARAMS(( FILE * in_str YY_PROTO_LAST_ARG ));
-#endif
+]])
 
-#ifndef YY_NO_GET_OUT
+m4_ifdef( [[M4_YY_NO_GET_OUT]],,
+[[
 FILE *yyget_out YY_PARAMS(( YY_PROTO_ONLY_ARG ));
-#endif
+]])
 
-#ifndef YY_NO_SET_OUT
+m4_ifdef( [[M4_YY_NO_SET_OUT]],,
+[[
 void yyset_out  YY_PARAMS(( FILE * out_str YY_PROTO_LAST_ARG ));
-#endif
+]])
 
-#ifndef YY_NO_GET_LENG
+m4_ifdef( [[M4_YY_NO_GET_LENG]],,
+[[
 int yyget_leng YY_PARAMS(( YY_PROTO_ONLY_ARG ));
-#endif
+]])
 
-#ifndef YY_NO_GET_TEXT
+m4_ifdef( [[M4_YY_NO_GET_TEXT]],,
+[[
 char *yyget_text YY_PARAMS(( YY_PROTO_ONLY_ARG ));
-#endif
+]])
 
-#ifndef YY_NO_GET_LINENO
+m4_ifdef( [[M4_YY_NO_GET_LINENO]],,
+[[
 int yyget_lineno YY_PARAMS(( YY_PROTO_ONLY_ARG ));
-#endif
+]])
 
-#ifndef YY_NO_SET_LINENO
+m4_ifdef( [[M4_YY_NO_SET_LINENO]],,
+[[
 void yyset_lineno YY_PARAMS(( int line_number YY_PROTO_LAST_ARG ));
-#endif
+]])
 
 %if-bison-bridge
-#ifndef YY_NO_GET_LVAL
+m4_ifdef( [[M4_YY_NO_GET_LVAL]],,
+[[
 YYSTYPE * yyget_lval YY_PARAMS(( YY_PROTO_ONLY_ARG ));
-#endif
+]])
 void yyset_lval YY_PARAMS(( YYSTYPE * yylvalp YY_PROTO_LAST_ARG ));
 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
-#ifndef YY_NO_GET_LLOC
+m4_ifdef( [[M4_YY_NO_GET_LLOC]],,
+[[
    YYLTYPE *yyget_lloc YY_PARAMS(( YY_PROTO_ONLY_ARG ));
-#endif
-#ifndef YY_NO_SET_LLOC
+]])
+m4_ifdef( [[M4_YY_NO_SET_LLOC]],,
+[[
     void yyset_lloc YY_PARAMS(( YYLTYPE * yyllocp YY_PROTO_LAST_ARG ));
-#endif
+]])
 #endif /* YYLTYPE */
 %endif
 
@@ -707,9 +730,10 @@ extern int yywrap YY_PARAMS(( YY_PROTO_ONLY_ARG ));
 #endif
 
 %not-for-header
-#ifndef YY_NO_UNPUT
+m4_ifdef( [[M4_YY_NO_UNPUT]],,
+[[
 static void yyunput YY_PARAMS(( int c, char *buf_ptr  YY_PROTO_LAST_ARG));
-#endif
+]])
 %ok-for-header
 %endif
 
@@ -744,15 +768,18 @@ static int *yy_start_stack = 0;
 %ok-for-header
 %endif
 
-#ifndef YY_NO_PUSH_STATE
+m4_ifdef( [[M4_YY_NO_PUSH_STATE]],,
+[[
 static void yy_push_state YY_PARAMS(( int new_state YY_PROTO_LAST_ARG));
-#endif
-#ifndef YY_NO_POP_STATE
+]])
+m4_ifdef( [[M4_YY_NO_POP_STATE]],,
+[[
 static void yy_pop_state YY_PARAMS(( YY_PROTO_ONLY_ARG ));
-#endif
-#ifndef YY_NO_TOP_STATE
+]])
+m4_ifdef( [[M4_YY_NO_TOP_STATE]],,
+[[
 static int yy_top_state YY_PARAMS(( YY_PROTO_ONLY_ARG ));
-#endif
+]])
 
 #else
 #define YY_NO_PUSH_STATE 1
@@ -818,7 +845,7 @@ static int yy_top_state YY_PARAMS(( YY_PROTO_ONLY_ARG ));
 #endif
 
 %if-tables-serialization structures and prototypes
-m4_include(`tables_shared.h')
+m4preproc_include(`tables_shared.h')
 
 /* Load the DFA tables from the given stream.  */
 int yytables_fload YY_PARAMS ((FILE * fp YY_PROTO_LAST_ARG));
@@ -936,10 +963,11 @@ YY_DECL
                YY_USER_INIT;
 #endif
 
-#ifdef YY_USES_REJECT
+m4_ifdef( [[M4_YY_USES_REJECT]],
+[[
         if ( ! YY_G(yy_state_buf) )
             YY_G(yy_state_buf) = (yy_state_type *)yyalloc(YY_BUF_SIZE + 2  YY_CALL_LAST_ARG);
-#endif
+]])
 
                if ( ! YY_G(yy_start) )
                        YY_G(yy_start) = 1;     /* first start state */
@@ -1156,11 +1184,12 @@ yyFlexLexer::yyFlexLexer( std::istream* arg_yyin, std::ostream* arg_yyout )
     YY_G(yy_buffer_stack_max) = 0;
 
 
-#ifdef YY_USES_REJECT
+m4_ifdef( [[M4_YY_USES_REJECT]],
+[[
        yy_state_buf = new yy_state_type[YY_BUF_SIZE + 2];
-#else
+,
        yy_state_buf = 0;
-#endif
+]])
        }
 
 yyFlexLexer::~yyFlexLexer()
@@ -1284,10 +1313,11 @@ int yyFlexLexer::yy_get_next_buffer()
 
                while ( num_to_read <= 0 )
                        { /* Not enough room in the buffer - grow it. */
-#ifdef YY_USES_REJECT
+m4_ifdef( [[M4_YY_USES_REJECT]],
+[[
                        YY_FATAL_ERROR(
 "input buffer overflow, can't enlarge buffer because scanner uses REJECT" );
-#else
+,
 
                        /* just a shorter name for the current buffer */
                        YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
@@ -1321,7 +1351,7 @@ int yyFlexLexer::yy_get_next_buffer()
 
                        num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
                                                number_to_move - 1;
-#endif
+]])
                        }
 
                if ( num_to_read > YY_READ_BUF_SIZE )
@@ -1844,7 +1874,8 @@ void yyFlexLexer::yyensure_buffer_stack(void)
 
 
 
-#ifndef YY_NO_SCAN_BUFFER
+m4_ifdef( [[M4_YY_NO_SCAN_BUFFER]],,
+[[
 %if-c-only
 YY_BUFFER_STATE yy_scan_buffer  YYFARGS2( char *,base, yy_size_t ,size)
        {
@@ -1875,10 +1906,11 @@ YY_BUFFER_STATE yy_scan_buffer  YYFARGS2( char *,base, yy_size_t ,size)
        return b;
        }
 %endif
-#endif
+]])
 
 
-#ifndef YY_NO_SCAN_STRING
+m4_ifdef( [[M4_YY_NO_SCAN_STRING]],,
+[[
 %if-c-only
 YY_BUFFER_STATE yy_scan_string YYFARGS1( yyconst char *,yy_str)
        {
@@ -1889,10 +1921,11 @@ YY_BUFFER_STATE yy_scan_string YYFARGS1( yyconst char *,yy_str)
        return yy_scan_bytes( yy_str, len YY_CALL_LAST_ARG);
        }
 %endif
-#endif
+]])
 
 
-#ifndef YY_NO_SCAN_BYTES
+m4_ifdef( [[M4_YY_NO_SCAN_BYTES]],,
+[[
 %if-c-only
 YY_BUFFER_STATE yy_scan_bytes  YYFARGS2( yyconst char *,bytes, int ,len)
        {
@@ -1924,10 +1957,11 @@ YY_BUFFER_STATE yy_scan_bytes  YYFARGS2( yyconst char *,bytes, int ,len)
        return b;
        }
 %endif
-#endif
+]])
 
 
-#ifndef YY_NO_PUSH_STATE
+m4_ifdef( [[M4_YY_NO_PUSH_STATE]],,
+[[
 %if-c-only
     static void yy_push_state YYFARGS1( int ,new_state)
 %endif
@@ -1958,10 +1992,11 @@ YY_BUFFER_STATE yy_scan_bytes  YYFARGS2( yyconst char *,bytes, int ,len)
 
        BEGIN(new_state);
        }
-#endif
+]])
 
 
-#ifndef YY_NO_POP_STATE
+m4_ifdef( [[M4_YY_NO_POP_STATE]],,
+[[
 %if-c-only
     static void yy_pop_state  YYFARGS0(void)
 %endif
@@ -1974,10 +2009,11 @@ YY_BUFFER_STATE yy_scan_bytes  YYFARGS2( yyconst char *,bytes, int ,len)
 
        BEGIN(YY_G(yy_start_stack)[YY_G(yy_start_stack_ptr)]);
        }
-#endif
+]])
 
 
-#ifndef YY_NO_TOP_STATE
+m4_ifdef( [[M4_YY_NO_TOP_STATE]],,
+[[
 %if-c-only
     static int yy_top_state  YYFARGS0(void)
 %endif
@@ -1987,7 +2023,7 @@ YY_BUFFER_STATE yy_scan_bytes  YYFARGS2( yyconst char *,bytes, int ,len)
        {
        return YY_G(yy_start_stack)[YY_G(yy_start_stack_ptr) - 1];
        }
-#endif
+]])
 
 #ifndef YY_EXIT_FAILURE
 #define YY_EXIT_FAILURE 2
@@ -2031,128 +2067,144 @@ void yyFlexLexer::LexerError( yyconst char msg[] )
 
 %if-c-only
 %if-reentrant
-#ifndef YY_NO_GET_EXTRA
+m4_ifdef( [[M4_YY_NO_GET_EXTRA]],,
+[[
 YY_EXTRA_TYPE yyget_extra  YYFARGS0(void)
 {
     return yyextra;
 }
-#endif /* !YY_NO_GET_EXTRA */
+]])
 %endif
 
-#ifndef YY_NO_GET_LINENO
+m4_ifdef( [[M4_YY_NO_GET_LINENO]],,
+[[
 int yyget_lineno  YYFARGS0(void)
 {
     return yylineno;
 }
-#endif /* !YY_NO_GET_LINENO */
+]])
 
-#ifndef YY_NO_GET_IN
+m4_ifdef( [[M4_YY_NO_GET_IN]],,
+[[
 FILE *yyget_in  YYFARGS0(void)
 {
     return yyin;
 }
-#endif /* !YY_NO_GET_IN */
+]])
 
-#ifndef YY_NO_GET_OUT
+m4_ifdef( [[M4_YY_NO_GET_OUT]],,
+[[
 FILE *yyget_out  YYFARGS0(void)
 {
     return yyout;
 }
-#endif /* !YY_NO_GET_OUT */
+]])
 
-#ifndef YY_NO_GET_LENG
+m4_ifdef( [[M4_YY_NO_GET_LENG]],,
+[[
 int yyget_leng  YYFARGS0(void)
 {
     return yyleng;
 }
-#endif /* !YY_NO_GET_LENG */
+]])
 
-#ifndef YY_NO_GET_TEXT
+m4_ifdef( [[M4_YY_NO_GET_TEXT]],,
+[[
 char *yyget_text  YYFARGS0(void)
 {
     return yytext;
 }
-#endif /* !YY_NO_GET_TEXT */
+]])
 
 %if-reentrant
-#ifndef YY_NO_SET_EXTRA
+m4_ifdef( [[M4_YY_NO_SET_EXTRA]],,
+[[
 void yyset_extra YYFARGS1( YY_EXTRA_TYPE ,user_defined)
 {
     yyextra = user_defined ;
 }
-#endif /* !YY_NO_SET_EXTRA */
+]])
 %endif
 
-#ifndef YY_NO_SET_LINENO
+m4_ifdef( [[M4_YY_NO_SET_LINENO]],,
+[[
 void yyset_lineno YYFARGS1( int ,line_number)
 {
     yylineno = line_number;
 }
-#endif /* !YY_NO_SET_LINENO */
+]])
 
 
-#ifndef YY_NO_SET_IN
+m4_ifdef( [[M4_YY_NO_SET_IN]],,
+[[
 void yyset_in YYFARGS1( FILE * ,in_str)
 {
     yyin = in_str ;
 }
-#endif /* !YY_NO_SET_IN */
+]])
 
-#ifndef YY_NO_SET_OUT
+m4_ifdef( [[M4_YY_NO_SET_OUT]],,
+[[
 void yyset_out YYFARGS1( FILE * ,out_str)
 {
     yyout = out_str ;
 }
-#endif /* !YY_NO_SET_OUT */
+]])
 
 
-#ifndef YY_NO_GET_DEBUG
+m4_ifdef( [[M4_YY_NO_GET_DEBUG]],,
+[[
 int yyget_debug  YYFARGS0(void)
 {
     return yy_flex_debug;
 }
-#endif /* !YY_NO_GET_DEBUG */
+]])
 
-#ifndef YY_NO_SET_DEBUG
+m4_ifdef( [[M4_YY_NO_SET_DEBUG]],,
+[[
 void yyset_debug YYFARGS1( int ,bdebug)
 {
     yy_flex_debug = bdebug ;
 }
-#endif /* !YY_NO_SET_DEBUG */
+]])
 %endif
 
 %if-reentrant
 /* Accessor methods for yylval and yylloc */
 
 %if-bison-bridge
-#ifndef YY_NO_GET_LVAL
+m4_ifdef( [[M4_YY_NO_GET_LVAL]],,
+[[
 YYSTYPE * yyget_lval  YYFARGS0(void)
 {
     return yylval;
 }
-#endif /* !YY_NO_GET_LVAL */
+]])
 
-#ifndef YY_NO_SET_LVAL
+m4_ifdef( [[M4_YY_NO_SET_LVAL]],,
+[[
 void yyset_lval YYFARGS1( YYSTYPE * ,yylvalp)
 {
     yylval = yylvalp;
 }
-#endif /* !YY_NO_SET_LVAL */
+]])
 
 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
-#ifndef YY_NO_GET_LLOC
+m4_ifdef( [[M4_YY_NO_GET_LLOC]],,
+[[
 YYLTYPE *yyget_lloc  YYFARGS0(void)
 {
     return yylloc;
 }
-#endif /* !YY_NO_GET_LLOC */
+]])
 
-#ifndef YY_NO_SET_LLOC
+m4_ifdef( [[M4_YY_NO_SET_LLOC]],,
+[[
 void yyset_lloc YYFARGS1( YYLTYPE * ,yyllocp)
 {
     yylloc = yyllocp;
 }
-#endif /* !YY_NO_SET_LLOC */
+]])
 
 #endif /* YYLTYPE */
 %endif
@@ -2177,12 +2229,13 @@ static int yy_init_globals YYFARGS0(void)
     YY_G(yy_start_stack_depth) = 0;
     YY_G(yy_start_stack) = (int *) 0;
 
-#ifdef YY_USES_REJECT
+m4_ifdef( [[M4_YY_USES_REJECT]],
+[[
     YY_G(yy_state_buf) = 0;
     YY_G(yy_state_ptr) = 0;
     YY_G(yy_full_match) = 0;
     YY_G(yy_lp) = 0;
-#endif
+]])
 
 #ifdef YY_TEXT_IS_ARRAY
     YY_G(yytext_ptr) = 0;
@@ -2260,9 +2313,10 @@ int yylex_destroy  YYFARGS0(void)
         YY_G(yy_start_stack) = NULL;
 #endif
 
-#ifdef YY_USES_REJECT
+m4_ifdef( [[M4_YY_USES_REJECT]],
+[[
     yyfree ( YY_G(yy_state_buf) YY_CALL_LAST_ARG);
-#endif
+]])
 
 %if-reentrant
     /* Destroy the main struct (reentrant only). */
@@ -2295,18 +2349,16 @@ static int yy_flex_strlen YYFARGS1( yyconst char *,s)
        }
 #endif
 
-/* You may override yyalloc by defining YY_NO_FLEX_ALLOC and linking to
- * your own version */
-#ifndef YY_NO_FLEX_ALLOC
+m4_ifdef( [[M4_YY_NO_FLEX_ALLOC]],,
+[[
 void *yyalloc YYFARGS1( yy_size_t ,size)
        {
        return (void *) malloc( size );
        }
-#endif
+]])
 
-/* You may override yyrealloc by defining YY_NO_FLEX_REALLOC and linking
- * to your own version. */
-#ifndef YY_NO_FLEX_REALLOC
+m4_ifdef( [[M4_YY_NO_FLEX_REALLOC]],,
+[[
 void *yyrealloc  YYFARGS2( void *,ptr, yy_size_t ,size)
        {
        /* The cast to (char *) in the following accommodates both
@@ -2318,19 +2370,18 @@ void *yyrealloc  YYFARGS2( void *,ptr, yy_size_t ,size)
         */
        return (void *) realloc( (char *) ptr, size );
        }
-#endif
+]])
 
-/* You may override yyfree by defining YY_NO_FLEX_FREE and linking to
- * your own version.*/
-#ifndef YY_NO_FLEX_FREE
+m4_ifdef( [[M4_YY_NO_FLEX_FREE]],,
+[[
 void yyfree YYFARGS1( void *,ptr)
        {
        free( (char *) ptr );   /* see yyrealloc() for (char *) cast */
        }
-#endif
+]])
 
 %if-tables-serialization definitions
-m4_include(`tables_shared.c')
+m4preproc_include(`tables_shared.c')
 
 static int yytbl_read8 (void *v, struct yytbl_reader * rd)
 {
@@ -2368,7 +2419,7 @@ static int yytbl_read32 (void *v, struct yytbl_reader * rd)
 }
 
 /** Read the header */
-static int yytbl_hdr_read YYFARGS2 (struct yytbl_hdr *, th, struct yytbl_reader *, rd)
+static int yytbl_hdr_read YYFARGS2(struct yytbl_hdr *, th, struct yytbl_reader *, rd)
 {
     int     bytes;
     memset (th, 0, sizeof (struct yytbl_hdr));
@@ -2414,7 +2465,7 @@ static int yytbl_hdr_read YYFARGS2 (struct yytbl_hdr *, th, struct yytbl_reader
  *  @param dmap pointer to first element in list
  *  @return NULL if not found.
  */
-static struct yytbl_dmap *yytbl_dmap_lookup YYFARGS2 (struct yytbl_dmap *, dmap,
+static struct yytbl_dmap *yytbl_dmap_lookup YYFARGS2(struct yytbl_dmap *, dmap,
                                                       int, id)
 {
     while (dmap->dm_id)
@@ -2429,7 +2480,7 @@ static struct yytbl_dmap *yytbl_dmap_lookup YYFARGS2 (struct yytbl_dmap *, dmap,
  *  @param dmap used to performing mapping
  *  @return 0 on success
  */
-static int yytbl_data_load YYFARGS2 (struct yytbl_dmap *, dmap, struct yytbl_reader*, rd)
+static int yytbl_data_load YYFARGS2(struct yytbl_dmap *, dmap, struct yytbl_reader*, rd)
 {
     struct yytbl_data td;
     struct yytbl_dmap *transdmap=0;
@@ -2468,7 +2519,7 @@ static int yytbl_data_load YYFARGS2 (struct yytbl_dmap *, dmap, struct yytbl_rea
     else
         bytes = td.td_lolen * (td.td_hilen ? td.td_hilen : 1) * dmap->dm_sz;
 
-    if(YY_TABLES_VERIFY)
+    if(M4_YY_TABLES_VERIFY)
         /* We point to the array itself */
         p = dmap->dm_arr; 
     else
@@ -2534,21 +2585,21 @@ static int yytbl_data_load YYFARGS2 (struct yytbl_dmap *, dmap, struct yytbl_rea
 
                 switch (dmap->dm_sz) {
                 case sizeof (int32_t):
-                    if (YY_TABLES_VERIFY){
+                    if (M4_YY_TABLES_VERIFY){
                         if( ((int32_t *) v)[0] != (int32_t) t32)
                            yy_fatal_error("tables verification failed at YYTD_STRUCT int32_t" YY_CALL_LAST_ARG);
                     }else
                         ((int32_t *) v)[0] = (int32_t) t32;
                     break;
                 case sizeof (int16_t):
-                    if (YY_TABLES_VERIFY ){
+                    if (M4_YY_TABLES_VERIFY ){
                         if(((int16_t *) v)[0] != (int16_t) t32)
                         yy_fatal_error("tables verification failed at YYTD_STRUCT int16_t" YY_CALL_LAST_ARG);
                     }else
                         ((int16_t *) v)[0] = (int16_t) t32;
                     break;
                 case sizeof(int8_t):
-                    if (YY_TABLES_VERIFY ){
+                    if (M4_YY_TABLES_VERIFY ){
                          if( ((int8_t *) v)[0] != (int8_t) t32)
                         yy_fatal_error("tables verification failed at YYTD_STRUCT int8_t" YY_CALL_LAST_ARG);
                     }else
@@ -2573,12 +2624,12 @@ static int yytbl_data_load YYFARGS2 (struct yytbl_dmap *, dmap, struct yytbl_rea
                     return -1;
                 }
                 
-                if( YY_TABLES_VERIFY)
+                if( M4_YY_TABLES_VERIFY)
                     v = &(((struct yy_trans_info *) (transdmap->dm_arr))[t32]);
                 else
                     v = &((*((struct yy_trans_info **) (transdmap->dm_arr)))[t32]);
 
-                if(YY_TABLES_VERIFY ){
+                if(M4_YY_TABLES_VERIFY ){
                     if( ((struct yy_trans_info **) p)[0] != v)
                         yy_fatal_error("tables verification failed at YYTD_PTRANS" YY_CALL_LAST_ARG);
                 }else
@@ -2591,7 +2642,7 @@ static int yytbl_data_load YYFARGS2 (struct yytbl_dmap *, dmap, struct yytbl_rea
                 /* t32 is a plain int. copy data, then incrememnt p. */
                 switch (dmap->dm_sz) {
                 case sizeof (int32_t):
-                    if(YY_TABLES_VERIFY ){
+                    if(M4_YY_TABLES_VERIFY ){
                         if( ((int32_t *) p)[0] != (int32_t) t32)
                         yy_fatal_error("tables verification failed at int32_t" YY_CALL_LAST_ARG);
                     }else
@@ -2599,7 +2650,7 @@ static int yytbl_data_load YYFARGS2 (struct yytbl_dmap *, dmap, struct yytbl_rea
                     p = ((int32_t *) p) + 1;
                     break;
                 case sizeof (int16_t):
-                    if(YY_TABLES_VERIFY ){
+                    if(M4_YY_TABLES_VERIFY ){
                         if( ((int16_t *) p)[0] != (int16_t) t32)
                         yy_fatal_error("tables verification failed at int16_t" YY_CALL_LAST_ARG);
                     }else
@@ -2607,7 +2658,7 @@ static int yytbl_data_load YYFARGS2 (struct yytbl_dmap *, dmap, struct yytbl_rea
                     p = ((int16_t *) p) + 1;
                     break;
                 case sizeof (int8_t):
-                    if(YY_TABLES_VERIFY ){
+                    if(M4_YY_TABLES_VERIFY ){
                         if( ((int8_t *) p)[0] != (int8_t) t32)
                         yy_fatal_error("tables verification failed at int8_t" YY_CALL_LAST_ARG);
                     }else
@@ -2640,7 +2691,7 @@ static int yytbl_data_load YYFARGS2 (struct yytbl_dmap *, dmap, struct yytbl_rea
 %define-yytables   The name for this specific scanner's tables.
 
 /* Find the key and load the DFA tables from the given stream.  */
-static int yytbl_fload YYFARGS2 (FILE *, fp, const char *, key)
+static int yytbl_fload YYFARGS2(FILE *, fp, const char *, key)
 {
     int rv=0;
     struct yytbl_hdr th;
@@ -2689,7 +2740,7 @@ return_rv:
 }
 
 /** Load the DFA tables for this scanner from the given stream.  */
-int yytables_fload YYFARGS1 (FILE *, fp)
+int yytables_fload YYFARGS1(FILE *, fp)
 {
     if( yytbl_fload(fp, YYTABLES_NAME YY_CALL_LAST_ARG) != 0)
         return -1;
@@ -2701,7 +2752,7 @@ int yytables_destroy YYFARGS0(void)
 {   
     struct yytbl_dmap *dmap=0;
 
-    if(!YY_TABLES_VERIFY){
+    if(!M4_YY_TABLES_VERIFY){
         /* Walk the dmap, freeing the pointers */
         for(dmap=yydmap; dmap->dm_id; dmap++) {
             void * v;
@@ -2719,7 +2770,8 @@ int yytables_destroy YYFARGS0(void)
 /* end table serialization code definitions */
 %endif
 
-#if YY_MAIN
+
+m4_ifdef([[M4_YY_MAIN]], [[
 int main YY_PARAMS((void));
 
 int main ()
@@ -2738,5 +2790,5 @@ int main ()
 
        return 0;
        }
-#endif
+]])
 %ok-for-header
index 5a1af81d2009408e82b8db6c74b65d1cedd3c606..2a047aa50431126ab8fafcd9c12bec432c4f2a17 100644 (file)
--- a/flexdef.h
+++ b/flexdef.h
@@ -1084,6 +1084,8 @@ PROTO ((struct Buf *, const char *str, int nchars));
 extern struct Buf *buf_strdefine
 PROTO ((struct Buf * buf, const char *str, const char *def));
 extern struct Buf *buf_prints PROTO((struct Buf *buf, const char *fmt, const char* s));
+extern struct Buf *buf_m4_define PROTO((struct Buf *buf, const char* def, const char* val));
+extern struct Buf *buf_print_strings PROTO((struct Buf * buf, FILE* out));
 
 /* a string buffer for #define's generated by user-options on cmd line. */
 extern struct Buf userdef_buf;
@@ -1094,6 +1096,9 @@ extern struct Buf defs_buf;
 /* a string buffer to hold yydmap elements */
 extern struct Buf yydmap_buf;
 
+/* Holds m4 definitions. */
+extern struct Buf m4defs_buf;
+
 /* For blocking out code from the header file. */
 #define OUT_BEGIN_CODE() out_str("#ifndef %sIN_HEADER /* YY-DISCARD-FROM-HEADER */\n",prefix)
 #define OUT_END_CODE() out_str("#endif /* !%sIN_HEADER YY-END-DISCARD-FROM-HEADER */\n",prefix);
@@ -1149,12 +1154,12 @@ extern struct filter * output_chain;
  *            not including argv[0].
  * @return newest filter in chain
  */
-struct filter *filter_create (struct filter * chain, const char *cmd, ...);
+struct filter *filter_create PROTO((struct filter * chain, const char *cmd, ...));
 
 /* Fork and exec entire filter chain.
  *  @param chain The head of the chain.
  * @return true on success.
  */
-bool filter_apply_chain (struct filter * chain);
+bool filter_apply_chain PROTO((struct filter * chain));
 
 #endif /* not defined FLEXDEF_H */
diff --git a/gen.c b/gen.c
index eb9acd80951dd6b527f55bda70704973b5512f61..1529fffeb1914a8966047faa32b5ecd017d4cf4c 100644 (file)
--- a/gen.c
+++ b/gen.c
@@ -1038,12 +1038,12 @@ void gen_start_state ()
 
                if (reject) {
                        /* Set up for storing up states. */
-                       outn ("#ifdef YY_USES_REJECT");
+                       outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
                        indent_puts
                                ("YY_G(yy_state_ptr) = YY_G(yy_state_buf);");
                        indent_puts
                                ("*YY_G(yy_state_ptr)++ = yy_current_state;");
-                       outn ("#endif");
+                       outn ("]])");
                }
        }
 }
@@ -1761,7 +1761,7 @@ void make_tables ()
        }
 
        if (reject) {
-               outn ("#ifdef YY_USES_REJECT");
+               outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
                /* Declare state buffer variables. */
                if (!C_plus_plus && !reentrant) {
                        outn ("static yy_state_type *yy_state_buf=0, *yy_state_ptr=0;");
@@ -1797,7 +1797,7 @@ void make_tables ()
                outn ("goto find_rule; \\");
 
                outn ("}");
-               outn ("#endif");
+               outn ("]])\n");
        }
 
        else {
diff --git a/main.c b/main.c
index 4440edf22b9c2ee2db111968efa54178bda7f435..7cf006ad5bd2b837bd60140142fd6f7fc2c92793 100644 (file)
--- a/main.c
+++ b/main.c
@@ -338,12 +338,13 @@ void check_options ()
 
     /* Setup the filter chain. */
     output_chain = filter_create(NULL,"m4","-P",0);
+    /* filter_create(output_chain,"cat",0); */
     filter_apply_chain(output_chain);
     yyout = stdout;
     
 
        /* always generate the tablesverify flag. */
-       action_define ("YY_TABLES_VERIFY", tablesverify ? 1 : 0);
+       buf_m4_define (&m4defs_buf, "M4_YY_TABLES_VERIFY", tablesverify ? "1" : "0");
        if (tablesext)
                gentables = false;
 
@@ -389,6 +390,7 @@ void check_options ()
                lerrsf (_("can't open skeleton file %s"), skelname);
 
        if (reentrant) {
+        buf_m4_define (&m4defs_buf, "M4_YY_REENTRANT", NULL);
                outn ("#define YY_REENTRANT 1");
                if (yytext_is_array)
                        outn ("#define YY_TEXT_IS_ARRAY");
@@ -479,6 +481,9 @@ void check_options ()
        buf_strdefine (&userdef_buf, "YY_INT_ALIGNED",
                       long_align ? "long int" : "short int");
 
+    /* Dump the m4 definitions. */
+    buf_print_strings(&m4defs_buf, stdout);
+    
        /* Dump the user defined preproc directives. */
        if (userdef_buf.elts)
                outn ((char *) (userdef_buf.elts));
@@ -700,34 +705,6 @@ void flexend (exit_status)
                 "YY_MORE_ADJ",
                 "YY_NEED_STRLEN",
                 "YY_NEW_FILE",
-                "YY_NO_FLEX_ALLOC",
-                "YY_NO_FLEX_FREE",
-                "YY_NO_FLEX_REALLOC",
-                "YY_NO_GET_DEBUG",
-                "YY_NO_GET_EXTRA",
-                "YY_NO_GET_IN",
-                "YY_NO_GET_LENG",
-                "YY_NO_GET_LINENO",
-                "YY_NO_GET_LLOC",
-                "YY_NO_GET_LVAL",
-                "YY_NO_GET_OUT",
-                "YY_NO_GET_TEXT",
-                "YY_NO_INPUT",
-                "YY_NO_POP_STATE",
-                "YY_NO_PUSH_STATE",
-                "YY_NO_SCAN_BUFFER",
-                "YY_NO_SCAN_BYTES",
-                "YY_NO_SCAN_STRING",
-                "YY_NO_SET_DEBUG",
-                "YY_NO_SET_EXTRA",
-                "YY_NO_SET_IN",
-                "YY_NO_SET_LINENO",
-                "YY_NO_SET_LLOC",
-                "YY_NO_SET_LVAL",
-                "YY_NO_SET_OUT",
-                "YY_NO_TOP_STATE",
-                "YY_NO_UNISTD_H",
-                "YY_NO_UNPUT",
                 "YY_NULL",
                 "YY_NUM_RULES",
                 "YY_ONLY_ARG",
@@ -750,7 +727,6 @@ void flexend (exit_status)
                 "YY_TRAILING_HEAD_MASK",
                 "YY_TRAILING_MASK",
                 "YY_USER_ACTION",
-                "YY_USES_REJECT",
                 "YY_USE_CONST",
                 "YY_USE_LINENO",
                 "YY_USE_PROTOS",
@@ -1110,6 +1086,7 @@ void flexinit (argc, argv)
        buf_init (&userdef_buf, sizeof (char)); /* one long string */
        buf_init (&defs_buf, sizeof (char *));  /* list of strings */
        buf_init (&yydmap_buf, sizeof (char));  /* one long string */
+       buf_init (&m4defs_buf, sizeof (char *)); /* list of strings */
 
 
        /* Enable C++ if program name ends with '+'. */
@@ -1290,8 +1267,8 @@ void flexinit (argc, argv)
                        break;
 
                case OPT_NO_UNISTD_H:
-                       buf_strdefine (&userdef_buf, "YY_NO_UNISTD_H",
-                                      "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_UNISTD_H", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_UNISTD_H",0);
                        break;
 
                case OPT_TABLES_FILE:
@@ -1455,83 +1432,88 @@ void flexinit (argc, argv)
                        break;
 
                case OPT_NO_YY_PUSH_STATE:
-                       buf_strdefine (&userdef_buf, "YY_NO_PUSH_STATE",
-                                      "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_PUSH_STATE", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_PUSH_STATE",0);
                        break;
                case OPT_NO_YY_POP_STATE:
-                       buf_strdefine (&userdef_buf, "YY_NO_POP_STATE",
-                                      "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_POP_STATE", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_POP_STATE",0);
                        break;
                case OPT_NO_YY_TOP_STATE:
-                       buf_strdefine (&userdef_buf, "YY_NO_TOP_STATE",
-                                      "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_TOP_STATE", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_TOP_STATE",0);
                        break;
                case OPT_NO_UNPUT:
-                       buf_strdefine (&userdef_buf, "YY_NO_UNPUT", "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_UNPUT", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_UNPUT",0);
                        break;
                case OPT_NO_YY_SCAN_BUFFER:
-                       buf_strdefine (&userdef_buf, "YY_NO_SCAN_BUFFER",
-                                      "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_SCAN_BUFFER", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_BUFFER",0);
                        break;
                case OPT_NO_YY_SCAN_BYTES:
-                       buf_strdefine (&userdef_buf, "YY_NO_SCAN_BYTES",
-                                      "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_SCAN_BYTES", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_BYTES",0);
                        break;
                case OPT_NO_YY_SCAN_STRING:
-                       buf_strdefine (&userdef_buf, "YY_NO_SCAN_STRING",
-                                      "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_SCAN_STRING", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_STRING",0);
                        break;
                case OPT_NO_YYGET_EXTRA:
-                       buf_strdefine (&userdef_buf, "YY_NO_GET_EXTRA",
-                                      "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_GET_EXTRA", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_EXTRA",0);
                        break;
                case OPT_NO_YYSET_EXTRA:
-                       buf_strdefine (&userdef_buf, "YY_NO_SET_EXTRA",
-                                      "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_SET_EXTRA", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_EXTRA",0);
                        break;
                case OPT_NO_YYGET_LENG:
-                       buf_strdefine (&userdef_buf, "YY_NO_GET_LENG",
-                                      "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_GET_LENG", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LENG",0);
                        break;
                case OPT_NO_YYGET_TEXT:
-                       buf_strdefine (&userdef_buf, "YY_NO_GET_TEXT",
-                                      "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_GET_TEXT", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_TEXT",0);
                        break;
                case OPT_NO_YYGET_LINENO:
-                       buf_strdefine (&userdef_buf, "YY_NO_GET_LINENO",
-                                      "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_GET_LINENO", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LINENO",0);
                        break;
                case OPT_NO_YYSET_LINENO:
-                       buf_strdefine (&userdef_buf, "YY_NO_SET_LINENO",
-                                      "1");
+                       //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_IN:
-                       buf_strdefine (&userdef_buf, "YY_NO_GET_IN", "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_GET_IN", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_IN",0);
                        break;
                case OPT_NO_YYSET_IN:
-                       buf_strdefine (&userdef_buf, "YY_NO_SET_IN", "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_SET_IN", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_IN",0);
                        break;
                case OPT_NO_YYGET_OUT:
-                       buf_strdefine (&userdef_buf, "YY_NO_GET_OUT", "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_GET_OUT", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_OUT",0);
                        break;
                case OPT_NO_YYSET_OUT:
-                       buf_strdefine (&userdef_buf, "YY_NO_SET_OUT", "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_SET_OUT", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_OUT",0);
                        break;
                case OPT_NO_YYGET_LVAL:
-                       buf_strdefine (&userdef_buf, "YY_NO_GET_LVAL",
-                                      "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_GET_LVAL", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LVAL",0);
                        break;
                case OPT_NO_YYSET_LVAL:
-                       buf_strdefine (&userdef_buf, "YY_NO_SET_LVAL",
-                                      "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_SET_LVAL", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LVAL",0);
                        break;
                case OPT_NO_YYGET_LLOC:
-                       buf_strdefine (&userdef_buf, "YY_NO_GET_LLOC",
-                                      "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_GET_LLOC", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LLOC",0);
                        break;
                case OPT_NO_YYSET_LLOC:
-                       buf_strdefine (&userdef_buf, "YY_NO_SET_LLOC",
-                                      "1");
+                       //buf_strdefine (&userdef_buf, "YY_NO_SET_LLOC", "1");
+            buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LLOC",0);
                        break;
 
                }               /* switch */
@@ -1681,8 +1663,10 @@ void readin ()
                                   ("variable trailing context rules cannot be used with -f or -F"));
        }
 
-       if (reject)
-               outn ("\n#define YY_USES_REJECT");
+       if (reject){
+        buf_m4_define( &m4defs_buf, "M4_YY_USES_REJECT", NULL);
+               //outn ("\n#define YY_USES_REJECT");
+    }
 
        if (!do_yywrap) {
                outn ("\n#define yywrap(n) 1");
diff --git a/misc.c b/misc.c
index 9ff31d4e759a45bd200c280b3066ba29e6b9effe..0801bf8d976f769929ce06cf0c4fcf1bf652ee60 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -111,6 +111,28 @@ void action_define (defname, value)
 }
 
 
+/** Append "m4_define([[defname]],[[value]])m4_dnl\n" to the running buffer.
+ *  @param defname The macro name.
+ *  @param value The macro value, can be NULL, which is the same as the empty string.
+ */
+void action_m4_define (const char *defname, const char * value)
+{
+       char    buf[MAXLINE];
+       char   *cpy;
+
+    flexfatal ("DO NOT USE THIS FUNCTION!");
+
+       if ((int) strlen (defname) > MAXLINE / 2) {
+               format_pinpoint_message (_
+                                        ("name \"%s\" ridiculously long"),
+                                        defname);
+               return;
+       }
+
+       sprintf (buf, "m4_define([[%s]],[[%s]])m4_dnl\n", defname, value?value:"");
+       add_action (buf);
+}
+
 /* Append "new_text" to the running buffer. */
 void add_action (new_text)
      char   *new_text;
diff --git a/scan.l b/scan.l
index 079fafb5a1efc2361364dd461511528e94387365..88b3240ce7e94377b9ee0853a7d5db07d3cc77e1 100644 (file)
--- a/scan.l
+++ b/scan.l
@@ -43,6 +43,12 @@ extern bool tablesverify, tablesext;
                action_define( def, 1 ); \
        }
 
+#define ACTION_M4_IFDEF(def, should_define) \
+    do{ \
+        if ( should_define ) \
+            buf_m4_define( &m4defs_buf, def, NULL);\
+    } while(0)
+
 #define MARK_END_OF_PROLOG mark_prolog();
 
 #define YY_DECL \
@@ -280,7 +286,7 @@ LEXOPT              [aceknopr]
        lex-compat      lex_compat = option_sense;
        posix-compat    posix_compat = option_sense;
        main            {
-                       action_define( "YY_MAIN", option_sense );
+                       ACTION_M4_IFDEF( "M4_YY_MAIN", option_sense);
             /* Override yywrap */
             if( option_sense == true )
                 do_yywrap = false;
@@ -306,34 +312,34 @@ LEXOPT            [aceknopr]
        yymore          yymore_really_used = option_sense;
        yywrap      do_yywrap = option_sense;
 
-       yy_push_state   ACTION_IFDEF("YY_NO_PUSH_STATE", ! option_sense);
-       yy_pop_state    ACTION_IFDEF("YY_NO_POP_STATE", ! option_sense);
-       yy_top_state    ACTION_IFDEF("YY_NO_TOP_STATE", ! option_sense);
-
-       yy_scan_buffer  ACTION_IFDEF("YY_NO_SCAN_BUFFER", ! option_sense);
-       yy_scan_bytes   ACTION_IFDEF("YY_NO_SCAN_BYTES", ! option_sense);
-       yy_scan_string  ACTION_IFDEF("YY_NO_SCAN_STRING", ! option_sense);
-
-    yyalloc         ACTION_IFDEF("YY_NO_FLEX_ALLOC", ! option_sense);
-    yyrealloc       ACTION_IFDEF("YY_NO_FLEX_REALLOC", ! option_sense);
-    yyfree          ACTION_IFDEF("YY_NO_FLEX_FREE", ! option_sense);
-
-    yyget_debug     ACTION_IFDEF("YY_NO_GET_DEBUG", ! option_sense);
-    yyset_debug     ACTION_IFDEF("YY_NO_SET_DEBUG", ! option_sense);
-    yyget_extra     ACTION_IFDEF("YY_NO_GET_EXTRA", ! option_sense);
-    yyset_extra     ACTION_IFDEF("YY_NO_SET_EXTRA", ! option_sense);
-    yyget_leng      ACTION_IFDEF("YY_NO_GET_LENG", ! option_sense);
-    yyget_text      ACTION_IFDEF("YY_NO_GET_TEXT", ! option_sense);
-    yyget_lineno    ACTION_IFDEF("YY_NO_GET_LINENO", ! option_sense);
-    yyset_lineno    ACTION_IFDEF("YY_NO_SET_LINENO", ! option_sense);
-    yyget_in        ACTION_IFDEF("YY_NO_GET_IN", ! option_sense);
-    yyset_in        ACTION_IFDEF("YY_NO_SET_IN", ! option_sense);
-    yyget_out       ACTION_IFDEF("YY_NO_GET_OUT", ! option_sense);
-    yyset_out       ACTION_IFDEF("YY_NO_SET_OUT", ! option_sense);
-    yyget_lval      ACTION_IFDEF("YY_NO_GET_LVAL", ! option_sense);
-    yyset_lval      ACTION_IFDEF("YY_NO_SET_LVAL", ! option_sense);
-    yyget_lloc      ACTION_IFDEF("YY_NO_GET_LLOC", ! option_sense);
-    yyset_lloc      ACTION_IFDEF("YY_NO_SET_LLOC", ! option_sense);
+       yy_push_state   ACTION_M4_IFDEF("M4_YY_NO_PUSH_STATE", ! option_sense);
+       yy_pop_state    ACTION_M4_IFDEF("M4_YY_NO_POP_STATE", ! option_sense);
+       yy_top_state    ACTION_M4_IFDEF("M4_YY_NO_TOP_STATE", ! option_sense);
+
+       yy_scan_buffer  ACTION_M4_IFDEF("M4_YY_NO_SCAN_BUFFER", ! option_sense);
+       yy_scan_bytes   ACTION_M4_IFDEF("M4_YY_NO_SCAN_BYTES", ! option_sense);
+       yy_scan_string  ACTION_M4_IFDEF("M4_YY_NO_SCAN_STRING", ! option_sense);
+
+    yyalloc         ACTION_M4_IFDEF("M4_YY_NO_FLEX_ALLOC", ! option_sense);
+    yyrealloc       ACTION_M4_IFDEF("M4_YY_NO_FLEX_REALLOC", ! option_sense);
+    yyfree          ACTION_M4_IFDEF("M4_YY_NO_FLEX_FREE", ! option_sense);
+
+    yyget_debug     ACTION_M4_IFDEF("M4_YY_NO_GET_DEBUG", ! option_sense);
+    yyset_debug     ACTION_M4_IFDEF("M4_YY_NO_SET_DEBUG", ! option_sense);
+    yyget_extra     ACTION_M4_IFDEF("M4_YY_NO_GET_EXTRA", ! option_sense);
+    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_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);
+    yyset_in        ACTION_M4_IFDEF("M4_YY_NO_SET_IN", ! option_sense);
+    yyget_out       ACTION_M4_IFDEF("M4_YY_NO_GET_OUT", ! option_sense);
+    yyset_out       ACTION_M4_IFDEF("M4_YY_NO_SET_OUT", ! option_sense);
+    yyget_lval      ACTION_M4_IFDEF("M4_YY_NO_GET_LVAL", ! option_sense);
+    yyset_lval      ACTION_M4_IFDEF("M4_YY_NO_SET_LVAL", ! option_sense);
+    yyget_lloc      ACTION_M4_IFDEF("M4_YY_NO_GET_LLOC", ! option_sense);
+    yyset_lloc      ACTION_M4_IFDEF("M4_YY_NO_SET_LLOC", ! option_sense);
 
        outfile         return OPT_OUTFILE;
        prefix          return OPT_PREFIX;