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]
Other format: [Raw text]

fixinclude fnmatch patch


This patch "seems to work for me".  I (mostly) completed a bootstrap build
with these changes and successfully ran the regression tests.

Per a few examples:
@@ -2250,13 +2248,7 @@
 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  = "sun*/asm_linkage.h";
     files  = "arm/as_support.h";
     files  = "arm/mc_type.h";
     files  = "arm/xcb.h";

fixincludes will be able to use file name match patterns for the
"files" entries.  ('/' characters are treated as normal characters,
so it isn't shell globbing, exactly.)  Before applying, it would
be nice to know that it does not break platforms I don't have
access to (viz., most especially, a Sun box).

The attached patch is what I used (except for, again, abbreviating
the generated "fixincl.x" file).

Thanks to whoever tries this.

Regards, Bruce
Index: inclhack.def
===================================================================
--- inclhack.def	(revision 120173)
+++ inclhack.def	(working copy)
@@ -1028,9 +1028,7 @@
  */
 fix = {
     hackname = broken_cabs;
-    files    = "math.h";
-    files    = "architecture/ppc/math.h";
-    files    = "architecture/i386/math.h";
+    files    = math.h, "architecture/*/math.h";
     select   = "^extern[ \t]+double[ \t]+cabs";
 
     c_fix     = format;
@@ -1294,7 +1292,7 @@
  */
 fix = {
     hackname  = glibc_c99_inline_1;
-    files     = features.h;
+    files     = features.h, '*/features.h';
     select    = "^ *&& !defined __OPTIMIZE_SIZE__ && !defined __NO_INLINE__$";
     c_fix     = format;
     c_fix_arg = "%0 && __STDC_VERSION__ < 199901L";
@@ -2250,13 +2248,7 @@
 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  = "sun*/asm_linkage.h";
     files  = "arm/as_support.h";
     files  = "arm/mc_type.h";
     files  = "arm/xcb.h";
@@ -2851,14 +2843,7 @@
  */
 fix = {
     hackname = sco_math;
-    files    = math.h;
-    files    = ansi/math.h;
-    files    = posix/math.h;
-    files    = xpg4/math.h;
-    files    = xpg4v2/math.h;
-    files    = xpg4plus/math.h;
-    files    = ods_30_compat/math.h;
-    files    = oldstyle/math.h;
+    files    = math.h, '*/math.h';
     select   = "inline double abs";
     bypass   = "__GNUG__";
     sed      = "/#define.*__fp_class(a) \\\\/i\\\n"
Index: fixincl.c
===================================================================
--- fixincl.c	(revision 120173)
+++ fixincl.c	(working copy)
@@ -23,6 +23,7 @@
 
 #include "fixlib.h"
 
+#include <fnmatch.h>
 #include <sys/stat.h>
 #ifndef SEPARATE_FIX_PROC
 #include <sys/wait.h>
@@ -359,96 +360,31 @@
 
 static int
 machine_matches( tFixDesc* p_fixd )
-        {
-# ifndef SEPARATE_FIX_PROC
-          tSCC case_fmt[] = "case %s in\n";     /*  9 bytes, plus string */
-          tSCC esac_fmt[] =
-               " )\n    echo %s ;;\n* ) echo %s ;;\nesac";/*  4 bytes */
-          tSCC skip[] = "skip";                 /*  4 bytes */
-          tSCC run[] = "run";                   /*  3 bytes */
-          /* total bytes to add to machine sum:    49 - see fixincl.tpl */
+{
+  char const ** papz_machs = p_fixd->papz_machs;
+  int have_match = BOOL_FALSE;
 
-          const char **papz_machs = p_fixd->papz_machs;
-          char *pz;
-          const char *pz_sep = "";
-          tCC *pz_if_true;
-          tCC *pz_if_false;
-          char cmd_buf[ MACH_LIST_SIZE_LIMIT ]; /* size lim from fixincl.tpl */
-
-          /* Start the case statement */
-
-          sprintf (cmd_buf, case_fmt, pz_machine);
-          pz = cmd_buf + strlen (cmd_buf);
-
-          /*  Determine if a match means to apply the fix or not apply it */
-
-          if (p_fixd->fd_flags & FD_MACH_IFNOT)
-            {
-              pz_if_true  = skip;
-              pz_if_false = run;
-            }
-          else
-            {
-              pz_if_true  = run;
-              pz_if_false = skip;
-            }
-
-          /*  Emit all the machine names.  If there are more than one,
-              then we will insert " | \\\n" between the names  */
-
-          for (;;)
-            {
-              const char* pz_mach = *(papz_machs++);
-
-              if (pz_mach == (const char*) NULL)
-                break;
-              sprintf (pz, "%s%s", pz_sep, pz_mach);
-              pz += strlen (pz);
-              pz_sep = " | \\\n";
-            }
-
-          /* Now emit the match and not-match actions and the esac */
-
-          sprintf (pz, esac_fmt, pz_if_true, pz_if_false);
-
-          /*  Run the script.
-              The result will start either with 's' or 'r'.  */
-
-          {
-            int skip;
-            pz = run_shell (cmd_buf);
-            skip = (*pz == 's');
-            free ( (void*)pz );
-            if (skip)
-              {
-                p_fixd->fd_flags |= FD_SKIP_TEST;
-		return BOOL_FALSE;
-	      }
-	  }
-
-  return BOOL_TRUE;
-# else /* is SEPARATE_FIX_PROC */
-  const char **papz_machs = p_fixd->papz_machs;
-  int invert = (p_fixd->fd_flags & FD_MACH_IFNOT) != 0;
   for (;;)
     {
-      const char* pz_mach = *(papz_machs++);
-
-      if (pz_mach == (const char*) NULL)
+      char const * pz_mpat = *(papz_machs++);
+      if (pz_mpat == NULL)
         break;
-      if (strstr (pz_mach, "dos") != NULL && !invert)
-	return BOOL_TRUE;
+      if (fnmatch(pz_mpat, pz_machine, 0) == 0)
+        {
+          have_match = BOOL_TRUE;
+          break;
+        }
     }
 
-  p_fixd->fd_flags |= FD_SKIP_TEST;
-  return BOOL_FALSE;
-# endif
+  if (p_fixd->fd_flags & FD_MACH_IFNOT)
+    return ! have_match;
+  return have_match;
 }
 
 /* * * * * * * * * * * * *
-
-   run_compiles   run all the regexp compiles for all the fixes once.
-   */
+ *
+ *  run_compiles   run all the regexp compiles for all the fixes once.
+ */
 void
 run_compiles (void)
 {
@@ -1074,11 +1010,11 @@
 
 
 /* * * * * * * * * * * * *
-
-   Process the potential fixes for a particular include file.
-   Input:  the original text of the file and the file's name
-   Result: none.  A new file may or may not be created.  */
-
+ *
+ *  Process the potential fixes for a particular include file.
+ *  Input:  the original text of the file and the file's name
+ *  Result: none.  A new file may or may not be created.
+ */
 static t_bool
 fix_applies (tFixDesc* p_fixd)
 {
@@ -1087,7 +1023,7 @@
   int test_ct;
   tTestDesc *p_test;
 
-# ifdef SEPARATE_FIX_PROC
+#ifdef SEPARATE_FIX_PROC
   /*
    *  There is only one fix that uses a shell script as of this writing.
    *  I hope to nuke it anyway, it does not apply to DOS and it would
@@ -1095,10 +1031,10 @@
    */
   if (p_fixd->fd_flags & (FD_SHELL_SCRIPT | FD_SKIP_TEST))
     return BOOL_FALSE;
-# else
+#else
   if (p_fixd->fd_flags & FD_SKIP_TEST)
     return BOOL_FALSE;
-# endif
+#endif
 
   /*  IF there is a file name restriction,
       THEN ensure the current file name matches one in the pattern  */
@@ -1113,17 +1049,11 @@
 
       for (;;)
         {
-          pz_scan = strstr (pz_scan + 1, pz_fname);
-          /*  IF we can't match the string at all,
-              THEN bail  */
-          if (pz_scan == (char *) NULL)
-            return BOOL_FALSE;
-
-          /*  IF the match is surrounded by the '|' markers,
-              THEN we found a full match -- time to run the tests  */
-
-          if ((pz_scan[-1] == '|') && (pz_scan[name_len] == '|'))
+          if (fnmatch (pz_scan, pz_fname, 0) == 0)
             break;
+          pz_scan += strlen (pz_scan) + 1;
+          if (*pz_scan == NUL)
+            return BOOL_FALSE;
         }
     }
 
Index: fixincl.x
===================================================================
--- fixincl.x	(revision 120173)
+++ fixincl.x	(working copy)
@@ -2,11 +2,11 @@
  * 
  * DO NOT EDIT THIS FILE   (fixincl.x)
  * 
- * It has been AutoGen-ed  Monday November  6, 2006 at 11:04:01 AM CET
+ * It has been AutoGen-ed  Saturday December 23, 2006 at 03:50:06 PM PST
  * From the definitions    inclhack.def
  * and the template file   fixincl
  */
-/* DO NOT CVS-MERGE THIS FILE, EITHER Mon Nov  6 11:04:01 CET 2006
+/* DO NOT CVS-MERGE THIS FILE, EITHER Sat Dec 23 15:50:06 PST 2006
  *
  * You must regenerate it.  Use the ./genfixes script.
  *
@@ -26,7 +26,8 @@
  *  
  *  You may redistribute it and/or modify it under the terms of the
  *  GNU General Public License, as published by the Free Software
- *  Foundation; either version 2, or (at your option) any later version.
+ *  Foundation; either version 2 of the License, or (at your option)
+ *  any later version.
  *  
  *  inclhack is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -34,10 +35,10 @@
  *  See the GNU General Public License for more details.
  *  
  *  You should have received a copy of the GNU General Public License
- *  along with inclhack.  See the file "COPYING".  If not,
- *  write to:  The Free Software Foundation, Inc.,
- *             59 Temple Place - Suite 330,
- *             Boston,  MA  02111-1307, USA.
+ *  along with inclhack.  If not, write to:
+ *  	The Free Software Foundation, Inc.,
+ *  	51 Franklin Street, Fifth Floor
+ *  	Boston, MA  02110-1301, USA.
  */
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * *
@@ -51,7 +52,7 @@
  *  File name selection pattern
  */
 tSCC zAab_Darwin7_9_Long_Double_FuncsList[] =
-  "|architecture/ppc/math.h|";
+  "architecture/ppc/math.h\0";
 /*
  *  Machine/OS name selection pattern
  */
## [[ ... ]]
@@ -1362,7 +1363,7 @@
  *  File name selection pattern
  */
 tSCC zAvoid_Bool_DefineList[] =
-  "|curses.h|curses_colr/curses.h|term.h|tinfo.h|";
+  "curses.h\0curses_colr/curses.h\0term.h\0tinfo.h\0";
 /*
  *  Machine/OS name selection pattern
  */
Index: fixincl.tpl
===================================================================
--- fixincl.tpl	(revision 120173)
+++ fixincl.tpl	(working copy)
@@ -2,7 +2,7 @@
 x=fixincl.x =]
 [= (dne " * " "/* ")=]
  */
-/* DO NOT CVS-MERGE THIS FILE, EITHER [=`date`=]
+/* DO NOT SVN-MERGE THIS FILE, EITHER [=`date`=]
  *
  * You must regenerate it.  Use the ./genfixes script.
  *
@@ -48,7 +48,7 @@
 
   IF (exist? "files")=]
 tSCC z[=(. Hack)=]List[] =
-  "[=FOR files =]|[=files=][=ENDFOR=]|";[=
+  "[=  (join "\\0" (stack "files")) =]\0";[=
 
   ELSE =]
 #define z[=(. Hack)=]List (char*)NULL[=
@@ -73,7 +73,7 @@
 
   ELSE =]
 #define apz[=(. Hack)=]Machs (const char**)NULL[=
-  ENDIF (exist? "files") =][=
+  ENDIF (exist? "mach") =][=
 
   IF (exist? "select")=]
 

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