This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

fixincludes jumbo patch 2


Here is another jumbo patch for fixincludes.  The only behavioral
change that should happen is that header files that define ioctl
numbers on Linux are no longer mangled.  I am very interested to know
whether the new code works correctly on platforms where the ioctl
number #defines actually need fixing.  fixincl should also run a tad
faster.

I tried replacing the GNU regexp library with the one from 4.4BSD, and
the resulting binary ran 140% faster but used quite a bit more
memory.  Is this a change we want to make?

zw

1999-12-26 11:31 -0800  Zack Weinberg  <zack@wolery.cumb.org>

	* fixfixes.c: Add IO_use, CTRL_use, IO_defn, CTRL_defn to
	FIXUP_TABLE. Change 'const char' to 'tCC' and 'static
	const char' to 'tSCC' throughout, for consistency.  Use
	regcomp(..., REG_EXTENDED|REG_NEWLINE) instead of
	re_set_syntax/re_compile_pattern.
	(FIX_PROC_HEAD): Make the 'text' argument to fix functions
	const.
	(else_endif_label_fix): Compile regexp once and cache it for
	later calls.
	(fix_char_macro_uses, CTRL_use_fix, IO_use_fix, CTRL_defn_fix,
	IO_defn_fix): New functions.

	* fixincl.c: Fix all warnings, minor optimizations:
	(struct fix_desc): Remove unused field.
	(wait_for_pid): Remove unused label.
	(run_compiles): Use regcomp instead of re_compile_pattern.
	Const-ify a char *.  Use REG_NOSUB for patterns where we don't
	care where they matched.
	(egrep_test): Tell regexec it doesn't need to tell us where it
	matched.
	(start_fixer): Initialize pz_cmd and pz_cmd_save at
	definition.  Remove unnecessary cast.
	(process): Remove unused variable.

	* fixincl.tpl: Massive simplifications.  Do all calculations
	internally; never use _shell.  Reduce number of unnecessary
	defines.  Don't number fixes unless -DDEBUG.  Make the
	displayed name of the fix match the name in the source file.
	* hackshell.tpl: Likewise.

	* fixtests.c (is_cxx_header): Look for "template <" or
	"template<" in the file text, too.
	(else_endif_label): Use regcomp.

	* inclhack.def: Change fixes that use sed to create a brand
	new file to use 'replace =' instead.  Never quote file names
	or c_test/c_fix names.  Remove duplicated fixes for ISC Unix.
	Use the new IO_defn, IO_use, CTRL_defn, CTRL_use C fixes to
	fix ioctl macros.  Don't use globs in file names.

===================================================================
Index: fixfixes.c
--- fixfixes.c	1999/12/17 21:49:30	1.5
+++ fixfixes.c	1999/12/26 19:18:55
@@ -67,20 +67,22 @@ Boston, MA 02111-1307, USA.  */
 #include "fixlib.h"
 
 typedef struct {
-    const char*  fix_name;
+    tCC *fix_name;
     void (*fix_proc)();
 } fix_entry_t;
 
 #define FIXUP_TABLE \
   _FT_( "no_double_slash",  double_slash_fix ) \
-  _FT_( "else_endif_label", else_endif_label_fix )
+  _FT_( "else_endif_label", else_endif_label_fix ) \
+  _FT_( "IO_use",	    IO_use_fix ) \
+  _FT_( "CTRL_use",	    CTRL_use_fix ) \
+  _FT_( "IO_defn",	    IO_defn_fix ) \
+  _FT_( "CTRL_defn",	    CTRL_defn_fix )
 
-
 #define FIX_PROC_HEAD( fix ) \
 static void fix ( filname, text ) \
-    const char* filname; \
-    char* text;
-
+    tCC  *filname ATTRIBUTE_UNUSED; \
+    tCC  *text;
 
 /*
  *  Skip over a quoted string.  Single quote strings may
@@ -88,10 +90,10 @@ static void fix ( filname, text ) \
  *  a backslash.  Especially a backslash followed by octal digits.
  *  We are not doing a correctness syntax check here.
  */
-static char*
+static tCC *
 print_quote( q, text )
-  char  q;
-  char* text;
+  char q;
+  tCC  *text;
 {
   fputc( q, stdout );
 
@@ -119,8 +121,8 @@ print_quote( q, text )
         case NUL:
           goto quote_done;
         }
-    } quote_done:;
-
+    }
+ quote_done:
   return text;
 }
 
