Resolve conflicts.

This commit is contained in:
Xin LI 2006-08-20 15:50:51 +00:00
parent 8978d559b1
commit 89dd99dcac
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=161478
9 changed files with 915 additions and 537 deletions

View File

@ -1,6 +1,6 @@
/* $FreeBSD$ */ /* $FreeBSD$ */
/* /*
* Copyright (C) 1984-2002 Mark Nudelman * Copyright (C) 1984-2005 Mark Nudelman
* *
* You may distribute under the terms of either the GNU General Public * You may distribute under the terms of either the GNU General Public
* License or the Less License, as specified in the README file. * License or the Less License, as specified in the README file.
@ -22,7 +22,7 @@
#include "option.h" #include "option.h"
#include "cmd.h" #include "cmd.h"
extern int erase_char, kill_char; extern int erase_char, erase2_char, kill_char;
extern int sigs; extern int sigs;
extern int quit_at_eof; extern int quit_at_eof;
extern int quit_if_one_screen; extern int quit_if_one_screen;
@ -69,6 +69,7 @@ static char optchar;
static int optflag; static int optflag;
static int optgetname; static int optgetname;
static POSITION bottompos; static POSITION bottompos;
static int save_hshift;
#if PIPEC #if PIPEC
static char pipec; static char pipec;
#endif #endif
@ -394,7 +395,9 @@ mca_char(c)
* Already have a match for the name. * Already have a match for the name.
* Don't accept anything but erase/kill. * Don't accept anything but erase/kill.
*/ */
if (c == erase_char || c == kill_char) if (c == erase_char ||
c == erase2_char ||
c == kill_char)
return (MCA_DONE); return (MCA_DONE);
return (MCA_MORE); return (MCA_MORE);
} }
@ -405,7 +408,7 @@ mca_char(c)
if (cmd_char(c) == CC_QUIT) if (cmd_char(c) == CC_QUIT)
return (MCA_DONE); return (MCA_DONE);
p = get_cmdbuf(); p = get_cmdbuf();
lc = islower(p[0]); lc = ASCII_IS_LOWER(p[0]);
o = findopt_name(&p, &oname, NULL); o = findopt_name(&p, &oname, NULL);
if (o != NULL) if (o != NULL)
{ {
@ -415,15 +418,15 @@ mca_char(c)
* display the full option name. * display the full option name.
*/ */
optchar = o->oletter; optchar = o->oletter;
if (!lc && islower(optchar)) if (!lc && ASCII_IS_LOWER(optchar))
optchar = toupper(optchar); optchar = ASCII_TO_UPPER(optchar);
cmd_reset(); cmd_reset();
mca_opt_toggle(); mca_opt_toggle();
for (p = oname; *p != '\0'; p++) for (p = oname; *p != '\0'; p++)
{ {
c = *p; c = *p;
if (!lc && islower(c)) if (!lc && ASCII_IS_LOWER(c))
c = toupper(c); c = ASCII_TO_UPPER(c);
if (cmd_char(c) != CC_OK) if (cmd_char(c) != CC_OK)
return (MCA_DONE); return (MCA_DONE);
} }
@ -432,7 +435,7 @@ mca_char(c)
} }
} else } else
{ {
if (c == erase_char || c == kill_char) if (c == erase_char || c == erase2_char || c == kill_char)
break; break;
if (optchar != '\0') if (optchar != '\0')
/* We already have the option letter. */ /* We already have the option letter. */
@ -604,7 +607,10 @@ prompt()
bottompos = position(BOTTOM_PLUS_ONE); bottompos = position(BOTTOM_PLUS_ONE);
/* /*
* If the -E flag is set and we've hit EOF on the last file, quit. * If we've hit EOF on the last file, and the -E flag is set
* (or -F is set and this is the first prompt), then quit.
* {{ Relying on "first prompt" to detect a single-screen file
* fails if +G is used, for example. }}
*/ */
if ((quit_at_eof == OPT_ONPLUS || quit_if_one_screen) && if ((quit_at_eof == OPT_ONPLUS || quit_if_one_screen) &&
hit_eof && !(ch_getflags() & CH_HELPFILE) && hit_eof && !(ch_getflags() & CH_HELPFILE) &&
@ -633,13 +639,13 @@ prompt()
*/ */
clear_cmd(); clear_cmd();
p = pr_string(); p = pr_string();
if (p == NULL) if (p == NULL || *p == '\0')
putchr(':'); putchr(':');
else else
{ {
so_enter(); at_enter(AT_STANDOUT);
putstr(p); putstr(p);
so_exit(); at_exit();
} }
} }
@ -832,6 +838,9 @@ multi_search(pattern, n)
* Restore the file we were originally viewing. * Restore the file we were originally viewing.
*/ */
reedit_ifile(save_ifile); reedit_ifile(save_ifile);
} else
{
unsave_ifile(save_ifile);
} }
} }
@ -1217,6 +1226,7 @@ commands()
* just means return to viewing the * just means return to viewing the
* previous file. * previous file.
*/ */
hshift = save_hshift;
if (edit_prev(1) == 0) if (edit_prev(1) == 0)
break; break;
} }
@ -1306,6 +1316,8 @@ commands()
if (ch_getflags() & CH_HELPFILE) if (ch_getflags() & CH_HELPFILE)
break; break;
cmd_exec(); cmd_exec();
save_hshift = hshift;
hshift = 0;
(void) edit(FAKE_HELPFILE); (void) edit(FAKE_HELPFILE);
break; break;
@ -1346,9 +1358,8 @@ commands()
} }
if (curr_altfilename != NULL) if (curr_altfilename != NULL)
{ {
error("Cannot edit file processed with LESSOPEN", error("WARNING: This file was viewed via LESSOPEN",
NULL_PARG); NULL_PARG);
break;
} }
start_mca(A_SHELL, "!", ml_shell, 0); start_mca(A_SHELL, "!", ml_shell, 0);
/* /*
@ -1530,8 +1541,8 @@ commands()
break; break;
start_mca(A_SETMARK, "mark: ", (void*)NULL, 0); start_mca(A_SETMARK, "mark: ", (void*)NULL, 0);
c = getcc(); c = getcc();
if (c == erase_char || c == kill_char || if (c == erase_char || c == erase2_char ||
c == '\n' || c == '\r') c == kill_char || c == '\n' || c == '\r')
break; break;
setmark(c); setmark(c);
break; break;
@ -1542,8 +1553,8 @@ commands()
*/ */
start_mca(A_GOMARK, "goto mark: ", (void*)NULL, 0); start_mca(A_GOMARK, "goto mark: ", (void*)NULL, 0);
c = getcc(); c = getcc();
if (c == erase_char || c == kill_char || if (c == erase_char || c == erase2_char ||
c == '\n' || c == '\r') c == kill_char || c == '\n' || c == '\r')
break; break;
gomark(c); gomark(c);
break; break;
@ -1557,7 +1568,7 @@ commands()
} }
start_mca(A_PIPE, "|mark: ", (void*)NULL, 0); start_mca(A_PIPE, "|mark: ", (void*)NULL, 0);
c = getcc(); c = getcc();
if (c == erase_char || c == kill_char) if (c == erase_char || c == erase2_char || c == kill_char)
break; break;
if (c == '\n' || c == '\r') if (c == '\n' || c == '\r')
c = '.'; c = '.';

