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]

fixinc checking + fixfixfix


 

Theis patch restores the earlier algorithm for the char_macro_{def|use}_fix-es.
Using a regex fix method failed due to the creativity used in writing
some of these macros.  :-(

I also added the test result files for the fixinc "make check".
That is a work in progress, so they are not useful yet.

2000-05-30  Bruce Korb  <bkorb@gnu.org>

        * fixinc/tests/*:  Added expected result files for fixinc's make check
        * fixinc/fixfixes(char_macro_*_fix): Restore original algorithm

*** fixinc.old/fixfixes.c	Wed May 17 09:31:57 2000
--- fixinc/fixfixes.c	Mon May 22 16:39:18 2000
***************
*** 24,30 ****
  4.  Do not read anything from stdin.  It is closed.
  
  5.  Write to stderr only in the event of a reportable error
!     In such an event, call "exit(1)".
  
  6.  You have access to the fixDescList entry for the fix in question.
      This may be useful, for example, if there are interesting strings
--- 24,30 ----
  4.  Do not read anything from stdin.  It is closed.
  
  5.  Write to stderr only in the event of a reportable error
!     In such an event, call "exit (EXIT_FAILURE)".
  
  6.  You have access to the fixDescList entry for the fix in question.
      This may be useful, for example, if there are interesting strings
***************
*** 59,64 ****
--- 59,68 ----
  
  #include "fixlib.h"
  
+ tSCC zNeedsArg[] = "fixincl error:  `%s' needs %s argument (c_fix_arg[%d])\n";
+ 
+ #define EXIT_BROKEN  3
+ 
  typedef struct {
      const char*  fix_name;
      void (*fix_proc)();
***************
*** 192,198 ****
   */
  FIX_PROC_HEAD( format_fix )
  {
-   tSCC  zBad[] = "fixincl error:  `%s' needs %s c_fix_arg\n";
    tCC*  pz_pat = p_fixd->patch_args[2];
    tCC*  pz_fmt = p_fixd->patch_args[1];
    const char *p;
--- 196,201 ----
***************
*** 204,211 ****
     */
    if (pz_fmt == (tCC*)NULL)
      {
!       fprintf( stderr, zBad, p_fixd->fix_name, "replacement-format" );
!       exit( 3 );
      }
  
    /*
--- 207,214 ----
     */
    if (pz_fmt == (tCC*)NULL)
      {
!       fprintf( stderr, zNeedsArg, p_fixd->fix_name, "replacement format", 0 );
!       exit (EXIT_BROKEN);
      }
  
    /*
***************
*** 220,227 ****
          {
            if (ct-- <= 0)
              {
!               fprintf( stderr, zBad, p_fixd->fix_name, "search-text" );
!               exit( 3 );
              }
  
            if (pTD->type == TT_EGREP)
--- 223,230 ----
          {
            if (ct-- <= 0)
              {
!               fprintf( stderr, zNeedsArg, p_fixd->fix_name, "search text", 1 );
!               exit (EXIT_BROKEN);
              }
  
            if (pTD->type == TT_EGREP)
***************
*** 271,341 ****
  {
    /* This regexp looks for a traditional-syntax #define (# in column 1)
       of an object-like macro.  */
!   static const char zPatFmt[] =
! #ifdef __STDC__
!     /*
!      *  Match up to the replacement text
!      */
!     "^#[ \t]*define[ \t]+[_A-Za-z][_A-Za-z0-9]*[ \t]+"
!     /*
!      *  Match the replacement macro name and openening parenthesis
!      */
!     "[_A-Z][_A-Z0-9]*%s[A-Z]*\\("
!     /*
!      *  Match the single character that must be single-quoted,
!      *  plus some other non-name type character
!      */
!     "([A-Za-z])[^a-zA-Z0-9_]"
! #else
!     /*
!      *  Indecipherable gobbeldygook:
!      */
! 
!     "^#[ \t]*define[ \t]+[_A-Za-z][_A-Za-z0-9]*[ \t]+[_A-Z][_A-Z0-9]*\
! %s[A-Z]*\\(([A-Za-z])[^a-zA-Z0-9_]"
! #endif
!     ;
! 
! # define SUB_PAT_CT 1
!   char *pz_pat;
! 
    static regex_t re;
  
!   regmatch_t rm[SUB_PAT_CT+1];
! 
!   if (p_fixd->patch_args[1] == NULL)
!     {
!       fprintf (stderr, "%s needs macro-name-string argument",
!               p_fixd->fix_name);
!       exit(3);
!     }
  
!   asprintf (&pz_pat, zPatFmt, p_fixd->patch_args[1]);
!   if (!pz_pat)
      {
!       fprintf( stderr, "Virtual memory exhausted\n" );
!       exit(3);
      }
  
!   compile_re (pz_pat, &re, 1, "macro pattern", "char_macro_use_fix");
!   free (pz_pat);
  
!   while (regexec (&re, text, SUB_PAT_CT+1, rm, 0) == 0)
      {
!       const char* pz = text + rm[1].rm_so;
  
!       /*
!        *  Write up to, but not including, the character we must quote
!        */
!       fwrite( text, 1, rm[1].rm_so, stdout );
!       fputc( '\'', stdout );
!       fputc( *(pz++), stdout );
!       fputc( '\'', stdout );
!       text = pz;
      }
! 
    fputs (text, stdout);
- # undef SUB_PAT_CT
  }
  
  
--- 274,345 ----
  {
    /* This regexp looks for a traditional-syntax #define (# in column 1)
       of an object-like macro.  */
!   static const char pat[] =
!     "^#[ \t]*define[ \t]+[_A-Za-z][_A-Za-z0-9]*[ \t]+";
    static regex_t re;
  
!   const char* str = p_fixd->patch_args[1];
!   regmatch_t rm[1];
!   const char *p, *limit;
!   size_t len;
  
!   if (str == NULL)
      {
!       fprintf (stderr, zNeedsArg, p_fixd->fix_name, "ioctl type", 0);
!       exit (EXIT_BROKEN);
      }
  
!   len = strlen (str);
!   compile_re (pat, &re, 1, "macro pattern", "char_macro_use_fix");
  
!   for (p = text;
!        regexec (&re, p, 1, rm, 0) == 0;
!        p = limit + 1)
      {
!       /* p + rm[0].rm_eo is the first character of the macro replacement.
! 	 Find the end of the macro replacement, and the STR we were
! 	 sent to look for within the replacement.  */
!       p += rm[0].rm_eo;
!       limit = p - 1;
!       do
! 	{
! 	  limit = strchr (limit + 1, '\n');
! 	  if (!limit)
! 	    goto done;
! 	}
!       while (limit[-1] == '\\');
  
!       do
! 	{
! 	  if (*p == str[0] && !strncmp (p+1, str+1, len-1))
! 	    goto found;
! 	}
!       while (++p < limit - len);
!       /* Hit end of line.  */
!       continue;
! 
!     found:
!       /* 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++;
!       if (*p++ != '(')
! 	continue;
!       if (!isalpha (*p))
! 	continue;
!       if (isalnum (p[1]) || p[1] == '_')
! 	continue;
! 
!       /* Splat all preceding text into the output buffer,
! 	 quote the character at p, then proceed.  */
!       fwrite (text, 1, p - text, stdout);
!       putchar ('\'');
!       putchar (*p);
!       putchar ('\'');
!       text = p + 1;
      }
!  done:
    fputs (text, stdout);
  }
  
  
***************
*** 352,458 ****
     you provide as the `c_fix_arg' argument.  */
  FIX_PROC_HEAD( char_macro_def_fix )
  {
!   static const char zPatFmt[] =
! #ifdef __STDC__
!     /*
!      *  Find a #define name and opening parenthesis
!      */
!     "^#[ \t]*define[ \t]+[_A-Z][A-Z0-9_]*%s[A-Z]*\\("
!     /*
!      *  The next character must match a later one
!      */
!     "([a-zA-Z])"  /* rm[1] */
!     /*
!      *  now match over a comma, the argument list, intervening white space
!      *  an opening parenthesis, and on through a single quote character
!      */
!     "[ \t]*,[^)]*\\)[ \t]+\\([^']*'"
!     /*
!      *  Match the character that must match the remembered char above
!      */
!     "([a-zA-Z])'"  /* rm[2] */
! #else
!     /*
!      *  Indecipherable gobbeldygook:
!      */
! 
!     "^#[ \t]*define[ \t]+[_A-Z][A-Z0-9_]*%s[A-Z]*\\(\
! ([a-zA-Z])[ \t]*,[^)]*\\)[ \t]+\\([^']*'([a-zA-Z])'"
! #endif
!     ;
! 
!   char *pz_pat;
! 
    static regex_t re;
- # define SUB_PAT_CT 2
-   regmatch_t rm[SUB_PAT_CT+1];
-   const char *p;
-   int  rerr;
  
!   if (p_fixd->patch_args[1] == NULL)
!     {
!       fprintf (stderr, "%s needs macro-name-string argument",
!               p_fixd->fix_name);
!       exit(3);
!     }
  
!   asprintf (&pz_pat, zPatFmt, p_fixd->patch_args[1]);
!   if (!pz_pat)
      {
!       fprintf (stderr, "Virtual memory exhausted\n");
!       exit(3);
      }
  
!   compile_re (pz_pat, &re, 1, "macro pattern", "char_macro_def_fix");
  
! #ifdef DEBUG
!   if ((rerr = regexec (&re, text, SUB_PAT_CT+1, rm, 0)) != 0)
      {
!       fprintf( stderr, "Match error %d:\n%s\n", rerr, pz_pat );
!       exit(3);
!     }
! #endif
! 
!   free (pz_pat);
!   
!   while ((rerr = regexec (&re, text, SUB_PAT_CT+1, rm, 0)) == 0)
!     {
!       const char* pz = text + rm[2].rm_so;
! 
!       /*
!        *  Write up to, but not including, the opening single quote.
!        */
!       fwrite( text, 1, rm[2].rm_so-1, stdout );
! 
!       /*
!        *  The character inside the single quotes must match the
!        *  first single-character macro argument
!        */
!       if (text[ rm[1].rm_so ] != *pz)
!         {
!           /*
!            *  Advance text past what we have written out and continue
!            */
!           text = pz-1;
!           continue;
!         }
  
!       /*
!        *  emit the now unquoted character
!        */
!       putchar( *pz );
! 
!       /*
!        *  Point text to the character after the closing single quote
!        */
!       text = pz+2;
      }
! 
!   /*
!    *  Emit the rest of the text
!    */
    fputs (text, stdout);
- # undef SUB_PAT_CT
  }
  
  /* Fix for machine name #ifdefs that are not in the namespace reserved
--- 356,443 ----
     you provide as the `c_fix_arg' argument.  */
  FIX_PROC_HEAD( char_macro_def_fix )
  {
!   /* This regexp looks for any traditional-syntax #define (# in column 1).  */
!   static const char pat[] =
!     "^#[ \t]*define[ \t]+";
    static regex_t re;
  
!   const char* str = p_fixd->patch_args[1];
!   regmatch_t rm[1];
!   const char *p, *limit;
!   char arg;
!   size_t len;
  
!   if (str == NULL)
      {
!       fprintf (stderr, zNeedsArg, p_fixd->fix_name, "ioctl type", 0);
!       exit (EXIT_BROKEN);
      }
  
!   len = strlen (str);
!   compile_re (pat, &re, 1, "macro pattern", "fix_char_macro_defines");
  
!   for (p = text;
!        regexec (&re, p, 1, rm, 0) == 0;
!        p = limit + 1)
      {
!       /* p + rm[0].rm_eo is the first character of the macro name.
! 	 Find the end of the macro replacement, and the STR we were
! 	 sent to look for within the name.  */
!       p += rm[0].rm_eo;
!       limit = p - 1;
!       do
! 	{
! 	  limit = strchr (limit + 1, '\n');
! 	  if (!limit)
! 	    goto done;
! 	}
!       while (limit[-1] == '\\');
  
!       do
! 	{
! 	  if (*p == str[0] && !strncmp (p+1, str+1, len-1))
! 	    goto found;
! 	  p++;
! 	}
!       while (isalpha (*p) || isalnum (*p) || *p == '_');
!       /* Hit end of macro name without finding the string.  */
!       continue;
! 
!     found:
!       /* Found STR in this macro name.  If the macro needs fixing,
! 	 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++;
!       if (*p++ != '(')
! 	continue;
!       if (!isalpha (*p))
! 	continue;
!       if (isalnum (p[1]) || p[1] == '_')
! 	continue;
! 
!       /* The character at P is the one to look for in the following
! 	 text.  */
!       arg = *p;
!       p += 2;
! 
!       while (p < limit)
! 	{
! 	  if (p[-1] == '\'' && p[0] == arg && p[1] == '\'')
! 	    {
! 	      /* Remove the quotes from this use of ARG.  */
! 	      p--;
! 	      fwrite (text, 1, p - text, stdout);
! 	      putchar (arg);
! 	      p += 3;
! 	      text = p;
! 	    }
! 	  else
! 	    p++;
! 	}
      }
!  done:
    fputs (text, stdout);
  }
  
  /* Fix for machine name #ifdefs that are not in the namespace reserved
***************
*** 636,644 ****
          break;
        if (--ct <= 0)
          {
!           fprintf (stderr, "fixincludes error:  the `%s' fix is unknown\n",
                     fixname );
!           exit (3);
          }
        pfe++;
      }
--- 621,629 ----
          break;
        if (--ct <= 0)
          {
!           fprintf (stderr, "fixincl error:  the `%s' fix is unknown\n",
                     fixname );
!           exit (EXIT_BROKEN);
          }
        pfe++;
      }
*** fixinc.old/fixincl.x	Sun May 21 21:02:14 2000
--- fixinc/fixincl.x	Tue May 30 09:44:28 2000
***************
*** 4499,4507 ****
   */
  tSCC* apzUnixware7_Byteorder_FixMachs[] = {
          "*-*-sysv4*",
!         "i[34567]86-*-sysv5*",
!         "i[34567]86-*-udk*",
!         "i[34567]86-*-solaris2.[0-4]",
          "powerpcle-*-solaris2.[0-4]",
          "sparc-*-solaris2.[0-4]",
          (const char*)NULL };
--- 4499,4507 ----
   */
  tSCC* apzUnixware7_Byteorder_FixMachs[] = {
          "*-*-sysv4*",
!         "i?86-*-sysv5*",
!         "i?86-*-udk*",
!         "i?86-*-solaris2.[0-4]",
          "powerpcle-*-solaris2.[0-4]",
          "sparc-*-solaris2.[0-4]",
          (const char*)NULL };
*** fixinc.old/inclhack.def	Sun May 21 21:02:14 2000
--- fixinc/inclhack.def	Tue May 30 09:44:27 2000
***************
*** 832,838 ****
      select    = "define[ \t]+[A-Z0-9_]+CTRL\\([a-zA-Z],";
      c_fix     = char_macro_def;
      c_fix_arg = "CTRL";
!     test_text = "#define BSD43_CTRL(n, x) (('n'<<8)+x)";
  };
  
  fix = {
--- 832,839 ----
      select    = "define[ \t]+[A-Z0-9_]+CTRL\\([a-zA-Z],";
      c_fix     = char_macro_def;
      c_fix_arg = "CTRL";
!     test_text = "#define BSD43_CTRL(n, x) (('n'<<8)+x)\n"
!                 "#define _CTRL(c) ('c'&037)";
  };
  
  fix = {
***************
*** 840,846 ****
      select    = "define[ \t]+[A-Z0-9_]+[ \t]+[A-Z0-9_]+CTRL[ \t]*\\( *[^,']";
      c_fix     = char_macro_use;
      c_fix_arg = "CTRL";
!     test_text = "#define TIOCFOO BSD43_CTRL(T, 1)";
  };
  
  
