summaryrefslogtreecommitdiffstats
path: root/contrib/less/search.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/less/search.c')
-rw-r--r--contrib/less/search.c138
1 files changed, 37 insertions, 101 deletions
diff --git a/contrib/less/search.c b/contrib/less/search.c
index e098578..63e5875 100644
--- a/contrib/less/search.c
+++ b/contrib/less/search.c
@@ -1,5 +1,6 @@
+/* $FreeBSD$ */
/*
- * Copyright (C) 1984-2007 Mark Nudelman
+ * Copyright (C) 1984-2005 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.
@@ -22,7 +23,7 @@
#if HAVE_POSIX_REGCOMP
#include <regex.h>
#ifdef REG_EXTENDED
-#define REGCOMP_FLAG REG_EXTENDED
+#define REGCOMP_FLAG (more_mode ? 0 : REG_EXTENDED)
#else
#define REGCOMP_FLAG 0
#endif
@@ -52,9 +53,9 @@ extern int linenums;
extern int sc_height;
extern int jump_sline;
extern int bs_mode;
+extern int more_mode;
extern int ctldisp;
extern int status_col;
-extern void * constant ml_search;
extern POSITION start_attnpos;
extern POSITION end_attnpos;
#if HILITE_SEARCH
@@ -64,7 +65,6 @@ extern int size_linebuf;
extern int squished;
extern int can_goto_line;
static int hide_hilite;
-static int oldbot;
static POSITION prep_startpos;
static POSITION prep_endpos;
@@ -112,22 +112,15 @@ static char *last_pattern = NULL;
#define CVT_ANSI 010 /* Remove ANSI escape sequences */
static void
-cvt_text(odst, osrc, lenp, ops)
+cvt_text(odst, osrc, ops)
char *odst;
char *osrc;
- int *lenp;
int ops;
{
register char *dst;
register char *src;
- register char *src_end;
- if (lenp != NULL)
- src_end = osrc + *lenp;
- else
- src_end = osrc + strlen(osrc);
-
- for (src = osrc, dst = odst; src < src_end; src++)
+ for (src = osrc, dst = odst; *src != '\0'; src++)
{
if ((ops & CVT_TO_LC) && IS_UPPER(*src))
/* Convert uppercase to lowercase. */
@@ -138,7 +131,7 @@ cvt_text(odst, osrc, lenp, ops)
else if ((ops & CVT_ANSI) && *src == ESC)
{
/* Skip to end of ANSI escape sequence. */
- while (src + 1 != src_end)
+ while (src[1] != '\0')
if (!is_ansi_middle(*++src))
break;
} else
@@ -148,8 +141,6 @@ cvt_text(odst, osrc, lenp, ops)
if ((ops & CVT_CRLF) && dst > odst && dst[-1] == '\r')
dst--;
*dst = '\0';
- if (lenp != NULL)
- *lenp = dst - odst;
}
/*
@@ -276,8 +267,6 @@ repaint_hilite(on)
put_line();
}
}
- if (!oldbot)
- lower_left();
hide_hilite = save_hide_hilite;
}
@@ -461,9 +450,8 @@ uncompile_pattern()
* Set sp and ep to the start and end of the matched string.
*/
static int
-match_pattern(line, line_len, sp, ep, notbol)
+match_pattern(line, sp, ep, notbol)
char *line;
- int line_len;
char **sp;
char **ep;
int notbol;
@@ -471,7 +459,7 @@ match_pattern(line, line_len, sp, ep, notbol)
int matched;
if (last_search_type & SRCH_NO_REGEX)
- return (match(last_pattern, strlen(last_pattern), line, line_len, sp, ep));
+ return (match(last_pattern, line, sp, ep));
#if HAVE_POSIX_REGCOMP
{
@@ -493,7 +481,7 @@ match_pattern(line, line_len, sp, ep, notbol)
{
int flags = (notbol) ? PCRE_NOTBOL : 0;
int ovector[3];
- matched = pcre_exec(regpattern, NULL, line, line_len,
+ matched = pcre_exec(regpattern, NULL, line, strlen(line),
0, flags, ovector, 3) >= 0;
if (!matched)
return (0);
@@ -527,7 +515,7 @@ match_pattern(line, line_len, sp, ep, notbol)
*ep = regpattern->endp[0];
#endif
#if NO_REGEX
- matched = match(last_pattern, strlen(last_pattern), line, line_len, sp, ep);
+ matched = match(last_pattern, line, sp, ep);
#endif
return (matched);
}
@@ -664,14 +652,11 @@ add_hilite(anchor, hl)
}
static void
-adj_hilite_ansi(cvt_ops, line, line_len, npos)
+adj_hilite_ansi(cvt_ops, line, npos)
int cvt_ops;
char **line;
- int line_len;
POSITION *npos;
{
- char *line_end = *line + line_len;
-
if (cvt_ops & CVT_ANSI)
while (**line == ESC)
{
@@ -681,7 +666,7 @@ adj_hilite_ansi(cvt_ops, line, line_len, npos)
*/
(*line)++;
(*npos)++;
- while (*line < line_end)
+ while (**line != '\0')
{
(*npos)++;
if (!is_ansi_middle(*(*line)++))
@@ -700,8 +685,6 @@ adj_hilite(anchor, linepos, cvt_ops)
int cvt_ops;
{
char *line;
- int line_len;
- char *line_end;
struct hilite *hl;
int checkstart;
POSITION opos;
@@ -714,8 +697,7 @@ adj_hilite(anchor, linepos, cvt_ops)
* This may not be true if there are backspaces in the line.
* Get the raw line again. Look at each character.
*/
- (void) forw_raw_line(linepos, &line, &line_len);
- line_end = line + line_len;
+ (void) forw_raw_line(linepos, &line);
opos = npos = linepos;
hl = anchor->hl_first;
checkstart = TRUE;
@@ -740,9 +722,9 @@ adj_hilite(anchor, linepos, cvt_ops)
hl = hl->hl_next;
continue; /* {{ necessary }} */
}
- if (line == line_end)
+ if (*line == '\0')
break;
- adj_hilite_ansi(cvt_ops, &line, line_end - line, &npos);
+ adj_hilite_ansi(cvt_ops, &line, &npos);
opos++;
npos++;
line++;
@@ -752,8 +734,8 @@ adj_hilite(anchor, linepos, cvt_ops)
{
npos++;
line++;
- adj_hilite_ansi(cvt_ops, &line, line_end - line, &npos);
- if (line == line_end)
+ adj_hilite_ansi(cvt_ops, &line, &npos);
+ if (*line == '\0')
{
--npos;
--line;
@@ -777,16 +759,14 @@ adj_hilite(anchor, linepos, cvt_ops)
* sp,ep delimit the first match already found.
*/
static void
-hilite_line(linepos, line, line_len, sp, ep, cvt_ops)
+hilite_line(linepos, line, sp, ep, cvt_ops)
POSITION linepos;
char *line;
- int line_len;
char *sp;
char *ep;
int cvt_ops;
{
char *searchp;
- char *line_end = line + line_len;
struct hilite *hl;
struct hilite hilites;
@@ -800,7 +780,7 @@ hilite_line(linepos, line, line_len, sp, ep, cvt_ops)
* substrings of the line, may mark more than is correct
* 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). }}
+ * (currently POSIX and V8-with-regexec2). }}
*/
searchp = line;
/*
@@ -827,11 +807,11 @@ hilite_line(linepos, line, line_len, sp, ep, cvt_ops)
*/
if (ep > searchp)
searchp = ep;
- else if (searchp != line_end)
+ else if (*searchp != '\0')
searchp++;
else /* end of line */
break;
- } while (match_pattern(searchp, line_end - searchp, &sp, &ep, 1));
+ } while (match_pattern(searchp, &sp, &ep, 1));
/*
* If there were backspaces in the original line, they
@@ -962,7 +942,7 @@ search_pos(search_type)
pos = position(linenum);
if (search_type & SRCH_FORW)
{
- pos = forw_raw_line(pos, (char **)NULL, (int *)NULL);
+ pos = forw_raw_line(pos, (char **)NULL);
while (pos == NULL_POSITION)
{
if (++linenum >= sc_height)
@@ -996,7 +976,6 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos)
POSITION *pendpos;
{
char *line;
- int line_len;
LINENUM linenum;
char *sp, *ep;
int line_match;
@@ -1039,7 +1018,7 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos)
* starting position of that line in linepos.
*/
linepos = pos;
- pos = forw_raw_line(pos, &line, &line_len);
+ pos = forw_raw_line(pos, &line);
if (linenum != 0)
linenum++;
} else
@@ -1048,7 +1027,7 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos)
* Read the previous line and save the
* starting position of that line in linepos.
*/
- pos = back_raw_line(pos, &line, &line_len);
+ pos = back_raw_line(pos, &line);
linepos = pos;
if (linenum != 0)
linenum--;
@@ -1081,14 +1060,14 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos)
* If we're doing backspace processing, delete backspaces.
*/
cvt_ops = get_cvt_ops();
- cvt_text(line, line, &line_len, cvt_ops);
+ cvt_text(line, line, cvt_ops);
/*
* Test the next line to see if we have a match.
* We are successful if we either want a match and got one,
* or if we want a non-match and got one.
*/
- line_match = match_pattern(line, line_len, &sp, &ep, 0);
+ line_match = match_pattern(line, &sp, &ep, 0);
line_match = (!(search_type & SRCH_NO_MATCH) && line_match) ||
((search_type & SRCH_NO_MATCH) && !line_match);
if (!line_match)
@@ -1105,7 +1084,7 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos)
* hilite list and keep searching.
*/
if (line_match)
- hilite_line(linepos, line, line_len, sp, ep, cvt_ops);
+ hilite_line(linepos, line, sp, ep, cvt_ops);
#endif
} else if (--matches <= 0)
{
@@ -1122,7 +1101,7 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos)
*/
clr_hilite();
if (line_match)
- hilite_line(linepos, line, line_len, sp, ep, cvt_ops);
+ hilite_line(linepos, line, sp, ep, cvt_ops);
}
#endif
if (plinepos != NULL)
@@ -1132,44 +1111,6 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos)
}
}
- /*
- * search for a pattern in history. If found, compile that pattern.
- */
- static int
-hist_pattern(search_type)
- int search_type;
-{
-#if CMD_HISTORY
- char *pattern;
-
- set_mlist(ml_search, 0);
- pattern = cmd_lastpattern();
- if (pattern == NULL)
- return (0);
-
- if (caseless == OPT_ONPLUS)
- cvt_text(pattern, pattern, (int *)NULL, CVT_TO_LC);
-
- if (compile_pattern(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();
-#endif
-
- return (1);
-#else /* CMD_HISTORY */
- return (0);
-#endif /* CMD_HISTORY */
-}
-
/*
* Search for the n-th occurrence of a specified pattern,
* either forward or backward.
@@ -1193,7 +1134,7 @@ search(search_type, pattern, n)
/*
* A null pattern means use the previously compiled pattern.
*/
- if (!prev_pattern() && !hist_pattern(search_type))
+ if (!prev_pattern())
{
error("No previous regular expression", NULL_PARG);
return (-1);
@@ -1231,7 +1172,7 @@ search(search_type, pattern, n)
*/
ucase = is_ucase(pattern);
if (caseless == OPT_ONPLUS)
- cvt_text(pattern, pattern, (int *)NULL, CVT_TO_LC);
+ cvt_text(pattern, pattern, CVT_TO_LC);
if (compile_pattern(pattern, search_type) < 0)
return (-1);
/*
@@ -1359,7 +1300,7 @@ prep_hilite(spos, epos, maxlines)
{
max_epos = spos;
for (i = 0; i < maxlines; i++)
- max_epos = forw_raw_line(max_epos, (char **)NULL, (int *)NULL);
+ max_epos = forw_raw_line(max_epos, (char **)NULL);
}
/*
@@ -1455,23 +1396,18 @@ prep_hilite(spos, epos, maxlines)
* It supports no metacharacters like *, etc.
*/
static int
-match(pattern, pattern_len, buf, buf_len, pfound, pend)
- char *pattern;
- int pattern_len;
- char *buf;
- int buf_len;
+match(pattern, buf, pfound, pend)
+ char *pattern, *buf;
char **pfound, **pend;
{
register char *pp, *lp;
- register char *pattern_end = pattern + pattern_len;
- register char *buf_end = buf + buf_len;
- for ( ; buf < buf_end; buf++)
+ for ( ; *buf != '\0'; buf++)
{
for (pp = pattern, lp = buf; *pp == *lp; pp++, lp++)
- if (pp == pattern_end || lp == buf_end)
+ if (*pp == '\0' || *lp == '\0')
break;
- if (pp == pattern_end)
+ if (*pp == '\0')
{
if (pfound != NULL)
*pfound = buf;
OpenPOWER on IntegriCloud