| 741 | REPETITION is this repeat-count; 0 means the first time. */ |
| 742 | |
| 743 | static void |
| 744 | process_regexp (struct control *p, intmax_t repetition) |
| 745 | { |
| 746 | struct cstring *line; /* From input file. */ |
| 747 | idx_t line_len; /* To make "$" in regexps work. */ |
| 748 | intmax_t break_line; /* First line number of next file. */ |
| 749 | bool ignore = p->ignore; /* If true, skip this section. */ |
| 750 | regoff_t ret; |
| 751 | |
| 752 | if (!ignore) |
| 753 | create_output_file (); |
| 754 | |
| 755 | /* If there is no offset for the regular expression, or |
| 756 | it is positive, then it is not necessary to buffer the lines. */ |
| 757 | |
| 758 | if (p->offset >= 0) |
| 759 | { |
| 760 | while (true) |
| 761 | { |
| 762 | line = find_line (++current_line); |
| 763 | if (line == NULL) |
| 764 | { |
| 765 | if (p->repeat_forever) |
| 766 | { |
| 767 | if (!ignore) |
| 768 | { |
| 769 | dump_rest_of_file (); |
| 770 | close_output_file (); |
| 771 | } |
| 772 | exit (EXIT_SUCCESS); |
| 773 | } |
| 774 | else |
| 775 | regexp_error (p, repetition, ignore); |
| 776 | } |
| 777 | line_len = line->len; |
| 778 | if (line->str[line_len - 1] == '\n') |
| 779 | line_len--; |
| 780 | ret = re_search (&p->re_compiled, line->str, line_len, |
| 781 | 0, line_len, NULL); |
| 782 | if (ret == -2) |
| 783 | { |
| 784 | error (0, 0, _("error in regular expression search")); |
| 785 | cleanup_fatal (); |
| 786 | } |
| 787 | if (ret == -1) |
| 788 | { |
| 789 | line = remove_line (); |
| 790 | if (!ignore) |
| 791 | save_line_to_file (line); |
| 792 | } |
| 793 | else |
| 794 | break; |
| 795 | } |
| 796 | } |
| 797 | else |
| 798 | { |
| 799 | /* Buffer the lines. */ |
| 800 | while (true) |
no test coverage detected