@@ -184,16 +186,19 @@ FIX_PROC_HEAD( double_slash_fix )
 
 FIX_PROC_HEAD( else_endif_label_fix )
 {
-  static const char label_pat[] = "^[ \t]*#[ \t]*(else|endif)";
+  tSCC label_pat[] = "^[ \t]*#[ \t]*(else|endif)";
   static regex_t label_re;
+  static int compiled = 0;
 
   char ch;
-  char* pz_next = (char*)NULL;
+  tCC  *pz_next = 0;
   regmatch_t match[2];
 
-  re_set_syntax (RE_SYNTAX_EGREP);
-  (void)re_compile_pattern (label_pat, sizeof (label_pat)-1,
-                            &label_re);
+  if (!compiled)
+    {
+      regcomp (&label_re, label_pat, REG_EXTENDED|REG_NEWLINE);
+      compiled = 1;
+    }
 
   for (;;) /* entire file */
     {
@@ -355,6 +360,180 @@ FIX_PROC_HEAD( else_endif_label_fix )
   return;
 }
 
+/* Common routines used by the various ioctl fixes.  */
+
+void
+fix_char_macro_uses (text, str)
+     tCC *text;
+     tCC *str;
+{
+  tSCC pat[] =
+    "^[ \t]*#[ \t]*define[ \t]+[A-Za-z_][A-Za-z0-9_]*[ \t]+";
+  static regex_t re;
+  static int compiled = 0;
+
+  regmatch_t rm[1];
+  tCC *p, *limit;
+  size_t len = strlen (str);
+
+  if (!compiled)
+    {
+      regcomp (&re, pat, REG_EXTENDED|REG_NEWLINE);
+      compiled = 1;
+    }
+
+  for (p = text; *p; p = limit)
+    {
+      if (regexec (&re, p, 1, rm, 0))
+	goto done;
+      p += rm[0].rm_eo;
+      /* p now points to the first character of the macro replacement.
+	 Scan forward for the STR we were sent to look for.  LIMIT is the
+	 first non-escaped newline following.  We assume no one's put an
+	 escaped newline in the middle of STR.  */
+      limit = p;
+      do
+	{
+	  limit = strchr (limit, '\n');
+	  if (!limit)
+	    goto done;
+	}
+      while (limit[-1] == '\\');
+      limit++;
+
+      do
+	{
+	  if (*p == str[0] && !strncmp (p, str, len))
+	    break;
+	}
+      while (++p < limit);
+      if (p >= limit)
+	continue;
+
+      /* Found it.  The next few characters will be whitespace or
+	 uppercase, then an open paren, then a single letter.  */
+      while ((isspace (*p) || isupper (*p)) && p < limit) p++;
+      if (p >= limit)
+	continue;
+      if (*p++ != '(')
+	continue;
+      if (!isalpha (*p))
+	continue;
+      if (isalnum (p[1]) || p[1] == '_')
+	continue;
+
+      /* Splat all preceding text into the output buffer,
+	 quote the character at p, then proceed.  */
+      fwrite (text, 1, p - text, stdout);
+      putchar('\'');
+      putchar(*p);
+      putchar('\'');
+      text = p + 1;
+    }
+ done:
+  fputs(text, stdout);
+}
+
+void
+fix_char_macro_defines (text, str)
+     tCC *text;
+     tCC *str;
+{
+  tSCC pat[] =
+    "^[ \t]*#[ \t]*define[ \t]+";
+  static regex_t re;
+  static int compiled = 0;
+
+  regmatch_t rm[1];
+  tCC *p, *limit;
+  size_t len = strlen (str);
+  char arg;
+
+  if (!compiled)
+    {
+      regcomp (&re, pat, REG_EXTENDED|REG_NEWLINE);
+      compiled = 1;
+    }
+
+  for (p = text; *p; p = limit)
+    {
+      if (regexec (&re, p, 1, rm, 0))
+	goto done;
+      p += rm[0].rm_eo;
+      /* p now points to the first character of the macro name.
+	 Determine the end - the next non-escaped newline following.
+	 We assume no one's put a backslash-newline in an awkward place.  */
+      limit = p;
+      do
+	{
+	  limit = strchr (limit, '\n');
+	  if (!limit)
+	    goto done;
+	}
+      while (limit[-1] == '\\');
+      limit++;
+
+      /* The first few characters of the name are a prefix, which may
+	 be uppercase, numeric, or underscore.  Then we have the
+	 string passed in, and then we have an open paren with _no_
+	 intervening white space.  */
+      for (;;)
+	{
+	  if (*p == str[0] && !strncmp (p, str, len))
+	    break;
+	  if (isupper (*p) || isdigit (*p) || *p == '_')
+	    p++;
+	  else
+	    goto skip;
+	}
+      p += len;
+      if (*p++ != '(')
+	continue;
+
+      /* The next letter is the one to look for in the following text.  */
+      arg = *p++;
+
+      while (p < limit)
+	{
+	  if (p[-1] == '\'' && p[0] == arg && p[1] == '\'')
+	    {
+	      /* Remove the quotes from this use of ARG.  */
+	      p--;
+	      fwrite (text, 1, p - text, stdout);
+	      putchar (arg);
+	      p += 3;
+	      text = p;
+	    }
+	  else
+	    p++;
+	}
+
+    skip: ;
+    }
+ done:
+  fputs(text, stdout);
+}
+
+/* The various prefixes on these macros are handled automatically
+   because the fixers don't care where they start matching.  */
+FIX_PROC_HEAD( IO_use_fix )
+{
+  fix_char_macro_uses (text, "IO");
+}
+FIX_PROC_HEAD( CTRL_use_fix )
+{
+  fix_char_macro_uses (text, "CTRL");
+}
+
+FIX_PROC_HEAD( IO_defn_fix )
+{
+  fix_char_macro_defines (text, "IO");
+}
+FIX_PROC_HEAD( CTRL_defn_fix )
+{
+  fix_char_macro_defines (text, "CTRL");
+}
+
 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
 
      test for fix selector
@@ -364,8 +543,8 @@ FIX_PROC_HEAD( else_endif_label_fix )
 */
 void
 apply_fix( fixname, filname )
-  const char* fixname;
-  const char* filname;
+  tCC *fixname;
+  tCC *filname;
 {
 #define _FT_(n,p) { n, p },
   static fix_entry_t fix_table[] = { FIXUP_TABLE { NULL, NULL }};
===================================================================
Index: fixincl.c
--- fixincl.c	1999/12/17 21:49:30	1.22
+++ fixincl.c	1999/12/26 19:18:55
@@ -91,7 +91,6 @@ struct fix_desc
   const char*   fix_name;       /* Name of the fix */
   const char*   file_list;      /* List of files it applies to */
   const char**  papz_machs;     /* List of machine/os-es it applies to */
-  regex_t*      unused;
   int           test_ct;
   int           fd_flags;
   tTestDesc*    p_test_desc;
@@ -468,7 +467,7 @@ wait_for_pid(child)
           return;
         }
       }
-  } done_waiting:;
+  }
 }
 #endif /* NO_BOGOSITY */
 
@@ -539,7 +538,7 @@ run_compiles ()
   tTestDesc *p_test;
   int test_ct;
   int re_ct = REGEX_COUNT;
-  const char *pz_err;
+  int rc_err;
   regex_t *p_re = (regex_t *) malloc (REGEX_COUNT * sizeof (regex_t));
 
   if (p_re == (regex_t *) NULL)
@@ -549,8 +548,7 @@ run_compiles ()
       exit (EXIT_FAILURE);
     }
 
-  /*  Make sure re_compile_pattern does not stumble across invalid
-      data */
+  /*  Make sure regcomp does not stumble across invalid data */
 
   memset ( (void*)p_re, '\0', REGEX_COUNT * sizeof (regex_t) );
   memset ( (void*)&incl_quote_re, '\0', sizeof (regex_t) );
