| 510 | Return NULL if there is no more input. */ |
| 511 | |
| 512 | static struct cstring * |
| 513 | remove_line (void) |
| 514 | { |
| 515 | /* If non-null, this is the buffer for which the previous call |
| 516 | returned the final line. So now, presuming that line has been |
| 517 | processed, we can free the buffer and reset this pointer. */ |
| 518 | static struct buffer_record *prev_buf = NULL; |
| 519 | |
| 520 | struct cstring *line; /* Return value. */ |
| 521 | struct line *l; /* For convenience. */ |
| 522 | |
| 523 | if (prev_buf) |
| 524 | { |
| 525 | free_buffer (prev_buf); |
| 526 | prev_buf = NULL; |
| 527 | } |
| 528 | |
| 529 | if (head == NULL && !load_buffer ()) |
| 530 | return NULL; |
| 531 | |
| 532 | if (current_line < head->first_available) |
| 533 | current_line = head->first_available; |
| 534 | |
| 535 | ++(head->first_available); |
| 536 | |
| 537 | l = head->curr_line; |
| 538 | |
| 539 | line = &l->starts[l->retrieve_index]; |
| 540 | |
| 541 | /* Advance index to next line. */ |
| 542 | if (++l->retrieve_index == l->used) |
| 543 | { |
| 544 | /* Go on to the next line record. */ |
| 545 | head->curr_line = l->next; |
| 546 | if (head->curr_line == NULL || head->curr_line->used == 0) |
| 547 | { |
| 548 | /* Go on to the next data block. |
| 549 | but first record the current one so we can free it |
| 550 | once the line we're returning has been processed. */ |
| 551 | prev_buf = head; |
| 552 | head = head->next; |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | return line; |
| 557 | } |
| 558 | |
| 559 | /* Search the buffers for line LINENUM, reading more input if necessary. |
| 560 | Return a pointer to the line, or NULL if it is not found in the file. */ |
no test coverage detected