enhance the format style c_fix & remove unneeded wrapper funcs
authorZack Weinberg <zack@wolery.cumb.org>
Fri, 12 May 2000 15:51:55 +0000 (15:51 +0000)
committerBruce Korb <korbb@gcc.gnu.org>
Fri, 12 May 2000 15:51:55 +0000 (15:51 +0000)
From-SVN: r33872

gcc/ChangeLog
gcc/fixinc/fixfixes.c
gcc/fixinc/fixincl.x
gcc/fixinc/fixtests.c
gcc/fixinc/inclhack.def

index 9f254e6..456338e 100644 (file)
@@ -1,3 +1,23 @@
+2000-05-12  Zack Weinberg <zack@wolery.cumb.org>
+
+        * fixinc/fixfixes.c (IO_use_fix, IO_defn_fix, CTRL_use_fix,
+        CTRL_defn_fix): Delete.
+        (fix_char_macro_defines, fix_char_macro_uses): Rename to
+        char_macro_def_fix and char_macro_use_fix, respectively.  Put
+        them into the FIXUP_TABLE.  Get the string to search for from
+        a c_fix_arg.
+
+        (format_write): New function.
+        (format_fix): Use it.
+
+        (FIX_PROC_HEAD): Constify text parameter.
+        (machine_name_fix): Constify all char *s.
+        * fixtests.c (skip_quote): Remove double static.
+
+        * inclhack.def (io_def_quotes, io_use_quotes, ctrl_def_quotes,
+        ctrl_use_quotes): Update for new scheme.
+        * fixincl.x: Regenerate.
+
 2000-05-12  Alexandre Oliva  <aoliva@cygnus.com>
 
        * config/mn10300/mn10300.h (PREFERRED_DEBUGGING_TYPE): Redefine as
index 1c67c76..11a559d 100644 (file)
@@ -123,6 +123,37 @@ print_quote( q, text )
   return text;
 }
 
+static void
+format_write (format, text, av)
+     tCC* format;
+     tCC* text;
+     regmatch_t av[];
+{
+    tCC *p, *str;
+    int c;
+    size_t len;
+
+    for (p = 0; *p; p++) {
+       c = *p;
+       if (c != '%') {
+           putchar(c);
+           continue;
+       }
+
+       c = *++p;
+       if (c == '%') {
+           putchar(c);
+           continue;
+       } else if (c < '0' || c > '9') {
+           abort();
+       }
+
+       c -= '0';
+       str = text + av[c].rm_so;
+       len = av[c].rm_eo - av[c].rm_so;
+       fwrite(str, len, 1, stdout);
+    }
+}
 
 FIX_PROC_HEAD( format_fix )
 {
@@ -172,46 +203,8 @@ FIX_PROC_HEAD( format_fix )
         char* apz[10];
         int   i;
 
-        /*
-         *  Write the text up to the match
-         */
         fwrite( text, rm[0].rm_so, 1, stdout );
-
-        /*
-         *  Copy all the submatches into separate strings
-         */
-        for (i=0; i<10; i++) {
-            if (rm[i].rm_so == -1) {
-                apz[i] = (char*)NULL;
-                break;
-            }
-            {
-                int len = rm[i].rm_eo - rm[i].rm_so;
-                apz[i] = (char*)malloc( len + 1 );
-                memcpy( (void*)apz[i], text+rm[i].rm_so, len );
-                apz[i][len] = NUL;
-            }
-        }
-
-        /*
-         *  IF there are any submatches,
-         *  THEN only use the submatches in the formatting
-         */
-        if (apz[1] != (char*)NULL)
-            printf( pz_fmt, apz[1], apz[2], apz[3], apz[4],
-                    apz[5], apz[6], apz[7], apz[8], apz[9] );
-        else
-            printf( pz_fmt, apz[0] );
-
-        /*
-         *  Free our submatch strings
-         */
-        for (i=0; i<10; i++) {
-            if (apz[i] == (char*)NULL)
-                break;
-            free( (void*)apz[i] );
-        }
-
+       format_write( pz_fmt, text, rm );
         text += rm[0].rm_eo;
     }
 
@@ -232,10 +225,8 @@ FIX_PROC_HEAD( format_fix )
    which is the required syntax per the C standard.  (The definition of
    _IO also has to be tweaked - see below.)  'IO' is actually whatever you
    provide in the STR argument.  */
