public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [fixincludes, patch] PR30008 - fixes are not applied to files in non-standard locations (was: fixinclude fnmatch patch)
@ 2007-01-06 14:44 Daniel Franke
  2007-01-06 17:25 ` Bruce Korb
  2007-01-06 18:03 ` Bruce Korb
  0 siblings, 2 replies; 5+ messages in thread
From: Daniel Franke @ 2007-01-06 14:44 UTC (permalink / raw)
  To: gcc-patches; +Cc: Bruce Korb

[-- Attachment #1: Type: text/plain, Size: 1089 bytes --]


:ADDPATCH fixincludes:

Some distributions store files that need fixing in non-standard locations. 
Instead of enumerating those locations, this patch allows for wildcards in 
the files-section of hacks, e.g.

    files = "*features.h"

to match "features.h", "foo/features.h" or "foo/bar/../features.h".

Bootstrapped and regtested on x86_64-pc-linux-gnu and i686-pc-linux-gnu.


Most of the attached patch was provided by Bruce Korb [1], I only contributed 
some minor fixes.

2007-01-05  Bruce Korb <bkorb@gnu.org>, 
            Daniel Franke <franke.daniel@gmail.com>

	PR target/30008
	* fixincl.tpl: ? (Bruce?)
	* fixincl.c (fix_applies, machine_matches): Use fnmatch for pattern matching.
	* fixincl.x: Regenerate.
	* inclhack.def (glibc_c99_inline_[1234], broken_cabs, broken_nan,
	kandr_concat, sco_math): Replace lists of specfic file names by search
	patterns.


The patch does not include the changes to the generated file fixincl.x, anyone 
applying the patch has to regenerate that file.

Ok for trunk?

	Daniel


[1] http://gcc.gnu.org/ml/gcc-patches/2006-12/msg01653.html

[-- Attachment #2: pr30008.diff --]
[-- Type: text/x-diff, Size: 8706 bytes --]

Index: fixincl.tpl
===================================================================
--- fixincl.tpl	(revision 120492)
+++ fixincl.tpl	(working copy)
@@ -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: fixincl.c
===================================================================
--- fixincl.c	(revision 120492)
+++ 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,90 +360,30 @@
 
 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 (have_match == BOOL_FALSE)
+    p_fixd->fd_flags |= FD_SKIP_TEST;
+
+  if (p_fixd->fd_flags & FD_MACH_IFNOT)
+    return ! have_match;
+
+  return have_match;
 }
 
 /* * * * * * * * * * * * *
@@ -1074,11 +1015,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 +1028,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,35 +1036,26 @@
    */
   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  */
 
   if (pz_scan != (char *) NULL)
     {
-      size_t name_len;
-
       while ((pz_fname[0] == '.') && (pz_fname[1] == '/'))
         pz_fname += 2;
-      name_len = strlen (pz_fname);
 
       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: inclhack.def
===================================================================
--- inclhack.def	(revision 120492)
+++ inclhack.def	(working copy)
@@ -1029,8 +1029,7 @@
 fix = {
     hackname = broken_cabs;
     files    = "math.h";
-    files    = "architecture/ppc/math.h";
-    files    = "architecture/i386/math.h";
+    files    = "architecture/*/math.h";
     select   = "^extern[ \t]+double[ \t]+cabs";
 
     c_fix     = format;
@@ -1054,8 +1053,7 @@
     
 fix = {
     hackname  = broken_nan;
-    files     = "architecture/ppc/math.h";
-    files     = "architecture/i386/math.h";
+    files     = "architecture/*/math.h";
     select    = "#if defined(__APPLE_CC__) && (__APPLE_CC__ >= 1345)";
     bypass    = "powl";
     c_fix     = format; 
@@ -1294,7 +1292,7 @@
  */
 fix = {
     hackname  = glibc_c99_inline_1;
-    files     = features.h;
+    files     = *features.h;
     select    = "^ *&& !defined __OPTIMIZE_SIZE__ && !defined __NO_INLINE__$";
     c_fix     = format;
     c_fix_arg = "%0 && __STDC_VERSION__ < 199901L";
@@ -1314,7 +1312,7 @@
  */
 fix = {
     hackname  = glibc_c99_inline_2;
-    files     = sys/stat.h;
+    files     = *sys/stat.h;
     select    = "extern __inline__ int";
     sed	      = "s/extern int \\(stat\\|lstat\\|fstat\\|mknod\\)/"
 		"#if __STDC_VERSION__ < 199901L\\\nextern\\\n#endif\\\n"
@@ -1336,7 +1334,7 @@
 
 fix = {
     hackname  = glibc_c99_inline_3;
-    files     = bits/string2.h;
+    files     = *bits/string2.h;
     bypass    = "__STDC_VERSION__";
     c_fix     = format;
     c_fix_arg = "# if defined(__cplusplus) || __STDC_VERSION__ >= 19901L";
@@ -1353,7 +1351,7 @@
 
 fix = {
     hackname  = glibc_c99_inline_4;
-    files     = sys/sysmacros.h;
+    files     = *sys/sysmacros.h;
     bypass    = "__STDC_VERSION__";
     c_fix     = format;
     c_fix_arg = "\n#if __STDC_VERSION__ < 19901L\nextern\n#endif\n";
@@ -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;
     select   = "inline double abs";
     bypass   = "__GNUG__";
     sed      = "/#define.*__fp_class(a) \\\\/i\\\n"

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-01-06 20:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-06 14:44 [fixincludes, patch] PR30008 - fixes are not applied to files in non-standard locations (was: fixinclude fnmatch patch) Daniel Franke
2007-01-06 17:25 ` Bruce Korb
2007-01-06 18:03 ` Bruce Korb
2007-01-06 19:10   ` Daniel Franke
2007-01-06 20:05     ` Bruce Korb

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).