3 * Copyright (C) 1984-2007 Mark Nudelman
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Less License, as specified in the README file.
8 * For more information about less, or for information on how to
9 * contact the author, see the README file.
14 * Routines to search a file for a pattern.
20 #define MINPOS(a,b) (((a) < (b)) ? (a) : (b))
21 #define MAXPOS(a,b) (((a) > (b)) ? (a) : (b))
23 #if HAVE_POSIX_REGCOMP
26 #define REGCOMP_FLAG (less_is_more ? 0 : REG_EXTENDED)
28 #define REGCOMP_FLAG 0
50 extern int how_search;
54 extern int jump_sline;
56 extern int less_is_more;
58 extern int status_col;
59 extern void * constant ml_search;
60 extern POSITION start_attnpos;
61 extern POSITION end_attnpos;
63 extern int hilite_search;
64 extern int screen_trashed;
65 extern int size_linebuf;
67 extern int can_goto_line;
68 static int hide_hilite;
70 static POSITION prep_startpos;
71 static POSITION prep_endpos;
75 struct hilite *hl_next;
79 static struct hilite hilite_anchor = { NULL, NULL_POSITION, NULL_POSITION };
80 #define hl_first hl_next
84 * These are the static variables that represent the "remembered"
87 #if HAVE_POSIX_REGCOMP
88 static regex_t *regpattern = NULL;
91 pcre *regpattern = NULL;
97 static char *cpattern = NULL;
100 static struct regexp *regpattern = NULL;
103 static int is_caseless;
104 static int is_ucase_pattern;
105 static int last_search_type;
106 static char *last_pattern = NULL;
109 * Convert text. Perform one or more of these transformations:
111 #define CVT_TO_LC 01 /* Convert upper-case to lower-case */
112 #define CVT_BS 02 /* Do backspace processing */
113 #define CVT_CRLF 04 /* Remove CR after LF */
114 #define CVT_ANSI 010 /* Remove ANSI escape sequences */
117 cvt_text(odst, osrc, lenp, ops)
125 register char *src_end;
128 src_end = osrc + *lenp;
130 src_end = osrc + strlen(osrc);
132 for (src = osrc, dst = odst; src < src_end; src++)
134 if ((ops & CVT_TO_LC) && IS_UPPER(*src))
135 /* Convert uppercase to lowercase. */
136 *dst++ = TO_LOWER(*src);
137 else if ((ops & CVT_BS) && *src == '\b' && dst > odst)
138 /* Delete BS and preceding char. */
140 else if ((ops & CVT_ANSI) && *src == ESC)
142 /* Skip to end of ANSI escape sequence. */
143 while (src + 1 != src_end)
144 if (!is_ansi_middle(*++src))
150 if ((ops & CVT_CRLF) && dst > odst && dst[-1] == '\r')
158 * Determine which conversions to perform.
164 if (is_caseless || bs_mode == BS_SPECIAL)
168 if (bs_mode == BS_SPECIAL)
170 if (bs_mode != BS_CONTROL)
172 } else if (bs_mode != BS_CONTROL)
176 if (ctldisp == OPT_ONPLUS)
182 * Are there any uppercase letters in this string?
190 for (p = s; *p != '\0'; p++)
197 * Is there a previous (remembered) search pattern?
202 if (last_search_type & SRCH_NO_REGEX)
203 return (last_pattern != NULL);
204 #if HAVE_POSIX_REGCOMP
205 return (regpattern != NULL);
208 return (regpattern != NULL);
211 return (re_pattern != 0);
214 return (cpattern != NULL);
217 return (regpattern != NULL);
220 return (last_pattern != NULL);
226 * Repaint the hilites currently displayed on the screen.
227 * Repaint each line which contains highlighted text.
228 * If on==0, force all hilites off.
237 int save_hide_hilite;
242 save_hide_hilite = hide_hilite;
253 hide_hilite = save_hide_hilite;
257 for (slinenum = TOP; slinenum < TOP + sc_height-1; slinenum++)
259 pos = position(slinenum);
260 if (pos == NULL_POSITION)
262 epos = position(slinenum+1);
265 * If any character in the line is highlighted,
268 * {{ This doesn't work -- if line is drawn with highlights
269 * which should be erased (e.g. toggle -i with status column),
270 * we must redraw the line even if it has no highlights.
271 * For now, just repaint every line. }}
273 if (is_hilited(pos, epos, 1, NULL))
276 (void) forw_line(pos);
283 hide_hilite = save_hide_hilite;
287 * Clear the attn hilite.
293 POSITION old_start_attnpos;
294 POSITION old_end_attnpos;
299 if (start_attnpos == NULL_POSITION)
301 old_start_attnpos = start_attnpos;
302 old_end_attnpos = end_attnpos;
303 start_attnpos = end_attnpos = NULL_POSITION;
313 for (slinenum = TOP; slinenum < TOP + sc_height-1; slinenum++)
315 pos = position(slinenum);
316 if (pos == NULL_POSITION)
318 epos = position(slinenum+1);
319 if (pos < old_end_attnpos &&
320 (epos == NULL_POSITION || epos > old_start_attnpos))
322 (void) forw_line(pos);
334 * Hide search string highlighting.
341 error("No previous regular expression", NULL_PARG);
345 hide_hilite = !hide_hilite;
351 * Compile a search pattern, for future use by match_pattern.
354 compile_pattern(pattern, search_type)
358 if ((search_type & SRCH_NO_REGEX) == 0)
360 #if HAVE_POSIX_REGCOMP
361 regex_t *s = (regex_t *) ecalloc(1, sizeof(regex_t));
362 if (regcomp(s, pattern, REGCOMP_FLAG))
365 error("Invalid pattern", NULL_PARG);
368 if (regpattern != NULL)
374 const char *errstring;
377 comp = pcre_compile(pattern, 0,
378 &errstring, &erroffset, NULL);
381 parg.p_string = (char *) errstring;
389 if ((parg.p_string = re_comp(pattern)) != NULL)
398 if ((s = regcmp(pattern, 0)) == NULL)
400 error("Invalid pattern", NULL_PARG);
403 if (cpattern != NULL)
409 if ((s = regcomp(pattern)) == NULL)
412 * regcomp has already printed an error message
417 if (regpattern != NULL)
423 if (last_pattern != NULL)
425 last_pattern = (char *) calloc(1, strlen(pattern)+1);
426 if (last_pattern != NULL)
427 strcpy(last_pattern, pattern);
429 last_search_type = search_type;
434 * Forget that we have a compiled pattern.
439 #if HAVE_POSIX_REGCOMP
440 if (regpattern != NULL)
445 if (regpattern != NULL)
446 pcre_free(regpattern);
453 if (cpattern != NULL)
458 if (regpattern != NULL)
466 * Perform a pattern match with the previously compiled pattern.
467 * Set sp and ep to the start and end of the matched string.
470 match_pattern(line, line_len, sp, ep, notbol)
479 if (last_search_type & SRCH_NO_REGEX)
480 return (match(last_pattern, strlen(last_pattern), line, line_len, sp, ep));
482 #if HAVE_POSIX_REGCOMP
485 int flags = (notbol) ? REG_NOTBOL : 0;
486 matched = !regexec(regpattern, line, 1, &rm, flags);
490 *sp = line + rm.rm_so;
491 *ep = line + rm.rm_eo;
500 int flags = (notbol) ? PCRE_NOTBOL : 0;
502 matched = pcre_exec(regpattern, NULL, line, line_len,
503 0, flags, ovector, 3) >= 0;
506 *sp = line + ovector[0];
507 *ep = line + ovector[1];
511 matched = (re_exec(line) == 1);
513 * re_exec doesn't seem to provide a way to get the matched string.
518 *ep = regex(cpattern, line);
519 matched = (*ep != NULL);
526 matched = regexec2(regpattern, line, notbol);
528 matched = regexec(regpattern, line);
532 *sp = regpattern->startp[0];
533 *ep = regpattern->endp[0];
536 matched = match(last_pattern, strlen(last_pattern), line, line_len, sp, ep);
543 * Clear the hilite list.
549 struct hilite *nexthl;
551 for (hl = hilite_anchor.hl_first; hl != NULL; hl = nexthl)
553 nexthl = hl->hl_next;
556 hilite_anchor.hl_first = NULL;
557 prep_startpos = prep_endpos = NULL_POSITION;
561 * Should any characters in a specified range be highlighted?
564 is_hilited_range(pos, epos)
571 * Look at each highlight and see if any part of it falls in the range.
573 for (hl = hilite_anchor.hl_first; hl != NULL; hl = hl->hl_next)
575 if (hl->hl_endpos > pos &&
576 (epos == NULL_POSITION || epos > hl->hl_startpos))
583 * Should any characters in a specified range be highlighted?
584 * If nohide is nonzero, don't consider hide_hilite.
587 is_hilited(pos, epos, nohide, p_matches)
595 if (p_matches != NULL)
599 start_attnpos != NULL_POSITION &&
601 (epos == NULL_POSITION || epos > start_attnpos))
603 * The attn line overlaps this range.
607 match = is_hilited_range(pos, epos);
611 if (p_matches != NULL)
613 * Report matches, even if we're hiding highlights.
617 if (hilite_search == 0)
619 * Not doing highlighting.
623 if (!nohide && hide_hilite)
625 * Highlighting is hidden.
633 * Add a new hilite to a hilite list.
636 add_hilite(anchor, hl)
637 struct hilite *anchor;
643 * Hilites are sorted in the list; find where new one belongs.
644 * Insert new one after ihl.
646 for (ihl = anchor; ihl->hl_next != NULL; ihl = ihl->hl_next)
648 if (ihl->hl_next->hl_startpos > hl->hl_startpos)
653 * Truncate hilite so it doesn't overlap any existing ones
654 * above and below it.
657 hl->hl_startpos = MAXPOS(hl->hl_startpos, ihl->hl_endpos);
658 if (ihl->hl_next != NULL)
659 hl->hl_endpos = MINPOS(hl->hl_endpos, ihl->hl_next->hl_startpos);
660 if (hl->hl_startpos >= hl->hl_endpos)
663 * Hilite was truncated out of existence.
668 hl->hl_next = ihl->hl_next;
673 adj_hilite_ansi(cvt_ops, line, line_len, npos)
679 char *line_end = *line + line_len;
681 if (cvt_ops & CVT_ANSI)
682 while (**line == ESC)
685 * Found an ESC. The file position moves
686 * forward past the entire ANSI escape sequence.
690 while (*line < line_end)
693 if (!is_ansi_middle(*(*line)++))
700 * Adjust hl_startpos & hl_endpos to account for backspace processing.
703 adj_hilite(anchor, linepos, cvt_ops)
704 struct hilite *anchor;
717 * The line was already scanned and hilites were added (in hilite_line).
718 * But it was assumed that each char position in the line
719 * correponds to one char position in the file.
720 * This may not be true if there are backspaces in the line.
721 * Get the raw line again. Look at each character.
723 (void) forw_raw_line(linepos, &line, &line_len);
724 line_end = line + line_len;
725 opos = npos = linepos;
726 hl = anchor->hl_first;
731 * See if we need to adjust the current hl_startpos or
732 * hl_endpos. After adjusting startpos[i], move to endpos[i].
733 * After adjusting endpos[i], move to startpos[i+1].
734 * The hilite list must be sorted thus:
735 * startpos[0] < endpos[0] <= startpos[1] < endpos[1] <= etc.
737 if (checkstart && hl->hl_startpos == opos)
739 hl->hl_startpos = npos;
741 continue; /* {{ not really necessary }} */
742 } else if (!checkstart && hl->hl_endpos == opos)
744 hl->hl_endpos = npos;
747 continue; /* {{ necessary }} */
749 if (line == line_end)
751 adj_hilite_ansi(cvt_ops, &line, line_end - line, &npos);
755 if (cvt_ops & CVT_BS)
757 while (*line == '\b')
761 adj_hilite_ansi(cvt_ops, &line, line_end - line, &npos);
762 if (line == line_end)
769 * Found a backspace. The file position moves
770 * forward by 2 relative to the processed line
771 * which was searched in hilite_line.
781 * Make a hilite for each string in a physical line which matches
782 * the current pattern.
783 * sp,ep delimit the first match already found.
786 hilite_line(linepos, line, line_len, sp, ep, cvt_ops)
795 char *line_end = line + line_len;
797 struct hilite hilites;
799 if (sp == NULL || ep == NULL)
802 * sp and ep delimit the first match in the line.
803 * Mark the corresponding file positions, then
804 * look for further matches and mark them.
805 * {{ This technique, of calling match_pattern on subsequent
806 * substrings of the line, may mark more than is correct
807 * if the pattern starts with "^". This bug is fixed
808 * for those regex functions that accept a notbol parameter
809 * (currently POSIX, PCRE and V8-with-regexec2). }}
813 * Put the hilites into a temporary list until they're adjusted.
815 hilites.hl_first = NULL;
820 * Assume that each char position in the "line"
821 * buffer corresponds to one char position in the file.
822 * This is not quite true; we need to adjust later.
824 hl = (struct hilite *) ecalloc(1, sizeof(struct hilite));
825 hl->hl_startpos = linepos + (sp-line);
826 hl->hl_endpos = linepos + (ep-line);
827 add_hilite(&hilites, hl);
830 * If we matched more than zero characters,
831 * move to the first char after the string we matched.
832 * If we matched zero, just move to the next char.
836 else if (searchp != line_end)
838 else /* end of line */
840 } while (match_pattern(searchp, line_end - searchp, &sp, &ep, 1));
843 * If there were backspaces in the original line, they
844 * were removed, and hl_startpos/hl_endpos are not correct.
845 * {{ This is very ugly. }}
847 adj_hilite(&hilites, linepos, cvt_ops);
850 * Now put the hilites into the real list.
852 while ((hl = hilites.hl_next) != NULL)
854 hilites.hl_next = hl->hl_next;
855 add_hilite(&hilite_anchor, hl);
861 * Change the caseless-ness of searches.
862 * Updates the internal search state to reflect a change in the -i flag.
867 if (!is_ucase_pattern)
869 * Pattern did not have uppercase.
870 * Just set the search caselessness to the global caselessness.
872 is_caseless = caseless;
875 * Pattern did have uppercase.
876 * Discard the pattern; we can't change search caselessness now.
883 * Find matching text which is currently on screen and highlight it.
888 struct scrpos scrpos;
891 if (scrpos.pos == NULL_POSITION)
893 prep_hilite(scrpos.pos, position(BOTTOM_PLUS_ONE), -1);
898 * Change highlighting parameters.
904 * Erase any highlights currently on screen.
909 if (hilite_search == OPT_ONPLUS)
911 * Display highlights.
918 * Figure out where to start a search.
921 search_pos(search_type)
930 * Start at the beginning (or end) of the file.
931 * The empty_screen() case is mainly for
932 * command line initiated searches;
933 * for example, "+/xyz" on the command line.
934 * Also for multi-file (SRCH_PAST_EOF) searches.
936 if (search_type & SRCH_FORW)
942 if (pos == NULL_POSITION)
944 (void) ch_end_seek();
953 * Search does not include current screen.
955 if (search_type & SRCH_FORW)
956 linenum = BOTTOM_PLUS_ONE;
959 pos = position(linenum);
963 * Search includes current screen.
964 * It starts at the jump target (if searching backwards),
965 * or at the jump target plus one (if forwards).
967 linenum = adjsline(jump_sline);
968 pos = position(linenum);
969 if (search_type & SRCH_FORW)
971 pos = forw_raw_line(pos, (char **)NULL, (int *)NULL);
972 while (pos == NULL_POSITION)
974 if (++linenum >= sc_height)
976 pos = position(linenum);
980 while (pos == NULL_POSITION)
984 pos = position(linenum);
992 * Search a subset of the file, specified by start/end position.
995 search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos)
1010 POSITION linepos, oldpos;
1012 linenum = find_linenum(pos);
1017 * Get lines until we find a matching one or until
1018 * we hit end-of-file (or beginning-of-file if we're
1019 * going backwards), or until we hit the end position.
1024 * A signal aborts the search.
1029 if ((endpos != NULL_POSITION && pos >= endpos) || maxlines == 0)
1032 * Reached end position without a match.
1034 if (pendpos != NULL)
1041 if (search_type & SRCH_FORW)
1044 * Read the next line, and save the
1045 * starting position of that line in linepos.
1048 pos = forw_raw_line(pos, &line, &line_len);
1054 * Read the previous line and save the
1055 * starting position of that line in linepos.
1057 pos = back_raw_line(pos, &line, &line_len);
1063 if (pos == NULL_POSITION)
1066 * Reached EOF/BOF without a match.
1068 if (pendpos != NULL)
1074 * If we're using line numbers, we might as well
1075 * remember the information we have now (the position
1076 * and line number of the current line).
1077 * Don't do it for every line because it slows down
1078 * the search. Remember the line number only if
1079 * we're "far" from the last place we remembered it.
1081 if (linenums && abs((int)(pos - oldpos)) > 1024)
1082 add_lnum(linenum, pos);
1086 * If it's a caseless search, convert the line to lowercase.
1087 * If we're doing backspace processing, delete backspaces.
1089 cvt_ops = get_cvt_ops();
1090 cvt_text(line, line, &line_len, cvt_ops);
1093 * Test the next line to see if we have a match.
1094 * We are successful if we either want a match and got one,
1095 * or if we want a non-match and got one.
1097 line_match = match_pattern(line, line_len, &sp, &ep, 0);
1098 line_match = (!(search_type & SRCH_NO_MATCH) && line_match) ||
1099 ((search_type & SRCH_NO_MATCH) && !line_match);
1105 if (search_type & SRCH_FIND_ALL)
1109 * We are supposed to find all matches in the range.
1110 * Just add the matches in this line to the
1111 * hilite list and keep searching.
1114 hilite_line(linepos, line, line_len, sp, ep, cvt_ops);
1116 } else if (--matches <= 0)
1119 * Found the one match we're looking for.
1123 if (hilite_search == OPT_ON)
1126 * Clear the hilite list and add only
1127 * the matches in this one line.
1131 hilite_line(linepos, line, line_len, sp, ep, cvt_ops);
1134 if (plinepos != NULL)
1135 *plinepos = linepos;
1142 * search for a pattern in history. If found, compile that pattern.
1145 hist_pattern(search_type)
1151 set_mlist(ml_search, 0);
1152 pattern = cmd_lastpattern();
1153 if (pattern == NULL)
1156 if (caseless == OPT_ONPLUS)
1157 cvt_text(pattern, pattern, (int *)NULL, CVT_TO_LC);
1159 if (compile_pattern(pattern, search_type) < 0)
1162 is_ucase_pattern = is_ucase(pattern);
1163 if (is_ucase_pattern && caseless != OPT_ONPLUS)
1166 is_caseless = caseless;
1169 if (hilite_search == OPT_ONPLUS && !hide_hilite)
1174 #else /* CMD_HISTORY */
1176 #endif /* CMD_HISTORY */
1180 * Search for the n-th occurrence of a specified pattern,
1181 * either forward or backward.
1182 * Return the number of matches not yet found in this file
1183 * (that is, n minus the number of matches found).
1184 * Return -1 if the search should be aborted.
1185 * Caller may continue the search in another file
1186 * if less than n matches are found in this file.
1189 search(search_type, pattern, n)
1197 if (pattern == NULL || *pattern == '\0')
1200 * A null pattern means use the previously compiled pattern.
1202 if (!prev_pattern() && !hist_pattern(search_type))
1204 error("No previous regular expression", NULL_PARG);
1207 if ((search_type & SRCH_NO_REGEX) !=
1208 (last_search_type & SRCH_NO_REGEX))
1210 error("Please re-enter search pattern", NULL_PARG);
1214 if (hilite_search == OPT_ON)
1217 * Erase the highlights currently on screen.
1218 * If the search fails, we'll redisplay them later.
1222 if (hilite_search == OPT_ONPLUS && hide_hilite)
1225 * Highlight any matches currently on screen,
1226 * before we actually start the search.
1236 * Compile the pattern.
1238 ucase = is_ucase(pattern);
1239 if (caseless == OPT_ONPLUS)
1240 cvt_text(pattern, pattern, (int *)NULL, CVT_TO_LC);
1241 if (compile_pattern(pattern, search_type) < 0)
1244 * Ignore case if -I is set OR
1245 * -i is set AND the pattern is all lowercase.
1247 is_ucase_pattern = ucase;
1248 if (is_ucase_pattern && caseless != OPT_ONPLUS)
1251 is_caseless = caseless;
1256 * Erase the highlights currently on screen.
1257 * Also permanently delete them from the hilite list.
1263 if (hilite_search == OPT_ONPLUS)
1266 * Highlight any matches currently on screen,
1267 * before we actually start the search.
1275 * Figure out where to start the search.
1277 pos = search_pos(search_type);
1278 if (pos == NULL_POSITION)
1281 * Can't find anyplace to start searching from.
1283 if (search_type & SRCH_PAST_EOF)
1285 /* repaint(); -- why was this here? */
1286 error("Nothing to search", NULL_PARG);
1290 n = search_range(pos, NULL_POSITION, search_type, n, -1,
1291 &pos, (POSITION*)NULL);
1295 * Search was unsuccessful.
1298 if (hilite_search == OPT_ON && n > 0)
1300 * Redisplay old hilites.
1307 if (!(search_type & SRCH_NO_MOVE))
1310 * Go to the matching line.
1312 jump_loc(pos, jump_sline);
1316 if (hilite_search == OPT_ON)
1318 * Display new hilites in the matching line.
1328 * Prepare hilites in a given range of the file.
1330 * The pair (prep_startpos,prep_endpos) delimits a contiguous region
1331 * of the file that has been "prepared"; that is, scanned for matches for
1332 * the current search pattern, and hilites have been created for such matches.
1333 * If prep_startpos == NULL_POSITION, the prep region is empty.
1334 * If prep_endpos == NULL_POSITION, the prep region extends to EOF.
1335 * prep_hilite asks that the range (spos,epos) be covered by the prep region.
1338 prep_hilite(spos, epos, maxlines)
1343 POSITION nprep_startpos = prep_startpos;
1344 POSITION nprep_endpos = prep_endpos;
1350 * Search beyond where we're asked to search, so the prep region covers
1351 * more than we need. Do one big search instead of a bunch of small ones.
1353 #define SEARCH_MORE (3*size_linebuf)
1355 if (!prev_pattern())
1359 * If we're limited to a max number of lines, figure out the
1360 * file position we should stop at.
1363 max_epos = NULL_POSITION;
1367 for (i = 0; i < maxlines; i++)
1368 max_epos = forw_raw_line(max_epos, (char **)NULL, (int *)NULL);
1373 * The range that we need to search (spos,epos); and the range that
1374 * the "prep" region will then cover (nprep_startpos,nprep_endpos).
1377 if (prep_startpos == NULL_POSITION ||
1378 (epos != NULL_POSITION && epos < prep_startpos) ||
1382 * New range is not contiguous with old prep region.
1383 * Discard the old prep region and start a new one.
1386 if (epos != NULL_POSITION)
1387 epos += SEARCH_MORE;
1388 nprep_startpos = spos;
1392 * New range partially or completely overlaps old prep region.
1394 if (epos == NULL_POSITION)
1397 * New range goes to end of file.
1400 } else if (epos > prep_endpos)
1403 * New range ends after old prep region.
1404 * Extend prep region to end at end of new range.
1406 epos += SEARCH_MORE;
1407 } else /* (epos <= prep_endpos) */
1410 * New range ends within old prep region.
1411 * Truncate search to end at start of old prep region.
1413 epos = prep_startpos;
1416 if (spos < prep_startpos)
1419 * New range starts before old prep region.
1420 * Extend old prep region backwards to start at
1421 * start of new range.
1423 if (spos < SEARCH_MORE)
1426 spos -= SEARCH_MORE;
1427 nprep_startpos = spos;
1428 } else /* (spos >= prep_startpos) */
1431 * New range starts within or after old prep region.
1432 * Trim search to start at end of old prep region.
1438 if (epos != NULL_POSITION && max_epos != NULL_POSITION &&
1441 * Don't go past the max position we're allowed.
1445 if (epos == NULL_POSITION || epos > spos)
1447 result = search_range(spos, epos, SRCH_FORW|SRCH_FIND_ALL, 0,
1448 maxlines, (POSITION*)NULL, &new_epos);
1451 if (prep_endpos == NULL_POSITION || new_epos > prep_endpos)
1452 nprep_endpos = new_epos;
1454 prep_startpos = nprep_startpos;
1455 prep_endpos = nprep_endpos;
1460 * Simple pattern matching function.
1461 * It supports no metacharacters like *, etc.
1464 match(pattern, pattern_len, buf, buf_len, pfound, pend)
1469 char **pfound, **pend;
1471 register char *pp, *lp;
1472 register char *pattern_end = pattern + pattern_len;
1473 register char *buf_end = buf + buf_len;
1475 for ( ; buf < buf_end; buf++)
1477 for (pp = pattern, lp = buf; *pp == *lp; pp++, lp++)
1478 if (pp == pattern_end || lp == buf_end)
1480 if (pp == pattern_end)
1494 * This function is called by the V8 regcomp to report
1495 * errors in regular expressions.