aboutsummaryrefslogtreecommitdiff
path: root/contrib/less/search.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/less/search.c')
-rw-r--r--contrib/less/search.c423
1 files changed, 171 insertions, 252 deletions
diff --git a/contrib/less/search.c b/contrib/less/search.c
index f619fbebeae8..98f01e5fcedd 100644
--- a/contrib/less/search.c
+++ b/contrib/less/search.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2021 Mark Nudelman
+ * Copyright (C) 1984-2023 Mark Nudelman
*
* You may distribute under the terms of either the GNU General Public
* License or the Less License, as specified in the README file.
@@ -26,6 +26,8 @@ extern int linenums;
extern int sc_height;
extern int jump_sline;
extern int bs_mode;
+extern int proc_backspace;
+extern int proc_return;
extern int ctldisp;
extern int status_col;
extern void *ml_search;
@@ -35,8 +37,10 @@ extern int utf_mode;
extern int screen_trashed;
extern int sc_width;
extern int sc_height;
-extern int chopline;
extern int hshift;
+extern int nosearch_headers;
+extern int header_lines;
+extern int header_cols;
#if HILITE_SEARCH
extern int hilite_search;
extern int size_linebuf;
@@ -67,6 +71,7 @@ struct hilite
{
POSITION hl_startpos;
POSITION hl_endpos;
+ int hl_attr;
};
struct hilite_node
{
@@ -109,6 +114,7 @@ struct pattern_info {
PATTERN_TYPE compiled;
char* text;
int search_type;
+ int is_ucase_pattern;
struct pattern_info *next;
};
@@ -119,15 +125,12 @@ struct pattern_info {
#endif
static struct pattern_info search_info;
-static int is_ucase_pattern;
-static int is_caseless;
+public int is_caseless;
/*
* Are there any uppercase letters in this string?
*/
- static int
-is_ucase(str)
- char *str;
+static int is_ucase(char *str)
{
char *str_end = str + strlen(str);
LWCHAR ch;
@@ -144,9 +147,7 @@ is_ucase(str)
/*
* Discard a saved pattern.
*/
- static void
-clear_pattern(info)
- struct pattern_info *info;
+static void clear_pattern(struct pattern_info *info)
{
if (info->text != NULL)
free(info->text);
@@ -159,13 +160,14 @@ clear_pattern(info)
/*
* Compile and save a search pattern.
*/
- static int
-set_pattern(info, pattern, search_type, show_error)
- struct pattern_info *info;
- char *pattern;
- int search_type;
- int show_error;
+static int set_pattern(struct pattern_info *info, char *pattern, int search_type, int show_error)
{
+ /*
+ * Ignore case if -I is set OR
+ * -i is set AND the pattern is all lowercase.
+ */
+ info->is_ucase_pattern = (pattern == NULL) ? FALSE : is_ucase(pattern);
+ is_caseless = (info->is_ucase_pattern && caseless != OPT_ONPLUS) ? 0 : caseless;
#if !NO_REGEX
if (pattern == NULL)
SET_NULL_PATTERN(info->compiled);
@@ -182,25 +184,13 @@ set_pattern(info, pattern, search_type, show_error)
strcpy(info->text, pattern);
}
info->search_type = search_type;
-
- /*
- * Ignore case if -I is set OR
- * -i is set AND the pattern is all lowercase.
- */
- is_ucase_pattern = is_ucase(pattern);
- if (is_ucase_pattern && caseless != OPT_ONPLUS)
- is_caseless = 0;
- else
- is_caseless = caseless;
return 0;
}
/*
* Initialize saved pattern to nothing.
*/
- static void
-init_pattern(info)
- struct pattern_info *info;
+static void init_pattern(struct pattern_info *info)
{
SET_NULL_PATTERN(info->compiled);
info->text = NULL;
@@ -211,8 +201,7 @@ init_pattern(info)
/*
* Initialize search variables.
*/
- public void
-init_search(VOID_PARAM)
+public void init_search(void)
{
init_pattern(&search_info);
}
@@ -220,16 +209,15 @@ init_search(VOID_PARAM)
/*
* Determine which text conversions to perform before pattern matching.
*/
- static int
-get_cvt_ops(VOID_PARAM)
+static int get_cvt_ops(int search_type)
{
int ops = 0;
- if (is_caseless)
+ if (is_caseless && (!re_handles_caseless || (search_type & SRCH_NO_REGEX)))
ops |= CVT_TO_LC;
- if (bs_mode == BS_SPECIAL)
+ if (proc_backspace == OPT_ON || (bs_mode == BS_SPECIAL && proc_backspace == OPT_OFF))
ops |= CVT_BS;
- if (bs_mode != BS_CONTROL)
+ if (proc_return == OPT_ON || (bs_mode != BS_CONTROL && proc_backspace == OPT_OFF))
ops |= CVT_CRLF;
if (ctldisp == OPT_ONPLUS)
ops |= CVT_ANSI;
@@ -239,9 +227,7 @@ get_cvt_ops(VOID_PARAM)
/*
* Is there a previous (remembered) search pattern?
*/
- static int
-prev_pattern(info)
- struct pattern_info *info;
+static int prev_pattern(struct pattern_info *info)
{
#if !NO_REGEX
if ((info->search_type & SRCH_NO_REGEX) == 0)
@@ -256,9 +242,7 @@ prev_pattern(info)
* Repaint each line which contains highlighted text.
* If on==0, force all hilites off.
*/
- public void
-repaint_hilite(on)
- int on;
+public void repaint_hilite(int on)
{
int sindex;
POSITION pos;
@@ -289,8 +273,10 @@ repaint_hilite(on)
continue;
(void) forw_line(pos);
goto_line(sindex);
+ clear_eol();
put_line();
}
+ overlay_header();
lower_left();
hide_hilite = save_hide_hilite;
}
@@ -299,8 +285,7 @@ repaint_hilite(on)
/*
* Clear the attn hilite.
*/
- public void
-clear_attn(VOID_PARAM)
+public void clear_attn(void)
{
#if HILITE_SEARCH
int sindex;
@@ -335,10 +320,13 @@ clear_attn(VOID_PARAM)
{
(void) forw_line(pos);
goto_line(sindex);
+ clear_eol();
put_line();
moved = 1;
}
}
+ if (overlay_header())
+ moved = 1;
if (moved)
lower_left();
#endif
@@ -347,9 +335,7 @@ clear_attn(VOID_PARAM)
/*
* Toggle or clear search string highlighting.
*/
- public void
-undo_search(clear)
- int clear;
+public void undo_search(int clear)
{
clear_pattern(&search_info);
#if HILITE_SEARCH
@@ -373,9 +359,7 @@ undo_search(clear)
/*
* Clear the hilite list.
*/
- public void
-clr_hlist(anchor)
- struct hilite_tree *anchor;
+public void clr_hlist(struct hilite_tree *anchor)
{
struct hilite_storage *hls;
struct hilite_storage *nexthls;
@@ -395,52 +379,23 @@ clr_hlist(anchor)
prep_startpos = prep_endpos = NULL_POSITION;
}
- public void
-clr_hilite(VOID_PARAM)
+public void clr_hilite(void)
{
clr_hlist(&hilite_anchor);
}
- public void
-clr_filter(VOID_PARAM)
+public void clr_filter(void)
{
clr_hlist(&filter_anchor);
}
- struct hilite_node*
-hlist_last(anchor)
- struct hilite_tree *anchor;
-{
- struct hilite_node *n = anchor->root;
- while (n != NULL && n->right != NULL)
- n = n->right;
- return n;
-}
-
- struct hilite_node*
-hlist_next(n)
- struct hilite_node *n;
-{
- return n->next;
-}
-
- struct hilite_node*
-hlist_prev(n)
- struct hilite_node *n;
-{
- return n->prev;
-}
-
/*
* Find the node covering pos, or the node after it if no node covers it,
* or return NULL if pos is after the last range. Remember the found node,
* to speed up subsequent searches for the same or similar positions (if
* we return NULL, remember the last node.)
*/
- struct hilite_node*
-hlist_find(anchor, pos)
- struct hilite_tree *anchor;
- POSITION pos;
+static struct hilite_node* hlist_find(struct hilite_tree *anchor, POSITION pos)
{
struct hilite_node *n, *m;
@@ -530,21 +485,20 @@ hlist_find(anchor, pos)
/*
* Should any characters in a specified range be highlighted?
*/
- static int
-is_hilited_range(pos, epos)
- POSITION pos;
- POSITION epos;
+static int hilited_range_attr(POSITION pos, POSITION epos)
{
struct hilite_node *n = hlist_find(&hilite_anchor, pos);
- return (n != NULL && (epos == NULL_POSITION || epos > n->r.hl_startpos));
+ if (n == NULL)
+ return 0;
+ if (epos != NULL_POSITION && epos <= n->r.hl_startpos)
+ return 0;
+ return n->r.hl_attr;
}
/*
* Is a line "filtered" -- that is, should it be hidden?
*/
- public int
-is_filtered(pos)
- POSITION pos;
+public int is_filtered(POSITION pos)
{
struct hilite_node *n;
@@ -559,9 +513,7 @@ is_filtered(pos)
* If pos is hidden, return the next position which isn't, otherwise
* just return pos.
*/
- public POSITION
-next_unfiltered(pos)
- POSITION pos;
+public POSITION next_unfiltered(POSITION pos)
{
struct hilite_node *n;
@@ -581,9 +533,7 @@ next_unfiltered(pos)
* If pos is hidden, return the previous position which isn't or 0 if
* we're filtered right to the beginning, otherwise just return pos.
*/
- public POSITION
-prev_unfiltered(pos)
- POSITION pos;
+public POSITION prev_unfiltered(POSITION pos)
{
struct hilite_node *n;
@@ -607,14 +557,9 @@ prev_unfiltered(pos)
* Should any characters in a specified range be highlighted?
* If nohide is nonzero, don't consider hide_hilite.
*/
- public int
-is_hilited_attr(pos, epos, nohide, p_matches)
- POSITION pos;
- POSITION epos;
- int nohide;
- int *p_matches;
+public int is_hilited_attr(POSITION pos, POSITION epos, int nohide, int *p_matches)
{
- int match;
+ int attr;
if (p_matches != NULL)
*p_matches = 0;
@@ -628,8 +573,8 @@ is_hilited_attr(pos, epos, nohide, p_matches)
*/
return (AT_HILITE|AT_COLOR_ATTN);
- match = is_hilited_range(pos, epos);
- if (!match)
+ attr = hilited_range_attr(pos, epos);
+ if (attr == 0)
return (0);
if (p_matches == NULL)
@@ -638,7 +583,7 @@ is_hilited_attr(pos, epos, nohide, p_matches)
* hilite in status column. In this case we want to return
* hilite status even if hiliting is disabled or hidden.
*/
- return (AT_HILITE|AT_COLOR_SEARCH);
+ return (attr);
/*
* Report matches, even if we're hiding highlights.
@@ -657,16 +602,14 @@ is_hilited_attr(pos, epos, nohide, p_matches)
*/
return (0);
- return (AT_HILITE|AT_COLOR_SEARCH);
+ return (attr);
}
/*
* Tree node storage: get the current block of nodes if it has spare
* capacity, or create a new one if not.
*/
- static struct hilite_storage*
-hlist_getstorage(anchor)
- struct hilite_tree *anchor;
+static struct hilite_storage * hlist_getstorage(struct hilite_tree *anchor)
{
int capacity = 1;
struct hilite_storage *s;
@@ -695,9 +638,7 @@ hlist_getstorage(anchor)
* Tree node storage: retrieve a new empty node to be inserted into the
* tree.
*/
- static struct hilite_node*
-hlist_getnode(anchor)
- struct hilite_tree *anchor;
+static struct hilite_node * hlist_getnode(struct hilite_tree *anchor)
{
struct hilite_storage *s = hlist_getstorage(anchor);
return &s->nodes[s->used++];
@@ -706,10 +647,7 @@ hlist_getnode(anchor)
/*
* Rotate the tree left around a pivot node.
*/
- static void
-hlist_rotate_left(anchor, n)
- struct hilite_tree *anchor;
- struct hilite_node *n;
+static void hlist_rotate_left(struct hilite_tree *anchor, struct hilite_node *n)
{
struct hilite_node *np = n->parent;
struct hilite_node *nr = n->right;
@@ -737,10 +675,7 @@ hlist_rotate_left(anchor, n)
/*
* Rotate the tree right around a pivot node.
*/
- static void
-hlist_rotate_right(anchor, n)
- struct hilite_tree *anchor;
- struct hilite_node *n;
+static void hlist_rotate_right(struct hilite_tree *anchor, struct hilite_node *n)
{
struct hilite_node *np = n->parent;
struct hilite_node *nl = n->left;
@@ -769,10 +704,7 @@ hlist_rotate_right(anchor, n)
/*
* Add a new hilite to a hilite list.
*/
- static void
-add_hilite(anchor, hl)
- struct hilite_tree *anchor;
- struct hilite *hl;
+static void add_hilite(struct hilite_tree *anchor, struct hilite *hl)
{
struct hilite_node *p, *n, *u;
@@ -801,7 +733,7 @@ add_hilite(anchor, hl)
{
if (hl->hl_startpos < p->r.hl_startpos)
{
- if (hl->hl_endpos > p->r.hl_startpos)
+ if (hl->hl_endpos > p->r.hl_startpos && hl->hl_attr == p->r.hl_attr)
hl->hl_endpos = p->r.hl_startpos;
if (p->left != NULL)
{
@@ -810,7 +742,7 @@ add_hilite(anchor, hl)
}
break;
}
- if (hl->hl_startpos < p->r.hl_endpos) {
+ if (hl->hl_startpos < p->r.hl_endpos && hl->hl_attr == p->r.hl_attr) {
hl->hl_startpos = p->r.hl_endpos;
if (hl->hl_startpos >= hl->hl_endpos)
return;
@@ -829,17 +761,19 @@ add_hilite(anchor, hl)
* insertion. Otherwise insert a new node at the leaf.
*/
if (hl->hl_startpos < p->r.hl_startpos) {
- if (hl->hl_endpos == p->r.hl_startpos)
- {
- p->r.hl_startpos = hl->hl_startpos;
- return;
- }
- if (p->prev != NULL && p->prev->r.hl_endpos == hl->hl_startpos)
+ if (hl->hl_attr == p->r.hl_attr)
{
- p->prev->r.hl_endpos = hl->hl_endpos;
- return;
+ if (hl->hl_endpos == p->r.hl_startpos)
+ {
+ p->r.hl_startpos = hl->hl_startpos;
+ return;
+ }
+ if (p->prev != NULL && p->prev->r.hl_endpos == hl->hl_startpos)
+ {
+ p->prev->r.hl_endpos = hl->hl_endpos;
+ return;
+ }
}
-
p->left = n = hlist_getnode(anchor);
n->next = p;
if (p->prev != NULL)
@@ -849,16 +783,18 @@ add_hilite(anchor, hl)
}
p->prev = n;
} else {
- if (p->r.hl_endpos == hl->hl_startpos)
+ if (hl->hl_attr == p->r.hl_attr)
{
- p->r.hl_endpos = hl->hl_endpos;
- return;
- }
- if (p->next != NULL && hl->hl_endpos == p->next->r.hl_startpos) {
- p->next->r.hl_startpos = hl->hl_startpos;
- return;
+ if (p->r.hl_endpos == hl->hl_startpos)
+ {
+ p->r.hl_endpos = hl->hl_endpos;
+ return;
+ }
+ if (p->next != NULL && hl->hl_endpos == p->next->r.hl_startpos) {
+ p->next->r.hl_startpos = hl->hl_startpos;
+ return;
+ }
}
-
p->right = n = hlist_getnode(anchor);
n->prev = p;
if (p->next != NULL)
@@ -946,20 +882,18 @@ add_hilite(anchor, hl)
}
/*
- * Hilight every character in a range of displayed characters.
+ * Highlight every character in a range of displayed characters.
*/
- static void
-create_hilites(linepos, start_index, end_index, chpos)
- POSITION linepos;
- int start_index;
- int end_index;
- int *chpos;
+static void create_hilites(POSITION linepos, char *line, char *sp, char *ep, int attr, int *chpos)
{
+ int start_index = sp - line;
+ int end_index = ep - line;
struct hilite hl;
int i;
/* Start the first hilite. */
hl.hl_startpos = linepos + chpos[start_index];
+ hl.hl_attr = attr;
/*
* Step through the displayed chars.
@@ -989,21 +923,13 @@ create_hilites(linepos, start_index, end_index, chpos)
* the current pattern.
* sp,ep delimit the first match already found.
*/
- static void
-hilite_line(linepos, line, line_len, chpos, sp, ep, cvt_ops)
- POSITION linepos;
- char *line;
- int line_len;
- int *chpos;
- char *sp;
- char *ep;
- int cvt_ops;
+static void hilite_line(POSITION linepos, char *line, int line_len, int *chpos, char **sp, char **ep, int nsp, int cvt_ops)
{
char *searchp;
char *line_end = line + line_len;
/*
- * sp and ep delimit the first match in the line.
+ * sp[0] and ep[0] delimit the first match in the line.
* Mark the corresponding file positions, then
* look for further matches and mark them.
* {{ This technique, of calling match_pattern on subsequent
@@ -1011,25 +937,44 @@ hilite_line(linepos, line, line_len, chpos, sp, ep, cvt_ops)
* if the pattern starts with "^". This bug is fixed
* for those regex functions that accept a notbol parameter
* (currently POSIX, PCRE and V8-with-regexec2). }}
+ * sp[i] and ep[i] for i>0 delimit subpattern matches.
+ * Color each of them with its unique color.
*/
searchp = line;
do {
- if (sp == NULL || ep == NULL)
- return;
- create_hilites(linepos, sp-line, ep-line, chpos);
+ char *lep = sp[0];
+ int i;
+ if (sp[0] == NULL || ep[0] == NULL)
+ break;
+ for (i = 1; i < nsp; i++)
+ {
+ if (sp[i] == NULL || ep[i] == NULL)
+ break;
+ if (ep[i] > sp[i])
+ {
+ create_hilites(linepos, line, lep, sp[i],
+ AT_HILITE | AT_COLOR_SEARCH, chpos);
+ create_hilites(linepos, line, sp[i], ep[i],
+ AT_HILITE | AT_COLOR_SUBSEARCH(i), chpos);
+ lep = ep[i];
+ }
+ }
+ create_hilites(linepos, line, lep, ep[0],
+ AT_HILITE | AT_COLOR_SEARCH, chpos);
+
/*
* If we matched more than zero characters,
* move to the first char after the string we matched.
* If we matched zero, just move to the next char.
*/
- if (ep > searchp)
- searchp = ep;
+ if (ep[0] > searchp)
+ searchp = ep[0];
else if (searchp != line_end)
searchp++;
else /* end of line */
break;
} while (match_pattern(info_compiled(&search_info), search_info.text,
- searchp, line_end - searchp, &sp, &ep, 1, search_info.search_type));
+ searchp, line_end - searchp, sp, ep, nsp, 1, search_info.search_type));
}
#endif
@@ -1037,8 +982,7 @@ hilite_line(linepos, line, line_len, chpos, sp, ep, cvt_ops)
/*
* Find matching text which is currently on screen and highlight it.
*/
- static void
-hilite_screen(VOID_PARAM)
+static void hilite_screen(void)
{
struct scrpos scrpos;
@@ -1052,8 +996,7 @@ hilite_screen(VOID_PARAM)
/*
* Change highlighting parameters.
*/
- public void
-chg_hilite(VOID_PARAM)
+public void chg_hilite(void)
{
/*
* Erase any highlights currently on screen.
@@ -1072,9 +1015,7 @@ chg_hilite(VOID_PARAM)
/*
* Figure out where to start a search.
*/
- static POSITION
-search_pos(search_type)
- int search_type;
+static POSITION search_pos(int search_type)
{
POSITION pos;
int sindex;
@@ -1167,22 +1108,14 @@ search_pos(search_type)
* If so, add an entry to the filter list.
*/
#if HILITE_SEARCH
- static int
-matches_filters(pos, cline, line_len, chpos, linepos, sp, ep)
- POSITION pos;
- char *cline;
- int line_len;
- int *chpos;
- POSITION linepos;
- char **sp;
- char **ep;
+static int matches_filters(POSITION pos, char *cline, int line_len, int *chpos, POSITION linepos, char **sp, char **ep, int nsp)
{
struct pattern_info *filter;
for (filter = filter_infos; filter != NULL; filter = filter->next)
{
int line_filter = match_pattern(info_compiled(filter), filter->text,
- cline, line_len, sp, ep, 0, filter->search_type);
+ cline, line_len, sp, ep, nsp, 0, filter->search_type);
if (line_filter)
{
struct hilite hl;
@@ -1202,11 +1135,7 @@ matches_filters(pos, cline, line_len, chpos, linepos, sp, ep)
* Get the position of the first char in the screen line which
* puts tpos on screen.
*/
- static POSITION
-get_lastlinepos(pos, tpos, sheight)
- POSITION pos;
- POSITION tpos;
- int sheight;
+static POSITION get_lastlinepos(POSITION pos, POSITION tpos, int sheight)
{
int nlines;
@@ -1227,16 +1156,13 @@ get_lastlinepos(pos, tpos, sheight)
* Get the segment index of tpos in the line starting at pos.
* A segment is a string of printable chars that fills the screen width.
*/
- static int
-get_seg(pos, tpos)
- POSITION pos;
- POSITION tpos;
+static int get_seg(POSITION pos, POSITION tpos)
{
int seg;
for (seg = 0;; seg++)
{
- POSITION npos = forw_line_seg(pos, TRUE);
+ POSITION npos = forw_line_seg(pos, FALSE, FALSE, TRUE);
if (npos > tpos)
return seg;
pos = npos;
@@ -1246,31 +1172,32 @@ get_seg(pos, tpos)
/*
* Search a subset of the file, specified by start/end position.
*/
- static int
-search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos, plastlinepos)
- POSITION pos;
- POSITION endpos;
- int search_type;
- int matches;
- int maxlines;
- POSITION *plinepos;
- POSITION *pendpos;
- POSITION *plastlinepos;
+static int search_range(POSITION pos, POSITION endpos, int search_type, int matches, int maxlines, POSITION *plinepos, POSITION *pendpos, POSITION *plastlinepos)
{
char *line;
char *cline;
int line_len;
LINENUM linenum;
- char *sp, *ep;
+ #define NSP (NUM_SEARCH_COLORS+2)
+ char *sp[NSP];
+ char *ep[NSP];
int line_match;
int cvt_ops;
int cvt_len;
int *chpos;
POSITION linepos, oldpos;
+ int skip_bytes = 0;
int swidth = sc_width - line_pfx_width();
int sheight = sc_height - sindex_from_sline(jump_sline);
linenum = find_linenum(pos);
+ if (nosearch_headers && linenum <= header_lines)
+ {
+ linenum = header_lines + 1;
+ pos = find_pos(linenum);
+ }
+ if (pos == NULL_POSITION)
+ return (-1);
oldpos = pos;
/* When the search wraps around, end at starting position. */
if ((search_type & SRCH_WRAP) && endpos == NULL_POSITION)
@@ -1381,12 +1308,14 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos, pla
if (is_filtered(linepos))
continue;
#endif
+ if (nosearch_headers)
+ skip_bytes = skip_columns(header_cols, &line, &line_len);
/*
* If it's a caseless search, convert the line to lowercase.
* If we're doing backspace processing, delete backspaces.
*/
- cvt_ops = get_cvt_ops();
+ cvt_ops = get_cvt_ops(search_type);
cvt_len = cvt_length(line_len, cvt_ops);
cline = (char *) ecalloc(1, cvt_len);
chpos = cvt_alloc_chpos(cvt_len);
@@ -1400,7 +1329,7 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos, pla
((search_type & SRCH_FIND_ALL) ||
prep_startpos == NULL_POSITION ||
linepos < prep_startpos || linepos >= prep_endpos)) {
- if (matches_filters(pos, cline, line_len, chpos, linepos, &sp, &ep))
+ if (matches_filters(pos, cline, line_len, chpos, linepos, sp, ep, NSP))
continue;
}
#endif
@@ -1413,7 +1342,7 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos, pla
if (prev_pattern(&search_info))
{
line_match = match_pattern(info_compiled(&search_info), search_info.text,
- cline, line_len, &sp, &ep, 0, search_type);
+ cline, line_len, sp, ep, NSP, 0, search_type);
if (line_match)
{
/*
@@ -1427,7 +1356,7 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos, pla
* Just add the matches in this line to the
* hilite list and keep searching.
*/
- hilite_line(linepos, cline, line_len, chpos, sp, ep, cvt_ops);
+ hilite_line(linepos + skip_bytes, cline, line_len, chpos, sp, ep, NSP, cvt_ops);
#endif
} else if (--matches <= 0)
{
@@ -1443,27 +1372,25 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos, pla
* the matches in this one line.
*/
clr_hilite();
- hilite_line(linepos, cline, line_len, chpos, sp, ep, cvt_ops);
+ hilite_line(linepos + skip_bytes, cline, line_len, chpos, sp, ep, NSP, cvt_ops);
}
#endif
- if (chopline)
+ if (chop_line())
{
/*
* If necessary, shift horizontally to make sure
* search match is fully visible.
*/
- if (sp != NULL && ep != NULL)
+ if (sp[0] != NULL && ep[0] != NULL)
{
- int start_off = sp - cline;
- int end_off = ep - cline;
+ int start_off = sp[0] - cline;
+ int end_off = ep[0] - cline;
int save_hshift = hshift;
int sshift;
int eshift;
hshift = 0; /* make get_seg count screen lines */
- chopline = FALSE;
sshift = swidth * get_seg(linepos, linepos + chpos[start_off]);
eshift = swidth * get_seg(linepos, linepos + chpos[end_off]);
- chopline = TRUE;
if (sshift >= save_hshift && eshift <= save_hshift)
{
hshift = save_hshift;
@@ -1483,9 +1410,9 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos, pla
* of the match appears in the last line on the screen.
* lastlinepos is the position of the first char of that last line.
*/
- if (ep != NULL)
+ if (ep[0] != NULL)
{
- int end_off = ep - cline;
+ int end_off = ep[0] - cline;
if (end_off >= swidth * sheight / 4) /* heuristic */
*plastlinepos = get_lastlinepos(linepos, linepos + chpos[end_off], sheight);
}
@@ -1506,9 +1433,7 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos, pla
/*
* search for a pattern in history. If found, compile that pattern.
*/
- static int
-hist_pattern(search_type)
- int search_type;
+static int hist_pattern(int search_type)
{
#if CMD_HISTORY
char *pattern;
@@ -1536,24 +1461,28 @@ hist_pattern(search_type)
* Change the caseless-ness of searches.
* Updates the internal search state to reflect a change in the -i flag.
*/
- public void
-chg_caseless(VOID_PARAM)
+public void chg_caseless(void)
{
- if (!is_ucase_pattern)
+ if (!search_info.is_ucase_pattern)
+ {
/*
* Pattern did not have uppercase.
- * Just set the search caselessness to the global caselessness.
+ * Set the search caselessness to the global caselessness.
*/
is_caseless = caseless;
- else
- {
/*
- * Pattern did have uppercase.
- * Regenerate the pattern using the new state.
+ * If regex handles caseless, we need to discard
+ * the pattern which was compiled with the old caseless.
*/
- clear_pattern(&search_info);
- (void) hist_pattern(search_info.search_type);
+ if (!re_handles_caseless)
+ /* We handle caseless, so the pattern doesn't change. */
+ return;
}
+ /*
+ * Regenerate the pattern using the new state.
+ */
+ clear_pattern(&search_info);
+ (void) hist_pattern(search_info.search_type);
}
/*
@@ -1565,11 +1494,7 @@ chg_caseless(VOID_PARAM)
* Caller may continue the search in another file
* if less than n matches are found in this file.
*/
- public int
-search(search_type, pattern, n)
- int search_type;
- char *pattern;
- int n;
+public int search(int search_type, char *pattern, int n)
{
POSITION pos;
POSITION opos;
@@ -1714,11 +1639,7 @@ search(search_type, pattern, n)
* If prep_endpos == NULL_POSITION, the prep region extends to EOF.
* prep_hilite asks that the range (spos,epos) be covered by the prep region.
*/
- public void
-prep_hilite(spos, epos, maxlines)
- POSITION spos;
- POSITION epos;
- int maxlines;
+public void prep_hilite(POSITION spos, POSITION epos, int maxlines)
{
POSITION nprep_startpos = prep_startpos;
POSITION nprep_endpos = prep_endpos;
@@ -1833,7 +1754,7 @@ prep_hilite(spos, epos, maxlines)
if (epos == NULL_POSITION || epos > spos)
{
int search_type = SRCH_FORW | SRCH_FIND_ALL;
- search_type |= (search_info.search_type & SRCH_NO_REGEX);
+ search_type |= (search_info.search_type & (SRCH_NO_REGEX|SRCH_SUBSEARCH_ALL));
for (;;)
{
result = search_range(spos, epos, search_type, 0, maxlines, (POSITION*)NULL, &new_epos, (POSITION*)NULL);
@@ -1884,10 +1805,7 @@ prep_hilite(spos, epos, maxlines)
/*
* Set the pattern to be used for line filtering.
*/
- public void
-set_filter_pattern(pattern, search_type)
- char *pattern;
- int search_type;
+public void set_filter_pattern(char *pattern, int search_type)
{
struct pattern_info *filter;
@@ -1908,7 +1826,11 @@ set_filter_pattern(pattern, search_type)
/* Create a new filter and add it to the filter_infos list. */
filter = ecalloc(1, sizeof(struct pattern_info));
init_pattern(filter);
- set_pattern(filter, pattern, search_type, 1);
+ if (set_pattern(filter, pattern, search_type, 1) < 0)
+ {
+ free(filter);
+ return;
+ }
filter->next = filter_infos;
filter_infos = filter;
}
@@ -1918,8 +1840,7 @@ set_filter_pattern(pattern, search_type)
/*
* Is there a line filter in effect?
*/
- public int
-is_filtering(VOID_PARAM)
+public int is_filtering(void)
{
if (ch_getflags() & CH_HELPFILE)
return (0);
@@ -1934,9 +1855,7 @@ is_filtering(VOID_PARAM)
*/
public int reg_show_error = 1;
- void
-regerror(s)
- char *s;
+void regerror(char *s)
{
PARG parg;