Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 14 Mar 2010 10:18:58 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r205146 - in head: . include lib/libcompat lib/libcompat/4.3 lib/libcompat/regexp
Message-ID:  <201003141018.o2EAIwHj009485@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ed
Date: Sun Mar 14 10:18:58 2010
New Revision: 205146
URL: http://svn.freebsd.org/changeset/base/205146

Log:
  Trim down libcompat by removing <regexp.h>.
  
  Erwin ran an exp-run with libcompat and <regexp.h> removed. It turns out
  the regexp library is almost entirely unused. In fact, it looks like it
  is sometimes used by accident. Because these function names clash with
  libc's <regex.h>, some application use both <regex.h> and libcompat,
  which means they link against the wrong regex library.
  
  This commit removes the regexp library and reimplements re_comp() and
  re_exec() using <regex.h>. It seems the grammar of the regular
  expressions accepted by these functions is similar to POSIX EREs.
  
  After this commit, 1 low-profile port will be broken, but the maintainer
  already has a patch for it sitting in his mailbox.

Added:
  head/lib/libcompat/4.3/re_comp.c
     - copied, changed from r205145, head/lib/libcompat/4.3/regex.c
Deleted:
  head/include/regexp.h
  head/lib/libcompat/4.3/regex.c
  head/lib/libcompat/regexp/
Modified:
  head/ObsoleteFiles.inc
  head/include/Makefile
  head/lib/libcompat/4.3/re_comp.3
  head/lib/libcompat/Makefile

Modified: head/ObsoleteFiles.inc
==============================================================================
--- head/ObsoleteFiles.inc	Sun Mar 14 05:22:46 2010	(r205145)
+++ head/ObsoleteFiles.inc	Sun Mar 14 10:18:58 2010	(r205146)
@@ -14,6 +14,10 @@
 # The file is partitioned: OLD_FILES first, then OLD_LIBS and OLD_DIRS last.
 #
 
+# 20100314: removal of regexp.h
+OLD_FILES+=usr/include/regexp.h
+OLD_FILES+=usr/share/man/man3/regexp.3.gz
+OLD_FILES+=usr/share/man/man3/regsub.3.gz
 # 20100303: actual removal of utmp.h
 OLD_FILES+=usr/include/utmp.h
 # 20100227: [ia64] removed <machine/sapicreg.h> and <machine/sapicvar.h>

Modified: head/include/Makefile
==============================================================================
--- head/include/Makefile	Sun Mar 14 05:22:46 2010	(r205145)
+++ head/include/Makefile	Sun Mar 14 10:18:58 2010	(r205146)
@@ -17,7 +17,7 @@ INCS=	a.out.h ar.h assert.h bitstring.h 
 	ndbm.h netconfig.h \
 	netdb.h nl_types.h nlist.h nss.h nsswitch.h paths.h \
 	printf.h proc_service.h pthread.h \
-	pthread_np.h pwd.h ranlib.h readpassphrase.h regex.h regexp.h \
+	pthread_np.h pwd.h ranlib.h readpassphrase.h regex.h \
 	res_update.h resolv.h runetype.h search.h semaphore.h setjmp.h \
 	signal.h spawn.h stab.h \
 	stdbool.h stddef.h stdio.h stdlib.h string.h stringlist.h \

Modified: head/lib/libcompat/4.3/re_comp.3
==============================================================================
--- head/lib/libcompat/4.3/re_comp.3	Sun Mar 14 05:22:46 2010	(r205145)
+++ head/lib/libcompat/4.3/re_comp.3	Sun Mar 14 10:18:58 2010	(r205146)
@@ -100,15 +100,10 @@ returns \-1 for an internal error.
 The
 .Fn re_comp
 function
-returns one of the following strings if an error occurs:
-.Bd -unfilled -offset indent
-No previous regular expression,
-Regular expression too long,
-unmatched \e(,
-missing ],
-too many \e(\e) pairs,
-unmatched \e).
-.Ed
+returns
+.Dq no previous regular expression
+or one of the strings generated by
+.Xr regerror 3 .
 .Sh SEE ALSO
 .Xr ed 1 ,
 .Xr egrep 1 ,

Copied and modified: head/lib/libcompat/4.3/re_comp.c (from r205145, head/lib/libcompat/4.3/regex.c)
==============================================================================
--- head/lib/libcompat/4.3/regex.c	Sun Mar 14 05:22:46 2010	(r205145, copy source)
+++ head/lib/libcompat/4.3/re_comp.c	Sun Mar 14 10:18:58 2010	(r205146)
@@ -44,49 +44,49 @@ __FBSDID("$FreeBSD$");
 static char sccsid[] = "@(#)regex.c	5.1 (Berkeley) 3/29/92";
 #endif /* LIBC_SCCS and not lint */
 
