diff options
Diffstat (limited to 'search.c')
-rw-r--r-- | search.c | 160 |
1 files changed, 88 insertions, 72 deletions
@@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2009 Mark Nudelman + * Copyright (C) 1984-2011 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. @@ -71,6 +71,25 @@ static struct pattern_info search_info; static struct pattern_info filter_info; /* + * Are there any uppercase letters in this string? + */ + static int +is_ucase(str) + char *str; +{ + char *str_end = str + strlen(str); + LWCHAR ch; + + while (str < str_end) + { + ch = step_char(&str, +1, str_end); + if (IS_UPPER(ch)) + return (1); + } + return (0); +} + +/* * Compile and save a search pattern. */ static int @@ -93,6 +112,16 @@ set_pattern(info, pattern, search_type) 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; } @@ -156,25 +185,6 @@ get_cvt_ops() } /* - * Are there any uppercase letters in this string? - */ - static int -is_ucase(str) - char *str; -{ - char *str_end = str + strlen(str); - LWCHAR ch; - - while (str < str_end) - { - ch = step_char(&str, +1, str_end); - if (IS_UPPER(ch)) - return (1); - } - return (0); -} - -/* * Is there a previous (remembered) search pattern? */ static int @@ -229,7 +239,7 @@ repaint_hilite(on) goto_line(slinenum); put_line(); } - lower_left(); // if !oldbot + lower_left(); hide_hilite = save_hide_hilite; } @@ -599,7 +609,7 @@ search_pos(search_type) */ if (search_type & SRCH_FORW) { - return (ch_zero()); + pos = ch_zero(); } else { pos = ch_length(); @@ -608,46 +618,66 @@ search_pos(search_type) (void) ch_end_seek(); pos = ch_length(); } - return (pos); } - } - if (how_search) + linenum = 0; + } else { - /* - * Search does not include current screen. - */ - if (search_type & SRCH_FORW) - linenum = BOTTOM_PLUS_ONE; - else - linenum = TOP; - pos = position(linenum); - } else - { - /* - * Search includes current screen. - * It starts at the jump target (if searching backwards), - * or at the jump target plus one (if forwards). - */ - linenum = adjsline(jump_sline); - pos = position(linenum); - if (search_type & SRCH_FORW) + int add_one = 0; + + if (how_search == OPT_ON) { - pos = forw_raw_line(pos, (char **)NULL, (int *)NULL); - while (pos == NULL_POSITION) - { - if (++linenum >= sc_height) - break; - pos = position(linenum); - } + /* + * Search does not include current screen. + */ + if (search_type & SRCH_FORW) + linenum = BOTTOM_PLUS_ONE; + else + linenum = TOP; + } else if (how_search == OPT_ONPLUS && !(search_type & SRCH_AFTER_TARGET)) + { + /* + * Search includes all of displayed screen. + */ + if (search_type & SRCH_FORW) + linenum = TOP; + else + linenum = BOTTOM_PLUS_ONE; } else { - while (pos == NULL_POSITION) - { - if (--linenum < 0) - break; - pos = position(linenum); - } + /* + * Search includes the part of current screen beyond the jump target. + * It starts at the jump target (if searching backwards), + * or at the jump target plus one (if forwards). + */ + linenum = jump_sline; + if (search_type & SRCH_FORW) + add_one = 1; } + linenum = adjsline(linenum); + pos = position(linenum); + if (add_one) + pos = forw_raw_line(pos, (char **)NULL, (int *)NULL); + } + + /* + * If the line is empty, look around for a plausible starting place. + */ + if (search_type & SRCH_FORW) + { + while (pos == NULL_POSITION) + { + if (++linenum >= sc_height) + break; + pos = position(linenum); + } + } else + { + while (pos == NULL_POSITION) + { + if (--linenum < 0) + break; + pos = position(linenum); + } } return (pos); } @@ -789,7 +819,7 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos) if (prev_pattern(&search_info)) { line_match = match_pattern(search_info.compiled, search_info.text, - cline, line_len, &sp, &ep, 0, search_type); //FIXME search_info.search_type + cline, line_len, &sp, &ep, 0, search_type); if (line_match) { /* @@ -853,12 +883,6 @@ hist_pattern(search_type) if (set_pattern(&search_info, pattern, search_type) < 0) return (0); - is_ucase_pattern = is_ucase(pattern); - if (is_ucase_pattern && caseless != OPT_ONPLUS) - is_caseless = 0; - else - is_caseless = caseless; - #if HILITE_SEARCH if (hilite_search == OPT_ONPLUS && !hide_hilite) hilite_screen(); @@ -892,6 +916,7 @@ search(search_type, pattern, n) /* * A null pattern means use the previously compiled pattern. */ + search_type |= SRCH_AFTER_TARGET; if (!prev_pattern(&search_info) && !hist_pattern(search_type)) { error("No previous regular expression", NULL_PARG); @@ -930,15 +955,6 @@ search(search_type, pattern, n) */ if (set_pattern(&search_info, pattern, search_type) < 0) return (-1); - /* - * 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; #if HILITE_SEARCH if (hilite_search) { |