/*************************************************************************
* This program is copyright (C) 1985, 1986 by Jonathan Payne. It is *
* provided to you without charge for use only on a licensed Unix *
* system. You may copy JOVE provided that this notice is included with *
* the copy. You may not sell copies of this program or versions *
* modified for use on microcomputer systems, unless the copies are *
* included with a Unix system distribution and the source is provided. *
*************************************************************************/
substitute(query
, l1
, char1
, l2
, char2
)
for (lp
= l1
; (lp
!= l2
->l_next
) && !stop
; lp
= lp
->l_next
) {
offset
= (lp
== l1
) ? char1
: 0;
while (!stop
&& re_lindex(lp
, offset
, compbuf
, alternates
, 0)) {
if (lp
== l2
&& REeom
> char2
) /* nope, leave this alone */
message("Replace (Type '?' for help)? ");
switch (Upper(getchar())) {
if (linebuf
[offset
++] == '\0')
offset
= curchar
= REbom
;
lp
->l_dline
= UNDO_da
| DIRTY
;
message("Space or Y, Period, Rubout or N, C-R or R, C-W, C-U or U, P or !, Return.");
offset
= curchar
= REeom
;
message(mesgbuf
); /* No blinking. */
redisplay(); /* Show the change. */
UNDO_da
= curline
->l_dline
;
if (linebuf
[offset
] == 0)
done
: s_mess("%d substitution%n.", numdone
, numdone
);
/* Prompt for search and replacement strings and do the substitution. The
point is restored when we're done. */
Mark
*save
= MakeMark(curline
, curchar
, FLOATER
),
char2
= length(curbuf
->b_last
);
(void) fixorder(&l1
, &char1
, &l2
, &char2
);
strcpy(rep_search
, ask(rep_search
[0] ? rep_search
: (char *) 0, ProcFmt
));
REcompile(rep_search
, UseRE
, compbuf
, alternates
);
/* Now the replacement string. Do_ask() so the user can play with
the default (previous) replacement string by typing C-R in ask(),
OR, he can just hit Return to replace with nothing. */
rep_ptr
= do_ask("\r\n", (int (*)()) 0, rep_str
, ": %f %s with ", rep_search
);
strcpy(rep_str
, rep_ptr
);
substitute(query
, l1
, char1
, l2
, char2
);
lookup(searchbuf
, filebuf
, tag
, file
)
register int taglen
= strlen(tag
);
fp
= open_file(file
, iobuff
, F_READ
, !COMPLAIN
, QUIET
);
sprintf(pattern
, "^%s[^\t]*\t\\([^\t]*\\)\t[?/]\\(.*\\)[?/]$", tag
);
while (f_gets(fp
, line
, sizeof line
) != EOF
) {
if (line
[0] != *tag
|| strncmp(tag
, line
, taglen
) != 0)
if (!LookingAt(pattern
, line
, 0)) {
complain("I thought I saw it!");
putmatch(2, searchbuf
, 100);
putmatch(1, filebuf
, 100);
s_mess("Can't find tag \"%s\".", tag
);
char TagFile
[128] = "./tags";
tagfname
= ask(TagFile
, "With tag file (%s default): ", TagFile
);
if (lookup(sstr
, filebuf
, tag
, tagfname
) == 0)
b
= do_find(curwind
, filebuf
, 0);
if ((bp
= dosearch(sstr
, BACKWARD
, 0)) == 0 &&
(WrapScan
|| ((bp
= dosearch(sstr
, FORWARD
, 0)) == 0)))
message("Well, I found the file, but the tag is missing.");
strcpy(tag
, ask((char *) 0, ProcFmt
));
if (!ismword(linebuf
[curchar
]))
while (c1
> 0 && ismword(linebuf
[c1
- 1]))
while (ismword(linebuf
[c2
]))
null_ncpy(tagname
, linebuf
+ c1
, c2
- c1
);
find_tag(tagname
, !exp_p
);
/* I-search returns a code saying what to do:
STOP: We found the match, so unwind the stack and leave
DELETE: Rubout the last command.
BACKUP: Back up to where the isearch was last NOT failing.
When a character is typed it is appended to the search string, and
then, isearch is called recursively. When C-S or C-R is typed, isearch
is again called recursively. */
#define cmp_char(a, b) ((a) == (b) || (CaseIgnore && (Upper(a) == Upper(b))))
doisearch(dir
, c
, failing
)
if (c
== CTL(S
) || c
== CTL(R
))
if (cmp_char(linebuf
[curchar
], c
)) {
buf
.p_char
= curchar
+ 1;
dosrch
: if ((bp
= dosearch(ISbuf
, dir
, 0)) == 0)
rbell(); /* ring the first time there's no match */
if (isearch(dir
, &save_env
) == TOSTART
)
if (LineDist(curline
, save_env
.p_line
) >= MarkThresh
)
DoSetMark(save_env
.p_line
, save_env
.p_char
);
if (bp
!= 0) { /* Move to the new position. */
pushbp
.p_line
= bp
->p_line
;
pushbp
.p_char
= bp
->p_char
;
ndir
= dir
; /* Same direction as when we got here, unless
we change it with C-S or C-R. */
add_mess("I-search: %s", ISbuf
);
add_mess(NullStr
); /* tell me this is disgusting ... */
/* If we're failing, we backup until we're no longer
failing or we've reached the beginning; else, we
just about the search and go back to the start. */
/* If this is the first time through and we have a
search string left over from last time, use that
strcpy(ISbuf
, getsearch());
incp
= &ISbuf
[strlen(ISbuf
)];
ndir
= (c
== CTL(S
)) ? FORWARD
: BACKWARD
;
/* If we're failing and we're not changing our
direction, don't recur since there's no way
if (failing
&& ndir
== dir
) {
if (incp
> &ISbuf
[(sizeof ISbuf
) - 1]) {
if (c
> RUBOUT
|| (c
< ' ' && c
!= '\t')) {
if (incp
> &ISbuf
[(sizeof ISbuf
) - 1]) {
add_mess("%s", orig_incp
);
add_mess(" ..."); /* so we know what's going on */
DrawMesg(NO
); /* do it now */
switch (isearch(ndir
, doisearch(ndir
, c
, failing
))) {
/* If we're not failing, we just continue to to the
for loop; otherwise we keep returning to the
previous levels until we find one that isn't
failing OR we reach the beginning. */