-#include <sys/types.h>
+#include <regex.h>
 #include <stddef.h>
-#include <regexp.h>
-#include <string.h>
-#include <stdlib.h>
-#include <string.h>
-
-static regexp *re_regexp;
-static int re_goterr;
-static char *re_errstr;
+#include <unistd.h>
+
+static regex_t re_regexp;
+static int re_gotexp;
+static char re_errstr[100];
 
 char *
-re_comp(char *s)
+re_comp(const char *s)
 {
+	int rc;
+
 	if (s == NULL || *s == '\0') {
-		if (re_regexp == NULL)
-			return "no previous regular expression";
+		if (!re_gotexp)
+			return __DECONST(char *,
+			    "no previous regular expression");
+		return (NULL);
+	}
+
+	if (re_gotexp) {
+		regfree(&re_regexp);
+		re_gotexp = 0;
+	}
+
+	rc = regcomp(&re_regexp, s, REG_EXTENDED);
+	if (rc == 0) {
+		re_gotexp = 1;
 		return (NULL);
 	}
-	if (re_regexp)
-		free(re_regexp);
-	if (re_errstr)
-		free(re_errstr);
-	re_goterr = 0;
-	re_regexp = regcomp(s);
-	return (re_goterr ? re_errstr : NULL);
+
+	regerror(rc, &re_regexp, re_errstr, sizeof(re_errstr));
+	re_errstr[sizeof(re_errstr) - 1] = '\0';
+	return (re_errstr);
 }
 
 int
-re_exec(char *s)
+re_exec(const char *s)
 {
 	int rc;
 
-	re_goterr = 0;
-	rc = regexec(re_regexp, s);
-	return (re_goterr ? -1 : rc);
-}
-
-void
-regerror(const char *s)
-{
-	re_goterr = 1;
-	if (re_errstr)
-		free(re_errstr);
-	re_errstr = strdup(s);
+	if (!re_gotexp)
+		return (-1);
+	rc = regexec(&re_regexp, s, 0, NULL, 0);
+	return (rc == 0 ? 1 : 0);
 }

Modified: head/lib/libcompat/Makefile
==============================================================================
--- head/lib/libcompat/Makefile	Sun Mar 14 05:22:46 2010	(r205145)
+++ head/lib/libcompat/Makefile	Sun Mar 14 10:18:58 2010	(r205146)
@@ -1,19 +1,15 @@
 #	@(#)Makefile	8.1 (Berkeley) 6/4/93
 # $FreeBSD$
 
-LIB=compat
+LIB=	compat
 CFLAGS+=-DLIBC_SCCS -DSYSLIBC_SCCS -I${.CURDIR}/../libc/locale
 NO_PIC=
 
 WARNS?=	0
 
-.PATH:	${.CURDIR}/4.1/${MACHINE_ARCH} ${.CURDIR}/4.1 \
-	${.CURDIR}/4.3/${MACHINE_ARCH} ${.CURDIR}/4.3 \
-	${.CURDIR}/4.4/${MACHINE_ARCH} ${.CURDIR}/4.4 \
-	${.CURDIR}/regexp
+.PATH:	${.CURDIR}/4.1 ${.CURDIR}/4.3 ${.CURDIR}/4.4
 
 # compat 4.1 sources
-# XXX MISSING:	tell.c
 SRCS+=	ascftime.c cftime.c ftime.c getpw.c
 
 MAN+=	4.1/ftime.3 4.1/getpw.3
@@ -22,27 +18,15 @@ MAN+=	4.1/cftime.3
 MLINKS+=cftime.3 ascftime.3
 
 # compat 4.3 sources
-# XXX MISSING:	ecvt.c gcvt.c sibuf.c sobuf.c strout.c
-SRCS+=	cfree.c regex.c rexec.c
+SRCS+=	cfree.c re_comp.c rexec.c
 
-# XXX MISSING:	ecvt.0
 MAN+=	4.3/cfree.3 4.3/re_comp.3 4.3/rexec.3
 
-# XXX MISSING:	ecvt.3, so can't MLINK
-#MLINKS+=ecvt.3 fcvt.3 ecvt.3 gcvt.3
 MLINKS+=re_comp.3 re_exec.3
 
 # compat 4.4 sources
 SRCS+=	cuserid.c
-MAN+=	4.4/cuserid.3
-
-# regexp sources
-SRCS+=	regerror.c regexp.c regsub.c
 
-MAN+=	regexp/regexp.3
-
-# XXX name clash with libc
-# MLINKS+=regexp.3 regcomp.3 regexp.3 regexec.3 regexp.3 regerror.3
-MLINKS+=regexp.3 regsub.3
+MAN+=	4.4/cuserid.3
 
 .include <bsd.lib.mk>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201003141018.o2EAIwHj009485>