@@ -558,15 +556,15 @@ run_compiles ()
   /*  The patterns we search for are all egrep patterns.
       In the shell version of this program, we invoke egrep
       with the supplied pattern.  Here, we will run
-      re_compile_pattern, but it must be using the same rules.  */
+      regcomp, but it must be using the same rules.  */
 
-  re_set_syntax (RE_SYNTAX_EGREP);
-  pz_err = re_compile_pattern (incl_quote_pat, sizeof (incl_quote_pat)-1,
-                              &incl_quote_re);
-  if (pz_err != (char *) NULL)
+  rc_err = regcomp (&incl_quote_re, incl_quote_pat, REG_EXTENDED|REG_NEWLINE);
+  if (rc_err)
     {
+      char rerrbuf[1024];
+      regerror(rc_err, &incl_quote_re, rerrbuf, 1024);
       fprintf (stderr, z_bad_comp, "quoted include", "run_compiles",
-               incl_quote_pat, pz_err);
+               incl_quote_pat, rerrbuf);
       exit (EXIT_FAILURE);
     }
 
@@ -592,7 +590,7 @@ run_compiles ()
 
           const char **papz_machs = p_fixd->papz_machs;
           char *pz;
-          char *pz_sep = "";
+          tCC *pz_sep = "";
           tCC *pz_if_true;
           tCC *pz_if_false;
           char cmd_buf[ MACH_LIST_SIZE_LIMIT ]; /* size lim from fixincl.tpl */
@@ -668,15 +666,20 @@ run_compiles ()
                 }
 
               p_test->p_test_regex = p_re++;
-              pz_err = re_compile_pattern (p_test->pz_test_text,
-                                          strlen (p_test->pz_test_text),
-                                          p_test->p_test_regex);
-              if (pz_err != (char *) NULL)
-                {
-                  fprintf (stderr, z_bad_comp, "select test", p_fixd->fix_name,
-                           p_test->pz_test_text, pz_err);
-                  exit (EXIT_FAILURE);
-                }
+	      rc_err = regcomp (p_test->p_test_regex,
+				p_test->pz_test_text,
+				REG_EXTENDED|REG_NEWLINE|REG_NOSUB);
+	      if (rc_err)
+		{
+		  char rerrbuf[1024];
+		  regerror(rc_err, p_test->p_test_regex, rerrbuf, 1024);
+		  fprintf (stderr, z_bad_comp, "select test",
+			   p_fixd->fix_name, p_test->pz_test_text, rerrbuf);
+		  exit (EXIT_FAILURE);
+		}
+	    case TT_TEST:
+	    case TT_FUNCTION:
+	      /* Nothing to do for these.  */
             }
           p_test++;
         }
@@ -814,14 +817,12 @@ egrep_test (pz_data, p_test)
      char *pz_data;
      tTestDesc *p_test;
 {
-  regmatch_t match;
-
 #ifdef DEBUG
   if (p_test->p_test_regex == 0)
     fprintf (stderr, "fixincl ERROR RE not compiled:  `%s'\n",
              p_test->pz_test_text);
 #endif
-  if (regexec (p_test->p_test_regex, pz_data, 1, &match, 0) == 0)
+  if (regexec (p_test->p_test_regex, pz_data, 0, 0, 0) == 0)
     return APPLY_FIX;
   return SKIP_FIX;
 }