-static void
-fix_char_macro_uses (text, str)
-     const char *text;
-     const char *str;
+
+FIX_PROC_HEAD( char_macro_use_fix )
 {
   /* This regexp looks for a traditional-syntax #define (# in column 1)
      of an object-like macro.  */
@@ -245,8 +236,17 @@ fix_char_macro_uses (text, str)
 
   regmatch_t rm[1];
   const char *p, *limit;
-  size_t len = strlen (str);
+  const char *str = p_fixd->patch_args[0];
+  size_t len;
 
+  if (str == NULL)
+    {
+      fprintf (stderr, "%s needs macro-name-string argument",
+              p_fixd->fix_name);
+      exit(3);
+    }
+
+  len = strlen (str);
   compile_re (pat, &re, 1, "macro pattern", "fix_char_macro_uses");
 
   for (p = text;
@@ -310,10 +310,7 @@ fix_char_macro_uses (text, str)
    which is the required syntax per the C standard.  (The uses of _IO
    also have to be tweaked - see above.)  'IO' is actually whatever
    you provide in the STR argument.  */
-static void
-fix_char_macro_defines (text, str)
-     const char *text;
-     const char *str;
+FIX_PROC_HEAD( char_macro_def_fix )
 {
   /* This regexp looks for any traditional-syntax #define (# in column 1).  */
   static const char pat[] =
@@ -322,9 +319,17 @@ fix_char_macro_defines (text, str)
 
   regmatch_t rm[1];
   const char *p, *limit;
-  size_t len = strlen (str);
+  const char *str = p_fixd->patch_args[0];
+  size_t len;
   char arg;
 
+  if (str == NULL)
+    {
+      fprintf (stderr, "%s needs macro-name-string argument",
+              p_fixd->fix_name);
+      exit(3);
+    }
+
   compile_re (pat, &re, 1, "macro pattern", "fix_char_macro_defines");
 
   for (p = text;
@@ -391,27 +396,6 @@ fix_char_macro_defines (text, str)
   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");
-}
-
-
 /* Fix for machine name #ifdefs that are not in the namespace reserved
    by the C standard.  They won't be defined if compiling with -ansi,
    and the headers will break.  We go to some trouble to only change
@@ -426,7 +410,7 @@ FIX_PROC_HEAD( machine_name_fix )
   fputs( "The target machine has no needed machine name fixes\n", stderr );
 #else
   regmatch_t match[2];
-  char *line, *base, *limit, *p, *q;
+  const char *line, *base, *limit, *p, *q;
   regex_t *label_re, *name_re;
   char scratch[SCRATCHSZ];
   size_t len;
index 10090c6..184d7d2 100644 (file)
@@ -1686,7 +1686,8 @@ tTestDesc aIo_Use_QuotesTests[] = {
  *  Fix Command Arguments for Io_Use_Quotes
  */
 const char* apzIo_Use_QuotesPatch[] = {
-    "IO_use",
+    "char_macro_use",
+    "IO",
     (char*)NULL };
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * *
@@ -1720,7 +1721,8 @@ tTestDesc aIo_Def_QuotesTests[] = {
  *  Fix Command Arguments for Io_Def_Quotes
  */
 const char* apzIo_Def_QuotesPatch[] = {
-    "IO_defn",
+    "char_macro_def",
+    "IO",
     (char*)NULL };
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * *
@@ -1754,7 +1756,8 @@ tTestDesc aCtrl_Use_QuotesTests[] = {
  *  Fix Command Arguments for Ctrl_Use_Quotes
  */
 const char* apzCtrl_Use_QuotesPatch[] = {
-    "CTRL_use",
+    "char_macro_use",
+    "CTRL",
     (char*)NULL };
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * *
@@ -1788,7 +1791,8 @@ tTestDesc aCtrl_Def_QuotesTests[] = {
  *  Fix Command Arguments for Ctrl_Def_Quotes
  */
 const char* apzCtrl_Def_QuotesPatch[] = {
-    "CTRL_defn",
+    "char_macro_def",
+    "CTRL",
     (char*)NULL };
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * *
index 06f998e..bf16fba 100644 (file)
@@ -72,7 +72,7 @@ static apply_fix_p_t test ( fname, text ) \
  *  a backslash.  Especially a backslash followed by octal digits.
  *  We are not doing a correctness syntax check here.
  */
-static tSCC*
+static tCC*
 skip_quote( q, text )
   char  q;
   char* text;
index 6249130..fd282c8 100644 (file)
@@ -978,15 +978,17 @@ fix = {
  *  _IO might be: _IO DESIO BSD43__IO with W, R, WR, C, ... suffixes.
  */
 fix = {
-    hackname = io_use_quotes;
-    select = "define[ \t]+[A-Z0-9_]+[ \t]+[A-Z0-9_]+IO[A-Z]*[ \t]*\\( *[^,']";
-    c_fix = IO_use;
+    hackname  = io_use_quotes;
+    select  = "define[ \t]+[A-Z0-9_]+[ \t]+[A-Z0-9_]+IO[A-Z]*[ \t]*\\( *[^,']";
+    c_fix     = char_macro_use;
+    c_fix_arg = "IO";
 };
 
 fix = {
-    hackname = io_def_quotes;
-    select = "define[ \t]+[A-Z0-9_]+IO[A-Z]*\\(([a-zA-Z]).*'\\1'";
-    c_fix = IO_defn;
+    hackname  = io_def_quotes;
+    select    = "define[ \t]+[A-Z0-9_]+IO[A-Z]*\\(([a-zA-Z]).*'\\1'";
+    c_fix     = char_macro_def;
+    c_fix_arg = "IO";
 };
  
  
@@ -995,15 +997,17 @@ fix = {
  *  CTRL might be: CTRL _CTRL ISCTRL BSD43_CTRL ...
  */
 fix = {
-    hackname = ctrl_use_quotes;
-    select = "define[ \t]+[A-Z0-9_]+[ \t]+[A-Z0-9_]+CTRL[ \t]*\\( *[^,']";
-    c_fix = CTRL_use;
+    hackname  = ctrl_use_quotes;
+    select    = "define[ \t]+[A-Z0-9_]+[ \t]+[A-Z0-9_]+CTRL[ \t]*\\( *[^,']";
+    c_fix     = char_macro_use;
+    c_fix_arg = "CTRL";
 };
+  
 fix = {
-    hackname = ctrl_def_quotes;
-    select = "define[ \t]+[A-Z0-9_]+CTRL\\(([a-zA-Z]).*'\\1'";
-    c_fix = CTRL_defn;
+    hackname  = ctrl_def_quotes;
+    select    = "define[ \t]+[A-Z0-9_]+CTRL\\(([a-zA-Z]).*'\\1'";
+    c_fix     = char_macro_def;
+    c_fix_arg = "CTRL";
 };