summaryrefslogtreecommitdiff
path: root/history.c
diff options
context:
space:
mode:
authortjg <tjg>2002-05-22 13:23:59 +0000
committerToby Goodwin <toby@paccrat.org>2015-05-16 21:23:22 +0100
commitb241fc272dde1a99ca058d90bed8a0de166bfb88 (patch)
tree6331ce3ceb570fbca76a58738e41acdb5c0b509c /history.c
parente9d74072f34b43258aa10e45d35389fc52a9f042 (diff)
Feature: "stuttering" colons for multiple replacements in the
history programs (thanks Callum Gibson).
Diffstat (limited to 'history.c')
-rw-r--r--history.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/history.c b/history.c
index 629751d..2993a69 100644
--- a/history.c
+++ b/history.c
@@ -26,6 +26,7 @@ static const char id[] = "$Release: @(#)" PACKAGE " " VERSION " " RELDATE " $";
static struct {
char *old, *new;
+ int reps; /* no. of repetitions. i.e. 1 means sub twice. */
} *replace;
static char **search, *progname, *history;
@@ -296,8 +297,12 @@ int main(int argc, char **argv) {
search[nsearch++] = argv[i];
else {
*(char *)s = '\0'; /* do we confuse ps too much? */
+ replace[nreplace].reps = 0;
+ while(*(++s) == ':') {
+ replace[nreplace].reps++;
+ }
replace[nreplace].old = argv[i];
- replace[nreplace].new = s + 1;
+ replace[nreplace].new = s;
nreplace++;
}
@@ -312,8 +317,11 @@ next: s = getcommand();
for (i = 0; i < nreplace; i++)
if (!isin(s, replace[i].old))
goto next;
- else
- s = sub(s, replace[i].old, replace[i].new);
+ else {
+ int j;
+ for (j = 0; j <= replace[i].reps; j++)
+ s = sub(s, replace[i].old, replace[i].new);
+ }
if (editit) {
s = edit(s);
if (s == NULL)