diff options
Diffstat (limited to 'contrib/less/linenum.c')
-rw-r--r-- | contrib/less/linenum.c | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/contrib/less/linenum.c b/contrib/less/linenum.c index 184306b..ecbfdc2 100644 --- a/contrib/less/linenum.c +++ b/contrib/less/linenum.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2007 Mark Nudelman + * Copyright (C) 1984-2008 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. @@ -56,12 +56,10 @@ struct linenum_info * when we have a new one to insert and the table is full. */ -#define NPOOL 50 /* Size of line number pool */ +#define NPOOL 200 /* Size of line number pool */ #define LONGTIME (2) /* In seconds */ -public int lnloop = 0; /* Are we in the line num loop? */ - static struct linenum_info anchor; /* Anchor of the list */ static struct linenum_info *freelist; /* Anchor of the unused entries */ static struct linenum_info pool[NPOOL]; /* The pool itself */ @@ -70,6 +68,7 @@ static struct linenum_info *spare; /* We always keep one spare entry */ extern int linenums; extern int sigs; extern int sc_height; +extern int screen_trashed; /* * Initialize the line number structures. @@ -214,12 +213,6 @@ add_lnum(linenum, pos) longloopmessage() { ierror("Calculating line numbers", NULL_PARG); - /* - * Set the lnloop flag here, so if the user interrupts while - * we are calculating line numbers, the signal handler will - * turn off line numbers (linenums=0). - */ - lnloop = 1; } static int loopcount; @@ -250,6 +243,22 @@ longish() } /* + * Turn off line numbers because the user has interrupted + * a lengthy line number calculation. + */ + static void +abort_long() +{ + if (linenums == OPT_ONPLUS) + /* + * We were displaying line numbers, so need to repaint. + */ + screen_trashed = 1; + linenums = 0; + error("Line numbers turned off", NULL_PARG); +} + +/* * Find the line number associated with a given position. * Return 0 if we can't figure it out. */ @@ -315,11 +324,14 @@ find_linenum(pos) * Allow a signal to abort this loop. */ cpos = forw_raw_line(cpos, (char **)NULL, (int *)NULL); - if (ABORT_SIGS() || cpos == NULL_POSITION) + if (ABORT_SIGS()) { + abort_long(); + return (0); + } + if (cpos == NULL_POSITION) return (0); longish(); } - lnloop = 0; /* * We might as well cache it. */ @@ -344,11 +356,14 @@ find_linenum(pos) * Allow a signal to abort this loop. */ cpos = back_raw_line(cpos, (char **)NULL, (int *)NULL); - if (ABORT_SIGS() || cpos == NULL_POSITION) + if (ABORT_SIGS()) { + abort_long(); + return (0); + } + if (cpos == NULL_POSITION) return (0); longish(); } - lnloop = 0; /* * We might as well cache it. */ @@ -399,7 +414,9 @@ find_pos(linenum) * Allow a signal to abort this loop. */ cpos = forw_raw_line(cpos, (char **)NULL, (int *)NULL); - if (ABORT_SIGS() || cpos == NULL_POSITION) + if (ABORT_SIGS()) + return (NULL_POSITION); + if (cpos == NULL_POSITION) return (NULL_POSITION); } } else @@ -415,7 +432,9 @@ find_pos(linenum) * Allow a signal to abort this loop. */ cpos = back_raw_line(cpos, (char **)NULL, (int *)NULL); - if (ABORT_SIGS() || cpos == NULL_POSITION) + if (ABORT_SIGS()) + return (NULL_POSITION); + if (cpos == NULL_POSITION) return (NULL_POSITION); } } |