summaryrefslogtreecommitdiff
path: root/usr.bin/less/linenum.c
diff options
context:
space:
mode:
authorAlexandr Shadchin <shadchin@cvs.openbsd.org>2011-09-16 18:12:10 +0000
committerAlexandr Shadchin <shadchin@cvs.openbsd.org>2011-09-16 18:12:10 +0000
commit00ca0ae1e02785b8e3a17a927d3bd3a7d1d4930f (patch)
treeeef6a7bbb153bb50173090055013f1f648d63801 /usr.bin/less/linenum.c
parent04892254e3fb39e77520f4d6a8d29ae06772a2bb (diff)
Merge in less 444 plus local changes
ok nicm@
Diffstat (limited to 'usr.bin/less/linenum.c')
-rw-r--r--usr.bin/less/linenum.c59
1 files changed, 39 insertions, 20 deletions
diff --git a/usr.bin/less/linenum.c b/usr.bin/less/linenum.c
index 24026fa327b..4369f87b266 100644
--- a/usr.bin/less/linenum.c
+++ b/usr.bin/less/linenum.c
@@ -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 @@ 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.
*/
@@ -314,12 +323,15 @@ find_linenum(pos)
/*
* 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 @@ find_linenum(pos)
/*
* 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,8 +413,10 @@ find_pos(linenum)
/*
* 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 @@ find_pos(linenum)
/*
* 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);
}
}