From b94e07106038dfb07ccfc184cd76bbf48aa966d0 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Fri, 29 Apr 2022 21:19:44 -0400 Subject: implement ! in searching --- more.c | 26 ++++++++++++++++++-------- 1 file 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; } -- cgit v1.2.1