5 * 14407 SW Teal Blvd. #C
11 /* This function contains the movement functions that perform RE searching */
19 static regexp
*re
; /* compiled version of the pattern to search for */
20 static prevsf
; /* boolean: previous search direction was forward? */
24 MARK
m_wsrch(word
, m
, cnt
)
25 char *word
; /* the word to search for */
26 MARK m
; /* the starting point */
27 int cnt
; /* ignored */
31 /* wrap \< and \> around the word */
32 strcpy(buffer
, "/\\<");
34 strcat(buffer
, "\\>");
36 /* show the searched-for word on the bottom line */
42 /* search for the word */
43 return m_fsrch(m
, buffer
);
48 MARK m
; /* where to start searching */
52 m
= m_fsrch(m
, (char *)0);
57 m
= m_bsrch(m
, (char *)0);
64 MARK m
; /* where to start searching */
68 m
= m_bsrch(m
, (char *)0);
73 m
= m_fsrch(m
, (char *)0);
80 MARK m
; /* where to start searching */
81 char *ptrn
; /* pattern to search for */
83 long l
; /* line# of line to be searched */
84 char *line
; /* text of line to be searched */
85 int wrapped
;/* boolean: has our search wrapped yet? */
86 int pos
; /* where we are in the line */
88 long delta
= INFINITY
;/* line offset, for things like "/foo/+1" */
91 /* remember: "previous search was forward" */
96 /* locate the closing '/', if any */
97 line
= parseptrn(ptrn
);
106 /* free the previous pattern */
109 /* compile the pattern */
118 msg("No previous expression");
122 /* search forward for the pattern */
123 pos
= markidx(m
) + 1;
128 m
= (m
| (BLKSIZE
- 1)) + 1;
131 for (l
= markline(m
); l
!= markline(m
) + 1 || !wrapped
; l
++)
136 /* if we wrapped once already, then the search failed */
142 /* else maybe we should wrap now? */
158 /* check this line */
159 if (regexec(re
, &line
[pos
], (pos
== 0)))
162 if (wrapped
&& *o_warn
)
165 if (delta
!= INFINITY
)
168 if (l
< 1 || l
> nlines
)
170 msg("search offset too big");
173 force_flags
= LNMD
|INCL
;
174 return MARK_AT_LINE(l
);
177 return MARK_AT_LINE(l
) + (int)(re
->startp
[0] - line
);
183 msg(*o_wrapscan
? "Not found" : "Hit bottom without finding RE");
187 MARK
m_bsrch(m
, ptrn
)
188 MARK m
; /* where to start searching */
189 char *ptrn
; /* pattern to search for */
191 long l
; /* line# of line to be searched */
192 char *line
; /* text of line to be searched */
193 int wrapped
;/* boolean: has our search wrapped yet? */
194 int pos
; /* last acceptable idx for a match on this line */
195 int last
; /* remembered idx of the last acceptable match on this line */
196 int try; /* an idx at which we strat searching for another match */
198 long delta
= INFINITY
;/* line offset, for things like "/foo/+1" */
201 /* remember: "previous search was not forward" */
206 /* locate the closing '?', if any */
207 line
= parseptrn(ptrn
);
216 /* free the previous pattern, if any */
219 /* compile the pattern */
228 msg("No previous expression");
232 /* search backward for the pattern */
235 for (l
= markline(m
); l
!= markline(m
) - 1 || !wrapped
; l
--)
255 /* check this line */
256 if (regexec(re
, line
, 1) && (int)(re
->startp
[0] - line
) < pos
)
258 /* match! now find the last acceptable one in this line */
261 last
= (int)(re
->startp
[0] - line
);
262 try = (int)(re
->endp
[0] - line
);
264 && regexec(re
, &line
[try], FALSE
)
265 && (int)(re
->startp
[0] - line
) < pos
);
267 if (wrapped
&& *o_warn
)
270 if (delta
!= INFINITY
)
273 if (l
< 1 || l
> nlines
)
275 msg("search offset too big");
278 force_flags
= LNMD
|INCL
;
279 return MARK_AT_LINE(l
);
282 return MARK_AT_LINE(l
) + last
;
288 msg(*o_wrapscan
? "Not found" : "Hit top without finding RE");