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: patch to use portable RE interface


This patch makes fixincl use the POSIX interface to regular expressions.
This will make it much easier to replace the regexp library, should we
ever want to do that, or to use the system-provided routines.

zw

2000-01-11 16:41 -0800  Zack Weinberg  <zack@wolery.cumb.org>

	* fixlib.c: Add copyright notice.
	(compile_re): New function.
	* fixlib.h: Prototype compile_re.

	* fixfixes.c, fixtests.c, fixincl.c: Use compile_re to compile
	regular expressions.

	* fixincl.c (egrep_test): Don't bother asking regexec where
	the pattern matched.

===================================================================
Index: fixlib.c
--- fixlib.c	1999/12/29 22:58:06	1.4
+++ fixlib.c	2000/01/12 00:40:40
@@ -1,4 +1,27 @@
 
+/* Install modified versions of certain ANSI-incompatible system header
+   files which are fixed to work correctly with ANSI C and placed in a
+   directory that GNU C will search.
+
+   Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+
+This file is part of GNU CC.
+
+GNU CC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU CC 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.
+
+You should have received a copy of the GNU General Public License
+along with GNU CC; see the file COPYING.  If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
 #include "fixlib.h"
 
 /* * * * * * * * * * * * *
@@ -127,4 +150,40 @@ is_cxx_header (fname, text)
     } text_done:;
 
   return BOOL_FALSE;
+}
+
+/* * * * * * * * * * * * *
+ 
+   Compile one regular expression pattern for later use.  PAT contains
+   the pattern, RE points to a regex_t structure (which should have
+   been bzeroed).  MATCH is 1 if we need to know where the regex
+   matched, 0 if not. If regcomp fails, prints an error message and
+   aborts; E1 and E2 are strings to shove into the error message.
+
+   The patterns we search for are all egrep patterns.
+   REG_EXTENDED|REG_NEWLINE produces identical regex syntax/semantics
+   to egrep (verified from 4.4BSD Programmer's Reference Manual).  */
+void
+compile_re( pat, re, match, e1, e2 )
+     tCC *pat;
+     regex_t *re;
+     int match;
+     tCC *e1;
+     tCC *e2;
+{
+  tSCC z_bad_comp[] = "fixincl ERROR:  cannot compile %s regex for %s\n\
+\texpr = `%s'\n\terror %s\n";
+  int flags, err;
+
+  flags = (match ? REG_EXTENDED|REG_NEWLINE
+	   : REG_EXTENDED|REG_NEWLINE|REG_NOSUB);
+  err = regcomp (re, pat, flags);
+
+  if (err)
+    {
+      char rerrbuf[1024];
+      regerror (err, re, rerrbuf, 1024);
+      fprintf (stderr, z_bad_comp, e1, e2, pat, rerrbuf);
+      exit (EXIT_FAILURE);
+    }
 }
===================================================================
Index: fixlib.h
--- fixlib.h	1999/12/29 22:58:06	1.4
+++ fixlib.h	2000/01/12 00:40:40
@@ -3,7 +3,7 @@
    files which are fixed to work correctly with ANSI C and placed in a
    directory that GNU C will search.
 
-   Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1997-1999, 2000 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -97,5 +97,6 @@ typedef int apply_fix_p_t;  /* Apply Fix
  */
 char * load_file_data _P_(( FILE* fp ));
 t_bool is_cxx_header  _P_(( tCC* filename, tCC* filetext ));
-
+void   compile_re     _P_(( tCC* pat, regex_t* re, int match,
+			    tCC *e1, tCC *e2 ));
 #endif /* FIXINCLUDES_FIXLIB_H */
===================================================================
Index: fixtests.c
--- fixtests.c	1999/12/29 22:58:06	1.7
+++ fixtests.c	2000/01/12 00:40:40
@@ -3,7 +3,7 @@
 
    Test to see if a particular fix should be applied to a header file.
 
-   Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1997-1999, 2000 Free Software Foundation, Inc.
 
 = = = = = = = = = = = = = = = = = = = = = = = = =
 
@@ -164,9 +164,8 @@ TEST_FOR_FIX_PROC_HEAD( else_endif_label
   if (! compiled)
     {
       compiled++;
-      re_set_syntax (RE_SYNTAX_EGREP);
-      (void)re_compile_pattern (label_pat, sizeof (label_pat)-1,
-                                &label_re);
+      compile_re (label_pat, &label_re, 1,
+		  "label pattern", "else_endif_label_test");
     }
 
   for (;;) /* entire file */
===================================================================
Index: fixfixes.c
--- fixfixes.c	1999/12/17 21:49:30	1.5
+++ fixfixes.c	2000/01/12 00:40:39
@@ -3,7 +3,7 @@
 
    Test to see if a particular fix should be applied to a header file.
 
-   Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1997-1999, 2000 Free Software Foundation, Inc.
 
 = = = = = = = = = = = = = = = = = = = = = = = = =
 
@@ -181,7 +181,6 @@ FIX_PROC_HEAD( double_slash_fix )
   fclose (stdout);;
 }
 
