diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-05-06 00:23:04 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-05-06 00:23:04 +0000 |
commit | ad94b0a87e1222252af5c932b6d5ad9e60499fee (patch) | |
tree | 20103c16dd1e190aa304ad63f224f7462c078adc /distrib/special | |
parent | 6d2267a379b77fbb4f78c0567dd38a4f77451d33 (diff) |
more(1) now uses POSIX regex, no more ned for -lcompat; deraadt@ OK
Diffstat (limited to 'distrib/special')
-rw-r--r-- | distrib/special/more/Makefile | 6 | ||||
-rw-r--r-- | distrib/special/more/more.c | 26 |
2 files changed, 23 insertions, 9 deletions
diff --git a/distrib/special/more/Makefile b/distrib/special/more/Makefile index c0f8866a52b..98ac18f3c58 100644 --- a/distrib/special/more/Makefile +++ b/distrib/special/more/Makefile @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile,v 1.1 2003/04/17 22:53:12 millert Exp $ +# $OpenBSD: Makefile,v 1.2 2003/05/06 00:23:03 millert Exp $ PROG= more MAN= CFLAGS+=-D_USE_OLD_CURSES_ -DPADD= ${LIBOCURSES} ${LIBCOMPAT} -LDADD= -locurses -lcompat +DPADD= ${LIBOCURSES} +LDADD= -locurses .include <bsd.prog.mk> diff --git a/distrib/special/more/more.c b/distrib/special/more/more.c index 8a747d82fcb..3acb96c4bb2 100644 --- a/distrib/special/more/more.c +++ b/distrib/special/more/more.c @@ -59,6 +59,7 @@ static const char sccsid[] = "@(#)more.c 5.28 (Berkeley) 3/1/93"; #include <curses.h> #include <errno.h> #include <locale.h> +#include <regex.h> #include <setjmp.h> #include <signal.h> #include <stdarg.h> @@ -1359,20 +1360,31 @@ search (char *buf, FILE *file, int n) register long line3 = startline; register int lncount; int saveln, rv; - char *s; + char ebuf[BUFSIZ]; + static regex_t reg; + static int initialized; context.line = saveln = Currline; context.chrctr = startline; lncount = 0; - if ((s = re_comp (buf)) != 0) - error (s); + if (buf != NULL && *buf != '\0') { + if ((rv = regcomp(®, buf, REG_NOSUB)) != 0) { + initialized = 0; + regerror(rv, ®, ebuf, sizeof(ebuf)); + regfree(®); + error(ebuf); + } + initialized = 1; + } else if (!initialized) { + error("No previous regular expression"); + } while (!feof (file)) { line3 = line2; line2 = line1; line1 = Ftell (file); rdline (file); lncount++; - if ((rv = re_exec (Line)) == 1) { + if ((rv = regexec(®, Line, 0, NULL, 0)) == 0) { if (--n == 0) { if (lncount > 3 || (lncount > 1 && no_intty)) { @@ -1406,8 +1418,10 @@ search (char *buf, FILE *file, int n) } break; } - } else if (rv == -1) - error ("Regular expression botch"); + } else if (rv != REG_NOMATCH) { + regerror(rv, ®, ebuf, sizeof(ebuf)); + error(ebuf); + } } if (feof (file)) { if (!no_intty) { |