OSDN Git Service

Add fix test from irix_stdio_dummy_va_list
[pf3gnuchains/gcc-fork.git] / gcc / fixinc / fixfixes.c
index 526cc69..56b9f54 100644 (file)
@@ -60,11 +60,16 @@ Boston, MA 02111-1307, USA.  */
 #include "fixlib.h"
 #define    GTYPE_SE_CT 1
 
+#ifdef SEPARATE_FIX_PROC
+#include "fixincl.x"
+#endif
+
 tSCC zNeedsArg[] = "fixincl error:  `%s' needs %s argument (c_fix_arg[%d])\n";
 
+typedef void t_fix_proc PARAMS ((const char *, const char *, tFixDesc *));
 typedef struct {
     const char*  fix_name;
-    void (*fix_proc)();
+    t_fix_proc*  fix_proc;
 } fix_entry_t;
 
 #define FIXUP_TABLE \
@@ -76,13 +81,14 @@ typedef struct {
   _FT_( "gnu_type",         gnu_type_fix )
 
 
-#define FIX_PROC_HEAD( fix ) \
-static void fix ( filname, text, p_fixd ) \
-    const char* filname; \
-    const char* text; \
+#define FIX_PROC_HEAD( fix )                    \
+static void fix PARAMS ((const char *, const char *, tFixDesc *)); /* avoid warning */      \
+static void fix ( filname, text, p_fixd )       \
+    const char* filname;                        \
+    const char* text;                           \
     tFixDesc* p_fixd;
 
-
+#ifdef NEED_PRINT_QUOTE
 /*
  *  Skip over a quoted string.  Single quote strings may
  *  contain multiple characters if the first character is
@@ -124,6 +130,7 @@ print_quote( q, text )
 
   return text;
 }
+#endif /* NEED_PRINT_QUOTE */
 
 
 /*
@@ -131,54 +138,47 @@ print_quote( q, text )
  *  this thing can be encountered countless times during a compile
  *  and not cause even a warning.
  */
+static const char *emit_gnu_type PARAMS ((const char *, regmatch_t *));
 static const char*
 emit_gnu_type ( text, rm )
   const char* text;
   regmatch_t* rm;
 {
-  extern t_gnu_type_map gnu_type_map[];
-  extern int gnu_type_map_ct;
-
-  const char*     pzt  = text + rm[GTYPE_SE_CT].rm_so;
-  t_gnu_type_map* p_tm = gnu_type_map;
-  int   ct = gnu_type_map_ct;
+  char z_TYPE[ 64 ];
+  char z_type[ 64 ];
 
   fwrite (text, rm[0].rm_so, 1, stdout);
-  text += rm[0].rm_eo;
 
-  for (;;)
-    {
-      if (strncmp (pzt, p_tm->pz_type, p_tm->type_name_len) == 0)
-        break;
+  {
+    const char* ps = text   + rm[1].rm_so;
+    const char* pe = text   + rm[1].rm_eo;
+    char* pd = z_type;
+    char* pD = z_TYPE;
 
-#ifdef DEBUG
-      if (--ct <= 0)
-        return (const char*)NULL;
-#else
-      if (--ct <= 0)
-        return text;
-#endif
-      p_tm++;
-    }
+    while (ps < pe)
+      *(pD++) = TOUPPER( *(pd++) = *(ps++) );
+
+    *pD = *pd = NUL;
+  }
 
   /*
-   *  Now print out the reformed typedef
+   *  Now print out the reformed typedef,
+   *  with a C++ guard for WCHAR
    */
-  printf ("\
-#ifndef __%s_TYPE__\n\
-#define __%s_TYPE__ %s\n\
-#endif\n",
-          p_tm->pz_TYPE, p_tm->pz_TYPE, p_tm->pz_gtype );
-
-  printf ("\
+  {
+    tSCC z_fmt[] = "\
 #if !defined(_GCC_%s_T)%s\n\
 #define _GCC_%s_T\n\
 typedef __%s_TYPE__ %s_t;\n\
-#endif\n",
-          p_tm->pz_TYPE, p_tm->pz_cxx_guard,
-          p_tm->pz_TYPE, p_tm->pz_TYPE, p_tm->pz_type);
+#endif\n";
 
-  return text;
+    const char* pz_guard = (strcmp (z_type, "wchar") == 0)
+                           ? " && ! defined(__cplusplus)" : "";
+
+    printf (z_fmt, z_TYPE, pz_guard, z_TYPE, z_TYPE, z_type);
+  }
+
+  return text += rm[0].rm_eo;
 }
 
 