-
 FIX_PROC_HEAD( else_endif_label_fix )
 {
   static const char label_pat[] = "^[ \t]*#[ \t]*(else|endif)";
@@ -191,9 +190,8 @@ FIX_PROC_HEAD( else_endif_label_fix )
   char* pz_next = (char*)NULL;
   regmatch_t match[2];
 
-  re_set_syntax (RE_SYNTAX_EGREP);
-  (void)re_compile_pattern (label_pat, sizeof (label_pat)-1,
-                            &label_re);
+  compile_re (label_pat, &label_re, 1,
+	      "label pattern", "else_endif_label_fix");
 
   for (;;) /* entire file */
     {
===================================================================
Index: fixincl.c
--- fixincl.c	1999/12/29 22:58:06	1.23
+++ fixincl.c	2000/01/12 00:40:40
@@ -3,7 +3,7 @@
    files which are fixed to work correctly with ANSI C and placed in a
    directory that GNU C will search.
 
-   Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1997-1999, 2000 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -533,8 +533,6 @@ load_file ( fname )
 void
 run_compiles ()
 {
-  tSCC z_bad_comp[] = "fixincl ERROR:  cannot compile %s regex for %s\n\
-\texpr = `%s'\n\terror %s\n";
   tFixDesc *p_fixd = fixDescList;
   int fix_ct = FIX_COUNT;
   tTestDesc *p_test;
@@ -550,26 +548,13 @@ run_compiles ()
       exit (EXIT_FAILURE);
     }
 
-  /*  Make sure re_compile_pattern does not stumble across invalid
-      data */
+  /*  Make sure compile_re does not stumble across invalid data */
 
   memset ( (void*)p_re, '\0', REGEX_COUNT * sizeof (regex_t) );
   memset ( (void*)&incl_quote_re, '\0', sizeof (regex_t) );
 
-  /*  The patterns we search for are all egrep patterns.
-      In the shell version of this program, we invoke egrep
-      with the supplied pattern.  Here, we will run
-      re_compile_pattern, but it must be using the same rules.  */
-
-  re_set_syntax (RE_SYNTAX_EGREP);
-  pz_err = re_compile_pattern (incl_quote_pat, sizeof (incl_quote_pat)-1,
-                              &incl_quote_re);
-  if (pz_err != (char *) NULL)
-    {
-      fprintf (stderr, z_bad_comp, "quoted include", "run_compiles",
-               incl_quote_pat, pz_err);
-      exit (EXIT_FAILURE);
-    }
+  compile_re (incl_quote_pat, &incl_quote_re, 1,
+	      "quoted include", "run_compiles");
 
   /* FOR every fixup, ...  */
   do
@@ -669,16 +654,9 @@ run_compiles ()
                 }
 
               p_test->p_test_regex = p_re++;
-              pz_err = re_compile_pattern (p_test->pz_test_text,
-                                          strlen (p_test->pz_test_text),
-                                          p_test->p_test_regex);
-              if (pz_err != (char *) NULL)
-                {
-                  fprintf (stderr, z_bad_comp, "select test", p_fixd->fix_name,
-                           p_test->pz_test_text, pz_err);
-                  exit (EXIT_FAILURE);
-                }
-            }
+	      compile_re (p_test->pz_test_text, p_test->p_test_regex, 0,
+			  "select test", p_fixd->fix_name);
+	    }
           p_test++;
         }
     }
@@ -815,14 +793,12 @@ egrep_test (pz_data, p_test)
      char *pz_data;
      tTestDesc *p_test;
 {
-  regmatch_t match;
-
 #ifdef DEBUG
   if (p_test->p_test_regex == 0)
     fprintf (stderr, "fixincl ERROR RE not compiled:  `%s'\n",
              p_test->pz_test_text);
 #endif
-  if (regexec (p_test->p_test_regex, pz_data, 1, &match, 0) == 0)
+  if (regexec (p_test->p_test_regex, pz_data, 0, 0, 0) == 0)
     return APPLY_FIX;
   return SKIP_FIX;
 }

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