| 797 | callers to hand off mid-line. */ |
| 798 | |
| 799 | static void |
| 800 | cut_bytes (FILE *stream) |
| 801 | { |
| 802 | static char bytes_in[IO_BUFSIZE]; |
| 803 | uintmax_t byte_idx = 0; |
| 804 | bool print_delimiter = false; |
| 805 | int fd = fileno (stream); |
| 806 | |
| 807 | current_rp = frp; |
| 808 | |
| 809 | while (true) |
| 810 | { |
| 811 | idx_t available = read (fd, bytes_in, sizeof bytes_in); |
| 812 | if (available <= 0) |
| 813 | { |
| 814 | if (available < 0) |
| 815 | fseterr (stream); |
| 816 | write_pending_line_delim (byte_idx); |
| 817 | break; |
| 818 | } |
| 819 | |
| 820 | idx_t processed = 0; |
| 821 | |
| 822 | while (processed < available) |
| 823 | { |
| 824 | char *line = bytes_in + processed; |
| 825 | idx_t to_process = available - processed; |
| 826 | char *line_end = search_bytes (line, line_delim, to_process); |
| 827 | char *end = line + (line_end ? line_end - line : to_process); |
| 828 | char *p = line; |
| 829 | |
| 830 | while (0 < end - p) |
| 831 | { |
| 832 | sync_byte_selection (byte_idx); |
| 833 | |
| 834 | if (byte_idx + 1 < current_rp->lo) |
| 835 | { |
| 836 | idx_t skip = MIN (end - p, current_rp->lo - (byte_idx + 1)); |
| 837 | p += skip; |
| 838 | byte_idx += skip; |
| 839 | } |
| 840 | else |
| 841 | { |
| 842 | idx_t n = MIN (end - p, current_rp->hi - byte_idx); |
| 843 | write_selected_item (&print_delimiter, |
| 844 | is_range_start_index (byte_idx + 1), |
| 845 | p, n); |
| 846 | p += n; |
| 847 | byte_idx += n; |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | processed += end - line; |
| 852 | if (line_end) |
| 853 | { |
| 854 | processed++; |
| 855 | reset_item_line (&byte_idx, &print_delimiter); |
| 856 | } |
nothing calls this directly
no test coverage detected