View File

@ -1,6 +1,6 @@
/* $FreeBSD$ */ /* $FreeBSD$ */
/* /*
* Copyright (C) 1984-2002 Mark Nudelman * Copyright (C) 1984-2005 Mark Nudelman
* *
* You may distribute under the terms of either the GNU General Public * You may distribute under the terms of either the GNU General Public
* License or the Less License, as specified in the README file. * License or the Less License, as specified in the README file.
@ -126,13 +126,6 @@ forw(n, pos, force, only_last, nblank)
if (!do_repaint) if (!do_repaint)
{ {
/*
* Forget any current line shift we might have
* (from the last line of the previous screenful).
*/
extern int cshift;
cshift = 0;
if (top_scroll && n >= sc_height - 1 && pos != ch_length()) if (top_scroll && n >= sc_height - 1 && pos != ch_length())
{ {
/* /*
@ -146,7 +139,7 @@ forw(n, pos, force, only_last, nblank)
force = 1; force = 1;
if (more_mode == 0) if (more_mode == 0)
{ {
if (top_scroll == OPT_ONPLUS || first_time) if (top_scroll == OPT_ONPLUS || (first_time && top_scroll != OPT_ON))
clear(); clear();
home(); home();
} }
@ -246,7 +239,7 @@ forw(n, pos, force, only_last, nblank)
if (top_scroll == OPT_ON) if (top_scroll == OPT_ON)
clear_eol(); clear_eol();
put_line(); put_line();
if (clear_bg && final_attr != AT_NORMAL) if (clear_bg && apply_at_specials(final_attr) != AT_NORMAL)
{ {
/* /*
* Writing the last character on the last line * Writing the last character on the last line

View File

@ -1,6 +1,6 @@
/* $FreeBSD$ */ /* $FreeBSD$ */
/* /*
* Copyright (C) 1984-2002 Mark Nudelman * Copyright (C) 1984-2005 Mark Nudelman
* *
* You may distribute under the terms of either the GNU General Public * You may distribute under the terms of either the GNU General Public
* License or the Less License, as specified in the README file. * License or the Less License, as specified in the README file.
@ -80,13 +80,21 @@
#if HAVE_STRING_H #if HAVE_STRING_H
#include <string.h> #include <string.h>
#endif #endif
/* OS-specific includes */
#ifdef _OSK #ifdef _OSK
#include <modes.h> #include <modes.h>
#include <strings.h> #include <strings.h>
#endif #endif
#ifdef __TANDEM
#include <floss.h>
#endif
#if MSDOS_COMPILER==WIN32C || OS2 #if MSDOS_COMPILER==WIN32C || OS2
#include <io.h> #include <io.h>
#endif #endif
#if MSDOS_COMPILER==DJGPPC #if MSDOS_COMPILER==DJGPPC
#include <io.h> #include <io.h>
#include <sys/exceptn.h> #include <sys/exceptn.h>
@ -105,16 +113,40 @@ void free();
* Simple lowercase test which can be used during option processing * Simple lowercase test which can be used during option processing
* (before options are parsed which might tell us what charset to use). * (before options are parsed which might tell us what charset to use).
*/ */
#define SIMPLE_IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z') #define ASCII_IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
#define SIMPLE_IS_LOWER(c) ((c) >= 'a' && (c) <= 'z') #define ASCII_IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
#define SIMPLE_TO_UPPER(c) ((c) - 'a' + 'A') #define ASCII_TO_UPPER(c) ((c) - 'a' + 'A')
#define SIMPLE_TO_LOWER(c) ((c) - 'A' + 'a') #define ASCII_TO_LOWER(c) ((c) - 'A' + 'a')
#undef IS_UPPER
#undef IS_LOWER
#undef TO_UPPER
#undef TO_LOWER
#undef IS_SPACE
#undef IS_DIGIT
#if !HAVE_UPPER_LOWER #if !HAVE_UPPER_LOWER
#define isupper(c) SIMPLE_IS_UPPER(c) #define IS_UPPER(c) ASCII_IS_UPPER(c)
#define islower(c) SIMPLE_IS_LOWER(c) #define IS_LOWER(c) ASCII_IS_LOWER(c)
#define toupper(c) SIMPLE_TO_UPPER(c) #define TO_UPPER(c) ASCII_TO_UPPER(c)
#define tolower(c) SIMPLE_TO_LOWER(c) #define TO_LOWER(c) ASCII_TO_LOWER(c)
#else
#define IS_UPPER(c) isupper((unsigned char) (c))
#define IS_LOWER(c) islower((unsigned char) (c))
#define TO_UPPER(c) toupper((unsigned char) (c))
#define TO_LOWER(c) tolower((unsigned char) (c))
#endif
#ifdef isspace
#define IS_SPACE(c) isspace((unsigned char)(c))
#else
#define IS_SPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == '\f')
#endif
#ifdef isdigit
#define IS_DIGIT(c) isdigit((unsigned char)(c))
#else
#define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
#endif #endif
#ifndef NULL #ifndef NULL
@ -138,6 +170,19 @@ void free();
#endif #endif
#endif #endif
#if HAVE_SNPRINTF
#define SNPRINTF1(str, size, fmt, v1) snprintf((str), (size), (fmt), (v1))
#define SNPRINTF2(str, size, fmt, v1, v2) snprintf((str), (size), (fmt), (v1), (v2))
#define SNPRINTF3(str, size, fmt, v1, v2, v3) snprintf((str), (size), (fmt), (v1), (v2), (v3))
#define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) snprintf((str), (size), (fmt), (v1), (v2), (v3), (v4))
#else
/* Use unsafe sprintf if we don't have snprintf. */
#define SNPRINTF1(str, size, fmt, v1) sprintf((str), (fmt), (v1))
#define SNPRINTF2(str, size, fmt, v1, v2) sprintf((str), (fmt), (v1), (v2))
#define SNPRINTF3(str, size, fmt, v1, v2, v3) sprintf((str), (fmt), (v1), (v2), (v3))
#define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) sprintf((str), (fmt), (v1), (v2), (v3), (v4))
#endif
#define BAD_LSEEK ((off_t)-1) #define BAD_LSEEK ((off_t)-1)
#ifndef CHAR_BIT #ifndef CHAR_BIT
@ -154,9 +199,11 @@ void free();
/* /*
* Special types and constants. * Special types and constants.
*/ */
typedef unsigned long LWCHAR;
typedef off_t POSITION; typedef off_t POSITION;
typedef off_t LINENUM; typedef off_t LINENUM;
#define MIN_LINENUM_WIDTH 7 /* Min printing width of a line number */ #define MIN_LINENUM_WIDTH 7 /* Min printing width of a line number */
#define MAX_UTF_CHAR_LEN 6 /* Max bytes in one UTF-8 char */
#define NULL_POSITION ((POSITION)(-1)) #define NULL_POSITION ((POSITION)(-1))
@ -265,14 +312,14 @@ struct textlist
#define BS_CONTROL 2 /* \b treated as control char; prints as ^H */ #define BS_CONTROL 2 /* \b treated as control char; prints as ^H */
/* How should we search? */ /* How should we search? */
#define SRCH_FORW 000001 /* Search forward from current position */ #define SRCH_FORW (1 << 0) /* Search forward from current position */
#define SRCH_BACK 000002 /* Search backward from current position */ #define SRCH_BACK (1 << 1) /* Search backward from current position */
#define SRCH_NO_MOVE 000004 /* Highlight, but don't move */ #define SRCH_NO_MOVE (1 << 2) /* Highlight, but don't move */
#define SRCH_FIND_ALL 000010 /* Find and highlight all matches */ #define SRCH_FIND_ALL (1 << 4) /* Find and highlight all matches */
#define SRCH_NO_MATCH 000100 /* Search for non-matching lines */ #define SRCH_NO_MATCH (1 << 8) /* Search for non-matching lines */
#define SRCH_PAST_EOF 000200 /* Search past end-of-file, into next file */ #define SRCH_PAST_EOF (1 << 9) /* Search past end-of-file, into next file */
#define SRCH_FIRST_FILE 000400 /* Search starting at the first file */ #define SRCH_FIRST_FILE (1 << 10) /* Search starting at the first file */
#define SRCH_NO_REGEX 001000 /* Don't use regular expressions */ #define SRCH_NO_REGEX (1 << 12) /* Don't use regular expressions */
#define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \ #define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \
(((t) & ~SRCH_FORW) | SRCH_BACK) : \ (((t) & ~SRCH_FORW) | SRCH_BACK) : \
@ -290,13 +337,15 @@ struct textlist
#define CF_QUIT_ON_ERASE 0001 /* Abort cmd if its entirely erased */ #define CF_QUIT_ON_ERASE 0001 /* Abort cmd if its entirely erased */
/* Special chars used to tell put_line() to do something special */ /* Special char bit-flags used to tell put_line() to do something special */
#define AT_NORMAL (0) #define AT_NORMAL (0)
#define AT_UNDERLINE (1) #define AT_UNDERLINE (1 << 0)
#define AT_BOLD (2) #define AT_BOLD (1 << 1)
#define AT_BLINK (3) #define AT_BLINK (1 << 2)
#define AT_INVIS (4) #define AT_STANDOUT (1 << 3)
#define AT_STANDOUT (5) #define AT_ANSI (1 << 4) /* Content-supplied "ANSI" escape sequence */
#define AT_BINARY (1 << 5) /* LESS*BINFMT representation */
#define AT_HILITE (1 << 6) /* Internal highlights (e.g., for search) */
#if '0' == 240 #if '0' == 240
#define IS_EBCDIC_HOST 1 #define IS_EBCDIC_HOST 1

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/* $FreeBSD$ */ /* $FreeBSD$ */
/* /*
* Copyright (C) 1984-2002 Mark Nudelman * Copyright (C) 1984-2004 Mark Nudelman
* *
* You may distribute under the terms of either the GNU General Public * You may distribute under the terms of either the GNU General Public
* License or the Less License, as specified in the README file. * License or the Less License, as specified in the README file.
@ -120,6 +120,7 @@ main(argc, argv)
init_prompt(); init_prompt();
init_charset(); init_charset();
init_line(); init_line();
init_cmdhist();
init_option(); init_option();
if (more_mode) { if (more_mode) {
@ -350,14 +351,14 @@ sprefix(ps, s, uppercase)
c = *ps; c = *ps;
if (uppercase) if (uppercase)
{ {
if (len == 0 && SIMPLE_IS_LOWER(c)) if (len == 0 && ASCII_IS_LOWER(c))
return (-1); return (-1);
if (SIMPLE_IS_UPPER(c)) if (ASCII_IS_UPPER(c))
c = SIMPLE_TO_LOWER(c); c = ASCII_TO_LOWER(c);
} }
sc = *s; sc = *s;
if (len > 0 && SIMPLE_IS_UPPER(sc)) if (len > 0 && ASCII_IS_UPPER(sc))
sc = SIMPLE_TO_LOWER(sc); sc = ASCII_TO_LOWER(sc);
if (c != sc) if (c != sc)
break; break;
len++; len++;
@ -384,6 +385,7 @@ quit(status)
save_status = status; save_status = status;
quitting = 1; quitting = 1;
edit((char*)NULL); edit((char*)NULL);
save_cmdhist();
if (any_display && is_tty) if (any_display && is_tty)
clear_bot(); clear_bot();
deinit(); deinit();

View File

@ -1,6 +1,6 @@
/* $FreeBSD$ */ /* $FreeBSD$ */
/* /*
* Copyright (C) 1984-2002 Mark Nudelman * Copyright (C) 1984-2004 Mark Nudelman
* *
* You may distribute under the terms of either the GNU General Public * You may distribute under the terms of either the GNU General Public
* License or the Less License, as specified in the README file. * License or the Less License, as specified in the README file.
@ -165,7 +165,7 @@ curr_byte(where)
POSITION pos; POSITION pos;
pos = position(where); pos = position(where);
while (pos == NULL_POSITION && where >= 0 && where < sc_height) while (pos == NULL_POSITION && where >= 0 && where < sc_height-1)
pos = position(++where); pos = position(++where);
if (pos == NULL_POSITION) if (pos == NULL_POSITION)
pos = ch_length(); pos = ch_length();
@ -201,7 +201,7 @@ cond(c, where)
case 'd': /* Same as l */ case 'd': /* Same as l */
return (linenums); return (linenums);
case 'L': /* Final line number known? */ case 'L': /* Final line number known? */
case 'D': /* Same as L */ case 'D': /* Final page number known? */
return (linenums && ch_length() != NULL_POSITION); return (linenums && ch_length() != NULL_POSITION);
case 'm': /* More than one file? */ case 'm': /* More than one file? */
#if TAGS #if TAGS
@ -255,6 +255,9 @@ protochar(c, where, iseditproto)
LINENUM last_linenum; LINENUM last_linenum;
IFILE h; IFILE h;
#undef PAGE_NUM
#define PAGE_NUM(linenum) ((((linenum) - 1) / (sc_height - 1)) + 1)
switch (c) switch (c)
{ {
case 'b': /* Current byte offset */ case 'b': /* Current byte offset */
@ -270,17 +273,26 @@ protochar(c, where, iseditproto)
case 'd': /* Current page number */ case 'd': /* Current page number */
linenum = currline(where); linenum = currline(where);
if (linenum > 0 && sc_height > 1) if (linenum > 0 && sc_height > 1)
ap_linenum(((linenum - 1) / (sc_height - 1)) + 1); ap_linenum(PAGE_NUM(linenum));
else else
ap_quest(); ap_quest();
break; break;
case 'D': /* Last page number */ case 'D': /* Final page number */
/* Find the page number of the last byte in the file (len-1). */
len = ch_length(); len = ch_length();
if (len == NULL_POSITION || len == ch_zero() || if (len == NULL_POSITION)
(linenum = find_linenum(len)) <= 0)
ap_quest(); ap_quest();
else if (len == 0)
/* An empty file has no pages. */
ap_linenum(0);
else else
ap_linenum(((linenum - 1) / (sc_height - 1)) + 1); {
linenum = find_linenum(len - 1);
if (linenum <= 0)
ap_quest();
else
ap_linenum(PAGE_NUM(linenum));
}
break; break;
#if EDITOR #if EDITOR
case 'E': /* Editor name */ case 'E': /* Editor name */
@ -519,7 +531,7 @@ pr_expand(proto, maxwidth)
} }
if (mp == message) if (mp == message)
return (NULL); return ("");
if (maxwidth > 0 && mp >= message + maxwidth) if (maxwidth > 0 && mp >= message + maxwidth)
{ {
/* /*

View File

@ -1,6 +1,6 @@
/* $FreeBSD$ */ /* $FreeBSD$ */
/* /*
* Copyright (C) 1984-2002 Mark Nudelman * Copyright (C) 1984-2005 Mark Nudelman
* *
* You may distribute under the terms of either the GNU General Public * You may distribute under the terms of either the GNU General Public
* License or the Less License, as specified in the README file. * License or the Less License, as specified in the README file.
@ -39,11 +39,12 @@ extern int fd0;
#else #else
#if HAVE_TERMIOS_H && HAVE_TERMIOS_FUNCS #if HAVE_SYS_IOCTL_H
#include <termios.h>
#if HAVE_SYS_IOCTL_H && !defined(TIOCGWINSZ)
#include <sys/ioctl.h> #include <sys/ioctl.h>
#endif #endif
#if HAVE_TERMIOS_H && HAVE_TERMIOS_FUNCS
#include <termios.h>
#else #else
#if HAVE_TERMIO_H #if HAVE_TERMIO_H
#include <termio.h> #include <termio.h>
@ -53,9 +54,6 @@ extern int fd0;
#else #else
#include <sgtty.h> #include <sgtty.h>
#endif #endif
#if HAVE_SYS_IOCTL_H && (defined(TIOCGWINSZ) || defined(TCGETA) || defined(TIOCGETP) || defined(WIOCGETD))
#include <sys/ioctl.h>
#endif
#endif #endif
#endif #endif
@ -190,7 +188,9 @@ static int init_done = 0;
public int auto_wrap; /* Terminal does \r\n when write past margin */ public int auto_wrap; /* Terminal does \r\n when write past margin */
public int ignaw; /* Terminal ignores \n immediately after wrap */ public int ignaw; /* Terminal ignores \n immediately after wrap */
public int erase_char, kill_char; /* The user's erase and line-kill chars */ public int erase_char; /* The user's erase char */
public int erase2_char; /* The user's other erase char */
public int kill_char; /* The user's line-kill char */
public int werase_char; /* The user's word-erase char */ public int werase_char; /* The user's word-erase char */
public int sc_width, sc_height; /* Height & width of screen */ public int sc_width, sc_height; /* Height & width of screen */
public int bo_s_width, bo_e_width; /* Printing width of boldface seq */ public int bo_s_width, bo_e_width; /* Printing width of boldface seq */
@ -203,6 +203,7 @@ public int clear_bg; /* Clear fills with background color */
public int missing_cap = 0; /* Some capability is missing */ public int missing_cap = 0; /* Some capability is missing */
static int attrmode = AT_NORMAL; static int attrmode = AT_NORMAL;
extern int binattr;
#if !MSDOS_COMPILER #if !MSDOS_COMPILER
static char *cheaper(); static char *cheaper();
@ -233,6 +234,7 @@ extern int sigs;
extern int wscroll; extern int wscroll;
extern int screen_trashed; extern int screen_trashed;
extern int tty; extern int tty;
extern int top_scroll;
#if HILITE_SEARCH #if HILITE_SEARCH
extern int hilite_search; extern int hilite_search;
#endif #endif
@ -260,6 +262,7 @@ raw_mode(on)
if (on == curr_on) if (on == curr_on)
return; return;
erase2_char = '\b'; /* in case OS doesn't know about erase2 */
#if HAVE_TERMIOS_H && HAVE_TERMIOS_FUNCS #if HAVE_TERMIOS_H && HAVE_TERMIOS_FUNCS
{ {
struct termios s; struct termios s;
@ -342,6 +345,9 @@ raw_mode(on)
} }
#endif #endif
erase_char = s.c_cc[VERASE]; erase_char = s.c_cc[VERASE];
#ifdef VERASE2
erase2_char = s.c_cc[VERASE2];
#endif
kill_char = s.c_cc[VKILL]; kill_char = s.c_cc[VKILL];
#ifdef VWERASE #ifdef VWERASE
werase_char = s.c_cc[VWERASE]; werase_char = s.c_cc[VWERASE];
@ -1212,7 +1218,7 @@ get_term()
if (below_mem && (sc_eos_clear == NULL || *sc_eos_clear == '\0')) if (below_mem && (sc_eos_clear == NULL || *sc_eos_clear == '\0'))
{ {
missing_cap = 1; missing_cap = 1;
sc_eol_clear = ""; sc_eos_clear = "";
} }
sc_clear = ltgetstr("cl", &sp); sc_clear = ltgetstr("cl", &sp);
@ -1516,6 +1522,19 @@ init()
tputs(sc_init, sc_height, putchr); tputs(sc_init, sc_height, putchr);
if (!no_keypad) if (!no_keypad)
tputs(sc_s_keypad, sc_height, putchr); tputs(sc_s_keypad, sc_height, putchr);
if (top_scroll)
{
int i;
/*
* This is nice to terminals with no alternate screen,
* but with saved scrolled-off-the-top lines. This way,
* no previous line is lost, but we start with a whole
* screen to ourself.
*/
for (i = 1; i < sc_height; i++)
putchr('\n');
}
#else #else
#if MSDOS_COMPILER==WIN32C #if MSDOS_COMPILER==WIN32C
if (!no_init) if (!no_init)
@ -1857,12 +1876,12 @@ create_flash()
videopages = w.numvideopages; videopages = w.numvideopages;
if (videopages < 2) if (videopages < 2)
{ {
so_enter(); at_enter(AT_STANDOUT);
so_exit(); at_exit();
} else } else
{ {
_setactivepage(1); _setactivepage(1);
so_enter(); at_enter(AT_STANDOUT);
blanks = (char *) ecalloc(w.numtextcols, sizeof(char)); blanks = (char *) ecalloc(w.numtextcols, sizeof(char));
for (col = 0; col < w.numtextcols; col++) for (col = 0; col < w.numtextcols; col++)
blanks[col] = ' '; blanks[col] = ' ';
@ -1871,7 +1890,7 @@ create_flash()
_setactivepage(0); _setactivepage(0);
_setvisualpage(0); _setvisualpage(0);
free(blanks); free(blanks);
so_exit(); at_exit();
} }
#else #else
#if MSDOS_COMPILER==BORLANDC #if MSDOS_COMPILER==BORLANDC
@ -2101,153 +2120,111 @@ clear_bot()
* cleared area with the current attribute. * cleared area with the current attribute.
*/ */
lower_left(); lower_left();
switch (attrmode) if (attrmode == AT_NORMAL)
clear_eol_bot();
else
{ {
case AT_STANDOUT: int saved_attrmode = attrmode;
so_exit();
at_exit();
clear_eol_bot(); clear_eol_bot();
so_enter(); at_enter(saved_attrmode);
break;
case AT_UNDERLINE:
ul_exit();
clear_eol_bot();
ul_enter();
break;
case AT_BOLD:
bo_exit();
clear_eol_bot();
bo_enter();
break;
case AT_BLINK:
bl_exit();
clear_eol_bot();
bl_enter();
break;
default:
clear_eol_bot();
break;
} }
} }
/*
* Begin "standout" (bold, underline, or whatever).
*/
public void public void
so_enter() at_enter(attr)
int attr;
{ {
attr = apply_at_specials(attr);
#if !MSDOS_COMPILER #if !MSDOS_COMPILER
tputs(sc_s_in, 1, putchr); /* The one with the most priority is last. */
if (attr & AT_UNDERLINE)
tputs(sc_u_in, 1, putchr);
if (attr & AT_BOLD)
tputs(sc_b_in, 1, putchr);
if (attr & AT_BLINK)
tputs(sc_bl_in, 1, putchr);
if (attr & AT_STANDOUT)
tputs(sc_s_in, 1, putchr);
#else #else
flush(); flush();
SETCOLORS(so_fg_color, so_bg_color); /* The one with the most priority is first. */
if (attr & AT_STANDOUT)
{
SETCOLORS(so_fg_color, so_bg_color);
} else if (attr & AT_BLINK)
{
SETCOLORS(bl_fg_color, bl_bg_color);
}
else if (attr & AT_BOLD)
{
SETCOLORS(bo_fg_color, bo_bg_color);
}
else if (attr & AT_UNDERLINE)
{
SETCOLORS(ul_fg_color, ul_bg_color);
}
#endif #endif
attrmode = AT_STANDOUT;
attrmode = attr;
} }
/*
* End "standout".
*/
public void public void
so_exit() at_exit()
{ {
#if !MSDOS_COMPILER #if !MSDOS_COMPILER
tputs(sc_s_out, 1, putchr); /* Undo things in the reverse order we did them. */
if (attrmode & AT_STANDOUT)
tputs(sc_s_out, 1, putchr);
if (attrmode & AT_BLINK)
tputs(sc_bl_out, 1, putchr);
if (attrmode & AT_BOLD)
tputs(sc_b_out, 1, putchr);
if (attrmode & AT_UNDERLINE)
tputs(sc_u_out, 1, putchr);
#else #else
flush(); flush();
SETCOLORS(nm_fg_color, nm_bg_color); SETCOLORS(nm_fg_color, nm_bg_color);
#endif #endif
attrmode = AT_NORMAL; attrmode = AT_NORMAL;
} }
/*
* Begin "underline" (hopefully real underlining,
* otherwise whatever the terminal provides).
*/
public void public void
ul_enter() at_switch(attr)
int attr;
{ {
#if !MSDOS_COMPILER if (apply_at_specials(attr) != attrmode)
tputs(sc_u_in, 1, putchr); {
#else at_exit();
flush(); at_enter(attr);
SETCOLORS(ul_fg_color, ul_bg_color); }
#endif
attrmode = AT_UNDERLINE;
} }
/* public int
* End "underline". is_at_equiv(attr1, attr2)
*/ int attr1;
public void int attr2;
ul_exit()
{ {
#if !MSDOS_COMPILER attr1 = apply_at_specials(attr1);
tputs(sc_u_out, 1, putchr); attr2 = apply_at_specials(attr2);
#else
flush(); return (attr1 == attr2);
SETCOLORS(nm_fg_color, nm_bg_color);
#endif
attrmode = AT_NORMAL;
} }
/* public int
* Begin "bold" apply_at_specials(attr)
*/ int attr;
public void
bo_enter()
{ {
#if !MSDOS_COMPILER if (attr & AT_BINARY)
tputs(sc_b_in, 1, putchr); attr |= binattr;
#else if (attr & AT_HILITE)
flush(); attr |= AT_STANDOUT;
SETCOLORS(bo_fg_color, bo_bg_color); attr &= ~(AT_BINARY|AT_HILITE);
#endif
attrmode = AT_BOLD;
}
/* return attr;
* End "bold".
*/
public void
bo_exit()
{
#if !MSDOS_COMPILER
tputs(sc_b_out, 1, putchr);
#else
flush();
SETCOLORS(nm_fg_color, nm_bg_color);
#endif
attrmode = AT_NORMAL;
}
/*
* Begin "blink"
*/
public void
bl_enter()
{
#if !MSDOS_COMPILER
tputs(sc_bl_in, 1, putchr);
#else
flush();
SETCOLORS(bl_fg_color, bl_bg_color);
#endif
attrmode = AT_BLINK;
}
/*
* End "blink".
*/
public void
bl_exit()
{
#if !MSDOS_COMPILER
tputs(sc_bl_out, 1, putchr);
#else
flush();
SETCOLORS(nm_fg_color, nm_bg_color);
#endif
attrmode = AT_NORMAL;
} }
#if 0 /* No longer used */ #if 0 /* No longer used */

View File

@ -1,6 +1,6 @@
/* $FreeBSD$ */ /* $FreeBSD$ */
/* /*
* Copyright (C) 1984-2002 Mark Nudelman * Copyright (C) 1984-2005 Mark Nudelman
* *
* You may distribute under the terms of either the GNU General Public * You may distribute under the terms of either the GNU General Public
* License or the Less License, as specified in the README file. * License or the Less License, as specified in the README file.
@ -122,9 +122,9 @@ cvt_text(odst, osrc, ops)
for (src = osrc, dst = odst; *src != '\0'; src++) 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. */ /* Convert uppercase to lowercase. */
*dst++ = tolower((unsigned char) *src); *dst++ = TO_LOWER(*src);
else if ((ops & CVT_BS) && *src == '\b' && dst > odst) else if ((ops & CVT_BS) && *src == '\b' && dst > odst)
/* Delete BS and preceding char. */ /* Delete BS and preceding char. */
dst--; dst--;
@ -132,7 +132,7 @@ cvt_text(odst, osrc, ops)
{ {
/* Skip to end of ANSI escape sequence. */ /* Skip to end of ANSI escape sequence. */
while (src[1] != '\0') while (src[1] != '\0')
if (is_ansi_end(*++src)) if (!is_ansi_middle(*++src))
break; break;
} else } else
/* Just copy. */ /* Just copy. */
@ -177,7 +177,7 @@ is_ucase(s)
register char *p; register char *p;
for (p = s; *p != '\0'; p++) for (p = s; *p != '\0'; p++)
if (isupper((unsigned char) *p)) if (IS_UPPER(*p))
return (1); return (1);
return (0); return (0);
} }
@ -249,11 +249,18 @@ repaint_hilite(on)
if (pos == NULL_POSITION) if (pos == NULL_POSITION)
continue; continue;
epos = position(slinenum+1); epos = position(slinenum+1);
#if 0
/* /*
* If any character in the line is highlighted, * If any character in the line is highlighted,
* repaint the line. * 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); (void) forw_line(pos);
goto_line(slinenum); goto_line(slinenum);
@ -532,17 +539,43 @@ clr_hilite()
prep_startpos = prep_endpos = NULL_POSITION; prep_startpos = prep_endpos = NULL_POSITION;
} }
/*
* 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? * 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) is_hilited(pos, epos, nohide, p_matches)
POSITION pos; POSITION pos;
POSITION epos; POSITION epos;
int nohide; int nohide;
int *p_matches;
{ {
struct hilite *hl; int match;
if (p_matches != NULL)
*p_matches = 0;
if (!status_col && if (!status_col &&
start_attnpos != NULL_POSITION && start_attnpos != NULL_POSITION &&
@ -553,6 +586,16 @@ is_hilited(pos, epos, nohide)
*/ */
return (1); 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) if (hilite_search == 0)
/* /*
* Not doing highlighting. * Not doing highlighting.
@ -565,16 +608,7 @@ is_hilited(pos, epos, nohide)
*/ */
return (0); return (0);
/* return (1);
* 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);
} }
/* /*
@ -617,6 +651,30 @@ add_hilite(anchor, hl)
ihl->hl_next = 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. * Adjust hl_startpos & hl_endpos to account for backspace processing.
*/ */
@ -666,38 +724,30 @@ adj_hilite(anchor, linepos, cvt_ops)
} }
if (*line == '\0') if (*line == '\0')
break; break;
if (cvt_ops & CVT_ANSI) adj_hilite_ansi(cvt_ops, &line, &npos);
{
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;
}
}
}
opos++; opos++;
npos++; npos++;
line++; line++;
if (cvt_ops & CVT_BS) 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 * Found a backspace. The file position moves
* forward by 2 relative to the processed line * forward by 2 relative to the processed line
* which was searched in hilite_line. * which was searched in hilite_line.
*/ */
npos += 2; npos++;
line += 2; line++;
} }
} }
} }
@ -1043,7 +1093,7 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos)
* Return it. * Return it.
*/ */
#if HILITE_SEARCH #if HILITE_SEARCH
if (hilite_search == 1) if (hilite_search == OPT_ON)
{ {
/* /*
* Clear the hilite list and add only * Clear the hilite list and add only

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 1984-2002 Mark Nudelman * Copyright (C) 1984-2004 Mark Nudelman
* *
* You may distribute under the terms of either the GNU General Public * You may distribute under the terms of either the GNU General Public
* License or the Less License, as specified in the README file. * License or the Less License, as specified in the README file.
@ -34,6 +34,7 @@ extern int lnloop;
extern int linenums; extern int linenums;
extern int wscroll; extern int wscroll;
extern int reading; extern int reading;
extern int quit_on_intr;
extern int more_mode; extern int more_mode;
/* /*
@ -251,6 +252,8 @@ psignals()
#endif #endif
if (tsignals & S_INTERRUPT) if (tsignals & S_INTERRUPT)
{ {
if (quit_on_intr)
quit(QUIT_OK);
bell(); bell();
/* /*
* {{ You may wish to replace the bell() with * {{ You may wish to replace the bell() with