diff options
-rw-r--r-- | pw.1 | 13 | ||||
-rw-r--r-- | pw.c | 48 |
2 files changed, 42 insertions, 19 deletions
@@ -239,7 +239,8 @@ pattern onto the grep stack. The command pushes a plain pattern; the .B :v command pushes a logically inverted pattern. The grep stack holds up to 64 -patterns. If the pattern is successfully pushed onto the stack, it +patterns, which are extended regular expressions (EREs). +If the pattern is successfully pushed onto the stack, it restricts which lines are admitted into the FIFO and available for display. The plain pattern admits only the lines which match .IR pattern ; @@ -247,11 +248,15 @@ the inverted pattern admits only lines which do .I not match .IR pattern . +Lines which are already in the FIFO at the time a new pattern is introduced +are not affected. The status line shows .B GREP -.BI ( depth ) -to indicate that grep mode and the depth of the stack. Lines which are -already in the FIFO are not affected. +.BI ( pattern "[, ...])" +to indicate that grep mode is in effect, and gives the list of patterns, +separated by commas. The inverted patterns are indicated by a leading +.B ! +character. .IP \fB:r\fP[\fB!\fP] Remove and forget the most recent grep pattern @@ -31,7 +31,7 @@ typedef struct grep { int inv; } grep; -#define cmdsize 100 +#define cmdsize 256 #define maxgrep 64 typedef struct dstr { @@ -210,26 +210,44 @@ static void clrline() printf("\r\033[J"); } -static void drawstatus(unsigned stat, char *cmd) +static void drawstatus(int columns, unsigned stat, char *cmd) { + char status[cmdsize] = "", *ptr = status; + size_t lim = sizeof status; + + if (columns - 1 < (int) lim) + lim = columns - 1; + + char *end = ptr + lim; + if (cmd) { - printf("%s", cmd); + snprintf(status, lim, "%s", cmd); } else if ((stat & (stat_eof | stat_susp | stat_htmode | stat_ttmode | stat_grep))) { if ((stat & stat_eof)) - printf("EOF "); - if ((stat & stat_grep)) - printf("GREP (%d) ", ngrep); + ptr += snprintf(ptr, end - ptr, "EOF "); + + if ((stat & stat_grep)) { + ptr += snprintf(ptr, end - ptr, "GREP ("); + for (int i = 0; i < ngrep; i++) { + grep *gr = &grepstack[i]; + ptr += snprintf(ptr, end - ptr, "%s%s%c ", + gr->inv ? "!" : "", gr->pat, + (i < ngrep - 1) ? ',' : ')'); + } + } + if ((stat & stat_htmode)) - printf("TRIG (/%s) ", trigpat); + ptr += snprintf(ptr, end - ptr, "TRIG (/%s) ", trigpat); else if ((stat & stat_ttmode)) - printf("TRIG (?%s) ", trigpat); + ptr += snprintf(ptr, end - ptr, "TRIG (?%s) ", trigpat); + if ((stat & stat_susp)) - printf("SUSPENDED "); - } else { - clrline(); + ptr += snprintf(ptr, end - ptr, "SUSPENDED "); } + + fputs(status, stdout); fflush(stdout); } @@ -255,7 +273,7 @@ static void redraw(char **circbuf, int nlines, int hpos, for (int i = 0; i < snaplines; i++) drawline(snapshot[i], hpos, columns); } - drawstatus(stat, cmd); + drawstatus(columns, stat, cmd); } static void execute(char *cmd, unsigned *pstat) @@ -524,7 +542,7 @@ int main(int argc, char **argv) snapshot[snaplines++] = dsref(line); clrline(); drawline(line, hpos, columns); - drawstatus(stat, curcmd); + drawstatus(columns, stat, curcmd); } } line = 0; @@ -577,7 +595,7 @@ int main(int argc, char **argv) kbd_state = kbd_cmd; curcmd = 0; clrline(); - drawstatus(stat, curcmd); + drawstatus(columns, stat, curcmd); } } } else { @@ -751,7 +769,7 @@ int main(int argc, char **argv) } else switch (kbd_state) { case kbd_colon: case kbd_htrig: case kbd_ttrig: case kbd_result: clrline(); - drawstatus(stat, curcmd); + drawstatus(columns, stat, curcmd); } } } |