flex-2.5.31 patch

winkie at winkie at
Mon Mar 1 20:28:52 PST 2004


Flex 2.5.31 sucks.
Now it doesn't.
-------------- next part --------------
Submitted By: Zack Winkles <winkie at linuxfromscratch.org>
Date: 2004-03-01
Initial Package Version: 2.5.31
Origin: Debian
Description: This fixes a ton of things. I'm not entirely sure what, but
	it's all stuff that Debian thought to be broken, and I trust them.
	All the non-code changes have been stripped (otherwise it would
	be gargantuan). I've been using this patch for a few months now
	and it makes flex not suck anymore. That's a good thing.

diff -Naur flex-2.5.31.orig/filter.c flex-2.5.31/filter.c
--- flex-2.5.31.orig/filter.c	2003-03-25 11:39:08.000000000 -0500
+++ flex-2.5.31/filter.c	2004-03-01 23:14:28.868777672 -0500
@@ -157,11 +157,15 @@
 		if (chain->filter_func) {
 			int     r;
 
-			/* setup streams again */
+			/* setup streams again  -- Removed. POSIX states that children inherit
+			   open streams in the parent. Also, ANSI C99 states that the stdin
+				 and stdout macors need not be modified lvalues; so this code is 
+				 broken in the first place.
 			if ((stdin = fdopen (0, "r")) == NULL)
 				flexfatal (_("fdopen(0) failed"));
 			if ((stdout = fdopen (1, "w")) == NULL)
 				flexfatal (_("fdopen(1) failed"));
+      */
 
 			if ((r = chain->filter_func (chain)) == -1)
 				flexfatal (_("filter_func failed"));
@@ -181,9 +185,11 @@
 	if (dup2 (pipes[1], 1) == -1)
 		flexfatal (_("dup2(pipes[1],1)"));
 	close (pipes[1]);
+	/* This is not legal; stfout does not need to be a modifiable
+	lvalue 
 	if ((stdout = fdopen (1, "w")) == NULL)
 		flexfatal (_("fdopen(1) failed"));
-
+	*/
 	return true;
 }
 
diff -Naur flex-2.5.31.orig/flex.skl flex-2.5.31/flex.skl
--- flex-2.5.31.orig/flex.skl	2003-03-31 20:51:38.000000000 -0500
+++ flex-2.5.31/flex.skl	2004-03-01 23:14:28.870777368 -0500
@@ -27,6 +27,11 @@
 %# Macros for runtime processing stage.
 m4_changecom
 m4_changequote
+
+%# Let user use our quoting strings
+m4_changequote({, })
+m4_define( {m4_userquote_start}, {m4_changequote(<, >)[[m4_changequote([[, ]])})
+m4_define( {m4_userquote_end}, {m4_changequote(<, >)]]m4_changequote([[, ]])})
 m4_changequote([[, ]])
 
 %# 
@@ -345,19 +350,19 @@
 %#        yyscan_t yyscanner;
 %#
 %# Generate traditional function defs
