From mboxrd@z Thu Jan 1 00:00:00 1970 From: "J. Johnston" To: gcc-patches@gcc.gnu.org Cc: cgen@sources.redhat.com, gdb-patches@sources.redhat.com Subject: Libiberty regex support - revised patch Date: Thu, 28 Jun 2001 15:40:00 -0000 Message-id: <3B3BB266.551EDBCD@cygnus.com> X-SW-Source: 2001-q2/msg00102.html Responding to comments on my previous patch, I have a revised version. The change was designed to support the opcodes directory whereby CGEN optionally uses regex to help out in insn syntax parsing so as to dramatically improve error messages. Because Cygwin's regex doesn't conform to POSIX, the opcodes fix fails under Cygwin. As well, the regex code under Cygwin causes problems with gdb using the simulator due to the mismatch of the native regex dragged in by opcodes and the internal one used by gdb. The source for the latest patch has been taken from the latest CVS glibc sources. The regex.c file has only been modified to change #include to #include "xregex.h". A comment has been added regarding this. The regex.h file has been renamed to xregex2.h and is otherwise unchanged. An additional header file, xregex.h has been added which a) redefines all external names in regex.c to add an "x" prefix and b) includes xregex2.h. This has been designed so that changes in the glibc sources will be relatively easy to apply to the libiberty version. The rename in xregex.h is performed to avoid any name collision with the native regex or with any component's private regex implementation (e.g. gdb). The new regex code is always built into libiberty. A component can decide whether or not to use it by specifying #include "xregex.h" instead of or any internal regex header file. There are two patches attached. The first patch is to existing libiberty files. The second is for the new code being added. -- Jeff J. Index: libiberty/Makefile.in =================================================================== RCS file: /cvs/gcc/gcc/libiberty/Makefile.in,v retrieving revision 1.62 diff -u -r1.62 Makefile.in --- libiberty/Makefile.in 2001/04/16 15:30:17 1.62 +++ libiberty/Makefile.in 2001/06/28 21:57:52 @@ -127,7 +127,8 @@ floatformat.c hashtab.c hex.c index.c insque.c lbasename.c \ md5.c make-temp-file.c memchr.c \ memcmp.c memcpy.c memmove.c memset.c mkstemps.c objalloc.c obstack.c \ - partition.c pexecute.c putenv.c random.c rename.c rindex.c setenv.c \ + partition.c pexecute.c putenv.c random.c \ + regex.c rename.c rindex.c setenv.c \ sigsetmask.c safe-ctype.c sort.c spaces.c splay-tree.c strcasecmp.c \ strncasecmp.c strchr.c strdup.c strerror.c strncmp.c strrchr.c \ strsignal.c strstr.c strtod.c strtol.c strtoul.c tmpnam.c vasprintf.c \ @@ -139,7 +140,7 @@ cp-demangle.o dyn-string.o fdmatch.o fnmatch.o getopt.o getopt1.o \ getpwd.o getruntime.o hashtab.o hex.o floatformat.o lbasename.o \ md5.o make-temp-file.o objalloc.o \ - obstack.o partition.o pexecute.o safe-ctype.o sort.o spaces.o \ + obstack.o partition.o pexecute.o regex.o safe-ctype.o sort.o spaces.o \ splay-tree.o strerror.o strsignal.o xatexit.o xexit.o xmalloc.o \ xmemdup.o xstrdup.o xstrerror.o ternary.o @@ -281,6 +282,7 @@ obstack.o: config.h $(INCDIR)/obstack.h partition.o: config.h $(INCDIR)/partition.h pexecute.o: config.h $(INCDIR)/libiberty.h +regex.o: $(INCDIR)/xregex.h $(INCDIR)/xregex2.h rename.o: config.h setenv.o: config.h sort.o: config.h $(INCDIR)/sort.h $(INCDIR)/ansidecl.h Index: libiberty/aclocal.m4 =================================================================== RCS file: /cvs/gcc/gcc/libiberty/aclocal.m4,v retrieving revision 1.4 diff -u -r1.4 aclocal.m4 --- libiberty/aclocal.m4 2001/03/06 09:52:35 1.4 +++ libiberty/aclocal.m4 2001/06/28 21:57:52 @@ -70,6 +70,47 @@ fi ]) +dnl See whether native regexec exists and is POSIX-compliant. On Cygwin, for +dnl example, the regex family exists but does not follow POSIX prototypes. +AC_DEFUN(libiberty_AC_FUNC_REGEXEC, +[AC_CACHE_CHECK([for working regex functions], ac_cv_func_regexec_works, +[AC_TRY_RUN([ +/* Test by Jeff Johnston + Check whether regexec on simple string works. */ +#include + +#ifdef HAVE_REGEX_H +#include +#endif + +main () +{ + const char *pattern = "[abc]*.*[ghi]*$"; + const char *str = "ABCcbaDEFGHIihg" + regex_t k; + + int rc; + + rc = regcomp (&k, pattern, REG_ICASE); + + if (rc != REG_NOERROR) + exit(1); + + rc = regexec (&k, str, 0, NULL, 0); + + if (rc != REG_NOERROR) + exit(2); + + exit (0); +} +], ac_cv_func_regexec_works=yes, ac_cv_func_regexec_works=no, + ac_cv_func_regexec_works=no) +rm -f core core.* *.core]) +if test $ac_cv_func_regexec_works = no ; then + LIBOBJS="$LIBOBJS regex.o" +fi +]) + dnl See if errno must be declared even when is included. AC_DEFUN(libiberty_AC_DECLARE_ERRNO, [AC_CACHE_CHECK(whether errno must be declared, libiberty_cv_declare_errno,