linenum.c (170257) | linenum.c (191930) |
---|---|
1/* | 1/* |
2 * Copyright (C) 1984-2007 Mark Nudelman | 2 * Copyright (C) 1984-2008 Mark Nudelman |
3 * 4 * You may distribute under the terms of either the GNU General Public 5 * License or the Less License, as specified in the README file. 6 * 7 * For more information about less, or for information on how to 8 * contact the author, see the README file. 9 */ 10 --- 40 unchanged lines hidden (view full) --- 51 * "gap" needs some explanation: the gap of any particular line number 52 * is the distance between the previous one and the next one in the list. 53 * ("Distance" means difference in file position.) In other words, the 54 * gap of a line number is the gap which would be introduced if this 55 * line number were deleted. It is used to decide which one to replace 56 * when we have a new one to insert and the table is full. 57 */ 58 | 3 * 4 * You may distribute under the terms of either the GNU General Public 5 * License or the Less License, as specified in the README file. 6 * 7 * For more information about less, or for information on how to 8 * contact the author, see the README file. 9 */ 10 --- 40 unchanged lines hidden (view full) --- 51 * "gap" needs some explanation: the gap of any particular line number 52 * is the distance between the previous one and the next one in the list. 53 * ("Distance" means difference in file position.) In other words, the 54 * gap of a line number is the gap which would be introduced if this 55 * line number were deleted. It is used to decide which one to replace 56 * when we have a new one to insert and the table is full. 57 */ 58 |
59#define NPOOL 50 /* Size of line number pool */ | 59#define NPOOL 200 /* Size of line number pool */ |
60 61#define LONGTIME (2) /* In seconds */ 62 | 60 61#define LONGTIME (2) /* In seconds */ 62 |
63public int lnloop = 0; /* Are we in the line num loop? */ 64 | |
65static struct linenum_info anchor; /* Anchor of the list */ 66static struct linenum_info *freelist; /* Anchor of the unused entries */ 67static struct linenum_info pool[NPOOL]; /* The pool itself */ 68static struct linenum_info *spare; /* We always keep one spare entry */ 69 70extern int linenums; 71extern int sigs; 72extern int sc_height; | 63static struct linenum_info anchor; /* Anchor of the list */ 64static struct linenum_info *freelist; /* Anchor of the unused entries */ 65static struct linenum_info pool[NPOOL]; /* The pool itself */ 66static struct linenum_info *spare; /* We always keep one spare entry */ 67 68extern int linenums; 69extern int sigs; 70extern int sc_height; |
71extern int screen_trashed; |
|
73 74/* 75 * Initialize the line number structures. 76 */ 77 public void 78clr_linenum() 79{ 80 register struct linenum_info *p; --- 128 unchanged lines hidden (view full) --- 209/* 210 * If we get stuck in a long loop trying to figure out the 211 * line number, print a message to tell the user what we're doing. 212 */ 213 static void 214longloopmessage() 215{ 216 ierror("Calculating line numbers", NULL_PARG); | 72 73/* 74 * Initialize the line number structures. 75 */ 76 public void 77clr_linenum() 78{ 79 register struct linenum_info *p; --- 128 unchanged lines hidden (view full) --- 208/* 209 * If we get stuck in a long loop trying to figure out the 210 * line number, print a message to tell the user what we're doing. 211 */ 212 static void 213longloopmessage() 214{ 215 ierror("Calculating line numbers", NULL_PARG); |
217 /* 218 * Set the lnloop flag here, so if the user interrupts while 219 * we are calculating line numbers, the signal handler will 220 * turn off line numbers (linenums=0). 221 */ 222 lnloop = 1; | |
223} 224 225static int loopcount; 226#if HAVE_TIME 227static long startime; 228#endif 229 230 static void --- 14 unchanged lines hidden (view full) --- 245 { 246 longloopmessage(); 247 loopcount = -1; 248 } 249#endif 250} 251 252/* | 216} 217 218static int loopcount; 219#if HAVE_TIME 220static long startime; 221#endif 222 223 static void --- 14 unchanged lines hidden (view full) --- 238 { 239 longloopmessage(); 240 loopcount = -1; 241 } 242#endif 243} 244 245/* |
246 * Turn off line numbers because the user has interrupted 247 * a lengthy line number calculation. 248 */ 249 static void 250abort_long() 251{ 252 if (linenums == OPT_ONPLUS) 253 /* 254 * We were displaying line numbers, so need to repaint. 255 */ 256 screen_trashed = 1; 257 linenums = 0; 258 error("Line numbers turned off", NULL_PARG); 259} 260 261/* |
|
253 * Find the line number associated with a given position. 254 * Return 0 if we can't figure it out. 255 */ 256 public LINENUM 257find_linenum(pos) 258 POSITION pos; 259{ 260 register struct linenum_info *p; --- 49 unchanged lines hidden (view full) --- 310 return (0); 311 loopcount = 0; 312 for (linenum = p->line, cpos = p->pos; cpos < pos; linenum++) 313 { 314 /* 315 * Allow a signal to abort this loop. 316 */ 317 cpos = forw_raw_line(cpos, (char **)NULL, (int *)NULL); | 262 * Find the line number associated with a given position. 263 * Return 0 if we can't figure it out. 264 */ 265 public LINENUM 266find_linenum(pos) 267 POSITION pos; 268{ 269 register struct linenum_info *p; --- 49 unchanged lines hidden (view full) --- 319 return (0); 320 loopcount = 0; 321 for (linenum = p->line, cpos = p->pos; cpos < pos; linenum++) 322 { 323 /* 324 * Allow a signal to abort this loop. 325 */ 326 cpos = forw_raw_line(cpos, (char **)NULL, (int *)NULL); |
318 if (ABORT_SIGS() || cpos == NULL_POSITION) | 327 if (ABORT_SIGS()) { 328 abort_long(); |
319 return (0); | 329 return (0); |
330 } 331 if (cpos == NULL_POSITION) 332 return (0); |
|
320 longish(); 321 } | 333 longish(); 334 } |
322 lnloop = 0; | |
323 /* 324 * We might as well cache it. 325 */ 326 add_lnum(linenum, cpos); 327 /* 328 * If the given position is not at the start of a line, 329 * make sure we return the correct line number. 330 */ --- 8 unchanged lines hidden (view full) --- 339 return (0); 340 loopcount = 0; 341 for (linenum = p->line, cpos = p->pos; cpos > pos; linenum--) 342 { 343 /* 344 * Allow a signal to abort this loop. 345 */ 346 cpos = back_raw_line(cpos, (char **)NULL, (int *)NULL); | 335 /* 336 * We might as well cache it. 337 */ 338 add_lnum(linenum, cpos); 339 /* 340 * If the given position is not at the start of a line, 341 * make sure we return the correct line number. 342 */ --- 8 unchanged lines hidden (view full) --- 351 return (0); 352 loopcount = 0; 353 for (linenum = p->line, cpos = p->pos; cpos > pos; linenum--) 354 { 355 /* 356 * Allow a signal to abort this loop. 357 */ 358 cpos = back_raw_line(cpos, (char **)NULL, (int *)NULL); |
347 if (ABORT_SIGS() || cpos == NULL_POSITION) | 359 if (ABORT_SIGS()) { 360 abort_long(); |
348 return (0); | 361 return (0); |
362 } 363 if (cpos == NULL_POSITION) 364 return (0); |
|
349 longish(); 350 } | 365 longish(); 366 } |
351 lnloop = 0; | |
352 /* 353 * We might as well cache it. 354 */ 355 add_lnum(linenum, cpos); 356 } 357 358 return (linenum); 359} --- 34 unchanged lines hidden (view full) --- 394 if (ch_seek(p->pos)) 395 return (NULL_POSITION); 396 for (clinenum = p->line, cpos = p->pos; clinenum < linenum; clinenum++) 397 { 398 /* 399 * Allow a signal to abort this loop. 400 */ 401 cpos = forw_raw_line(cpos, (char **)NULL, (int *)NULL); | 367 /* 368 * We might as well cache it. 369 */ 370 add_lnum(linenum, cpos); 371 } 372 373 return (linenum); 374} --- 34 unchanged lines hidden (view full) --- 409 if (ch_seek(p->pos)) 410 return (NULL_POSITION); 411 for (clinenum = p->line, cpos = p->pos; clinenum < linenum; clinenum++) 412 { 413 /* 414 * Allow a signal to abort this loop. 415 */ 416 cpos = forw_raw_line(cpos, (char **)NULL, (int *)NULL); |
402 if (ABORT_SIGS() || cpos == NULL_POSITION) | 417 if (ABORT_SIGS()) |
403 return (NULL_POSITION); | 418 return (NULL_POSITION); |
419 if (cpos == NULL_POSITION) 420 return (NULL_POSITION); |
|
404 } 405 } else 406 { 407 /* 408 * Go backward. 409 */ 410 if (ch_seek(p->pos)) 411 return (NULL_POSITION); 412 for (clinenum = p->line, cpos = p->pos; clinenum > linenum; clinenum--) 413 { 414 /* 415 * Allow a signal to abort this loop. 416 */ 417 cpos = back_raw_line(cpos, (char **)NULL, (int *)NULL); | 421 } 422 } else 423 { 424 /* 425 * Go backward. 426 */ 427 if (ch_seek(p->pos)) 428 return (NULL_POSITION); 429 for (clinenum = p->line, cpos = p->pos; clinenum > linenum; clinenum--) 430 { 431 /* 432 * Allow a signal to abort this loop. 433 */ 434 cpos = back_raw_line(cpos, (char **)NULL, (int *)NULL); |
418 if (ABORT_SIGS() || cpos == NULL_POSITION) | 435 if (ABORT_SIGS()) |
419 return (NULL_POSITION); | 436 return (NULL_POSITION); |
437 if (cpos == NULL_POSITION) 438 return (NULL_POSITION); |
|
420 } 421 } 422 /* 423 * We might as well cache it. 424 */ 425 add_lnum(clinenum, cpos); 426 return (cpos); 427} --- 25 unchanged lines hidden --- | 439 } 440 } 441 /* 442 * We might as well cache it. 443 */ 444 add_lnum(clinenum, cpos); 445 return (cpos); 446} --- 25 unchanged lines hidden --- |