aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pw.119
-rw-r--r--pw.c39
2 files changed, 52 insertions, 6 deletions
diff --git a/pw.1 b/pw.1
index a596249..fcb4709 100644
--- a/pw.1
+++ b/pw.1
@@ -836,6 +836,25 @@ The
command displays these same parameters in the same format, so it is possible to
set them up interactively and then copy the values shown by
.BR Ctrl-G .
+.RE
+
+.IP "\fB-e\fP \fIcommand\fP"
+Execute a colon or trigger command. For instance
+
+.ft B
+ -e :c15
+.ft R
+
+sets the capture count to 15. Note that the colon is included in the command.
+Trigger commands may be preceded by a count. For example:
+
+.ft B
+ -e 3/^Failed
+.ft R
+
+sets a head-referenced trigger for the pattern
+.B ^Failed
+matching against line 3 of the FIFO.
.SH ENVIRONMENT
diff --git a/pw.c b/pw.c
index eec33fc..3f93fde 100644
--- a/pw.c
+++ b/pw.c
@@ -279,8 +279,11 @@ static void usage(void)
"-d do not quit on end-of-input\n"
"-q integer Require this many repetitions of q to quit\n"
"-E treat regular expressions as extended\n"
- "-B treat regular expressions as basic (default)\n\n"
- "-g [!]pattern add pattern to grep stack; ! inverts.\n\n"
+ "-B treat regular expressions as basic (default)\n"
+ "-g [!]pattern add pattern to grep stack; ! inverts\n"
+ "-m integer specify maixmum line length\n"
+ "-p values set display parameters\n"
+ "-e command execute :, / or ? command\n\n"
"<command> represents an arbitrary command that generates the\n"
"output to be monitored by %s.\n\n"
"Standard input must be redirected; it cannot be the same device\n"
@@ -820,7 +823,7 @@ static execode execute(pwstate *pw, const char *cmd, char *resbuf,
snprintf(resbuf, size, "bad command");
break;
} else {
- int trig = count;
+ int trig = count > 0 ? count - 1 : count;
if (trig < pw->maxlines && trig < maxtrig)
{
@@ -857,6 +860,9 @@ static execode execute(pwstate *pw, const char *cmd, char *resbuf,
res = exec_ok;
}
dsdrop(pat);
+ } else {
+ snprintf(resbuf, size, "trigger position out of range");
+ res = exec_failed;
}
if (res == exec_ok) {
@@ -968,7 +974,7 @@ int main(int argc, char **argv)
}
}
- while ((opt = getopt(argc, argv, "n:i:l:dEBg:q:m:p:")) != -1) {
+ while ((opt = getopt(argc, argv, "n:i:l:dEBg:q:m:p:e:")) != -1) {
switch (opt) {
case 'n':
{
@@ -1089,6 +1095,27 @@ int main(int argc, char **argv)
}
}
break;
+ case 'e':
+ {
+ size_t ndigits = strspn(optarg, "0123456789");
+ int count = 0;
+ const char *cmd = optarg;
+
+ if (ndigits > 3) {
+ error("-%c option %s: command count out of 0-999 range\n",
+ opt, optarg);
+ break;
+ } else if (ndigits) {
+ (void) sscanf(cmd, "%3d", &count);
+ cmd += ndigits;
+ }
+
+ if (execute(&pw, cmd, pw.cmdbuf, cmdsize, count) == exec_failed) {
+ error("-%c option %s: %s\n", opt, optarg, pw.cmdbuf);
+ return EXIT_FAILURE;
+ }
+ }
+ break;
default:
usage();
}
@@ -1606,8 +1633,7 @@ int main(int argc, char **argv)
break;
case CR: case ctrl('c'):
if (ch == CR) {
- int count = (cmdcount == INT_MAX || cmdcount == 0
- ? 0 : cmdcount - 1);
+ int count = (cmdcount == INT_MAX) ? 0 : cmdcount;
if (pw.cmdbuf[1]) {
int *pnhist = (kbd_state == kbd_lcmd ? &ncmdhist : &npathist);
int nhist = *pnhist;
@@ -1629,6 +1655,7 @@ int main(int argc, char **argv)
if (pw.columns < cmdsize)
pw.cmdbuf[pw.columns] = 0;
kbd_state = kbd_result;
+ cmdcount = INT_MAX;
break;
}
}