summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--more.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/more.c b/more.c
index 059af4c..896634a 100644
--- a/more.c
+++ b/more.c
@@ -498,7 +498,7 @@ static struct more_file * more_next(struct more_file *mf, int n)
static void more_search(struct more_file *mf, int count, int reuse)
{
static regex_t re;
- static enum { UNDEF = -1, MATCH = 0, NOMATCH = REG_NOMATCH } match = UNDEF;
+ static int match = -1;
if (!reuse) {
char *buf = NULL;
@@ -511,19 +511,29 @@ static void more_search(struct more_file *mf, int count, int reuse)
if (buf[0] != '\n') {
char *nl = strchr(buf, '\n');
*nl = '\0';
+ char *exp = buf;
+
regfree(&re);
- if (regcomp(&re, buf, REG_NOSUB) != 0) {
- fprintf(stderr, "more: invalid expression");
- match = UNDEF;
- } else if (buf[0] == '!') {
- match = NOMATCH;
+
+ if (buf[0] == '!') {
+ match = REG_NOMATCH;
+ exp++;
} else {
- match = MATCH;
+ match = 0;
}
+
+ if (regcomp(&re, exp, REG_NOSUB) != 0) {
+ fprintf(stderr, "more: invalid expression");
+ match = -1;
+ }
+
+ free(buf);
}
+ } else if (match == -1) {
+ fprintf(stderr, "more: no previous expression");
}
- if (match == UNDEF) {
+ if (match == -1) {
return;
}