input.c (7f074f9c8f37a841d4ed3a3947143d83c9972f81) | input.c (7374caaaed222af059fc66cb7fade7074ab391f4) |
---|---|
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 --- 37 unchanged lines hidden (view full) --- 48{ 49 POSITION base_pos; 50 POSITION new_pos; 51 register int c; 52 int blankline; 53 int endline; 54 int backchars; 55 | 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 --- 37 unchanged lines hidden (view full) --- 48{ 49 POSITION base_pos; 50 POSITION new_pos; 51 register int c; 52 int blankline; 53 int endline; 54 int backchars; 55 |
56get_forw_line: |
|
56 if (curr_pos == NULL_POSITION) 57 { 58 null_line(); 59 return (NULL_POSITION); 60 } 61#if HILITE_SEARCH | 57 if (curr_pos == NULL_POSITION) 58 { 59 null_line(); 60 return (NULL_POSITION); 61 } 62#if HILITE_SEARCH |
62 if (hilite_search == OPT_ONPLUS || status_col) | 63 if (hilite_search == OPT_ONPLUS || is_filtering() || status_col) |
63 /* 64 * If we are ignoring EOI (command F), only prepare 65 * one line ahead, to avoid getting stuck waiting for 66 * slow data without displaying the data we already have. 67 * If we're not ignoring EOI, we *could* do the same, but 68 * for efficiency we prepare several lines ahead at once. 69 */ 70 prep_hilite(curr_pos, curr_pos + 3*size_linebuf, 71 ignore_eoi ? 1 : -1); 72#endif 73 if (ch_seek(curr_pos)) 74 { 75 null_line(); 76 return (NULL_POSITION); 77 } 78 | 64 /* 65 * If we are ignoring EOI (command F), only prepare 66 * one line ahead, to avoid getting stuck waiting for 67 * slow data without displaying the data we already have. 68 * If we're not ignoring EOI, we *could* do the same, but 69 * for efficiency we prepare several lines ahead at once. 70 */ 71 prep_hilite(curr_pos, curr_pos + 3*size_linebuf, 72 ignore_eoi ? 1 : -1); 73#endif 74 if (ch_seek(curr_pos)) 75 { 76 null_line(); 77 return (NULL_POSITION); 78 } 79 |
80 /* 81 * Step back to the beginning of the line. 82 */ |
|
79 base_pos = curr_pos; 80 for (;;) 81 { 82 if (ABORT_SIGS()) 83 { 84 null_line(); 85 return (NULL_POSITION); 86 } 87 c = ch_back_get(); 88 if (c == EOI) 89 break; 90 if (c == '\n') 91 { 92 (void) ch_forw_get(); 93 break; 94 } 95 --base_pos; 96 } 97 | 83 base_pos = curr_pos; 84 for (;;) 85 { 86 if (ABORT_SIGS()) 87 { 88 null_line(); 89 return (NULL_POSITION); 90 } 91 c = ch_back_get(); 92 if (c == EOI) 93 break; 94 if (c == '\n') 95 { 96 (void) ch_forw_get(); 97 break; 98 } 99 --base_pos; 100 } 101 |
102 /* 103 * Read forward again to the position we should start at. 104 */ |
|
98 prewind(); 99 plinenum(base_pos); 100 (void) ch_seek(base_pos); | 105 prewind(); 106 plinenum(base_pos); 107 (void) ch_seek(base_pos); |
101 while (base_pos < curr_pos) | 108 new_pos = base_pos; 109 while (new_pos < curr_pos) |
102 { 103 if (ABORT_SIGS()) 104 { 105 null_line(); 106 return (NULL_POSITION); 107 } 108 c = ch_forw_get(); | 110 { 111 if (ABORT_SIGS()) 112 { 113 null_line(); 114 return (NULL_POSITION); 115 } 116 c = ch_forw_get(); |
109 backchars = pappend(c, base_pos); 110 base_pos++; | 117 backchars = pappend(c, new_pos); 118 new_pos++; |
111 if (backchars > 0) 112 { 113 pshift_all(); | 119 if (backchars > 0) 120 { 121 pshift_all(); |
114 base_pos -= backchars; | 122 new_pos -= backchars; |
115 while (--backchars >= 0) 116 (void) ch_back_get(); 117 } 118 } 119 (void) pflushmbc(); 120 pshift_all(); 121 | 123 while (--backchars >= 0) 124 (void) ch_back_get(); 125 } 126 } 127 (void) pflushmbc(); 128 pshift_all(); 129 |
130 /* 131 * Read the first character to display. 132 */ |
|
122 c = ch_forw_get(); 123 if (c == EOI) 124 { 125 null_line(); 126 return (NULL_POSITION); 127 } 128 blankline = (c == '\n' || c == '\r'); 129 | 133 c = ch_forw_get(); 134 if (c == EOI) 135 { 136 null_line(); 137 return (NULL_POSITION); 138 } 139 blankline = (c == '\n' || c == '\r'); 140 |
141 /* 142 * Read each character in the line and append to the line buffer. 143 */ |
|
130 for (;;) 131 { 132 if (ABORT_SIGS()) 133 { 134 null_line(); 135 return (NULL_POSITION); 136 } 137 if (c == '\n' || c == EOI) --- 38 unchanged lines hidden (view full) --- 176 { 177 new_pos = ch_tell() - backchars; 178 endline = FALSE; 179 } 180 break; 181 } 182 c = ch_forw_get(); 183 } | 144 for (;;) 145 { 146 if (ABORT_SIGS()) 147 { 148 null_line(); 149 return (NULL_POSITION); 150 } 151 if (c == '\n' || c == EOI) --- 38 unchanged lines hidden (view full) --- 190 { 191 new_pos = ch_tell() - backchars; 192 endline = FALSE; 193 } 194 break; 195 } 196 c = ch_forw_get(); 197 } |
184 pdone(endline); | |
185 | 198 |
199 pdone(endline, c); 200 201#if HILITE_SEARCH 202 if (is_filtered(base_pos)) 203 { 204 /* 205 * We don't want to display this line. 206 * Get the next line. 207 */ 208 curr_pos = new_pos; 209 goto get_forw_line; 210 } 211 212 if (status_col && is_hilited(base_pos, ch_tell()-1, 1, NULL)) 213 set_status_col('*'); 214#endif 215 |
|
186 if (squeeze && blankline) 187 { 188 /* 189 * This line is blank. 190 * Skip down to the last contiguous blank line 191 * and pretend it is the one which we are returning. 192 */ 193 while ((c = ch_forw_get()) == '\n' || c == '\r') --- 16 unchanged lines hidden (view full) --- 210 * The current position is the position of the first character of 211 * a line. The new position is the position of the first character 212 * of the PREVIOUS line. The line obtained is the one starting at new_pos. 213 */ 214 public POSITION 215back_line(curr_pos) 216 POSITION curr_pos; 217{ | 216 if (squeeze && blankline) 217 { 218 /* 219 * This line is blank. 220 * Skip down to the last contiguous blank line 221 * and pretend it is the one which we are returning. 222 */ 223 while ((c = ch_forw_get()) == '\n' || c == '\r') --- 16 unchanged lines hidden (view full) --- 240 * The current position is the position of the first character of 241 * a line. The new position is the position of the first character 242 * of the PREVIOUS line. The line obtained is the one starting at new_pos. 243 */ 244 public POSITION 245back_line(curr_pos) 246 POSITION curr_pos; 247{ |
218 POSITION new_pos, begin_new_pos; | 248 POSITION new_pos, begin_new_pos, base_pos; |
219 int c; 220 int endline; 221 int backchars; 222 | 249 int c; 250 int endline; 251 int backchars; 252 |
253get_back_line: |
|
223 if (curr_pos == NULL_POSITION || curr_pos <= ch_zero()) 224 { 225 null_line(); 226 return (NULL_POSITION); 227 } 228#if HILITE_SEARCH | 254 if (curr_pos == NULL_POSITION || curr_pos <= ch_zero()) 255 { 256 null_line(); 257 return (NULL_POSITION); 258 } 259#if HILITE_SEARCH |
229 if (hilite_search == OPT_ONPLUS || status_col) | 260 if (hilite_search == OPT_ONPLUS || is_filtering() || status_col) |
230 prep_hilite((curr_pos < 3*size_linebuf) ? 231 0 : curr_pos - 3*size_linebuf, curr_pos, -1); 232#endif 233 if (ch_seek(curr_pos-1)) 234 { 235 null_line(); 236 return (NULL_POSITION); 237 } 238 239 if (squeeze) 240 { 241 /* 242 * Find out if the "current" line was blank. 243 */ | 261 prep_hilite((curr_pos < 3*size_linebuf) ? 262 0 : curr_pos - 3*size_linebuf, curr_pos, -1); 263#endif 264 if (ch_seek(curr_pos-1)) 265 { 266 null_line(); 267 return (NULL_POSITION); 268 } 269 270 if (squeeze) 271 { 272 /* 273 * Find out if the "current" line was blank. 274 */ |
244 (void) ch_forw_get(); /* Skip the newline */ 245 c = ch_forw_get(); /* First char of "current" line */ 246 (void) ch_back_get(); /* Restore our position */ | 275 (void) ch_forw_get(); /* Skip the newline */ 276 c = ch_forw_get(); /* First char of "current" line */ 277 (void) ch_back_get(); /* Restore our position */ |
247 (void) ch_back_get(); 248 249 if (c == '\n' || c == '\r') 250 { 251 /* 252 * The "current" line was blank. 253 * Skip over any preceding blank lines, 254 * since we skipped them in forw_line(). --- 25 unchanged lines hidden (view full) --- 280 } 281 c = ch_back_get(); 282 if (c == '\n') 283 { 284 /* 285 * This is the newline ending the previous line. 286 * We have hit the beginning of the line. 287 */ | 278 (void) ch_back_get(); 279 280 if (c == '\n' || c == '\r') 281 { 282 /* 283 * The "current" line was blank. 284 * Skip over any preceding blank lines, 285 * since we skipped them in forw_line(). --- 25 unchanged lines hidden (view full) --- 311 } 312 c = ch_back_get(); 313 if (c == '\n') 314 { 315 /* 316 * This is the newline ending the previous line. 317 * We have hit the beginning of the line. 318 */ |
288 new_pos = ch_tell() + 1; | 319 base_pos = ch_tell() + 1; |
289 break; 290 } 291 if (c == EOI) 292 { 293 /* 294 * We have hit the beginning of the file. 295 * This must be the first line in the file. 296 * This must, of course, be the beginning of the line. 297 */ | 320 break; 321 } 322 if (c == EOI) 323 { 324 /* 325 * We have hit the beginning of the file. 326 * This must be the first line in the file. 327 * This must, of course, be the beginning of the line. 328 */ |
298 new_pos = ch_tell(); | 329 base_pos = ch_tell(); |
299 break; 300 } 301 } 302 303 /* 304 * Now scan forwards from the beginning of this line. 305 * We keep discarding "printable lines" (based on screen width) 306 * until we reach the curr_pos. 307 * 308 * {{ This algorithm is pretty inefficient if the lines 309 * are much longer than the screen width, 310 * but I don't know of any better way. }} 311 */ | 330 break; 331 } 332 } 333 334 /* 335 * Now scan forwards from the beginning of this line. 336 * We keep discarding "printable lines" (based on screen width) 337 * until we reach the curr_pos. 338 * 339 * {{ This algorithm is pretty inefficient if the lines 340 * are much longer than the screen width, 341 * but I don't know of any better way. }} 342 */ |
343 new_pos = base_pos; |
|
312 if (ch_seek(new_pos)) 313 { 314 null_line(); 315 return (NULL_POSITION); 316 } 317 endline = FALSE; 318 prewind(); 319 plinenum(new_pos); --- 41 unchanged lines hidden (view full) --- 361 { 362 (void) ch_back_get(); 363 new_pos--; 364 } 365 goto loop; 366 } 367 } while (new_pos < curr_pos); 368 | 344 if (ch_seek(new_pos)) 345 { 346 null_line(); 347 return (NULL_POSITION); 348 } 349 endline = FALSE; 350 prewind(); 351 plinenum(new_pos); --- 41 unchanged lines hidden (view full) --- 393 { 394 (void) ch_back_get(); 395 new_pos--; 396 } 397 goto loop; 398 } 399 } while (new_pos < curr_pos); 400 |
369 pdone(endline); | 401 pdone(endline, ch_forw_get()); |
370 | 402 |
403#if HILITE_SEARCH 404 if (is_filtered(base_pos)) 405 { 406 /* 407 * We don't want to display this line. 408 * Get the previous line. 409 */ 410 curr_pos = begin_new_pos; 411 goto get_back_line; 412 } 413 414 if (status_col && is_hilited(base_pos, ch_tell()-1, 1, NULL)) 415 set_status_col('*'); 416#endif 417 |
|
371 return (begin_new_pos); 372} 373 374/* 375 * Set attnpos. 376 */ 377 public void 378set_attnpos(pos) --- 28 unchanged lines hidden --- | 418 return (begin_new_pos); 419} 420 421/* 422 * Set attnpos. 423 */ 424 public void 425set_attnpos(pos) --- 28 unchanged lines hidden --- |