| 616 | ARGNUM is the index in ARGV of the current pattern. */ |
| 617 | |
| 618 | static void |
| 619 | write_to_file (intmax_t last_line, bool ignore, int argnum) |
| 620 | { |
| 621 | struct cstring *line; |
| 622 | intmax_t first_line; /* First available input line. */ |
| 623 | intmax_t lines; /* Number of lines to output. */ |
| 624 | |
| 625 | first_line = get_first_line_in_buffer (); |
| 626 | |
| 627 | if (! first_line || first_line > last_line) |
| 628 | { |
| 629 | error (0, 0, _("%s: line number out of range"), |
| 630 | quote (global_argv[argnum])); |
| 631 | cleanup_fatal (); |
| 632 | } |
| 633 | |
| 634 | lines = last_line - first_line; |
| 635 | |
| 636 | for (intmax_t i = 0; i < lines; i++) |
| 637 | { |
| 638 | line = remove_line (); |
| 639 | if (line == NULL) |
| 640 | { |
| 641 | error (0, 0, _("%s: line number out of range"), |
| 642 | quote (global_argv[argnum])); |
| 643 | cleanup_fatal (); |
| 644 | } |
| 645 | if (!ignore) |
| 646 | save_line_to_file (line); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | /* Output any lines left after all regexps have been processed. */ |
| 651 |
no test coverage detected