diff options
author | delphij <delphij@FreeBSD.org> | 2006-08-20 15:49:51 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2006-08-20 15:49:51 +0000 |
commit | 5297f4bc59da861bbe3beb5ee12839fa05e79882 (patch) | |
tree | 66e8cb2705abe3d167ba3a94a60d37c894690ff2 /contrib/less/search.c | |
parent | 71cad8a96df623ac7d9129aa5e8c983df1030b0c (diff) | |
download | FreeBSD-src-5297f4bc59da861bbe3beb5ee12839fa05e79882.zip FreeBSD-src-5297f4bc59da861bbe3beb5ee12839fa05e79882.tar.gz |
Import less v394
Diffstat (limited to 'contrib/less/search.c')
-rw-r--r-- | contrib/less/search.c | 130 |
1 files changed, 90 insertions, 40 deletions
diff --git a/contrib/less/search.c b/contrib/less/search.c index 7d0af8b..e58eda7 100644 --- a/contrib/less/search.c +++ b/contrib/less/search.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2002 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. @@ -120,9 +120,9 @@ cvt_text(odst, osrc, ops) for (src = osrc, dst = odst; *src != '\0'; src++) { - if ((ops & CVT_TO_LC) && isupper((unsigned char) *src)) + if ((ops & CVT_TO_LC) && IS_UPPER(*src)) /* Convert uppercase to lowercase. */ - *dst++ = tolower((unsigned char) *src); + *dst++ = TO_LOWER(*src); else if ((ops & CVT_BS) && *src == '\b' && dst > odst) /* Delete BS and preceding char. */ dst--; @@ -130,7 +130,7 @@ cvt_text(odst, osrc, ops) { /* Skip to end of ANSI escape sequence. */ while (src[1] != '\0') - if (is_ansi_end(*++src)) + if (!is_ansi_middle(*++src)) break; } else /* Just copy. */ @@ -175,7 +175,7 @@ is_ucase(s) register char *p; for (p = s; *p != '\0'; p++) - if (isupper((unsigned char) *p)) + if (IS_UPPER(*p)) return (1); return (0); } @@ -247,11 +247,18 @@ repaint_hilite(on) if (pos == NULL_POSITION) continue; epos = position(slinenum+1); +#if 0 /* * If any character in the line is highlighted, * repaint the line. + * + * {{ This doesn't work -- if line is drawn with highlights + * which should be erased (e.g. toggle -i with status column), + * we must redraw the line even if it has no highlights. + * For now, just repaint every line. }} */ - if (is_hilited(pos, epos, 1)) + if (is_hilited(pos, epos, 1, NULL)) +#endif { (void) forw_line(pos); goto_line(slinenum); @@ -532,15 +539,41 @@ clr_hilite() /* * Should any characters in a specified range be highlighted? + */ + static int +is_hilited_range(pos, epos) + POSITION pos; + POSITION epos; +{ + struct hilite *hl; + + /* + * Look at each highlight and see if any part of it falls in the range. + */ + for (hl = hilite_anchor.hl_first; hl != NULL; hl = hl->hl_next) + { + if (hl->hl_endpos > pos && + (epos == NULL_POSITION || epos > hl->hl_startpos)) + return (1); + } + return (0); +} + +/* + * Should any characters in a specified range be highlighted? * If nohide is nonzero, don't consider hide_hilite. */ public int -is_hilited(pos, epos, nohide) +is_hilited(pos, epos, nohide, p_matches) POSITION pos; POSITION epos; int nohide; + int *p_matches; { - struct hilite *hl; + int match; + + if (p_matches != NULL) + *p_matches = 0; if (!status_col && start_attnpos != NULL_POSITION && @@ -551,6 +584,16 @@ is_hilited(pos, epos, nohide) */ return (1); + match = is_hilited_range(pos, epos); + if (!match) + return (0); + + if (p_matches != NULL) + /* + * Report matches, even if we're hiding highlights. + */ + *p_matches = 1; + if (hilite_search == 0) /* * Not doing highlighting. @@ -563,16 +606,7 @@ is_hilited(pos, epos, nohide) */ return (0); - /* - * Look at each highlight and see if any part of it falls in the range. - */ - for (hl = hilite_anchor.hl_first; hl != NULL; hl = hl->hl_next) - { - if (hl->hl_endpos > pos && - (epos == NULL_POSITION || epos > hl->hl_startpos)) - return (1); - } - return (0); + return (1); } /* @@ -615,6 +649,30 @@ add_hilite(anchor, hl) ihl->hl_next = hl; } + static void +adj_hilite_ansi(cvt_ops, line, npos) + int cvt_ops; + char **line; + POSITION *npos; +{ + if (cvt_ops & CVT_ANSI) + while (**line == ESC) + { + /* + * Found an ESC. The file position moves + * forward past the entire ANSI escape sequence. + */ + (*line)++; + (*npos)++; + while (**line != '\0') + { + (*npos)++; + if (!is_ansi_middle(*(*line)++)) + break; + } + } +} + /* * Adjust hl_startpos & hl_endpos to account for backspace processing. */ @@ -664,38 +722,30 @@ adj_hilite(anchor, linepos, cvt_ops) } if (*line == '\0') break; - if (cvt_ops & CVT_ANSI) - { - while (line[0] == ESC) - { - /* - * Found an ESC. The file position moves - * forward past the entire ANSI escape sequence. - */ - line++; - npos++; - while (*line != '\0') - { - npos++; - if (is_ansi_end(*line++)) - break; - } - } - } + adj_hilite_ansi(cvt_ops, &line, &npos); opos++; npos++; line++; if (cvt_ops & CVT_BS) { - while (line[0] == '\b' && line[1] != '\0') + while (*line == '\b') { + npos++; + line++; + adj_hilite_ansi(cvt_ops, &line, &npos); + if (*line == '\0') + { + --npos; + --line; + break; + } /* * Found a backspace. The file position moves * forward by 2 relative to the processed line * which was searched in hilite_line. */ - npos += 2; - line += 2; + npos++; + line++; } } } @@ -1041,7 +1091,7 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos) * Return it. */ #if HILITE_SEARCH - if (hilite_search == 1) + if (hilite_search == OPT_ON) { /* * Clear the hilite list and add only |