OSDN Git Service

2008-04-25 Kai Tietz <kai.tietz@onevision.com>
[pf3gnuchains/gcc-fork.git] / fixincludes / fixincl.c
index 250f0b0..489f145 100644 (file)
@@ -14,7 +14,7 @@ any later version.
 GCC is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+GNU General Public License for more de\atails.
 
 You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING.  If not, write to
@@ -23,6 +23,7 @@ Boston, MA 02110-1301, USA.  */
 
 #include "fixlib.h"
 
+#include <fnmatch.h>
 #include <sys/stat.h>
 #ifndef SEPARATE_FIX_PROC
 #include <sys/wait.h>
@@ -359,96 +360,36 @@ load_file ( const char* fname )
 
 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 */
-
-          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;
-             }
-         }
+{
+  char const ** papz_machs = p_fixd->papz_machs;
+  int have_match = 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
+  /* Check for sense inversion then set the "skip test" flag, if needed */
+  if (p_fixd->fd_flags & FD_MACH_IFNOT)
+    have_match = ! have_match;
+
+  if (! have_match)
+    p_fixd->fd_flags |= FD_SKIP_TEST;
+
+  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)
 {
@@ -888,7 +829,7 @@ fix_with_system (tFixDesc* p_fixd,
       /*
        *  Now add the fix number and file names that may be needed
        */
-      sprintf (pz_scan, " %ld '%s' '%s' '%s'", p_fixd - fixDescList,
+      sprintf (pz_scan, " %ld '%s' '%s'",  (long) (p_fixd - fixDescList),
               pz_fix_file, pz_file_source, pz_temp_file);
     }
   else /* NOT an "internal" fix: */
@@ -1074,11 +1015,11 @@ start_fixer (int read_fd, tFixDesc* p_fixd, char* pz_fix_file)
 
 
 /* * * * * * * * * * * * *
-
-   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 @@ fix_applies (tFixDesc* p_fixd)
   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 @@ fix_applies (tFixDesc* p_fixd)
    */
   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;
         }
     }
 
@@ -1202,7 +1134,10 @@ write_replacement (tFixDesc* p_fixd)
 
    {
      FILE* out_fp = create_file ();
-     fputs (pz_text, out_fp);
+     size_t sz = strlen (pz_text);
+     fwrite (pz_text, sz, 1, out_fp);
+     if (pz_text[ sz-1 ] != '\n')
+       fputc ('\n', out_fp);
      fclose (out_fp);
    }
 }