aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pw.137
-rw-r--r--pw.c19
2 files changed, 49 insertions, 7 deletions
diff --git a/pw.1 b/pw.1
index c651588..afaaa62 100644
--- a/pw.1
+++ b/pw.1
@@ -30,7 +30,7 @@
pw \- Pipe Watch: monitor recent lines of output from pipe
.SH SYNOPSIS
-command | pw [-i interval] [-l interval] [-n number-of-lines] [-d]
+command | pw [-i interval] [-l interval] [-n number-of-lines] [-dEB]
.SH DESCRIPTION
.I pw
@@ -210,7 +210,8 @@ the top of the display. In tail trigger mode, the status string
appears, showing the pattern preceded by a question mark.
The
.I pattern
-is an extended regular expression (ERE).
+is interpreted as either an extended regular expression (ERE)
+or (BRE) depending on the current setting.
Trigger patterns saved in a history which may be navigated for
recall using the up and down arrow keys or
.B Ctrl-P
@@ -271,7 +272,7 @@ 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, which are extended regular expressions (EREs).
+patterns.
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
@@ -318,7 +319,18 @@ command option for the argument format and the
option for the semantics.
.PP
-Any other command results in a brief error message.
+.IP "\fB:E\fP, \fB:B\fP"
+Enable extended regular expressions (EREs) or basic regular expressions (BREs),
+respectively. If no
+.B -E
+option is given to the program, then BRE mode is in effect on start up.
+This setting does not affect the meaning of patterns that are currently in
+effect in the grep stack or in the trigger. The setting affects new patterns
+that will subsequently be presented to the program. Note that the currently
+active patterns shown in the status line are not accompanied by any indication
+of whether they were compiled as ERE or BRE.
+
+Any other command string results in a brief error message.
.SH OPTIONS
@@ -369,6 +381,23 @@ and staying in the interactive mode. This is useful when the last portion
of the input is of interest, and contains long lines that require
horizontal scrolling.
+.IP \fB-E\fP
+Enable extended regular expressions (EREs). By default, regular expressions
+processed by
+.I pw
+are treated as basic regular expressions (BREs). The mode can be switched
+at run time using the
+.B :E
+and
+.B :B
+commands.
+
+.IP \fB-B\fP
+Disable extended regular expressions (EREs), switching to basic (BREs). Since
+that is the default, this option has no effect unless it appears after a
+.B -E
+option.
+
.SH TERMINATION STATUS
If
diff --git a/pw.c b/pw.c
index b9868c6..e00750a 100644
--- a/pw.c
+++ b/pw.c
@@ -60,6 +60,7 @@ typedef struct dstr {
static int poll_interval = 1000;
static int long_interval = 10000;
+static int regex_flags = 0;
static char **snapshot;
static int snaplines;
@@ -470,7 +471,7 @@ static void execute(char *cmd, unsigned *pstat)
memset(gr, 0, sizeof *gr);
- if ((err = regcomp(&gr->rx, arg, REG_EXTENDED | REG_NOSUB)) != 0) {
+ if ((err = regcomp(&gr->rx, arg, regex_flags | REG_NOSUB)) != 0) {
regerror(err, &gr->rx, cmd, cmdsize);
break;
}
@@ -510,6 +511,12 @@ static void execute(char *cmd, unsigned *pstat)
dsdrop(err);
}
break;
+ case 'E':
+ regex_flags = REG_EXTENDED;
+ break;
+ case 'B':
+ regex_flags = 0;
+ break;
default:
sprintf(cmd, "bad command");
break;
@@ -574,7 +581,7 @@ int main(int argc, char **argv)
if (ttyfd < 0)
panic("unable to open /dev/tty");
- while ((opt = getopt(argc, argv, "n:i:l:d")) != -1) {
+ while ((opt = getopt(argc, argv, "n:i:l:dEB")) != -1) {
switch (opt) {
case 'n':
{
@@ -604,6 +611,12 @@ int main(int argc, char **argv)
case 'd':
auto_quit = 0;
break;
+ case 'E':
+ regex_flags = REG_EXTENDED;
+ break;
+ case 'B':
+ regex_flags = 0;
+ break;
default:
usage(argv[0]);
}
@@ -951,7 +964,7 @@ int main(int argc, char **argv)
int err;
trigpat = dsdup(cmdbuf + 1);
if ((err = regcomp(&trigex, trigpat,
- REG_EXTENDED | REG_NOSUB)))
+ regex_flags | REG_NOSUB)))
{
regerror(err, &trigex, cmdbuf, sizeof cmdbuf);
if (columns < (int) sizeof cmdbuf - 1)