* Read the next input line and stash it in line_buf. * * Result is true if read was terminated by EOF, false if terminated * by newline. The terminating newline or EOF marker is not included * in the final value of line_buf. */
| 763 | * in the final value of line_buf. |
| 764 | */ |
| 765 | bool |
| 766 | CopyReadLine(CopyFromState cstate) |
| 767 | { |
| 768 | bool result; |
| 769 | |
| 770 | resetStringInfo(&cstate->line_buf); |
| 771 | cstate->line_buf_valid = false; |
| 772 | |
| 773 | /* Parse data and transfer into line_buf */ |
| 774 | result = CopyReadLineText(cstate); |
| 775 | |
| 776 | if (result) |
| 777 | { |
| 778 | /* |
| 779 | * Reached EOF. In protocol version 3, we should ignore anything |
| 780 | * after \. up to the protocol end of copy data. (XXX maybe better |
| 781 | * not to treat \. as special?) |
| 782 | */ |
| 783 | if (cstate->copy_src == COPY_FRONTEND) |
| 784 | { |
| 785 | int inbytes; |
| 786 | |
| 787 | do |
| 788 | { |
| 789 | inbytes = CopyGetData(cstate, cstate->input_buf, |
| 790 | 1, INPUT_BUF_SIZE); |
| 791 | } while (inbytes > 0); |
| 792 | cstate->input_buf_index = 0; |
| 793 | cstate->input_buf_len = 0; |
| 794 | cstate->raw_buf_index = 0; |
| 795 | cstate->raw_buf_len = 0; |
| 796 | } |
| 797 | } |
| 798 | else |
| 799 | { |
| 800 | /* |
| 801 | * If we didn't hit EOF, then we must have transferred the EOL marker |
| 802 | * to line_buf along with the data. Get rid of it. |
| 803 | */ |
| 804 | switch (cstate->eol_type) |
| 805 | { |
| 806 | case EOL_NL: |
| 807 | Assert(cstate->line_buf.len >= 1); |
| 808 | Assert(cstate->line_buf.data[cstate->line_buf.len - 1] == '\n'); |
| 809 | cstate->line_buf.len--; |
| 810 | cstate->line_buf.data[cstate->line_buf.len] = '\0'; |
| 811 | break; |
| 812 | case EOL_CR: |
| 813 | Assert(cstate->line_buf.len >= 1); |
| 814 | Assert(cstate->line_buf.data[cstate->line_buf.len - 1] == '\r'); |
| 815 | cstate->line_buf.len--; |
| 816 | cstate->line_buf.data[cstate->line_buf.len] = '\0'; |
| 817 | break; |
| 818 | case EOL_CRNL: |
| 819 | Assert(cstate->line_buf.len >= 2); |
| 820 | Assert(cstate->line_buf.data[cstate->line_buf.len - 2] == '\r'); |
| 821 | Assert(cstate->line_buf.data[cstate->line_buf.len - 1] == '\n'); |
| 822 | cstate->line_buf.len -= 2; |
no test coverage detected