Lines Matching +full:one +full:- +full:to +full:- +full:one
2 * Copyright (C) 1984-2024 Mark Nudelman
12 * Code to handle displaying line numbers.
15 * We don't want to just start at the beginning of the file and
17 * wouldn't work if we couldn't get to the start of the file; e.g.
20 * So we use the function add_lnum to cache line numbers.
21 * We try to be very clever and keep only the more interesting
27 * 200 is more expensive to derive from 100.
31 * to cache the line number. Therefore currline is occasionally
32 * called to make sure we cache line numbers often enough.
38 * Structure to keep track of a line number and the associated file position.
39 * A doubly-linked circular list of line numbers is kept ordered by line number.
43 struct linenum_info *next; /* Link to next in the list */
44 struct linenum_info *prev; /* Line to previous in the list */
51 * is the distance between the previous one and the next one in the list.
54 * line number were deleted. It is used to decide which one to replace
55 * when we have a new one to insert and the table is full.
65 static struct linenum_info *spare; /* We always keep one spare entry */
83 * Leave one for the "spare".
85 for (p = pool; p < &pool[NPOOL-2]; p++)
86 p->next = p+1;
87 pool[NPOOL-2].next = NULL;
90 spare = &pool[NPOOL-1];
107 * Don't bother to compute a gap for the anchor.
108 * Also don't compute a gap for the last one in the list.
109 * The gap for that last one should be considered infinite,
112 if (p == &anchor || p->next == &anchor)
114 p->gap = p->next->pos - p->prev->pos;
118 * Add a new line number to the cache.
131 * Find the proper place in the list for the new one.
134 for (p = anchor.next; p != &anchor && p->pos < pos; p = p->next)
135 if (p->line == linenum)
136 /* We already have this one. */
139 prevp = p->prev;
145 * Use one of them.
148 freelist = freelist->next;
163 new->next = nextp;
164 new->prev = prevp;
165 new->pos = pos;
166 new->line = linenum;
168 nextp->prev = new;
169 prevp->next = new;
182 * Scan the list to find the one with the smallest
184 * We should never remove the last one, so stop when
185 * we get to p->next == &anchor. This also avoids
186 * looking at the gap of the last one, which is
189 mingap = anchor.next->gap;
190 for (p = anchor.next; p->next != &anchor; p = p->next)
192 if (p->gap <= mingap)
195 mingap = p->gap;
198 spare->next->prev = spare->prev;
199 spare->prev->next = spare->next;
204 * If we get stuck in a long loop trying to figure out the
205 * line number, print a message to tell the user what we're doing.
223 dmsg->loopcount = 0;
224 dmsg->message = message;
226 dmsg->startime = get_time();
233 if (dmsg->loopcount >= 0 && ++(dmsg->loopcount) > 100)
235 dmsg->loopcount = 0;
236 if (get_time() >= dmsg->startime + LONGTIME)
238 dmsg->message();
239 dmsg->loopcount = -1;
243 if (dmsg->loopcount >= 0 && ++(dmsg->loopcount) > LONGLOOP)
245 dmsg->message();
246 dmsg->loopcount = -1;
257 if (dmsg->loopcount >= 0)
261 * We were displaying line numbers, so need to repaint.
296 * Find the entry nearest to the position we want.
298 for (p = anchor.next; p != &anchor && p->pos < pos; p = p->next)
300 if (p->pos == pos)
302 return (p->line);
305 * This is the (possibly) time-consuming part.
308 * get to the place we want.
311 * previous one or backwards from the next one.
316 if (p == &anchor || pos - p->prev->pos < p->pos - pos)
321 p = p->prev;
322 if (ch_seek(p->pos))
324 for (linenum = p->line, cpos = p->pos; cpos < pos; linenum++)
327 * Allow a signal to abort this loop.
347 linenum--;
353 if (ch_seek(p->pos))
355 for (linenum = p->line, cpos = p->pos; cpos > pos; linenum--)
358 * Allow a signal to abort this loop.
394 * Find the entry nearest to the line number we want.
396 for (p = anchor.next; p != &anchor && p->line < linenum; p = p->next)
398 if (p->line == linenum)
400 return (p->pos);
402 if (p == &anchor || linenum - p->prev->line < p->line - linenum)
407 p = p->prev;
408 if (ch_seek(p->pos))
410 for (clinenum = p->line, cpos = p->pos; clinenum < linenum; clinenum++)
413 * Allow a signal to abort this loop.
426 if (ch_seek(p->pos))
428 for (clinenum = p->line, cpos = p->pos; clinenum > linenum; clinenum--)
431 * Allow a signal to abort this loop.
449 * The argument "where" tells which line is to be considered
466 linenum--;
494 /* For efficiency, only add one every 256 line numbers. */
510 * (handles the --no-number-headers option).
515 linenum = (linenum < header_lines) ? 0 : linenum - header_lines;