summaryrefslogtreecommitdiffstats
path: root/contrib/less/search.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2011-05-09 21:51:59 +0000
committerdelphij <delphij@FreeBSD.org>2011-05-09 21:51:59 +0000
commit142a49a4be37258477d8ce2b19011a75c36bd418 (patch)
treee6e6402d1f7ea7e3382a94b4f654586f41b93f2c /contrib/less/search.c
parent39f7e10a268694e139c11157f966ca179b834212 (diff)
downloadFreeBSD-src-142a49a4be37258477d8ce2b19011a75c36bd418.zip
FreeBSD-src-142a49a4be37258477d8ce2b19011a75c36bd418.tar.gz
MFV: Update to less v443.
MFC after: 1 month
Diffstat (limited to 'contrib/less/search.c')
-rw-r--r--contrib/less/search.c160
1 files changed, 88 insertions, 72 deletions
diff --git a/contrib/less/search.c b/contrib/less/search.c
index a70af0f..0b8b961 100644
--- a/contrib/less/search.c
+++ b/contrib/less/search.c
@@ -1,6 +1,6 @@
/* $FreeBSD$ */
/*
- * 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.
@@ -73,6 +73,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
@@ -95,6 +114,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;
}
@@ -158,25 +187,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
@@ -231,7 +241,7 @@ repaint_hilite(on)
goto_line(slinenum);
put_line();
}
- lower_left(); // if !oldbot
+ lower_left();
hide_hilite = save_hide_hilite;
}
@@ -601,7 +611,7 @@ search_pos(search_type)
*/
if (search_type & SRCH_FORW)
{
- return (ch_zero());
+ pos = ch_zero();
} else
{
pos = ch_length();
@@ -610,46 +620,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);
}
@@ -791,7 +821,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)
{
/*
@@ -855,12 +885,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();
@@ -894,6 +918,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);
@@ -932,15 +957,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)
{
OpenPOWER on IntegriCloud