aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pw.117
-rw-r--r--pw.c23
2 files changed, 37 insertions, 3 deletions
diff --git a/pw.1 b/pw.1
index 15f3d2f..5a580db 100644
--- a/pw.1
+++ b/pw.1
@@ -148,7 +148,10 @@ command.
The commands are:
.IP "\fBq\fP, \fBCtrl-C\fP"
-Quit the program.
+Quit the program. Must be used multiple times in succession if a quit
+count greater than 1 is in effect. (See the
+.B -q
+option).
.IP "\fBl\fP, \fILeft Arrow\fP"
Scroll the display to the left.
@@ -571,6 +574,18 @@ 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-q\fP \fIinteger\fP"
+Install a quit count specified by
+.I integer
+which must be positive. The quit count determines how many times the
+.B q
+or
+.B Ctrl-C
+commands have to be issued in succession before
+.I pw
+will quit. This is a safeguard against quitting accidentally. The default
+is 1: the commands quit immediately.
+
.IP \fB-E\fP
Enable extended regular expressions (EREs). By default, regular expressions
processed by
diff --git a/pw.c b/pw.c
index 01dfd68..1c883ec 100644
--- a/pw.c
+++ b/pw.c
@@ -243,6 +243,7 @@ static void usage(void)
"-l realnum long update interval (s)\n"
"-n integer display size (# of lines)\n"
"-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"
@@ -702,6 +703,7 @@ int main(int argc, char **argv)
kbd_colon, kbd_result, kbd_trig
};
int auto_quit = 1;
+ int quit_count = 1, quit_countdown = quit_count;
int exit_status = EXIT_FAILURE;
char cmdbuf[cmdsize], *curcmd = 0, *savedcmd = 0;
#ifdef SIGWINCH
@@ -726,7 +728,7 @@ int main(int argc, char **argv)
}
}
- while ((opt = getopt(argc, argv, "n:i:l:dEBg:")) != -1) {
+ while ((opt = getopt(argc, argv, "n:i:l:dEBg:q:")) != -1) {
switch (opt) {
case 'n':
{
@@ -756,6 +758,15 @@ int main(int argc, char **argv)
case 'd':
auto_quit = 0;
break;
+ case 'q':
+ {
+ char *err;
+ if ((quit_countdown = quit_count = getzp(optarg, &err)) < 0) {
+ error("-%c option: %s\n", opt, err);
+ return EXIT_FAILURE;
+ }
+ break;
+ }
case 'E':
regex_flags = REG_EXTENDED;
break;
@@ -1044,9 +1055,17 @@ int main(int argc, char **argv)
curcmd = 0;
// fallthrough
case kbd_cmd:
+ if (ch != 'q' && ch != 3)
+ quit_countdown = quit_count;
switch (ch) {
case 'q': case 3:
- kbd_state = kbd_exit;
+ if (--quit_countdown == 0) {
+ kbd_state = kbd_exit;
+ } else {
+ sprintf(cmdbuf, "%d more to quit", quit_countdown);
+ curcmd = cmdbuf;
+ kbd_state = kbd_result;
+ }
break;
case 'h':
if (hpos >= 8) {