linenum.c (009e81b16465ea457c0e63fd49fe77f47cc27a5a) | linenum.c (1ea316270f1f75922ac53976d5d8808a41442f46) |
---|---|
1/* 2 * Copyright (C) 1984-2015 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, see the README file. 8 */ --- 59 unchanged lines hidden (view full) --- 68extern int sigs; 69extern int sc_height; 70extern int screen_trashed; 71 72/* 73 * Initialize the line number structures. 74 */ 75 public void | 1/* 2 * Copyright (C) 1984-2015 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, see the README file. 8 */ --- 59 unchanged lines hidden (view full) --- 68extern int sigs; 69extern int sc_height; 70extern int screen_trashed; 71 72/* 73 * Initialize the line number structures. 74 */ 75 public void |
76clr_linenum() | 76clr_linenum(void) |
77{ | 77{ |
78 register struct linenum_info *p; | 78 struct linenum_info *p; |
79 80 /* 81 * Put all the entries on the free list. 82 * Leave one for the "spare". 83 */ 84 for (p = pool; p < &pool[NPOOL-2]; p++) 85 p->next = p+1; 86 pool[NPOOL-2].next = NULL; --- 9 unchanged lines hidden (view full) --- 96 anchor.pos = (POSITION)0; 97 anchor.line = 1; 98} 99 100/* 101 * Calculate the gap for an entry. 102 */ 103 static void | 79 80 /* 81 * Put all the entries on the free list. 82 * Leave one for the "spare". 83 */ 84 for (p = pool; p < &pool[NPOOL-2]; p++) 85 p->next = p+1; 86 pool[NPOOL-2].next = NULL; --- 9 unchanged lines hidden (view full) --- 96 anchor.pos = (POSITION)0; 97 anchor.line = 1; 98} 99 100/* 101 * Calculate the gap for an entry. 102 */ 103 static void |
104calcgap(p) 105 register struct linenum_info *p; | 104calcgap(struct linenum_info *p) |
106{ 107 /* 108 * Don't bother to compute a gap for the anchor. 109 * Also don't compute a gap for the last one in the list. 110 * The gap for that last one should be considered infinite, 111 * but we never look at it anyway. 112 */ 113 if (p == &anchor || p->next == &anchor) 114 return; 115 p->gap = p->next->pos - p->prev->pos; 116} 117 118/* 119 * Add a new line number to the cache. 120 * The specified position (pos) should be the file position of the 121 * FIRST character in the specified line. 122 */ 123 public void | 105{ 106 /* 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, 110 * but we never look at it anyway. 111 */ 112 if (p == &anchor || p->next == &anchor) 113 return; 114 p->gap = p->next->pos - p->prev->pos; 115} 116 117/* 118 * Add a new line number to the cache. 119 * The specified position (pos) should be the file position of the 120 * FIRST character in the specified line. 121 */ 122 public void |
124add_lnum(linenum, pos) 125 LINENUM linenum; 126 POSITION pos; | 123add_lnum(LINENUM linenum, POSITION pos) |
127{ | 124{ |
128 register struct linenum_info *p; 129 register struct linenum_info *new; 130 register struct linenum_info *nextp; 131 register struct linenum_info *prevp; 132 register POSITION mingap; | 125 struct linenum_info *p; 126 struct linenum_info *new; 127 struct linenum_info *nextp; 128 struct linenum_info *prevp; 129 POSITION mingap; |
133 134 /* 135 * Find the proper place in the list for the new one. 136 * The entries are sorted by position. 137 */ 138 for (p = anchor.next; p != &anchor && p->pos < pos; p = p->next) 139 if (p->line == linenum) 140 /* We already have this one. */ --- 63 unchanged lines hidden (view full) --- 204 } 205} 206 207/* 208 * If we get stuck in a long loop trying to figure out the 209 * line number, print a message to tell the user what we're doing. 210 */ 211 static void | 130 131 /* 132 * Find the proper place in the list for the new one. 133 * The entries are sorted by position. 134 */ 135 for (p = anchor.next; p != &anchor && p->pos < pos; p = p->next) 136 if (p->line == linenum) 137 /* We already have this one. */ --- 63 unchanged lines hidden (view full) --- 201 } 202} 203 204/* 205 * If we get stuck in a long loop trying to figure out the 206 * line number, print a message to tell the user what we're doing. 207 */ 208 static void |
212longloopmessage() | 209longloopmessage(void) |
213{ 214 ierror("Calculating line numbers", NULL_PARG); 215} 216 217static int loopcount; 218#if HAVE_TIME 219static time_type startime; 220#endif 221 222 static void | 210{ 211 ierror("Calculating line numbers", NULL_PARG); 212} 213 214static int loopcount; 215#if HAVE_TIME 216static time_type startime; 217#endif 218 219 static void |
223longish() | 220longish(void) |
224{ 225#if HAVE_TIME 226 if (loopcount >= 0 && ++loopcount > 100) 227 { 228 loopcount = 0; 229 if (get_time() >= startime + LONGTIME) 230 { 231 longloopmessage(); --- 9 unchanged lines hidden (view full) --- 241#endif 242} 243 244/* 245 * Turn off line numbers because the user has interrupted 246 * a lengthy line number calculation. 247 */ 248 static void | 221{ 222#if HAVE_TIME 223 if (loopcount >= 0 && ++loopcount > 100) 224 { 225 loopcount = 0; 226 if (get_time() >= startime + LONGTIME) 227 { 228 longloopmessage(); --- 9 unchanged lines hidden (view full) --- 238#endif 239} 240 241/* 242 * Turn off line numbers because the user has interrupted 243 * a lengthy line number calculation. 244 */ 245 static void |
249abort_long() | 246abort_long(void) |
250{ 251 if (linenums == OPT_ONPLUS) 252 /* 253 * We were displaying line numbers, so need to repaint. 254 */ 255 screen_trashed = 1; 256 linenums = 0; 257 error("Line numbers turned off", NULL_PARG); 258} 259 260/* 261 * Find the line number associated with a given position. 262 * Return 0 if we can't figure it out. 263 */ 264 public LINENUM | 247{ 248 if (linenums == OPT_ONPLUS) 249 /* 250 * We were displaying line numbers, so need to repaint. 251 */ 252 screen_trashed = 1; 253 linenums = 0; 254 error("Line numbers turned off", NULL_PARG); 255} 256 257/* 258 * Find the line number associated with a given position. 259 * Return 0 if we can't figure it out. 260 */ 261 public LINENUM |
265find_linenum(pos) 266 POSITION pos; | 262find_linenum(POSITION pos) |
267{ | 263{ |
268 register struct linenum_info *p; 269 register LINENUM linenum; | 264 struct linenum_info *p; 265 LINENUM linenum; |
270 POSITION cpos; 271 272 if (!linenums) 273 /* 274 * We're not using line numbers. 275 */ 276 return (0); 277 if (pos == NULL_POSITION) --- 94 unchanged lines hidden (view full) --- 372 return (linenum); 373} 374 375/* 376 * Find the position of a given line number. 377 * Return NULL_POSITION if we can't figure it out. 378 */ 379 public POSITION | 266 POSITION cpos; 267 268 if (!linenums) 269 /* 270 * We're not using line numbers. 271 */ 272 return (0); 273 if (pos == NULL_POSITION) --- 94 unchanged lines hidden (view full) --- 368 return (linenum); 369} 370 371/* 372 * Find the position of a given line number. 373 * Return NULL_POSITION if we can't figure it out. 374 */ 375 public POSITION |
380find_pos(linenum) 381 LINENUM linenum; | 376find_pos(LINENUM linenum) |
382{ | 377{ |
383 register struct linenum_info *p; | 378 struct linenum_info *p; |
384 POSITION cpos; 385 LINENUM clinenum; 386 387 if (linenum <= 1) 388 /* 389 * Line number 1 is beginning of file. 390 */ 391 return (ch_zero()); --- 53 unchanged lines hidden (view full) --- 445} 446 447/* 448 * Return the line number of the "current" line. 449 * The argument "where" tells which line is to be considered 450 * the "current" line (e.g. TOP, BOTTOM, MIDDLE, etc). 451 */ 452 public LINENUM | 379 POSITION cpos; 380 LINENUM clinenum; 381 382 if (linenum <= 1) 383 /* 384 * Line number 1 is beginning of file. 385 */ 386 return (ch_zero()); --- 53 unchanged lines hidden (view full) --- 440} 441 442/* 443 * Return the line number of the "current" line. 444 * The argument "where" tells which line is to be considered 445 * the "current" line (e.g. TOP, BOTTOM, MIDDLE, etc). 446 */ 447 public LINENUM |
453currline(where) 454 int where; | 448currline(int where) |
455{ 456 POSITION pos; 457 POSITION len; 458 LINENUM linenum; 459 460 pos = position(where); 461 len = ch_length(); 462 while (pos == NULL_POSITION && where >= 0 && where < sc_height) 463 pos = position(++where); 464 if (pos == NULL_POSITION) 465 pos = len; 466 linenum = find_linenum(pos); 467 if (pos == len) 468 linenum--; 469 return (linenum); 470} | 449{ 450 POSITION pos; 451 POSITION len; 452 LINENUM linenum; 453 454 pos = position(where); 455 len = ch_length(); 456 while (pos == NULL_POSITION && where >= 0 && where < sc_height) 457 pos = position(++where); 458 if (pos == NULL_POSITION) 459 pos = len; 460 linenum = find_linenum(pos); 461 if (pos == len) 462 linenum--; 463 return (linenum); 464} |