=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/less/linenum.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- src/usr.bin/less/linenum.c 2003/04/13 18:26:26 1.4 +++ src/usr.bin/less/linenum.c 2011/09/16 18:12:09 1.5 @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2002 Mark Nudelman + * Copyright (C) 1984-2011 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 @@ * 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 @@ extern int linenums; extern int sigs; extern int sc_height; +extern int screen_trashed; /* * Initialize the line number structures. @@ -214,12 +213,6 @@ 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 @@ } /* + * 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. */ @@ -314,12 +323,15 @@ /* * Allow a signal to abort this loop. */ - cpos = forw_raw_line(cpos, (char **)NULL); - if (ABORT_SIGS() || cpos == NULL_POSITION) + cpos = forw_raw_line(cpos, (char **)NULL, (int *)NULL); + if (ABORT_SIGS()) { + abort_long(); return (0); + } + if (cpos == NULL_POSITION) + return (0); longish(); } - lnloop = 0; /* * We might as well cache it. */ @@ -343,12 +355,15 @@ /* * Allow a signal to abort this loop. */ - cpos = back_raw_line(cpos, (char **)NULL); - if (ABORT_SIGS() || cpos == NULL_POSITION) + cpos = back_raw_line(cpos, (char **)NULL, (int *)NULL); + if (ABORT_SIGS()) { + abort_long(); return (0); + } + if (cpos == NULL_POSITION) + return (0); longish(); } - lnloop = 0; /* * We might as well cache it. */ @@ -398,9 +413,11 @@ /* * Allow a signal to abort this loop. */ - cpos = forw_raw_line(cpos, (char **)NULL); - if (ABORT_SIGS() || cpos == NULL_POSITION) + cpos = forw_raw_line(cpos, (char **)NULL, (int *)NULL); + if (ABORT_SIGS()) return (NULL_POSITION); + if (cpos == NULL_POSITION) + return (NULL_POSITION); } } else { @@ -414,8 +431,10 @@ /* * Allow a signal to abort this loop. */ - cpos = back_raw_line(cpos, (char **)NULL); - if (ABORT_SIGS() || cpos == NULL_POSITION) + cpos = back_raw_line(cpos, (char **)NULL, (int *)NULL); + if (ABORT_SIGS()) + return (NULL_POSITION); + if (cpos == NULL_POSITION) return (NULL_POSITION); } }