diff options
author | Jakob Kaivo <jkk@ung.org> | 2022-04-29 21:19:44 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2022-04-29 21:19:44 -0400 |
commit | b94e07106038dfb07ccfc184cd76bbf48aa966d0 (patch) | |
tree | 2902a7b00bf3d41f263d1bc63fd985a15f122e63 | |
parent | 444de9085aa591240671f704eb9b9ff91736dca1 (diff) |
implement ! in searching
-rw-r--r-- | more.c | 26 |
1 files changed, 18 insertions, 8 deletions
@@ -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; } |