@@ -189,6 +189,7 @@ typedef __%s_TYPE__ %s_t;\n\
  *  '%' characters in other contexts and all other characters are
  *  copied out verbatim.
  */
+static void format_write PARAMS ((tCC *, tCC *, regmatch_t[]));
 static void
 format_write (format, text, av)
      tCC* format;
@@ -213,7 +214,7 @@ format_write (format, text, av)
      *  not emit the following character.  We will end on
      *  a NUL and we will emit only one of a pair of '%'.
      */
-    if (! isdigit( c ))
+    if (! ISDIGIT ( c ))
       {
         putchar( '%' );
         switch (c) {
@@ -254,9 +255,9 @@ FIX_PROC_HEAD( format_fix )
 {
   tCC*  pz_pat = p_fixd->patch_args[2];
   tCC*  pz_fmt = p_fixd->patch_args[1];
-  const char *p;
   regex_t re;
   regmatch_t rm[10];
+  IGNORE_ARG(filname);
 
   /*
    *  We must have a format
@@ -299,9 +300,6 @@ FIX_PROC_HEAD( format_fix )
   compile_re (pz_pat, &re, 1, "format search-text", "format_fix" );
   while (regexec (&re, text, 10, rm, 0) == 0)
     {
-      char* apz[10];
-      int   i;
-
       fwrite( text, rm[0].rm_so, 1, stdout );
       format_write( pz_fmt, text, rm );
       text += rm[0].rm_eo;
@@ -338,6 +336,7 @@ FIX_PROC_HEAD( char_macro_use_fix )
   regmatch_t rm[1];
   const char *p, *limit;
   size_t len;
+  IGNORE_ARG(filname);
 
   if (str == NULL)
     {
@@ -378,12 +377,12 @@ FIX_PROC_HEAD( char_macro_use_fix )
       /* Found STR on this line.  If the macro needs fixing,
         the next few chars will be whitespace or uppercase,
         then an open paren, then a single letter.  */
-      while ((isspace (*p) || isupper (*p)) && p < limit) p++;
+      while ((ISSPACE (*p) || ISUPPER (*p)) && p < limit) p++;
       if (*p++ != '(')
        continue;
-      if (!isalpha (*p))
+      if (!ISALPHA (*p))
        continue;
-      if (isalnum (p[1]) || p[1] == '_')
+      if (ISALNUM (p[1]) || p[1] == '_')
        continue;
 
       /* Splat all preceding text into the output buffer,
@@ -422,6 +421,7 @@ FIX_PROC_HEAD( char_macro_def_fix )
   const char *p, *limit;
   char arg;
   size_t len;
+  IGNORE_ARG(filname);
 
   if (str == NULL)
     {
@@ -455,7 +455,7 @@ FIX_PROC_HEAD( char_macro_def_fix )
            goto found;
          p++;
        }
-      while (isalpha (*p) || isalnum (*p) || *p == '_');
+      while (ISALPHA (*p) || ISALNUM (*p) || *p == '_');
       /* Hit end of macro name without finding the string.  */
       continue;
 
@@ -464,12 +464,12 @@ FIX_PROC_HEAD( char_macro_def_fix )
         there may be a few uppercase letters, then there will be an
         open paren with _no_ intervening whitespace, and then a
         single letter.  */
-      while (isupper (*p) && p < limit) p++;
+      while (ISUPPER (*p) && p < limit) p++;
       if (*p++ != '(')
        continue;
-      if (!isalpha (*p))
+      if (!ISALPHA (*p))
        continue;
-      if (isalnum (p[1]) || p[1] == '_')
+      if (ISALNUM (p[1]) || p[1] == '_')
        continue;
 
       /* The character at P is the one to look for in the following
@@ -514,6 +514,8 @@ FIX_PROC_HEAD( machine_name_fix )
   regex_t *label_re, *name_re;
   char scratch[SCRATCHSZ];
   size_t len;
+  IGNORE_ARG(filname);
+  IGNORE_ARG(p_fixd);
 
   mn_get_regexps (&label_re, &name_re, "machine_name_fix");
 
@@ -600,27 +602,32 @@ FIX_PROC_HEAD( machine_name_fix )
 
 FIX_PROC_HEAD( wrap_fix )
 {
+  tSCC   z_no_wrap_pat[] = "^#if.*__need_";
+  static regex_t no_wrapping_re; /* assume zeroed data */
+
   char   z_fixname[ 64 ];
   tCC*   pz_src  = p_fixd->fix_name;
   tCC*   pz_name = z_fixname;
   char*  pz_dst  = z_fixname;
+  int    do_end  = 0;
   size_t len     = 0;
+  IGNORE_ARG(filname);
 
-  for (;;) {
-    char ch = *(pz_src++);
-
-    if (islower(ch))
-      *(pz_dst++) = toupper( ch );
+  if (no_wrapping_re.allocated == 0)
+    compile_re( z_no_wrap_pat, &no_wrapping_re, 0, "no-wrap pattern",
+                "wrap-fix" );
 
-    else if (isalnum( ch ))
-      *(pz_dst++) = ch;
+  for (;;) {
+    char ch = *pz_src++;
 
-    else if (ch == NUL) {
-      *(pz_dst++) = ch;
+    if (ch == NUL) {
+      *pz_dst++ = ch;
       break;
+    } else if (! ISALNUM (ch)) {
+      *pz_dst++ = '_';
+    } else {
+      *pz_dst++ = TOUPPER (ch);
     }
-    else
-      *(pz_dst++) = '_';
 
     if (++len >= sizeof( z_fixname )) {
       void* p = xmalloc( len + strlen( pz_src ) + 1 );
@@ -630,8 +637,16 @@ FIX_PROC_HEAD( wrap_fix )
     }
   }
 
-  printf( "#ifndef FIXINC_%s_CHECK\n", pz_name );
-  printf( "#define FIXINC_%s_CHECK 1\n\n", pz_name );
+  /*
+   *  IF we do *not* match the no-wrap re, then we have a double negative.
+   *  A double negative means YES.
+   */
+  if (regexec (&no_wrapping_re, text, 0, NULL, 0) != 0)
+    {
+      printf( "#ifndef FIXINC_%s_CHECK\n", pz_name );
+      printf( "#define FIXINC_%s_CHECK 1\n\n", pz_name );
+      do_end = 1;
+    }
 
   if (p_fixd->patch_args[1] == (tCC*)NULL)
     fputs( text, stdout );
@@ -643,7 +658,9 @@ FIX_PROC_HEAD( wrap_fix )
       fputs( p_fixd->patch_args[2], stdout );
   }
 
-  printf( "\n#endif  /* FIXINC_%s_CHECK */\n", pz_name );
+  if (do_end != 0)
+    printf( "\n#endif  /* FIXINC_%s_CHECK */\n", pz_name );
+
   if (pz_name != z_fixname)
     free( (void*)pz_name );
 }
@@ -659,6 +676,7 @@ FIX_PROC_HEAD( gnu_type_fix )
   const char* pz_pat;
   regex_t    re;
   regmatch_t rm[GTYPE_SE_CT+1];
+  IGNORE_ARG(filname);
 
   {
     tTestDesc* pTD = p_fixd->p_test_desc;
@@ -685,44 +703,7 @@ FIX_PROC_HEAD( gnu_type_fix )
 
   while (regexec (&re, text, GTYPE_SE_CT+1, rm, 0) == 0)
     {
-#ifndef DEBUG
       text = emit_gnu_type (text, rm);
-#else
-      tSCC z_mismatch[] = "``%s'' mismatched:\n";
-
-      /*
-       *  Make sure we matched *all* subexpressions
-       */
-      if (rm[GTYPE_SE_CT].rm_so == -1)
-        {
-          int i;
-
-          fprintf (stderr, z_mismatch, pz_pat);
-
-          for (i=0; i <= GTYPE_SE_CT; i++)
-            {
-              if (rm[i].rm_so != -1)
-                {
-                  fprintf( stderr, "%4d:  ``", i );
-                  fwrite( text + rm[i].rm_so, rm[i].rm_eo - rm[i].rm_so,
-                          1, stderr );
-                  fputs( "''\n", stderr );
-                }
-              else
-                {
-                  fprintf( stderr, "%4d:  BROKEN\n", i );
-                }
-            }
-          exit (EXIT_BROKEN);
-        }
-
-      text = emit_gnu_type (text, rm);
-      if (text == NULL)
-        {
-          fprintf (stderr, z_mismatch, pz_pat);
-          exit (EXIT_BROKEN);
-        }
-#endif
     }
 
   /*
@@ -747,7 +728,7 @@ apply_fix( p_fixd, filname )
 #define _FT_(n,p) { n, p },
   static fix_entry_t fix_table[] = { FIXUP_TABLE { NULL, NULL }};
 #undef _FT_
-#define FIX_TABLE_CT ((sizeof(fix_table)/sizeof(fix_table[0]))-1)
+#define FIX_TABLE_CT (ARRAY_SIZE (fix_table)-1)
 
   tCC* fixname = p_fixd->patch_args[0];
   char* buf;
@@ -770,3 +751,79 @@ apply_fix( p_fixd, filname )
   buf = load_file_data (stdin);
   (*pfe->fix_proc)( filname, buf, p_fixd );
 }
+
+#ifdef SEPARATE_FIX_PROC
+tSCC z_usage[] =
+"USAGE: applyfix <fix-name> <file-to-fix> <file-source> <file-destination>\n";
+tSCC z_reopen[] =
+"FS error %d (%s) reopening %s as std%s\n";
+
+int
+main( argc, argv )
+  int     argc;
+  char**  argv;
+{
+  tFixDesc* pFix;
+  char* pz_tmptmp;
+  char* pz_tmp_base;
+  char* pz_tmp_dot;
+
+  if (argc != 5)
+    {
+    usage_failure:
+      fputs (z_usage, stderr);
+      return EXIT_FAILURE;
+    }
+
+  {
+    char* pz = argv[1];
+    long  idx;
+
+    if (! ISDIGIT ( *pz ))
+      goto usage_failure;
+
+    idx = strtol (pz, &pz, 10);
+    if ((*pz != NUL) || ((unsigned)idx >= FIX_COUNT))
+      goto usage_failure;
+    pFix = fixDescList + idx;
+  }
+
+  if (freopen (argv[3], "r", stdin) != stdin)
+    {
+      fprintf (stderr, z_reopen, errno, strerror( errno ), argv[3], "in");
+      return EXIT_FAILURE;
+    }
+
+  pz_tmptmp = (char*)xmalloc( strlen( argv[4] ) + 5 );
+  strcpy( pz_tmptmp, argv[4] );
+
+  /* Don't lose because "12345678" and "12345678X" map to the same
+     file under DOS restricted 8+3 file namespace.  Note that DOS
+     doesn't allow more than one dot in the trunk of a file name.  */
+  pz_tmp_base = basename( pz_tmptmp );
+  pz_tmp_dot = strchr( pz_tmp_base, '.' );
+  if (pathconf( pz_tmptmp, _PC_NAME_MAX ) <= 12        /* is this DOS or Windows9X? */
+      && pz_tmp_dot != (char*)NULL)
+    strcpy (pz_tmp_dot+1, "X"); /* nuke the original extension */
+  else
+    strcat (pz_tmptmp, ".X");
+  if (freopen (pz_tmptmp, "w", stdout) != stdout)
+    {
+      fprintf (stderr, z_reopen, errno, strerror( errno ), pz_tmptmp, "out");
+      return EXIT_FAILURE;
+    }
+
+  apply_fix (pFix, argv[1]);
+  fclose (stdout);
+  fclose (stdin);
+  unlink (argv[4]);
+  if (rename (pz_tmptmp, argv[4]) != 0)
+    {
+      fprintf (stderr, "error %d (%s) renaming %s to %s\n", errno,
+               strerror( errno ), pz_tmptmp, argv[4]);
+      return EXIT_FAILURE;
+    }
+
+  return EXIT_SUCCESS;
+}
+#endif