Changeset View
Changeset View
Standalone View
Standalone View
contrib/less/search.c
Show First 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | |||||
static struct pattern_info search_info; | static struct pattern_info search_info; | ||||
static struct pattern_info filter_info; | static struct pattern_info filter_info; | ||||
/* | /* | ||||
* Are there any uppercase letters in this string? | * Are there any uppercase letters in this string? | ||||
*/ | */ | ||||
static int | static int | ||||
is_ucase(str) | is_ucase(constant char *str) | ||||
char *str; | |||||
{ | { | ||||
char *str_end = str + strlen(str); | constant char *str_end = str + strlen(str); | ||||
LWCHAR ch; | LWCHAR ch; | ||||
while (str < str_end) | while (str < str_end) | ||||
{ | { | ||||
ch = step_char(&str, +1, str_end); | ch = step_char(&str, +1, str_end); | ||||
if (IS_UPPER(ch)) | if (IS_UPPER(ch)) | ||||
return (1); | return (1); | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Compile and save a search pattern. | * Compile and save a search pattern. | ||||
*/ | */ | ||||
static int | static int | ||||
set_pattern(info, pattern, search_type) | set_pattern(struct pattern_info *info, char *pattern, int search_type) | ||||
struct pattern_info *info; | |||||
char *pattern; | |||||
int search_type; | |||||
{ | { | ||||
#if !NO_REGEX | #if !NO_REGEX | ||||
if (pattern == NULL) | if (pattern == NULL) | ||||
CLEAR_PATTERN(info->compiled); | CLEAR_PATTERN(info->compiled); | ||||
else if (compile_pattern(pattern, search_type, &info->compiled) < 0) | else if (compile_pattern(pattern, search_type, | ||||
(void **)&info->compiled) < 0) | |||||
return -1; | return -1; | ||||
#endif | #endif | ||||
/* Pattern compiled successfully; save the text too. */ | /* Pattern compiled successfully; save the text too. */ | ||||
if (info->text != NULL) | if (info->text != NULL) | ||||
free(info->text); | free(info->text); | ||||
info->text = NULL; | info->text = NULL; | ||||
if (pattern != NULL) | if (pattern != NULL) | ||||
{ | { | ||||
Show All 13 Lines | else | ||||
is_caseless = caseless; | is_caseless = caseless; | ||||
return 0; | return 0; | ||||
} | } | ||||
/* | /* | ||||
* Discard a saved pattern. | * Discard a saved pattern. | ||||
*/ | */ | ||||
static void | static void | ||||
clear_pattern(info) | clear_pattern(struct pattern_info *info) | ||||
struct pattern_info *info; | |||||
{ | { | ||||
if (info->text != NULL) | if (info->text != NULL) | ||||
free(info->text); | free(info->text); | ||||
info->text = NULL; | info->text = NULL; | ||||
#if !NO_REGEX | #if !NO_REGEX | ||||
uncompile_pattern(&info->compiled); | uncompile_pattern((void **)&info->compiled); | ||||
#endif | #endif | ||||
} | } | ||||
/* | /* | ||||
* Initialize saved pattern to nothing. | * Initialize saved pattern to nothing. | ||||
*/ | */ | ||||
static void | static void | ||||
init_pattern(info) | init_pattern(struct pattern_info *info) | ||||
struct pattern_info *info; | |||||
{ | { | ||||
CLEAR_PATTERN(info->compiled); | CLEAR_PATTERN(info->compiled); | ||||
info->text = NULL; | info->text = NULL; | ||||
info->search_type = 0; | info->search_type = 0; | ||||
} | } | ||||
/* | /* | ||||
* Initialize search variables. | * Initialize search variables. | ||||
*/ | */ | ||||
public void | public void | ||||
init_search() | init_search(void) | ||||
{ | { | ||||
init_pattern(&search_info); | init_pattern(&search_info); | ||||
init_pattern(&filter_info); | init_pattern(&filter_info); | ||||
} | } | ||||
/* | /* | ||||
* Determine which text conversions to perform before pattern matching. | * Determine which text conversions to perform before pattern matching. | ||||
*/ | */ | ||||
static int | static int | ||||
get_cvt_ops() | get_cvt_ops(void) | ||||
{ | { | ||||
int ops = 0; | int ops = 0; | ||||
if (is_caseless || bs_mode == BS_SPECIAL) | if (is_caseless || bs_mode == BS_SPECIAL) | ||||
{ | { | ||||
if (is_caseless) | if (is_caseless) | ||||
ops |= CVT_TO_LC; | ops |= CVT_TO_LC; | ||||
if (bs_mode == BS_SPECIAL) | if (bs_mode == BS_SPECIAL) | ||||
ops |= CVT_BS; | ops |= CVT_BS; | ||||
if (bs_mode != BS_CONTROL) | if (bs_mode != BS_CONTROL) | ||||
ops |= CVT_CRLF; | ops |= CVT_CRLF; | ||||
} else if (bs_mode != BS_CONTROL) | } else if (bs_mode != BS_CONTROL) | ||||
{ | { | ||||
ops |= CVT_CRLF; | ops |= CVT_CRLF; | ||||
} | } | ||||
if (ctldisp == OPT_ONPLUS) | if (ctldisp == OPT_ONPLUS) | ||||
ops |= CVT_ANSI; | ops |= CVT_ANSI; | ||||
return (ops); | return (ops); | ||||
} | } | ||||
/* | /* | ||||
* Is there a previous (remembered) search pattern? | * Is there a previous (remembered) search pattern? | ||||
*/ | */ | ||||
static int | static int | ||||
prev_pattern(info) | prev_pattern(struct pattern_info *info) | ||||
struct pattern_info *info; | |||||
{ | { | ||||
#if !NO_REGEX | #if !NO_REGEX | ||||
if ((info->search_type & SRCH_NO_REGEX) == 0) | if ((info->search_type & SRCH_NO_REGEX) == 0) | ||||
return (!is_null_pattern(info->compiled)); | return (!is_null_pattern(info->compiled)); | ||||
#endif | #endif | ||||
return (info->text != NULL); | return (info->text != NULL); | ||||
} | } | ||||
#if HILITE_SEARCH | #if HILITE_SEARCH | ||||
/* | /* | ||||
* Repaint the hilites currently displayed on the screen. | * Repaint the hilites currently displayed on the screen. | ||||
* Repaint each line which contains highlighted text. | * Repaint each line which contains highlighted text. | ||||
* If on==0, force all hilites off. | * If on==0, force all hilites off. | ||||
*/ | */ | ||||
public void | public void | ||||
repaint_hilite(on) | repaint_hilite(int on) | ||||
int on; | |||||
{ | { | ||||
int slinenum; | int slinenum; | ||||
POSITION pos; | POSITION pos; | ||||
int save_hide_hilite; | int save_hide_hilite; | ||||
if (squished) | if (squished) | ||||
repaint(); | repaint(); | ||||
Show All 24 Lines | repaint_hilite(int on) | ||||
lower_left(); | lower_left(); | ||||
hide_hilite = save_hide_hilite; | hide_hilite = save_hide_hilite; | ||||
} | } | ||||
/* | /* | ||||
* Clear the attn hilite. | * Clear the attn hilite. | ||||
*/ | */ | ||||
public void | public void | ||||
clear_attn() | clear_attn(void) | ||||
{ | { | ||||
int slinenum; | int slinenum; | ||||
POSITION old_start_attnpos; | POSITION old_start_attnpos; | ||||
POSITION old_end_attnpos; | POSITION old_end_attnpos; | ||||
POSITION pos; | POSITION pos; | ||||
POSITION epos; | POSITION epos; | ||||
int moved = 0; | int moved = 0; | ||||
Show All 30 Lines | if (moved) | ||||
lower_left(); | lower_left(); | ||||
} | } | ||||
#endif | #endif | ||||
/* | /* | ||||
* Hide search string highlighting. | * Hide search string highlighting. | ||||
*/ | */ | ||||
public void | public void | ||||
undo_search() | undo_search(void) | ||||
{ | { | ||||
if (!prev_pattern(&search_info)) | if (!prev_pattern(&search_info)) | ||||
{ | { | ||||
error("No previous regular expression", NULL_PARG); | error("No previous regular expression", NULL_PARG); | ||||
return; | return; | ||||
} | } | ||||
#if HILITE_SEARCH | #if HILITE_SEARCH | ||||
hide_hilite = !hide_hilite; | hide_hilite = !hide_hilite; | ||||
repaint_hilite(1); | repaint_hilite(1); | ||||
#endif | #endif | ||||
} | } | ||||
#if HILITE_SEARCH | #if HILITE_SEARCH | ||||
/* | /* | ||||
* Clear the hilite list. | * Clear the hilite list. | ||||
*/ | */ | ||||
public void | public void | ||||
clr_hlist(anchor) | clr_hlist(struct hilite_tree *anchor) | ||||
struct hilite_tree *anchor; | |||||
{ | { | ||||
struct hilite_storage *hls; | struct hilite_storage *hls; | ||||
struct hilite_storage *nexthls; | struct hilite_storage *nexthls; | ||||
for (hls = anchor->first; hls != NULL; hls = nexthls) | for (hls = anchor->first; hls != NULL; hls = nexthls) | ||||
{ | { | ||||
nexthls = hls->next; | nexthls = hls->next; | ||||
free((void*)hls->nodes); | free((void*)hls->nodes); | ||||
free((void*)hls); | free((void*)hls); | ||||
} | } | ||||
anchor->first = NULL; | anchor->first = NULL; | ||||
anchor->current = NULL; | anchor->current = NULL; | ||||
anchor->root = NULL; | anchor->root = NULL; | ||||
anchor->lookaside = NULL; | anchor->lookaside = NULL; | ||||
prep_startpos = prep_endpos = NULL_POSITION; | prep_startpos = prep_endpos = NULL_POSITION; | ||||
} | } | ||||
public void | public void | ||||
clr_hilite() | clr_hilite(void) | ||||
{ | { | ||||
clr_hlist(&hilite_anchor); | clr_hlist(&hilite_anchor); | ||||
} | } | ||||
public void | public void | ||||
clr_filter() | clr_filter(void) | ||||
{ | { | ||||
clr_hlist(&filter_anchor); | clr_hlist(&filter_anchor); | ||||
} | } | ||||
struct hilite_node* | struct hilite_node* | ||||
hlist_last(anchor) | hlist_last(anchor) | ||||
struct hilite_tree *anchor; | struct hilite_tree *anchor; | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | hlist_find(anchor, pos) | ||||
return n; | return n; | ||||
} | } | ||||
/* | /* | ||||
* Should any characters in a specified range be highlighted? | * Should any characters in a specified range be highlighted? | ||||
*/ | */ | ||||
static int | static int | ||||
is_hilited_range(pos, epos) | is_hilited_range(POSITION pos, POSITION epos) | ||||
POSITION pos; | |||||
POSITION epos; | |||||
{ | { | ||||
struct hilite_node *n = hlist_find(&hilite_anchor, pos); | struct hilite_node *n = hlist_find(&hilite_anchor, pos); | ||||
return (n != NULL && (epos == NULL_POSITION || epos > n->r.hl_startpos)); | return (n != NULL && (epos == NULL_POSITION || epos > n->r.hl_startpos)); | ||||
} | } | ||||
/* | /* | ||||
* Is a line "filtered" -- that is, should it be hidden? | * Is a line "filtered" -- that is, should it be hidden? | ||||
*/ | */ | ||||
public int | public int | ||||
is_filtered(pos) | is_filtered(POSITION pos) | ||||
POSITION pos; | |||||
{ | { | ||||
struct hilite_node *n; | struct hilite_node *n; | ||||
if (ch_getflags() & CH_HELPFILE) | if (ch_getflags() & CH_HELPFILE) | ||||
return (0); | return (0); | ||||
n = hlist_find(&filter_anchor, pos); | n = hlist_find(&filter_anchor, pos); | ||||
return (n != NULL && pos >= n->r.hl_startpos); | return (n != NULL && pos >= n->r.hl_startpos); | ||||
} | } | ||||
/* | /* | ||||
* If pos is hidden, return the next position which isn't, otherwise | * If pos is hidden, return the next position which isn't, otherwise | ||||
* just return pos. | * just return pos. | ||||
*/ | */ | ||||
public POSITION | public POSITION | ||||
next_unfiltered(pos) | next_unfiltered(POSITION pos) | ||||
POSITION pos; | |||||
{ | { | ||||
struct hilite_node *n; | struct hilite_node *n; | ||||
if (ch_getflags() & CH_HELPFILE) | if (ch_getflags() & CH_HELPFILE) | ||||
return (pos); | return (pos); | ||||
n = hlist_find(&filter_anchor, pos); | n = hlist_find(&filter_anchor, pos); | ||||
while (n != NULL && pos >= n->r.hl_startpos) | while (n != NULL && pos >= n->r.hl_startpos) | ||||
{ | { | ||||
pos = n->r.hl_endpos; | pos = n->r.hl_endpos; | ||||
n = n->next; | n = n->next; | ||||
} | } | ||||
return (pos); | return (pos); | ||||
} | } | ||||
/* | /* | ||||
* If pos is hidden, return the previous position which isn't or 0 if | * 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. | * we're filtered right to the beginning, otherwise just return pos. | ||||
*/ | */ | ||||
public POSITION | public POSITION | ||||
prev_unfiltered(pos) | prev_unfiltered(POSITION pos) | ||||
POSITION pos; | |||||
{ | { | ||||
struct hilite_node *n; | struct hilite_node *n; | ||||
if (ch_getflags() & CH_HELPFILE) | if (ch_getflags() & CH_HELPFILE) | ||||
return (pos); | return (pos); | ||||
n = hlist_find(&filter_anchor, pos); | n = hlist_find(&filter_anchor, pos); | ||||
while (n != NULL && pos >= n->r.hl_startpos) | while (n != NULL && pos >= n->r.hl_startpos) | ||||
{ | { | ||||
pos = n->r.hl_startpos; | pos = n->r.hl_startpos; | ||||
if (pos == 0) | if (pos == 0) | ||||
break; | break; | ||||
pos--; | pos--; | ||||
n = n->prev; | n = n->prev; | ||||
} | } | ||||
return (pos); | return (pos); | ||||
} | } | ||||
/* | /* | ||||
* Should any characters in a specified range be highlighted? | * Should any characters in a specified range be highlighted? | ||||
* If nohide is nonzero, don't consider hide_hilite. | * If nohide is nonzero, don't consider hide_hilite. | ||||
*/ | */ | ||||
public int | public int | ||||
is_hilited(pos, epos, nohide, p_matches) | is_hilited(POSITION pos, POSITION epos, int nohide, int *p_matches) | ||||
POSITION pos; | |||||
POSITION epos; | |||||
int nohide; | |||||
int *p_matches; | |||||
{ | { | ||||
int match; | int match; | ||||
if (p_matches != NULL) | if (p_matches != NULL) | ||||
*p_matches = 0; | *p_matches = 0; | ||||
if (!status_col && | if (!status_col && | ||||
start_attnpos != NULL_POSITION && | start_attnpos != NULL_POSITION && | ||||
Show All 29 Lines | is_hilited(POSITION pos, POSITION epos, int nohide, int *p_matches) | ||||
return (1); | return (1); | ||||
} | } | ||||
/* | /* | ||||
* Tree node storage: get the current block of nodes if it has spare | * Tree node storage: get the current block of nodes if it has spare | ||||
* capacity, or create a new one if not. | * capacity, or create a new one if not. | ||||
*/ | */ | ||||
static struct hilite_storage* | static struct hilite_storage* | ||||
hlist_getstorage(anchor) | hlist_getstorage(struct hilite_tree *anchor) | ||||
struct hilite_tree *anchor; | |||||
{ | { | ||||
int capacity = 1; | int capacity = 1; | ||||
struct hilite_storage *s; | struct hilite_storage *s; | ||||
if (anchor->current) | if (anchor->current) | ||||
{ | { | ||||
if (anchor->current->used < anchor->current->capacity) | if (anchor->current->used < anchor->current->capacity) | ||||
return anchor->current; | return anchor->current; | ||||
Show All 13 Lines | hlist_getstorage(struct hilite_tree *anchor) | ||||
return s; | return s; | ||||
} | } | ||||
/* | /* | ||||
* Tree node storage: retrieve a new empty node to be inserted into the | * Tree node storage: retrieve a new empty node to be inserted into the | ||||
* tree. | * tree. | ||||
*/ | */ | ||||
static struct hilite_node* | static struct hilite_node* | ||||
hlist_getnode(anchor) | hlist_getnode(struct hilite_tree *anchor) | ||||
struct hilite_tree *anchor; | |||||
{ | { | ||||
struct hilite_storage *s = hlist_getstorage(anchor); | struct hilite_storage *s = hlist_getstorage(anchor); | ||||
return &s->nodes[s->used++]; | return &s->nodes[s->used++]; | ||||
} | } | ||||
/* | /* | ||||
* Rotate the tree left around a pivot node. | * Rotate the tree left around a pivot node. | ||||
*/ | */ | ||||
static void | static void | ||||
hlist_rotate_left(anchor, n) | hlist_rotate_left(struct hilite_tree *anchor, struct hilite_node *n) | ||||
struct hilite_tree *anchor; | |||||
struct hilite_node *n; | |||||
{ | { | ||||
struct hilite_node *np = n->parent; | struct hilite_node *np = n->parent; | ||||
struct hilite_node *nr = n->right; | struct hilite_node *nr = n->right; | ||||
struct hilite_node *nrl = n->right->left; | struct hilite_node *nrl = n->right->left; | ||||
if (np != NULL) | if (np != NULL) | ||||
{ | { | ||||
if (n == np->left) | if (n == np->left) | ||||
Show All 12 Lines | hlist_rotate_left(struct hilite_tree *anchor, struct hilite_node *n) | ||||
if (nrl != NULL) | if (nrl != NULL) | ||||
nrl->parent = n; | nrl->parent = n; | ||||
} | } | ||||
/* | /* | ||||
* Rotate the tree right around a pivot node. | * Rotate the tree right around a pivot node. | ||||
*/ | */ | ||||
static void | static void | ||||
hlist_rotate_right(anchor, n) | hlist_rotate_right(struct hilite_tree *anchor, struct hilite_node *n) | ||||
struct hilite_tree *anchor; | |||||
struct hilite_node *n; | |||||
{ | { | ||||
struct hilite_node *np = n->parent; | struct hilite_node *np = n->parent; | ||||
struct hilite_node *nl = n->left; | struct hilite_node *nl = n->left; | ||||
struct hilite_node *nlr = n->left->right; | struct hilite_node *nlr = n->left->right; | ||||
if (np != NULL) | if (np != NULL) | ||||
{ | { | ||||
if (n == np->right) | if (n == np->right) | ||||
Show All 13 Lines | if (nlr != NULL) | ||||
nlr->parent = n; | nlr->parent = n; | ||||
} | } | ||||
/* | /* | ||||
* Add a new hilite to a hilite list. | * Add a new hilite to a hilite list. | ||||
*/ | */ | ||||
static void | static void | ||||
add_hilite(anchor, hl) | add_hilite(struct hilite_tree *anchor, struct hilite *hl) | ||||
struct hilite_tree *anchor; | |||||
struct hilite *hl; | |||||
{ | { | ||||
struct hilite_node *p, *n, *u; | struct hilite_node *p, *n, *u; | ||||
/* Ignore empty ranges. */ | /* Ignore empty ranges. */ | ||||
if (hl->hl_startpos >= hl->hl_endpos) | if (hl->hl_startpos >= hl->hl_endpos) | ||||
return; | return; | ||||
p = anchor->root; | p = anchor->root; | ||||
▲ Show 20 Lines • Show All 160 Lines • ▼ Show 20 Lines | for (;;) | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* Hilight every character in a range of displayed characters. | * Hilight every character in a range of displayed characters. | ||||
*/ | */ | ||||
static void | static void | ||||
create_hilites(linepos, start_index, end_index, chpos) | create_hilites(POSITION linepos, int start_index, int end_index, int *chpos) | ||||
POSITION linepos; | |||||
int start_index; | |||||
int end_index; | |||||
int *chpos; | |||||
{ | { | ||||
struct hilite hl; | struct hilite hl; | ||||
int i; | int i; | ||||
/* Start the first hilite. */ | /* Start the first hilite. */ | ||||
hl.hl_startpos = linepos + chpos[start_index]; | hl.hl_startpos = linepos + chpos[start_index]; | ||||
/* | /* | ||||
Show All 20 Lines | |||||
} | } | ||||
/* | /* | ||||
* Make a hilite for each string in a physical line which matches | * Make a hilite for each string in a physical line which matches | ||||
* the current pattern. | * the current pattern. | ||||
* sp,ep delimit the first match already found. | * sp,ep delimit the first match already found. | ||||
*/ | */ | ||||
static void | static void | ||||
hilite_line(linepos, line, line_len, chpos, sp, ep, cvt_ops) | hilite_line(POSITION linepos, char *line, int line_len, int *chpos, char *sp, | ||||
POSITION linepos; | char *ep, int cvt_ops) | ||||
char *line; | |||||
int line_len; | |||||
int *chpos; | |||||
char *sp; | |||||
char *ep; | |||||
int cvt_ops; | |||||
{ | { | ||||
char *searchp; | char *searchp; | ||||
char *line_end = line + line_len; | char *line_end = line + line_len; | ||||
/* | /* | ||||
* sp and ep delimit the first match in the line. | * sp and ep delimit the first match in the line. | ||||
* Mark the corresponding file positions, then | * Mark the corresponding file positions, then | ||||
* look for further matches and mark them. | * look for further matches and mark them. | ||||
Show All 24 Lines | |||||
} | } | ||||
#endif | #endif | ||||
/* | /* | ||||
* Change the caseless-ness of searches. | * Change the caseless-ness of searches. | ||||
* Updates the internal search state to reflect a change in the -i flag. | * Updates the internal search state to reflect a change in the -i flag. | ||||
*/ | */ | ||||
public void | public void | ||||
chg_caseless() | chg_caseless(void) | ||||
{ | { | ||||
if (!is_ucase_pattern) | if (!is_ucase_pattern) | ||||
/* | /* | ||||
* Pattern did not have uppercase. | * Pattern did not have uppercase. | ||||
* Just set the search caselessness to the global caselessness. | * Just set the search caselessness to the global caselessness. | ||||
*/ | */ | ||||
is_caseless = caseless; | is_caseless = caseless; | ||||
else | else | ||||
/* | /* | ||||
* Pattern did have uppercase. | * Pattern did have uppercase. | ||||
* Discard the pattern; we can't change search caselessness now. | * Discard the pattern; we can't change search caselessness now. | ||||
*/ | */ | ||||
clear_pattern(&search_info); | clear_pattern(&search_info); | ||||
} | } | ||||
#if HILITE_SEARCH | #if HILITE_SEARCH | ||||
/* | /* | ||||
* Find matching text which is currently on screen and highlight it. | * Find matching text which is currently on screen and highlight it. | ||||
*/ | */ | ||||
static void | static void | ||||
hilite_screen() | hilite_screen(void) | ||||
{ | { | ||||
struct scrpos scrpos; | struct scrpos scrpos; | ||||
get_scrpos(&scrpos); | get_scrpos(&scrpos); | ||||
if (scrpos.pos == NULL_POSITION) | if (scrpos.pos == NULL_POSITION) | ||||
return; | return; | ||||
prep_hilite(scrpos.pos, position(BOTTOM_PLUS_ONE), -1); | prep_hilite(scrpos.pos, position(BOTTOM_PLUS_ONE), -1); | ||||
repaint_hilite(1); | repaint_hilite(1); | ||||
} | } | ||||
/* | /* | ||||
* Change highlighting parameters. | * Change highlighting parameters. | ||||
*/ | */ | ||||
public void | public void | ||||
chg_hilite() | chg_hilite(void) | ||||
{ | { | ||||
/* | /* | ||||
* Erase any highlights currently on screen. | * Erase any highlights currently on screen. | ||||
*/ | */ | ||||
clr_hilite(); | clr_hilite(); | ||||
hide_hilite = 0; | hide_hilite = 0; | ||||
if (hilite_search == OPT_ONPLUS) | if (hilite_search == OPT_ONPLUS) | ||||
/* | /* | ||||
* Display highlights. | * Display highlights. | ||||
*/ | */ | ||||
hilite_screen(); | hilite_screen(); | ||||
} | } | ||||
#endif | #endif | ||||
/* | /* | ||||
* Figure out where to start a search. | * Figure out where to start a search. | ||||
*/ | */ | ||||
static POSITION | static POSITION | ||||
search_pos(search_type) | search_pos(int search_type) | ||||
int search_type; | |||||
{ | { | ||||
POSITION pos; | POSITION pos; | ||||
int linenum; | int linenum; | ||||
if (empty_screen()) | if (empty_screen()) | ||||
{ | { | ||||
/* | /* | ||||
* Start at the beginning (or end) of the file. | * Start at the beginning (or end) of the file. | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | search_pos(int search_type) | ||||
} | } | ||||
return (pos); | return (pos); | ||||
} | } | ||||
/* | /* | ||||
* Search a subset of the file, specified by start/end position. | * Search a subset of the file, specified by start/end position. | ||||
*/ | */ | ||||
static int | static int | ||||
search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos) | search_range(POSITION pos, POSITION endpos, int search_type, int matches, | ||||
POSITION pos; | int maxlines, POSITION *plinepos, POSITION *pendpos) | ||||
POSITION endpos; | |||||
int search_type; | |||||
int matches; | |||||
int maxlines; | |||||
POSITION *plinepos; | |||||
POSITION *pendpos; | |||||
{ | { | ||||
char *line; | char *line; | ||||
char *cline; | char *cline; | ||||
int line_len; | int line_len; | ||||
LINENUM linenum; | LINENUM linenum; | ||||
char *sp, *ep; | char *sp, *ep; | ||||
int line_match; | int line_match; | ||||
int cvt_ops; | int cvt_ops; | ||||
▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Lines | #endif | ||||
free(chpos); | free(chpos); | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* search for a pattern in history. If found, compile that pattern. | * search for a pattern in history. If found, compile that pattern. | ||||
*/ | */ | ||||
static int | static int | ||||
hist_pattern(search_type) | hist_pattern(int search_type) | ||||
int search_type; | |||||
{ | { | ||||
#if CMD_HISTORY | #if CMD_HISTORY | ||||
char *pattern; | char *pattern; | ||||
set_mlist(ml_search, 0); | set_mlist(ml_search, 0); | ||||
pattern = cmd_lastpattern(); | pattern = cmd_lastpattern(); | ||||
if (pattern == NULL) | if (pattern == NULL) | ||||
return (0); | return (0); | ||||
Show All 17 Lines | |||||
* either forward or backward. | * either forward or backward. | ||||
* Return the number of matches not yet found in this file | * Return the number of matches not yet found in this file | ||||
* (that is, n minus the number of matches found). | * (that is, n minus the number of matches found). | ||||
* Return -1 if the search should be aborted. | * Return -1 if the search should be aborted. | ||||
* Caller may continue the search in another file | * Caller may continue the search in another file | ||||
* if less than n matches are found in this file. | * if less than n matches are found in this file. | ||||
*/ | */ | ||||
public int | public int | ||||
search(search_type, pattern, n) | search(int search_type, char *pattern, int n) | ||||
int search_type; | |||||
char *pattern; | |||||
int n; | |||||
{ | { | ||||
POSITION pos; | POSITION pos; | ||||
if (pattern == NULL || *pattern == '\0') | if (pattern == NULL || *pattern == '\0') | ||||
{ | { | ||||
/* | /* | ||||
* A null pattern means use the previously compiled pattern. | * A null pattern means use the previously compiled pattern. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | |||||
* The pair (prep_startpos,prep_endpos) delimits a contiguous region | * The pair (prep_startpos,prep_endpos) delimits a contiguous region | ||||
* of the file that has been "prepared"; that is, scanned for matches for | * of the file that has been "prepared"; that is, scanned for matches for | ||||
* the current search pattern, and hilites have been created for such matches. | * the current search pattern, and hilites have been created for such matches. | ||||
* If prep_startpos == NULL_POSITION, the prep region is empty. | * If prep_startpos == NULL_POSITION, the prep region is empty. | ||||
* If prep_endpos == NULL_POSITION, the prep region extends to EOF. | * 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. | * prep_hilite asks that the range (spos,epos) be covered by the prep region. | ||||
*/ | */ | ||||
public void | public void | ||||
prep_hilite(spos, epos, maxlines) | prep_hilite(POSITION spos, POSITION epos, int maxlines) | ||||
POSITION spos; | |||||
POSITION epos; | |||||
int maxlines; | |||||
{ | { | ||||
POSITION nprep_startpos = prep_startpos; | POSITION nprep_startpos = prep_startpos; | ||||
POSITION nprep_endpos = prep_endpos; | POSITION nprep_endpos = prep_endpos; | ||||
POSITION new_epos; | POSITION new_epos; | ||||
POSITION max_epos; | POSITION max_epos; | ||||
int result; | int result; | ||||
int i; | int i; | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | #define SEARCH_MORE (3*size_linebuf) | ||||
prep_startpos = nprep_startpos; | prep_startpos = nprep_startpos; | ||||
prep_endpos = nprep_endpos; | prep_endpos = nprep_endpos; | ||||
} | } | ||||
/* | /* | ||||
* Set the pattern to be used for line filtering. | * Set the pattern to be used for line filtering. | ||||
*/ | */ | ||||
public void | public void | ||||
set_filter_pattern(pattern, search_type) | set_filter_pattern(char *pattern, int search_type) | ||||
char *pattern; | |||||
int search_type; | |||||
{ | { | ||||
clr_filter(); | clr_filter(); | ||||
if (pattern == NULL || *pattern == '\0') | if (pattern == NULL || *pattern == '\0') | ||||
clear_pattern(&filter_info); | clear_pattern(&filter_info); | ||||
else | else | ||||
set_pattern(&filter_info, pattern, search_type); | set_pattern(&filter_info, pattern, search_type); | ||||
screen_trashed = 1; | screen_trashed = 1; | ||||
} | } | ||||
/* | /* | ||||
* Is there a line filter in effect? | * Is there a line filter in effect? | ||||
*/ | */ | ||||
public int | public int | ||||
is_filtering() | is_filtering(void) | ||||
{ | { | ||||
if (ch_getflags() & CH_HELPFILE) | if (ch_getflags() & CH_HELPFILE) | ||||
return (0); | return (0); | ||||
return prev_pattern(&filter_info); | return prev_pattern(&filter_info); | ||||
} | } | ||||
#endif | #endif | ||||
#if HAVE_V8_REGCOMP | #if HAVE_V8_REGCOMP | ||||
Show All 19 Lines |