@@ -1033,15 +1034,13 @@ start_fixer (read_fd, p_fixd, pz_fix_fil
   tFixDesc* p_fixd;
   char* pz_fix_file;
 {
-  tCC* pz_cmd_save;
-  char* pz_cmd;
+  tCC* pz_cmd_save = (const char *)NULL;
+  char* pz_cmd = (char *)NULL;
 
   if ((p_fixd->fd_flags & FD_SUBROUTINE) != 0)
     return internal_fix (read_fd, p_fixd);
 
-  if ((p_fixd->fd_flags & FD_SHELL_SCRIPT) == 0)
-    pz_cmd = (char*)NULL;
-  else
+  if ((p_fixd->fd_flags & FD_SHELL_SCRIPT) != 0)
     {
       tSCC z_cmd_fmt[] = "file='%s'\n%s";
       pz_cmd = (char*)malloc (strlen (p_fixd->patch_args[2])
@@ -1068,8 +1067,7 @@ start_fixer (read_fd, p_fixd, pz_fix_fil
       static int failCt = 0;
       int fd;
 
-      fd = chain_open (read_fd,
-                       (t_pchar *) p_fixd->patch_args,
+      fd = chain_open (read_fd, p_fixd->patch_args,
                        (process_chain_head == -1)
                        ? &process_chain_head : (pid_t *) NULL);
 
@@ -1317,7 +1315,6 @@ test_for_changes (read_fd)
 void
 process ()
 {
-  static char env_current_file[1024];
   tFixDesc *p_fixd = fixDescList;
   int todo_ct = FIX_COUNT;
   int read_fd = -1;
===================================================================
Index: fixincl.tpl
--- fixincl.tpl	1999/10/12 14:31:20	1.9
+++ fixincl.tpl	1999/12/26 19:18:55
@@ -1,7 +1,7 @@
 [= autogen template -*- Mode: C -*-
 x =]
 /*
- *  DO NOT EDIT THIS FILE - it has been generated
+[=_eval "# *  " _dne=]
  *
  * Install modified versions of certain ANSI-incompatible system header
  * files which are fixed to work correctly with ANSI C and placed in a
@@ -15,104 +15,42 @@ x =]
                                 =] The Free Software Foundation, Inc.
  *
 [=_eval inclhack "# *  " _gpl=]
- *[=_EVAL "re_ct=0\nmax_mach=0" _shell=][=
-
-_FOR fix =]
- *
+ */
+[=_SETENV re_ct 0 =][=_SETENV max_mach 0 =]
+[=_FOR fix
+=]/* * * * * * * * * * * * * * * * * * * * * * * * * *
  *  Description of [=hackname _Cap=] fix
  */
-#define [=hackname _up #_FIXIDX + #%-32s _printf=] [=_eval _index=]
-tSCC z[=hackname _cap=]Name[] =
-     [=hackname _cap _krstr=];
+[=_IF FIXINC_DEBUG _exist
+=]#define [=hackname _up #_FIXIDX + #%-32s _printf=] [=_eval _index=][=_ENDIF
+=][=
+
+   _IF files _exist
+=]
 /*
  *  File name selection pattern
- */[=
-
-  _IF files _exist=]
+ */
 tSCC z[=hackname _cap=]List[] =
-  "[=_FOR files =]|[=files=][=/files=]|";[=
+  "[=_FOR files =]|[=files=][=/files=]|";
+[= _ENDIF =][=
 
-  _ELSE =]
-#define z[=hackname _cap=]List (char*)NULL[=
-  _ENDIF "files _exist" =]
+   _IF mach _exist=][=_SETENV this_mach 0
+=]
 /*
  *  Machine/OS name selection pattern
- */[=
-
-  _IF mach _exist=]
+ */
 tSCC* apz[=hackname _cap=]Machs[] = {[=
-    _EVAL "this_mach=0" _shell =][=
 
     _FOR mach =]
         [=mach _krstr=],[=
-      _EVAL mach _len "this_mach=`expr $this_mach + %d + 5`"
-            _printf _shell =][=
+      _SETENV this_mach this_mach _env _val mach _len 5 + + =][=
     /mach=]
-        (const char*)NULL };[=
+        0 };
+[=
+    _SETENV max_mach _mark this_mach _env _val max_mach _env _val _max
+=][= _ENDIF =][=
 
-    _EVAL "if [ $this_mach -gt $max_mach ] ; then max_mach=$this_mach ; fi"
-          _shell =][=
 
-  _ELSE =]
-#define apz[=hackname _cap=]Machs (const char**)NULL[=
-  _ENDIF "files _exist" =][=
-
-  _IF exesel _exist=]
-
-/*
- *  content selection pattern - do fix if pattern found
- *  This is a special pattern that not all egrep commands
- *  are capable of coping with.  We use the GNU library, tho :)
- */[=
-    _FOR exesel =]
-tSCC z[=hackname _cap=]Select[=_eval _index=][] =
-       [=exesel _krstr=];[=
-    /exesel =][=
-
-  _ELIF select _exist=]
-
-/*
- *  content selection pattern - do fix if pattern found
- */[=
-    _FOR select =]
-tSCC z[=hackname _cap=]Select[=_eval _index=][] =
-       [=select _krstr=];[=
-    /select =][=
-  _ENDIF =][=
-
-  _IF bypass _exist=]
-
-/*
- *  content bypass pattern - skip fix if pattern found
- */[=
-    _FOR bypass =]
-tSCC z[=hackname _cap=]Bypass[=_eval _index=][] =
-       [=bypass _krstr=];[=
-    /bypass =][=
-  _ENDIF =][=
-
-  _IF test _exist=]
-
-/*
- *  perform the 'test' shell command - do fix on success
- */[=
-    _FOR test =]
-tSCC z[=hackname _cap=]Test[=_eval _index=][] =
-       [=test _krstr=];[=
-    /test =][=
-  _ENDIF =][=
-
-  _IF c_test _exist=]
-
-/*
- *  perform the C function call test
- */[=
-    _FOR c_test =]
-tSCC z[=hackname _cap=]FTst[=_eval _index=][] = "[=c_test=]";[=
-    /c_test =][=
-  _ENDIF =][=
-
-
 #  Build the array of test descriptions for this fix: =][=
 
   _IF exesel  _exist
@@ -121,41 +59,35 @@ tSCC z[=hackname _cap=]FTst[=_eval _inde
       test    _exist |
       c_test  _exist |
 =]
-
+/*
+ * Content based tests
+ */
 #define    [=hackname _up =]_TEST_CT  [=
     _IF exesel _exist =][=
        _eval exesel       _count
       	     bypass       _count +
       	     test         _count + 
       	     c_test       _count + =][=
+       _setenv re_ct re_ct _env _val exesel _count bypass _count + + =][=
     _ELSE =][=
        _eval select       _count
       	     bypass       _count +
       	     test         _count + 
       	     c_test       _count + =][=
+       _setenv re_ct re_ct _env _val select _count bypass _count + + =][=
     _ENDIF =]
-#define    [=hackname _up =]_RE_CT    [=
-    _IF exesel _exist =][=
-       _eval exesel _count bypass _count
-             "#2$ct=`expr %d + %d` ; re_ct=`expr $ct + $re_ct` ; echo $ct"
-             _printf _shell =][=
-    _ELSE =][=
-       _eval select _count bypass _count
-             "#2$ct=`expr %d + %d` ; re_ct=`expr $ct + $re_ct` ; echo $ct"
-             _printf _shell =][=
-    _ENDIF =]
 tTestDesc a[=hackname _cap=]Tests[] = {[=
 
     _FOR test =]
-  { TT_TEST,     z[=hackname _cap=]Test[=_eval _index=],   0 /* unused */ },[=
+  { TT_TEST,     [=test _krstr=], 0 },[=
     /test =][=
 
     _FOR c_test =]
-  { TT_FUNCTION, z[=hackname _cap=]FTst[=_eval _index=],   0 /* unused */ },[=
+  { TT_FUNCTION, [=c_test _krstr=], 0 },[=
     /c_test =][=
 
     _FOR bypass =]
-  { TT_NEGREP,   z[=hackname _cap=]Bypass[=_eval _index=], (regex_t*)NULL },[=
+  { TT_NEGREP,   [=bypass _krstr=], 0 },[=
     /bypass =][=
 
     #  IF there is an exesel, then use that (those) selection
@@ -163,22 +95,21 @@ tTestDesc a[=hackname _cap=]Tests[] = {[
     =][=
     _IF exesel _exist =][=
       _FOR exesel =]
-  { TT_EGREP,    z[=hackname _cap=]Select[=_eval _index=], (regex_t*)NULL },[=
+  { TT_EGREP,    [=exesel _krstr=], 0 },[=
       /exesel =][=
 
     _ELSE =][=
       _FOR select =]
-  { TT_EGREP,    z[=hackname _cap=]Select[=_eval _index=], (regex_t*)NULL },[=
+  { TT_EGREP,   [=select _krstr=], 0 },[=
       /select =][=
     _ENDIF =] };[=
   _ELSE =]
 #define [=hackname _up=]_TEST_CT  0
-#define [=hackname _up=]_RE_CT    0
-#define a[=hackname _cap=]Tests   (tTestDesc*)NULL[=
+#define a[=hackname _cap=]Tests    0[=
   _ENDIF =]
 
 /*
- *  Fix Command Arguments for [=hackname _cap=]
+ *  Fix operation
  */
 const char* apz[=hackname _cap=]Patch[] = {[=
     _IF   sed         _exist =] "sed"[=
@@ -195,29 +126,30 @@ const char* apz[=hackname _cap=]Patch[] 
 [=replace _krstr=],[=
 
     _ENDIF=]
-    (char*)NULL };
+    0 };
 
-/* * * * * * * * * * * * * * * * * * * * * * * * * *[=
-/fix=]
- *
+[=/fix=]
+/*
  *  List of all fixes
  */
-[=_EVAL '
-echo "#define REGEX_COUNT          $re_ct"
-echo "#define MACH_LIST_SIZE_LIMIT `expr $max_mach + 128`" ' _shell =][=
+#define REGEX_COUNT		[=_eval re_ct _env=]
+#define MACH_LIST_SIZE_LIMIT	[=_eval max_mach _env _val 128 + =][=
 
 #  as of this writing, 49 bytes are needed by the case statement format.
    We also must allow for the size of the target machine machine name.
-   This allows for a 79 byte machine name.  Better be enough.
-=]
-#define FIX_COUNT            [=_eval fix _count =]
+   This allows for a 79 byte machine name.  Better be enough. =]
+#define FIX_COUNT		[=_eval fix _count =]
 
 tFixDesc fixDescList[ FIX_COUNT ] = {[=
 
-
 _FOR fix ",\n" =]
-  {  z[=hackname _cap=]Name,    z[=hackname _cap=]List,
-     apz[=hackname _cap=]Machs, (regex_t*)NULL,
+  {  [=hackname _krstr=],
+     [=
+       _IF files _exist =]z[=hackname _cap=]List, [=
+       _ELSE =]0 /* all files */, [=_ENDIF=][=
+       _IF mach _exist =]apz[=hackname _cap=]Machs,[=
+       _ELSE =]0 /* all machs */,[=_ENDIF
+     =]
      [=hackname  _up=]_TEST_CT, [=
        _IF not_machine _exist =]FD_MACH_IFNOT[=
        _ELSE                  =]FD_MACH_ONLY[=
===================================================================
Index: fixtests.c
--- fixtests.c	1999/12/17 21:49:30	1.6
+++ fixtests.c	1999/12/26 19:18:56
@@ -121,6 +121,11 @@ is_cxx_header (fname, text)
   /* Or it might contain the phrase 'extern "C++"' */
   if (strstr( text, "extern \"C++\"" ) != NULL)
     return SKIP_FIX;
+  /* Or the phrase 'template <' */
+  if (strstr( text, "template<" ) != NULL)
+    return SKIP_FIX;
+  if (strstr( text, "template <" ) != NULL)
+    return SKIP_FIX;
 
   return APPLY_FIX;
 }
@@ -187,10 +192,8 @@ TEST_FOR_FIX_PROC_HEAD( else_endif_label
      we waste 10 bytes of memory and a test, branch and increment delay.  */
   if (! compiled)
     {
-      compiled++;
-      re_set_syntax (RE_SYNTAX_EGREP);
-      (void)re_compile_pattern (label_pat, sizeof (label_pat)-1,
-                                &label_re);
+      regcomp(&label_re, label_pat, REG_EXTENDED|REG_NEWLINE);
+      compiled = 1;
     }
 
   for (;;) /* entire file */
@@ -353,7 +356,6 @@ main( argc, argv )
   char* fname = *++argv;
   char* tname = *++argv;
   char* buf;
-  size_t buf_size = 0;
 
   if (argc != 3)
     return run_test( "No test name provided", NULL, NULL, 0 );
===================================================================
Index: hackshell.tpl
--- hackshell.tpl	1999/12/17 21:49:30	1.11
+++ hackshell.tpl	1999/12/26 19:18:56
@@ -24,7 +24,9 @@
 
 _FOR fix "\n\n" =]
     #
-    # Fix [=_eval _index 1 + #%3d _printf=]:  [=hackname _Cap=]
+    # Fix [=
+	_IF FIXINC_DEBUG _exist =][=_eval _index 1 + #%3d _printf=]:  [=
+	_ENDIF =][=hackname _Cap=]
     #[=
     _IF files _exist=]
     case "${file}" in [=_FOR files " | \\\n\t"=]./[=files=][=/files=] )[=
@@ -117,12 +119,12 @@ _FOR fix "\n\n" =]
     _ELIF replace _exist =][=
 
       _IF replace _len 0 > =]
-    echo "[=hackname _down=] replacing file ${file}" >&2
+    echo "[=hackname =] replacing file ${file}" >&2
     cat > ${DESTFILE} << '_EOF_'
 [=replace=]
 _EOF_[=
       _ELSE =]
-    echo "[=hackname _down=] bypassing file ${file}"[=
+    echo "[=hackname =] bypassing file ${file}"[=
       _ENDIF =]
     continue
 [=
===================================================================
Index: inclhack.def
--- inclhack.def	1999/12/17 21:49:30	1.44
+++ inclhack.def	1999/12/26 19:18:56
@@ -10,7 +10,9 @@ Please see the README before adding or c
 
 Now, first:  DO NOT DO BROKEN FIXES (empty replacement fixes) */
 
-
+#ifdef DEBUG
+FIXINC_DEBUG = yes;
+#endif
 
 /*
  *  Purge some HP-UX 11 files that are only borken after they are "fixed".
@@ -278,6 +280,45 @@ fix = {
 
 
 /*
+ *  Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
+ *  declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
+ *  many other systems have similar text but correct versions of the file.
+ *  To ensure only Sun's is fixed, we grep for a likely unique string.
+ *  Fix also on sysV68 R3V7.1 (head/memory.h\t50.1\t )
+ */
+fix = {
+    hackname = AAB_sun_memcpy;
+    files    = memory.h;
+    select = "/\\*\t@\\(#\\)"
+             "(head/memory.h\t50.1\t "
+             "|memory\\.h 1\\.[2-4] 8./../.. SMI; from S5R2 1\\.2\t)\\*/";
+
+    replace =
+'/* This file was generated by fixincludes */
+\#ifndef __memory_h__
+\#define __memory_h__
+
+\#ifdef __STDC__
+extern void *memccpy();
+extern void *memchr();
+extern void *memcpy();
+extern void *memset();
+\#else
+extern char *memccpy();
+extern char *memchr();
+extern char *memcpy();
+extern char *memset();
+\#endif /* __STDC__ */
+
+extern int memcmp();
+
+\#endif /* __memory_h__ */
+';
+
+};
+
+
+/*
  *  Completely replace <sys/byteorder.h>; with a file that implements gcc's
  *  optimized byteswapping.  Restricted to "SVR4" machines until either
  *  it is shown to be safe to replace this file always, or we get bolder ;-)
@@ -464,6 +505,17 @@ fix = {
 
 
 /*
+ *  Cancel out ansi_compat.h on Ultrix.  Replace it with an empty file.
+ */
+fix = {
+    hackname = AAB_ultrix_ansi_compat;
+    files    = ansi_compat.h;
+    select   = ULTRIX;
+    replace  = "/* This file intentionally left blank.  */\n";
+};
+
+
+/*
  *  sys/wait.h on AIX 3.2.5 puts the declaration of wait3 before the definition
  *  of struct rusage, so the prototype (added by fixproto) causes havoc.
  */
@@ -496,8 +548,8 @@ fix = {
  */
 fix = {
     hackname = alpha_getopt;
-    files  = "stdio.h";
-    files  = "stdlib.h";
+    files  = stdio.h;
+    files  = stdlib.h;
     select = 'getopt\(int, char \*\[';
     sed    = 's/getopt(int, char \*\[\],[ ]*char \*)/'
                'getopt(int, char *const[], const char *)/';
@@ -533,7 +585,7 @@ fix = {
 fix = {
     hackname = arm_norcroft_hint;
     select   = "___type p_type";
-    files    = "X11/Intrinsic.h";
+    files    = X11/Intrinsic.h;
     sed      = "s/___type p_type/p_type/";
 };
 
@@ -694,21 +746,6 @@ fix = {
 
 
 /*
- *  Note that BSD43_* are used on recent MIPS systems.
- */
-fix = {
-    hackname = bsd43_io_macros;
-    select   = "BSD43__IO";
-    /*
-     *  Put single quotes aroung the character that appears after '('
-     *  and before ',', UNLESS it is a 'c' or 'g' or 'x'.
-     */
-    sed = "/[ \t]BSD43__IO[A-Z]*[ \t]*(/"       's/(\(.\),/(\'\1\',/';
-    sed = "/#[ \t]*define[ \t]*[ \t]BSD43__IO/" 's/\'\([cgx]\)\'/\1/g';
-};
-
-
-/*
  *  Fix <c_asm.h> on Digital UNIX V4.0:
  *  It contains a prototype for a DEC C internal asm() function,
  *  clashing with gcc's asm keyword.  So protect this with __DECC.
@@ -730,8 +767,8 @@ fix = {
  */
 fix = {
     hackname = no_double_slash;
-    c_test = "double_slash";
-    c_fix  = "no_double_slash";
+    c_test = double_slash;
+    c_fix  = no_double_slash;
 };
 
 
@@ -740,8 +777,8 @@ fix = {
  */
 fix = {
     hackname = ecd_cursor;
-    files  = "sunwindow/win_lock.h";
-    files  = "sunwindow/win_cursor.h";
+    files  = sunwindow/win_lock.h;
+    files  = sunwindow/win_cursor.h;
     sed    = "s/ecd.cursor/ecd_cursor/";
 };
 
@@ -753,7 +790,7 @@ fix = {
 fix = {
     hackname = sco5_stat_wrappers;
     mach     = "i*86-*-sco3.2v5*";
-    files    = "sys/stat.h";
+    files    = sys/stat.h;
 
     sed = "/^static int[ \t]*[a-z]*stat(/i\\\n"
         "#ifdef __cplusplus\\\n"
@@ -778,8 +815,8 @@ fix = {
      *  Select files that contain '#endif' or '#else' directives with
      *  some sort of following junk.
      */
-    c_test = "else_endif_label";
-    c_fix  = "else_endif_label";
+    c_test = else_endif_label;
+    c_fix  = else_endif_label;
 };
 
 
@@ -893,100 +930,69 @@ fix = {
 };
 
 /*
- *  Determine if we're on Interactive Unix 2.2 or later, in which case we
- *  need to fix some additional files.  This is the same test for ISC that
- *  Autoconf uses.  On Interactive 2.2, certain traditional Unix
+ *  On Interactive 2.2, certain traditional Unix
  *  definitions (notably getc and putc in stdio.h) are omitted if __STDC__
  *  is defined, not just if _POSIX_SOURCE is defined.  This makes it
  *  impossible to compile any nontrivial program except with -posix.
  */
 fix = {
-    hackname = interactv_add1;
+    hackname = isc_omits_with_stdc;
 
-    test   = " -d /etc/conf/kconfig.d";
-    test   = ' -n "`grep _POSIX_VERSION /usr/include/sys/unistd.h`"';
+    files  = stdio.h;
+    files  = math.h;
+    files  = ctype.h;
+    files  = sys/limits.h;
+    files  = sys/fcntl.h;
+    files  = sys/dirent.h;
 
-    files  = "stdio.h";
-    files  = "math.h";
-    files  = "ctype.h";
-    files  = "sys/limits.h";
-    files  = "sys/fcntl.h";
-    files  = "sys/dirent.h";
+    select = '!defined\(__STDC__\) &&';
 
     sed    = "s/!defined(__STDC__) && !defined(_POSIX_SOURCE)/"
                "!defined(_POSIX_SOURCE)/";
 };
 
-fix = {
-    hackname = interactv_add2;
-
-    test   = " -d /etc/conf/kconfig.d";
-    test   = ' -n "`grep _POSIX_VERSION /usr/include/sys/unistd.h`"';
-
-    files  = math.h;
-    sed    = "s/fmod(double)/fmod(double, double)/";
-};
 
+/*
+ *  Fix various macros used to define ioctl numbers.  The traditional
+ *  syntax was
+ *  #define _IO(n, x) (('n'<<8)+x)
+ *  #define TIOCFOO _IO(T, 1)
+ *  but this does not work with the C standard, which disallows macro
+ *  expansion inside strings.  We have to rewrite it thus:
+ *  #define _IO(n, x) ((n<<8)+x)
+ *  #define TIOCFOO  _IO('T', 1)
+ *  The select expressions match too much, but the c_fix code is cautious.
+ *
+ *  _IO might be: _IO DESIO BSD43__IO with W, R, WR, C, ... suffixes.
+ */
 fix = {
-    hackname = interactv_add3;
-
-    test   = " -d /etc/conf/kconfig.d";
-    test   = ' -n "`grep _POSIX_VERSION /usr/include/sys/unistd.h`"';
-
-    files  = sys/limits.h;
-
-    sed    = "/CHILD_MAX/s,/\\* Max, Max,";
-    sed    = "/OPEN_MAX/s,/\\* Max, Max,";
+    hackname = io_use_quotes;
+    select = "define[ \t]+[A-Z0-9_]+[ \t]+[A-Z0-9_]+IO[A-Z]*[ \t]*\\( *[^,']";
+    c_fix = IO_use;
 };
 
-
-/*
- *  Fix various _IO* defines, but do *not* quote the characters cgxtf.
- */
 fix = {
     hackname = io_def_quotes;
-    select = "[ \t]*[ \t](_|DES)IO[A-Z]*[ \t]*\\( *[^,']";
-    sed = "s/\\([ \t]*[ \t]_IO[A-Z]*[ \t]*(\\)\\([^,']\\),/\\1'\\2',/";
-    sed = "s/\\([ \t]*[ \t]DESIO[A-Z]*[ \t]*(\\)\\([^,']\\),/\\1'\\2',/";
-    sed = "/#[ \t]*define[ \t]*[ \t]_IO/"       "s/'\\([cgxtf]\\)'/\\1/g";
-    sed = "/#[ \t]*define[ \t]*[ \t]DESIOC/"    's/\'\([cdgx]\)\'/\1/g';
+    select = "define[ \t]+[A-Z0-9_]+IO[A-Z]*\\(([a-zA-Z]).*'\\1'";
+    c_fix = IO_defn;
 };
 
 
 /*
- *  Fix CTRL macros
+ *  Same deal for CTRL() macros.
  *
- * Basically, what is supposed to be happening is that every
- * _invocation_ of the "_CTRL()" or "CTRL()" macros is supposed to have
- * its argument inserted into single quotes.  We _must_ do this because
- * ANSI macro substitution rules prohibit looking inside quoted strings
- * for the substitution names.  A side effect is that the quotes are
- * inserted in the definitions of those macros as well.  So, the last
- * several sed expressions are supposed to clean up the definitions, as
- * long as those definitions are using "c", "g" or "x" as the macro
- * argument :).  Yuck.
+ *  CTRL might be: CTRL _CTRL ISCTRL BSD43_CTRL ...
  */
 fix = {
-    hackname = ioctl_fix_ctrl;
-    select = "CTRL[ \t]*\\(";
-
-    sed = "/[^A-Z0-9_]CTRL[ \t]*(/"
-              "s/\\([^']\\))/'\\1')/";
-
-    sed = "/[^A-Z0-9]_CTRL[ \t]*(/"
-              "s/\\([^']\\))/'\\1')/";
-
-    sed = "/#[ \t]*define[ \t]*[ \t]CTRL/"
-              "s/'\\([cgx]\\)'/\\1/g";
-
-    sed = "/#[ \t]*define[ \t]*[ \t]_CTRL/"
-              "s/'\\([cgx]\\)'/\\1/g";
-
-    sed = "/#[ \t]*define[ \t]*[ \t]BSD43_CTRL/"
-              "s/'\\([cgx]\\)'/\\1/g";
+    hackname = ctrl_use_quotes;
+    select = "define[ \t]+[A-Z0-9_]+[ \t]+[A-Z0-9_]+CTRL[ \t]*\\( *[^,']";
+    c_fix = CTRL_use;
+};
 
-    sed = "/#[ \t]*define[ \t]*[ \t][_]*ISCTRL/"
-              "s/'\\([cgx]\\)'/\\1/g";
+fix = {
+    hackname = ctrl_def_quotes;
+    select = "define[ \t]+[A-Z0-9_]+CTRL\\(([a-zA-Z]).*'\\1'";
+    c_fix = CTRL_defn;
 };
 
 
@@ -1096,23 +1102,23 @@ fix = {
  */
 fix = {
     hackname = kandr_concat;
-    files  = "sparc/asm_linkage.h";
-    files  = "sun3/asm_linkage.h";
-    files  = "sun3x/asm_linkage.h";
-    files  = "sun4/asm_linkage.h";
-    files  = "sun4c/asm_linkage.h";
-    files  = "sun4m/asm_linkage.h";
-    files  = "sun4c/debug/asm_linkage.h";
-    files  = "sun4m/debug/asm_linkage.h";
-    files  = "arm/as_support.h";
-    files  = "arm/mc_type.h";
-    files  = "arm/xcb.h";
-    files  = "dev/chardefmac.h";
-    files  = "dev/ps_irq.h";
-    files  = "dev/screen.h";
-    files  = "dev/scsi.h";
-    files  = "sys/tty.h";
-    files  = "Xm.acorn/XmP.h";
+    files  = sparc/asm_linkage.h;
+    files  = sun3/asm_linkage.h;
+    files  = sun3x/asm_linkage.h;
+    files  = sun4/asm_linkage.h;
+    files  = sun4c/asm_linkage.h;
+    files  = sun4m/asm_linkage.h;
+    files  = sun4c/debug/asm_linkage.h;
+    files  = sun4m/debug/asm_linkage.h;
+    files  = arm/as_support.h;
+    files  = arm/mc_type.h;
+    files  = arm/xcb.h;
+    files  = dev/chardefmac.h;
+    files  = dev/ps_irq.h;
+    files  = dev/screen.h;
+    files  = dev/scsi.h;
+    files  = sys/tty.h;
+    files  = Xm.acorn/XmP.h;
     files  = bsd43/bsd43_.h;
     select = '/\*\*/';
     sed    = 's|/\*\*/|##|g';
@@ -1131,8 +1137,8 @@ fix = {
  */
 fix = {
     hackname = limits_ifndefs;
-    files  = "limits.h";
-    files  = "sys/limits.h";
+    files  = limits.h;
+    files  = sys/limits.h;
     bypass = "ifndef[ \t]+FLT_MIN";
 
     sed  = "/[ \t]FLT_MIN[ \t]/i\\\n#ifndef FLT_MIN\n";
@@ -1182,7 +1188,7 @@ fix = {
 fix = {
     hackname = m88k_bad_hypot_opt;
     mach     = "m88k-motorola-sysv3*";
-    files    = "math.h";
+    files    = math.h;
 
     sed = "s/extern double floor(), ceil(), fmod(), fabs();/"
             "extern double floor(), ceil(), fmod(), fabs _PARAMS((double));/";
@@ -1229,7 +1235,7 @@ fix = {
 fix = {
     hackname = m88k_multi_incl;
     mach     = "m88k-tektronix-sysv3*";
-    files    = "time.h";
+    files    = time.h;
     bypass   = "#ifndef";
     shell    =
       "echo Fixing $file, to protect against multiple inclusion. >&2
@@ -1647,8 +1653,8 @@ fix = {
  */
 fix = {
     hackname = rs6000_param;
-    files  = "stdio.h";
-    files  = "unistd.h";
+    files  = stdio.h;
+    files  = unistd.h;
     select = 'const char new';
 
     sed = 's@rename(const char \*old, const char \*new)@'
@@ -1782,8 +1788,8 @@ fix = {
  */
 fix = {
     hackname = sun_bogus_ifdef;
-    files  = "hsfs/hsfs_spec.h";
-    files  = "hsfs/iso_spec.h";
+    files  = hsfs/hsfs_spec.h;
+    files  = hsfs/iso_spec.h;
     select = '#ifdef __i386__ || __vax__';
     sed    = "s/\\#ifdef __i386__ || __vax__/\\#if __i386__ || __vax__/g";
 };
@@ -1794,7 +1800,7 @@ fix = {
  */
 fix = {
     hackname = sun_bogus_ifdef_sun4c;
-    files  = "hsfs/hsnode.h";
+    files  = hsfs/hsnode.h;
     select = '#ifdef __i386__ || __sun4c__';
     sed    = "s/\\#ifdef __i386__ || __sun4c__/\\#if __i386__ || __sun4c__/g";
 };
@@ -1833,41 +1839,6 @@ fix = {
 
 
 /*
- *  Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
- *  declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
- *  many other systems have similar text but correct versions of the file.
- *  To ensure only Sun's is fixed, we grep for a likely unique string.
- *  Fix also on sysV68 R3V7.1 (head/memory.h\t50.1\t )
- */
-fix = {
-    hackname = sun_memcpy;
-    files    = memory.h;
-    select = "/\\*\t@\\(#\\)"
-             "(head/memory.h\t50.1\t "
-             "|memory\\.h 1\\.[2-4] 8./../.. SMI; from S5R2 1\\.2\t)\\*/";
-
-    sed    = "1i\\\n/* This file was generated by fixincludes */\\\n"
-             "#ifndef __memory_h__\\\n"
-             "#define __memory_h__\\\n\\\n"
-             "#ifdef __STDC__\\\n"
-             "extern void *memccpy();\\\n"
-             "extern void *memchr();\\\n"
-             "extern void *memcpy();\\\n"
-             "extern void *memset();\\\n"
-             "#else\\\n"
-             "extern char *memccpy();\\\n"
-             "extern char *memchr();\\\n"
-             "extern char *memcpy();\\\n"
-             "extern char *memset();\\\n"
-             "#endif /* __STDC__ */\\\n\\\n"
-             "extern int memcmp();\\\n\\\n"
-             "#endif /* __memory_h__ */\n";
-
-    sed    = "1,$d";
-};
-
-
-/*
  *  Check for yet more missing ';' in struct (in SunOS 4.0.x)
  */
 fix = {
@@ -2293,12 +2264,12 @@ fix = {
  */
 fix = {
     hackname = systypes;
-    files  = "sys/types.h";
-    files  = "stdlib.h";
-    files  = "sys/stdtypes.h";
-    files  = "stddef.h";
-    files  = "memory.h";
-    files  = "unistd.h";
+    files  = sys/types.h;
+    files  = stdlib.h;
+    files  = sys/stdtypes.h;
+    files  = stddef.h;
+    files  = memory.h;
+    files  = unistd.h;
     select = "typedef[ \t]+[a-z_][ \ta-z_]*[ \t]"
              "(size|ptrdiff|wchar)_t";
 
@@ -2451,18 +2422,6 @@ fix = {
 
 
 /*
- *  Cancel out ansi_compat.h on Ultrix.  Replace it with empty file.
- */
-fix = {
-    hackname = ultrix_ansi_compat;
-    files    = ansi_compat.h;
-    select   = ULTRIX;
-    sed      = "1i\\\n/* This file intentionally left blank. */\n";
-    sed      = "1,$d";
-};
-
-
-/*
  * Ultrix V4.[35] puts the declaration of uname before the definition
  * of struct utsname, so the prototype (added by fixproto) causes havoc.
  */
@@ -2753,7 +2712,10 @@ fix = {
  */
 fix = {
     hackname = x11_sprintf;
-    files    = X11*/Xmu.h;
+    files    = X11/Xmu.h;
+    files    = X11/Xmu/Xmu.h;
+    select   = 'sprintf\(\)';
+
     sed      = "s,^extern char \\*\tsprintf();$,#ifndef __STDC__\\\n"
                "extern char *\tsprintf();\\\n"
                "#endif /* !defined __STDC__ */,";


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]