diff options
author | Chad Loder <cloder@cvs.openbsd.org> | 2005-05-27 08:08:19 +0000 |
---|---|---|
committer | Chad Loder <cloder@cvs.openbsd.org> | 2005-05-27 08:08:19 +0000 |
commit | 0d2991c584ff46d1969268d0d449da3d41460aac (patch) | |
tree | e7c445cd7b0d2889c1e10cee5772d8585f201856 /usr.bin/mg/search.c | |
parent | 01b5e624bc03f48e6b93c9542088caa94ee45e8d (diff) |
Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt
Diffstat (limited to 'usr.bin/mg/search.c')
-rw-r--r-- | usr.bin/mg/search.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/usr.bin/mg/search.c b/usr.bin/mg/search.c index b15f5b53b2c..1564b74d95e 100644 --- a/usr.bin/mg/search.c +++ b/usr.bin/mg/search.c @@ -1,4 +1,4 @@ -/* $OpenBSD: search.c,v 1.16 2005/05/27 07:22:52 cloder Exp $ */ +/* $OpenBSD: search.c,v 1.17 2005/05/27 08:08:18 cloder Exp $ */ /* * Search commands. @@ -553,6 +553,44 @@ stopsearch: } /* + * Replace string globally without individual prompting. + */ +/* ARGSUSED */ +int +replstr(int f, int n) +{ + char news[NPAT]; + int s, plen, rcnt = 0; + char *r; + + if ((s = readpattern("Replace string")) != TRUE) + return s; + + r = ereply("Replace string %s with: ", news, NPAT, pat); + if (r == NULL) + return (ABORT); + + plen = strlen(pat); + while (forwsrch() == TRUE) { + update(); + if (lreplace((RSIZE)plen, news, f) == FALSE) + return (FALSE); + + rcnt++; + } + + curwp->w_flag |= WFHARD; + update(); + + if (rcnt == 1) + ewprintf("(1 replacement done)"); + else + ewprintf("(%d replacements done)", rcnt); + + return (TRUE); +} + +/* * This routine does the real work of a forward search. The pattern is sitting * in the external variable "pat". If found, dot is updated, the window system * is notified of the change, and TRUE is returned. If the string isn't found, |