summaryrefslogtreecommitdiffstats
path: root/contrib/less
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/less')
-rw-r--r--contrib/less/command.c55
-rw-r--r--contrib/less/forwback.c40
-rw-r--r--contrib/less/less.h8
-rw-r--r--contrib/less/line.c31
-rw-r--r--contrib/less/main.c41
-rw-r--r--contrib/less/prompt.c12
-rw-r--r--contrib/less/screen.c66
-rw-r--r--contrib/less/search.c138
-rw-r--r--contrib/less/signal.c13
9 files changed, 128 insertions, 276 deletions
diff --git a/contrib/less/command.c b/contrib/less/command.c
index da0f3ea..18ea4d4 100644
--- a/contrib/less/command.c
+++ b/contrib/less/command.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.
@@ -23,6 +24,7 @@
extern int erase_char, erase2_char, kill_char;
extern int sigs;
+extern int quit_at_eof;
extern int quit_if_one_screen;
extern int squished;
extern int hit_eof;
@@ -37,6 +39,7 @@ extern int ignore_eoi;
extern int secure;
extern int hshift;
extern int show_attn;
+extern int more_mode;
extern char *every_first_cmd;
extern char *curr_altfilename;
extern char version[];
@@ -53,8 +56,6 @@ extern char *editproto;
#endif
extern int screen_trashed; /* The screen has been overwritten */
extern int shift_count;
-extern int oldbot;
-extern int forw_prompt;
static char ungot[UNGOT_SIZE];
static char *ungotp = NULL;
@@ -64,7 +65,6 @@ static char *shellcmd = NULL; /* For holding last shell command for "!!" */
static int mca; /* The multicharacter command (action) */
static int search_type; /* The previous type of search */
static LINENUM number; /* The number typed by the user */
-static long fraction; /* The fractional part of the number */
static char optchar;
static int optflag;
static int optgetname;
@@ -77,7 +77,7 @@ static char pipec;
static void multi_search();
/*
- * Move the cursor to start of prompt line before executing a command.
+ * Move the cursor to lower left before executing a command.
* This looks nicer if the command takes a long time before
* updating the screen.
*/
@@ -85,7 +85,7 @@ static void multi_search();
cmd_exec()
{
clear_attn();
- line_left();
+ lower_left();
flush();
}
@@ -100,7 +100,6 @@ start_mca(action, prompt, mlist, cmdflags)
int cmdflags;
{
mca = action;
- clear_bot();
clear_cmd();
cmd_putstr(prompt);
set_mlist(mlist, cmdflags);
@@ -123,7 +122,6 @@ mca_search()
else
mca = A_B_SEARCH;
- clear_bot();
clear_cmd();
if (search_type & SRCH_NO_MATCH)
@@ -159,7 +157,6 @@ mca_opt_toggle()
dash = (flag == OPT_NO_TOGGLE) ? "_" : "-";
mca = A_OPT_TOGGLE;
- clear_bot();
clear_cmd();
cmd_putstr(dash);
if (optgetname)
@@ -296,14 +293,14 @@ mca_char(c)
* Entering digits of a number.
* Terminated by a non-digit.
*/
- if (!((c >= '0' && c <= '9') || c == '.') &&
+ if ((c < '0' || c > '9') &&
editchar(c, EC_PEEK|EC_NOHISTORY|EC_NOCOMPLETE|EC_NORIGHTLEFT) == A_INVALID)
{
/*
* Not part of the number.
* Treat as a normal command character.
*/
- number = cmd_int(&fraction);
+ number = cmd_int();
mca = 0;
cmd_accept();
return (NO_MCA);
@@ -484,12 +481,16 @@ mca_char(c)
flag = 0;
switch (c)
{
- case CONTROL('E'): /* ignore END of file */
case '*':
+ if (more_mode)
+ break;
+ case CONTROL('E'): /* ignore END of file */
flag = SRCH_PAST_EOF;
break;
- case CONTROL('F'): /* FIRST file */
case '@':
+ if (more_mode)
+ break;
+ case CONTROL('F'): /* FIRST file */
flag = SRCH_FIRST_FILE;
break;
case CONTROL('K'): /* KEEP position */
@@ -611,7 +612,7 @@ prompt()
* {{ Relying on "first prompt" to detect a single-screen file
* fails if +G is used, for example. }}
*/
- if ((get_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) &&
next_ifile(curr_ifile) == NULL_IFILE)
quit(QUIT_OK);
@@ -621,7 +622,7 @@ prompt()
* If the -e flag is set and we've hit EOF on the last file,
* and the file is squished (shorter than the screen), quit.
*/
- if (get_quit_at_eof() && squished &&
+ if (quit_at_eof && squished &&
next_ifile(curr_ifile) == NULL_IFILE)
quit(QUIT_OK);
#endif
@@ -636,20 +637,7 @@ prompt()
/*
* Select the proper prompt and display it.
*/
- /*
- * If the previous action was a forward movement,
- * don't clear the bottom line of the display;
- * just print the prompt since the forward movement guarantees
- * that we're in the right position to display the prompt.
- * Clearing the line could cause a problem: for example, if the last
- * line displayed ended at the right screen edge without a newline,
- * then clearing would clear the last displayed line rather than
- * the prompt line.
- */
- if (!forw_prompt)
- clear_bot();
clear_cmd();
- forw_prompt = 0;
p = pr_string();
if (p == NULL || *p == '\0')
putchr(':');
@@ -659,7 +647,6 @@ prompt()
putstr(p);
at_exit();
}
- clear_eol();
}
/*
@@ -1180,17 +1167,11 @@ commands()
* Go to a specified percentage into the file.
*/
if (number < 0)
- {
number = 0;
- fraction = 0;
- }
if (number > 100)
- {
number = 100;
- fraction = 0;
- }
cmd_exec();
- jump_percent((int) number, fraction);
+ jump_percent((int) number);
break;
case A_GOEND:
@@ -1411,7 +1392,7 @@ commands()
number = 1;
if (edit_next((int) number))
{
- if (get_quit_at_eof() && hit_eof &&
+ if (quit_at_eof && hit_eof &&
!(ch_getflags() & CH_HELPFILE))
quit(QUIT_OK);
parg.p_string = (number > 1) ? "(N-th) " : "";
diff --git a/contrib/less/forwback.c b/contrib/less/forwback.c
index 1eafd6a..a514c9f 100644
--- a/contrib/less/forwback.c
+++ b/contrib/less/forwback.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.
@@ -21,19 +22,19 @@ public int hit_eof; /* Keeps track of how many times we hit end of file */
public int screen_trashed;
public int squished;
public int no_back_scroll = 0;
-public int forw_prompt;
extern int sigs;
extern int top_scroll;
extern int quiet;
extern int sc_width, sc_height;
+extern int quit_at_eof;
+extern int more_mode;
extern int plusoption;
extern int forw_scroll;
extern int back_scroll;
extern int ignore_eoi;
extern int clear_bg;
extern int final_attr;
-extern int oldbot;
#if TAGS
extern char *tagoption;
#endif
@@ -78,7 +79,7 @@ eof_check()
* of the screen; this can happen when we display a short file
* for the first time.
*/
- public void
+ static void
squish_check()
{
if (!squished)
@@ -136,8 +137,12 @@ forw(n, pos, force, only_last, nblank)
pos_clear();
add_forw_pos(pos);
force = 1;
- clear();
- home();
+ if (more_mode == 0)
+ {
+ if (top_scroll == OPT_ONPLUS || (first_time && top_scroll != OPT_ON))
+ clear();
+ home();
+ }
} else
{
clear_bot();
@@ -155,7 +160,8 @@ forw(n, pos, force, only_last, nblank)
force = 1;
if (top_scroll)
{
- clear();
+ if (top_scroll == OPT_ONPLUS)
+ clear();
home();
} else if (!first_time)
{
@@ -220,7 +226,8 @@ forw(n, pos, force, only_last, nblank)
* start the display after the beginning of the file,
* and it is not appropriate to squish in that case.
*/
- if (first_time && pos == NULL_POSITION && !top_scroll &&
+ if ((first_time || more_mode) &&
+ pos == NULL_POSITION && !top_scroll &&
#if TAGS
tagoption == NULL &&
#endif
@@ -229,16 +236,9 @@ forw(n, pos, force, only_last, nblank)
squished = 1;
continue;
}
+ if (top_scroll == OPT_ON)
+ clear_eol();
put_line();
-#if 0
- /* {{
- * Can't call clear_eol here. The cursor might be at end of line
- * on an ignaw terminal, so clear_eol would clear the last char
- * of the current line instead of all of the next line.
- * If we really need to do this on clear_bg terminals, we need
- * to find a better way.
- * }}
- */
if (clear_bg && apply_at_specials(final_attr) != AT_NORMAL)
{
/*
@@ -250,8 +250,6 @@ forw(n, pos, force, only_last, nblank)
*/
clear_eol();
}
-#endif
- forw_prompt = 1;
}
if (ignore_eoi)
@@ -317,8 +315,6 @@ back(n, pos, force, only_last)
eof_bell();
else if (do_repaint)
repaint();
- else if (!oldbot)
- lower_left();
(void) currline(BOTTOM);
}
@@ -334,7 +330,7 @@ forward(n, force, only_last)
{
POSITION pos;
- if (get_quit_at_eof() && hit_eof && !(ch_getflags() & CH_HELPFILE))
+ if (quit_at_eof && hit_eof && !(ch_getflags() & CH_HELPFILE))
{
/*
* If the -e flag is set and we're trying to go
diff --git a/contrib/less/less.h b/contrib/less/less.h
index bf8b803..3700b4f 100644
--- a/contrib/less/less.h
+++ b/contrib/less/less.h
@@ -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.
@@ -8,7 +9,6 @@
* contact the author, see the README file.
*/
-#define NEWBOT 1
/*
* Standard include file for "less".
@@ -296,10 +296,6 @@ struct textlist
#define READ_INTR (-2)
-/* A fraction is represented by an int n; the fraction is n/NUM_FRAC_DENOM */
-#define NUM_FRAC_DENOM 1000000
-#define NUM_LOG_FRAC_DENOM 6
-
/* How quiet should we be? */
#define NOT_QUIET 0 /* Ring bell at eof and for errors */
#define LITTLE_QUIET 1 /* Ring bell only for errors */
diff --git a/contrib/less/line.c b/contrib/less/line.c
index e4b9731..42a2ea3 100644
--- a/contrib/less/line.c
+++ b/contrib/less/line.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.
@@ -59,7 +60,6 @@ extern int bl_s_width, bl_e_width;
extern int so_s_width, so_e_width;
extern int sc_width, sc_height;
extern int utf_mode;
-extern int oldbot;
extern POSITION start_attnpos;
extern POSITION end_attnpos;
@@ -995,8 +995,6 @@ pflushmbc()
pdone(endline)
int endline;
{
- int nl;
-
(void) pflushmbc();
if (pendc && (pendc != '\r' || !endline))
@@ -1027,21 +1025,8 @@ pdone(endline)
/*
* Add a newline if necessary,
* and append a '\0' to the end of the line.
- * We output a newline if we're not at the right edge of the screen,
- * or if the terminal doesn't auto wrap,
- * or if this is really the end of the line AND the terminal ignores
- * a newline at the right edge.
- * (In the last case we don't want to output a newline if the terminal
- * doesn't ignore it since that would produce an extra blank line.
- * But we do want to output a newline if the terminal ignores it in case
- * the next line is blank. In that case the single newline output for
- * that blank line would be ignored!)
*/
- if (!oldbot)
- nl = (column < sc_width || !auto_wrap || (endline && ignaw) || ctldisp == OPT_ON);
- else
- nl = (column < sc_width || !auto_wrap || ignaw || ctldisp == OPT_ON);
- if (nl)
+ if (column < sc_width || !auto_wrap || ignaw || ctldisp == OPT_ON)
{
linebuf[curr] = '\n';
attr[curr] = AT_NORMAL;
@@ -1109,10 +1094,9 @@ null_line()
* {{ This is supposed to be more efficient than forw_line(). }}
*/
public POSITION
-forw_raw_line(curr_pos, linep, line_lenp)
+forw_raw_line(curr_pos, linep)
POSITION curr_pos;
char **linep;
- int *line_lenp;
{
register int n;
register int c;
@@ -1148,8 +1132,6 @@ forw_raw_line(curr_pos, linep, line_lenp)
linebuf[n] = '\0';
if (linep != NULL)
*linep = linebuf;
- if (line_lenp != NULL)
- *line_lenp = n;
return (new_pos);
}
@@ -1158,10 +1140,9 @@ forw_raw_line(curr_pos, linep, line_lenp)
* {{ This is supposed to be more efficient than back_line(). }}
*/
public POSITION
-back_raw_line(curr_pos, linep, line_lenp)
+back_raw_line(curr_pos, linep)
POSITION curr_pos;
char **linep;
- int *line_lenp;
{
register int n;
register int c;
@@ -1222,7 +1203,5 @@ back_raw_line(curr_pos, linep, line_lenp)
}
if (linep != NULL)
*linep = &linebuf[n];
- if (line_lenp != NULL)
- *line_lenp = size_linebuf - 1 - n;
return (new_pos);
}
diff --git a/contrib/less/main.c b/contrib/less/main.c
index 36a230e..c7dbdb8 100644
--- a/contrib/less/main.c
+++ b/contrib/less/main.c
@@ -1,5 +1,6 @@
+/* $FreeBSD$ */
/*
- * Copyright (C) 1984-2007 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
@@ -32,7 +33,7 @@ public char * progname;
public int quitting;
public int secure;
public int dohelp;
-public int less_is_more;
+public int more_mode = 0;
#if LOGFILE
public int logfile = -1;
@@ -57,8 +58,6 @@ static char consoleTitle[256];
extern int missing_cap;
extern int know_dumb;
-extern int quit_if_one_screen;
-extern int pr_type;
/*
@@ -71,6 +70,7 @@ main(argc, argv)
{
IFILE ifile;
char *s;
+ extern char *__progname;
#ifdef __EMX__
_response(&argc, &argv);
@@ -111,29 +111,27 @@ main(argc, argv)
* Process command line arguments and LESS environment arguments.
* Command line arguments override environment arguments.
*/
+ if (strcmp(__progname, "more") == 0)
+ more_mode = 1;
+
is_tty = isatty(1);
get_term();
init_cmds();
+ init_prompt();
init_charset();
init_line();
init_cmdhist();
init_option();
-
- /*
- * If the name of the executable program is "more",
- * act like LESS_IS_MORE is set.
- */
- for (s = progname + strlen(progname); s > progname; s--)
- {
- if (s[-1] == PATHNAME_SEP[0])
- break;
+
+ if (more_mode) {
+ scan_option("-E");
+ scan_option("-m");
+ scan_option("-G");
+ scan_option("-f");
+ s = lgetenv("MORE");
+ } else {
+ s = lgetenv("LESS");
}
- if (strcmp(s, "more") == 0)
- less_is_more = 1;
-
- init_prompt();
-
- s = lgetenv(less_is_more ? "MORE" : "LESS");
if (s != NULL)
scan_option(save(s));
@@ -158,9 +156,6 @@ main(argc, argv)
quit(QUIT_OK);
}
- if (less_is_more && get_quit_at_eof())
- quit_if_one_screen = TRUE;
-
#if EDITOR
editor = lgetenv("VISUAL");
if (editor == NULL || *editor == '\0')
@@ -235,7 +230,7 @@ main(argc, argv)
quit(QUIT_OK);
}
- if (missing_cap && !know_dumb)
+ if (missing_cap && !know_dumb && !more_mode)
error("WARNING: terminal is not fully functional", NULL_PARG);
init_mark();
open_getchr();
diff --git a/contrib/less/prompt.c b/contrib/less/prompt.c
index 67b5ddc..7e22f99 100644
--- a/contrib/less/prompt.c
+++ b/contrib/less/prompt.c
@@ -1,5 +1,6 @@
+/* $FreeBSD$ */
/*
- * Copyright (C) 1984-2007 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
@@ -30,7 +31,6 @@ extern int linenums;
extern int hshift;
extern int sc_height;
extern int jump_sline;
-extern int less_is_more;
extern IFILE curr_ifile;
#if EDITOR
extern char *editor;
@@ -53,8 +53,6 @@ static constant char h_proto[] =
"HELP -- ?eEND -- Press g to see it again:Press RETURN for more., or q when done";
static constant char w_proto[] =
"Waiting for data";
-static constant char more_proto[] =
- "--More--(?eEND ?x- Next\\: %x.:?pB%pB\\%:byte %bB?s/%s...%t)";
public char *prproto[3];
public char constant *eqproto = e_proto;
@@ -71,7 +69,7 @@ static char *mp;
init_prompt()
{
prproto[0] = save(s_proto);
- prproto[1] = save(less_is_more ? more_proto : m_proto);
+ prproto[1] = save(m_proto);
prproto[2] = save(M_proto);
eqproto = save(e_proto);
hproto = save(h_proto);
@@ -564,11 +562,9 @@ eq_message()
pr_string()
{
char *prompt;
- int type;
- type = (!less_is_more) ? pr_type : pr_type ? 0 : 1;
prompt = pr_expand((ch_getflags() & CH_HELPFILE) ?
- hproto : prproto[type],
+ hproto : prproto[pr_type],
sc_width-so_s_width-so_e_width-2);
new_file = 0;
return (prompt);
diff --git a/contrib/less/screen.c b/contrib/less/screen.c
index 6c4fc84..03960c7 100644
--- a/contrib/less/screen.c
+++ b/contrib/less/screen.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.
@@ -163,7 +164,6 @@ static char
*sc_home, /* Cursor home */
*sc_addline, /* Add line, scroll down following lines */
*sc_lower_left, /* Cursor to last line, first column */
- *sc_return, /* Cursor to beginning of current line */
*sc_move, /* General cursor positioning */
*sc_clear, /* Clear screen */
*sc_eol_clear, /* Clear to end of line */
@@ -227,13 +227,14 @@ extern int quiet; /* If VERY_QUIET, use visual bell for bell */
extern int no_back_scroll;
extern int swindow;
extern int no_init;
+extern int quit_at_eof;
+extern int more_mode;
extern int no_keypad;
extern int sigs;
extern int wscroll;
extern int screen_trashed;
extern int tty;
extern int top_scroll;
-extern int oldbot;
#if HILITE_SEARCH
extern int hilite_search;
#endif
@@ -1129,7 +1130,7 @@ get_term()
if ((term = lgetenv("TERM")) == NULL)
term = DEFAULT_TERM;
hardcopy = 0;
- if (tgetent(termbuf, term) != TGETENT_OK)
+ if (tgetent(termbuf, term) <= 0)
hardcopy = 1;
if (ltgetflag("hc"))
hardcopy = 1;
@@ -1190,11 +1191,19 @@ get_term()
if (sc_e_keypad == NULL)
sc_e_keypad = "";
- sc_init = ltgetstr("ti", &sp);
+ /*
+ * This loses for terminals with termcap entries with ti/te strings
+ * that switch to/from an alternate screen, and we're in quit_at_eof
+ * (eg, more(1)).
+ */
+ if (!quit_at_eof && !more_mode) {
+ sc_init = ltgetstr("ti", &sp);
+ sc_deinit = ltgetstr("te", &sp);
+ }
+
if (sc_init == NULL)
sc_init = "";
- sc_deinit= ltgetstr("te", &sp);
if (sc_deinit == NULL)
sc_deinit = "";
@@ -1285,13 +1294,6 @@ get_term()
sc_lower_left = cheaper(t1, t2, "\r");
/*
- * Get carriage return string.
- */
- sc_return = ltgetstr("cr", &sp);
- if (sc_return == NULL)
- sc_return = "\r";
-
- /*
* Choose between using "al" or "sr" ("add line" or "scroll reverse")
* to add a line at the top of the screen.
*/
@@ -1810,33 +1812,6 @@ lower_left()
}
/*
- * Move cursor to left position of current line.
- */
- public void
-line_left()
-{
-#if !MSDOS_COMPILER
- tputs(sc_return, 1, putchr);
-#else
- int row;
- flush();
-#if MSDOS_COMPILER==WIN32C
- {
- CONSOLE_SCREEN_BUFFER_INFO scr;
- GetConsoleScreenBufferInfo(con_out, &scr);
- row = scr.dwCursorPosition.Y - scr.srWindow.Top + 1;
- }
-#else
- {
- struct rccoord tpos = _gettextposition();
- row = tpos.row;
- }
-#endif
- _settextposition(row, 1);
-#endif
-}
-
-/*
* Check if the console size has changed and reset internals
* (in lieu of SIGWINCH for WIN32).
*/
@@ -2144,11 +2119,7 @@ clear_bot()
* the mode while we do the clear. Some terminals fill the
* cleared area with the current attribute.
*/
- if (oldbot)
- lower_left();
- else
- line_left();
-
+ lower_left();
if (attrmode == AT_NORMAL)
clear_eol_bot();
else
@@ -2225,10 +2196,7 @@ at_exit()
at_switch(attr)
int attr;
{
- int new_attrmode = apply_at_specials(attr);
- int ignore_modes = AT_ANSI;
-
- if ((new_attrmode & ~ignore_modes) != (attrmode & ~ignore_modes))
+ if (apply_at_specials(attr) != attrmode)
{
at_exit();
at_enter(attr);
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;
diff --git a/contrib/less/signal.c b/contrib/less/signal.c
index c19d892..8b0691f 100644
--- a/contrib/less/signal.c
+++ b/contrib/less/signal.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2007 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
@@ -8,6 +8,7 @@
* contact the author, see the README file.
*/
+/* $FreeBSD$ */
/*
* Routines dealing with signals.
@@ -34,7 +35,7 @@ extern int linenums;
extern int wscroll;
extern int reading;
extern int quit_on_intr;
-extern long jump_sline_fraction;
+extern int more_mode;
/*
* Interrupt signal handler.
@@ -58,6 +59,8 @@ u_interrupt(type)
if (kbhit())
getkey();
#endif
+ if (more_mode)
+ quit(0);
if (reading)
intread();
}
@@ -89,6 +92,8 @@ winch(type)
{
LSIGNAL(SIGWINCH, winch);
sigs |= S_WINCH;
+ if (reading)
+ intread();
}
#else
#ifdef SIGWIND
@@ -152,13 +157,14 @@ init_signals(on)
#endif
#ifdef SIGWINCH
(void) LSIGNAL(SIGWINCH, winch);
-#endif
+#else
#ifdef SIGWIND
(void) LSIGNAL(SIGWIND, winch);
#endif
#ifdef SIGQUIT
(void) LSIGNAL(SIGQUIT, SIG_IGN);
#endif
+#endif
} else
{
/*
@@ -240,7 +246,6 @@ psignals()
if (sc_width != old_width || sc_height != old_height)
{
wscroll = (sc_height + 1) / 2;
- calc_jump_sline();
screen_trashed = 1;
}
}
OpenPOWER on IntegriCloud