-    m4_define( [[YYFARGS0]], [[(M4_YY_DEF_ONLY_ARG)
+    m4_define( [[YYFARGS0]], [[(M4_YY_DEF_ONLY_ARG) [[\]]
         M4_YY_DECL_LAST_ARG]])
-    m4_define( [[YYFARGS1]], [[($2 M4_YY_DEF_LAST_ARG)
-        $1 $2;
+    m4_define( [[YYFARGS1]], [[($2 M4_YY_DEF_LAST_ARG) [[\]]
+        $1 $2; [[\]]
         M4_YY_DECL_LAST_ARG]])
-    m4_define( [[YYFARGS2]], [[($2,$4 M4_YY_DEF_LAST_ARG)
-        $1 $2;
-        $3 $4;
+    m4_define( [[YYFARGS2]], [[($2,$4 M4_YY_DEF_LAST_ARG) [[\]]
+        $1 $2; [[\]]
+        $3 $4; [[\]]
         M4_YY_DECL_LAST_ARG]])
-    m4_define( [[YYFARGS3]], [[($2,$4,$6 M4_YY_DEF_LAST_ARG)
-        $1 $2;
-        $3 $4;
-        $5 $6;
+    m4_define( [[YYFARGS3]], [[($2,$4,$6 M4_YY_DEF_LAST_ARG) [[\]]
+        $1 $2; [[\]]
+        $3 $4; [[\]]
+        $5 $6; [[\]]
         M4_YY_DECL_LAST_ARG]])
 ]],
 [[
@@ -724,6 +729,7 @@
 
 m4_ifdef( [[M4_YY_NO_UNISTD_H]],,
 [[
+#ifndef YY_NO_UNISTD_H
 /* Special case for "unistd.h", since it is non-ANSI. We include it way
  * 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.
@@ -734,6 +740,7 @@
 %if-c++-only
 #include <unistd.h>
 %endif
+#endif
 ]])
 
 #ifndef YY_EXTRA_TYPE
@@ -1124,9 +1131,9 @@
     m4_dnl  The bison pure parser is used. Redefine yylex to
     m4_dnl  accept the lval parameter.
 
-    m4_define( [[M4_YY_LEX_PROTO]],
+    m4_define( [[M4_YY_LEX_PROTO]], [[\]]
                [[M4_YY_PARAMS(YYSTYPE * yylval_param M4_YY_PROTO_LAST_ARG)]])
-    m4_define( [[M4_YY_LEX_DECLARATION]],
+    m4_define( [[M4_YY_LEX_DECLARATION]], [[\]]
                [[YYFARGS1(YYSTYPE *,yylval_param)]])
 ]])
 
@@ -1134,9 +1141,9 @@
 [[
     m4_dnl  Locations are used. yylex should also accept the ylloc parameter.
 
-    m4_define( [[M4_YY_LEX_PROTO]],
+    m4_define( [[M4_YY_LEX_PROTO]], [[\]]
                [[M4_YY_PARAMS(YYSTYPE * yylval_param, YYLTYPE * yylloc_param M4_YY_PROTO_LAST_ARG)]])
-    m4_define( [[M4_YY_LEX_DECLARATION]],
+    m4_define( [[M4_YY_LEX_DECLARATION]], [[\]]
                [[YYFARGS2(YYSTYPE *,yylval_param, YYLTYPE *,yylloc_param)]])
 ]])
 
@@ -2251,11 +2258,11 @@
  * @note If you want to scan bytes that may contain NUL values, then use
  *       yy_scan_bytes() instead.
  */
-YY_BUFFER_STATE yy_scan_string YYFARGS1( yyconst char *,str)
+YY_BUFFER_STATE yy_scan_string YYFARGS1( yyconst char *,yy_str)
 {
     m4_dnl M4_YY_DECL_GUTS_VAR();
 
-	return yy_scan_bytes( str, strlen(str) M4_YY_CALL_LAST_ARG);
+	return yy_scan_bytes( yy_str, strlen(yy_str) M4_YY_CALL_LAST_ARG);
 }
 %endif
 ]])
diff -Naur flex-2.5.31.orig/gen.c flex-2.5.31/gen.c
--- flex-2.5.31.orig/gen.c	2003-03-30 14:58:44.000000000 -0500
+++ flex-2.5.31/gen.c	2004-03-01 23:14:28.862778584 -0500
@@ -1812,7 +1812,6 @@
 			if (yytext_is_array) {
 				if (!reentrant){
     				indent_puts ("static int yy_more_offset = 0;");
-                }else{
                     indent_puts ("static int yy_prev_more_offset = 0;");
                 }
 			}
diff -Naur flex-2.5.31.orig/main.c flex-2.5.31/main.c
--- flex-2.5.31.orig/main.c	2003-03-31 20:51:38.000000000 -0500
+++ flex-2.5.31/main.c	2004-03-01 23:14:28.863778432 -0500
@@ -199,6 +199,7 @@
 {
 #if ENABLE_NLS
 	setlocale (LC_MESSAGES, "");
+	setlocale (LC_CTYPE, "");
 	textdomain (PACKAGE);
 	bindtextdomain (PACKAGE, LOCALEDIR);
 #endif
@@ -1595,7 +1596,6 @@
 			outn ("#else");
 			outn (yy_stdinit);
 			outn ("#endif");
-			outn ("#endif");
 		}
 
 		else {
diff -Naur flex-2.5.31.orig/scan.c flex-2.5.31/scan.c
--- flex-2.5.31.orig/scan.c	2003-04-01 11:33:17.000000000 -0500
+++ flex-2.5.31/scan.c	2004-03-01 23:14:28.860778888 -0500
@@ -1619,11 +1619,13 @@
 #define LINEDIR 18
 #define CODEBLOCK_MATCH_BRACE 19
 
+#ifndef YY_NO_UNISTD_H
 /* Special case for "unistd.h", since it is non-ANSI. We include it way
  * 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.
  */
 #include <unistd.h>
+#endif
 
 #ifndef YY_EXTRA_TYPE
 #define YY_EXTRA_TYPE void *
diff -Naur flex-2.5.31.orig/scan.l flex-2.5.31/scan.l
--- flex-2.5.31.orig/scan.l	2003-03-31 20:51:38.000000000 -0500
+++ flex-2.5.31/scan.l	2004-03-01 23:14:28.864778280 -0500
@@ -194,8 +194,14 @@
 <COMMENT>{
 	"*/"		ACTION_ECHO; yy_pop_state();
 	"*"		ACTION_ECHO;
-	[^*\n]+		ACTION_ECHO;
-	[^*\n]*{NL}	++linenum; ACTION_ECHO;
+	[\[\]]		ACTION_ECHO;
+	[^*\[\]\n]+	ACTION_ECHO;
+	[^*\[\]\n]*{NL}	++linenum; ACTION_ECHO;
+	\[\[		add_action("[" "[]" "]m4_" "userquote_start()");
+	\]\]		add_action("[" "[]" "]m4_" "userquote_end()");
+			/* Macros need to be clearly separated from surrounding
+			 * text and this file needs to go through flex untouched.
+			 */
 }
 
 <LINEDIR>{
diff -Naur flex-2.5.31.orig/skel.c flex-2.5.31/skel.c
--- flex-2.5.31.orig/skel.c	2003-04-01 11:33:08.000000000 -0500
+++ flex-2.5.31/skel.c	2004-03-01 23:14:28.867777824 -0500
@@ -404,16 +404,16 @@
   "%#        yyscan_t yyscanner;",
   "%#",
   "%# Generate traditional function defs",
-  "    m4_define( [[YYFARGS0]], [[(M4_YY_DEF_ONLY_ARG)",
+  "    m4_define( [[YYFARGS0]], [[(M4_YY_DEF_ONLY_ARG) [[\\]]",
   "        M4_YY_DECL_LAST_ARG]])",
-  "    m4_define( [[YYFARGS1]], [[($2 M4_YY_DEF_LAST_ARG)",
+  "    m4_define( [[YYFARGS1]], [[($2 M4_YY_DEF_LAST_ARG) [[\\]]",
   "        $1 $2;",
   "        M4_YY_DECL_LAST_ARG]])",
-  "    m4_define( [[YYFARGS2]], [[($2,$4 M4_YY_DEF_LAST_ARG)",
+  "    m4_define( [[YYFARGS2]], [[($2,$4 M4_YY_DEF_LAST_ARG) [[\\]]",
   "        $1 $2;",
   "        $3 $4;",
   "        M4_YY_DECL_LAST_ARG]])",
-  "    m4_define( [[YYFARGS3]], [[($2,$4,$6 M4_YY_DEF_LAST_ARG)",
+  "    m4_define( [[YYFARGS3]], [[($2,$4,$6 M4_YY_DEF_LAST_ARG) [[\\]]",
   "        $1 $2;",
   "        $3 $4;",
   "        $5 $6;",
@@ -783,6 +783,7 @@
   "",
   "m4_ifdef( [[M4_YY_NO_UNISTD_H]],,",
   "[[",
+  "#ifndef YY_NO_UNISTD_H",
   "/* Special case for \"unistd.h\", since it is non-ANSI. We include it way",
   " * 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.",
@@ -793,6 +794,7 @@
   "%if-c++-only",
   "#include <unistd.h>",
   "%endif",
+  "#endif",
   "]])",
   "",
   "#ifndef YY_EXTRA_TYPE",
@@ -2454,11 +2456,11 @@
   " * @note If you want to scan bytes that may contain NUL values, then use",
   " *       yy_scan_bytes() instead.",
   " */",
-  "YY_BUFFER_STATE yy_scan_string YYFARGS1( yyconst char *,str)",
+  "YY_BUFFER_STATE yy_scan_string YYFARGS1( yyconst char *,yy_str)",
   "{",
   "    m4_dnl M4_YY_DECL_GUTS_VAR();",
   "",
-  "	return yy_scan_bytes( str, strlen(str) M4_YY_CALL_LAST_ARG);",
+  "	return yy_scan_bytes( yy_str, strlen(yy_str) M4_YY_CALL_LAST_ARG);",
   "}",
   "%endif",
   "]])",


More information about the patches mailing list