--- 841,847 ----
      select    = "define[ \t]+[A-Z0-9_]+[ \t]+[A-Z0-9_]+CTRL[ \t]*\\( *[^,']";
      c_fix     = char_macro_use;
      c_fix_arg = "CTRL";
!     test_text = "#define TCTRLFOO BSD43_CTRL(T, 1)";
  };
  
  
***************
*** 1097,1103 ****
                  "\\( *[^,']";
      c_fix     = char_macro_use;
      c_fix_arg = "IO";
!     test_text = "#define TIOCFOO BSD43__IOWR(T, 1)";
  };
  
  
--- 1098,1106 ----
                  "\\( *[^,']";
      c_fix     = char_macro_use;
      c_fix_arg = "IO";
!     test_text = "#define TIOCFOO BSD43__IOWR(T, 1)\n"
!                 "#define TIOCFOO \\\\\n"
!                 "BSD43__IOWR(T, 1) /* Some are multi-line */";
  };
  
  
***************
*** 1797,1818 ****
  
  
  /*
-  *  Sony NEWSOS 5.0 does not support the complete ANSI C standard.
-  */
- #ifdef SONY
- fix = {
-     hackname = sony_stdio;
-     files    = stdio.h;
-     test     = " -x /bin/sony";
-     test     = " ! -z \"`if /bin/sony ; then echo true ; fi`\"";
-     sed      = "s/__filbuf/_filbuf/g\n"
-                "s/__flsbuf/_flsbuf/g\n"
-                "s/__iob/_iob/g";
- };
- #endif
- 
- 
- /*
   *  Incorrect #include in Sony News-OS 3.2.
   */
  fix = {
--- 1800,1805 ----
***************
*** 2719,2727 ****
      select   = "in_port_t";
  #ifndef SVR5
  	mach = "*-*-sysv4*";
! 	mach = "i[34567]86-*-sysv5*";
! 	mach = "i[34567]86-*-udk*";
! 	mach = "i[34567]86-*-solaris2.[0-4]";
  	mach = "powerpcle-*-solaris2.[0-4]";
  	mach = "sparc-*-solaris2.[0-4]";
  #endif /* SVR5 */
--- 2706,2714 ----
      select   = "in_port_t";
  #ifndef SVR5
  	mach = "*-*-sysv4*";
! 	mach = "i?86-*-sysv5*";
! 	mach = "i?86-*-udk*";
! 	mach = "i?86-*-solaris2.[0-4]";
  	mach = "powerpcle-*-solaris2.[0-4]";
  	mach = "sparc-*-solaris2.[0-4]";
  #endif /* SVR5 */

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