2 * The functions in this file implement commands that search in the forward
3 * and backward directions. There are no special characters in the search
4 * strings. Probably should have a regular expression search, or something
9 * ? Steve Wilhite, 1-Dec-85
10 * - massive cleanup on code.
19 * Search forward. Get a search string from the user, and search, beginning at
20 * ".", for the string. If found, reset the "." to be just after the match
21 * string, and [perhaps] repaint the display. Bound to "C-S".
35 if ((s
= readpattern("Search")) != TRUE
)
41 while (clp
!= curbp
->b_linep
)
43 if (cbo
== llength(clp
))
50 c
= lgetc(clp
, cbo
++);
52 if (eq(c
, pat
[0]) != FALSE
)
60 if (tlp
== curbp
->b_linep
)
63 if (tbo
== llength(tlp
))
70 c
= lgetc(tlp
, tbo
++);
72 if (eq(c
, *pp
++) == FALSE
)
78 curwp
->w_flag
|= WFMOVE
;
89 * Reverse search. Get a search string from the user, and search, starting at
90 * "." and proceeding toward the front of the buffer. If found "." is left
91 * pointing at the first character of the pattern [the last character that was
92 j matched]. Bound to "C-R".
107 if ((s
= readpattern("Reverse search")) != TRUE
)
110 for (epp
= &pat
[0]; epp
[1] != 0; ++epp
)
122 if (clp
== curbp
->b_linep
)
124 mlwrite("Not found");
128 cbo
= llength(clp
)+1;
131 if (--cbo
== llength(clp
))
136 if (eq(c
, *epp
) != FALSE
)
142 while (pp
!= &pat
[0])
147 if (tlp
== curbp
->b_linep
)
150 tbo
= llength(tlp
)+1;
153 if (--tbo
== llength(tlp
))
158 if (eq(c
, *--pp
) == FALSE
)
164 curwp
->w_flag
|= WFMOVE
;
172 * Compare two characters. The "bc" comes from the buffer. It has it's case
173 * folded out. The "pc" is from the pattern.
179 if (bc
>='a' && bc
<='z')
182 if (pc
>='a' && pc
<='z')
192 * Read a pattern. Stash it in the external variable "pat". The "pat" is not
193 * updated if the user types in an empty line. If the user typed an empty line,
194 * and there is no old pattern, it is an error. Display the old pattern, in the
195 * style of Jeff Lomicka. There is some do-it-yourself control expansion.
197 int readpattern(prompt
)
201 register const char *cp2
;
206 cp1
= &tpat
[0]; /* Copy prompt */
209 while ((c
= *cp2
++) != '\0')
212 if (pat
[0] != '\0') /* Old pattern */
218 while ((c
= *cp2
++) != 0)
220 if (cp1
< &tpat
[NPAT
+20-6]) /* "??]: \0" */
222 if (c
<0x20 || c
==0x7F) {
226 else if (c
== '%') /* Map "%" to */
227 *cp1
++ = c
; /* "%%". */
236 *cp1
++ = ':'; /* Finish prompt */
239 s
= mlreply(tpat
, tpat
, NPAT
); /* Read pattern */
241 if (s
== TRUE
) /* Specified */
243 else if (s
== FALSE
&& pat
[0] != 0) /* CR, but old one */