Read a line from the file Returns Error::Ok if a line was read, even if the line was empty. Returns Error::EOF on end of file. Returns other Error code on error, after displaying a message. */
| 13 | Returns other Error code on error, after displaying a message. |
| 14 | */ |
| 15 | Error InputFile::readLine(char* line, size_t maxlen) { |
| 16 | size_t len = 0; |
| 17 | int c; |
| 18 | while ((c = read()) >= 0) { |
| 19 | if (len >= maxlen) { |
| 20 | return Error::LineLengthExceeded; |
| 21 | } |
| 22 | if (c == '\r') { |
| 23 | continue; |
| 24 | } |
| 25 | if (c == '\n') { |
| 26 | ++_line_number; |
| 27 | if (len == 0) { |
| 28 | ++_blank_lines; |
| 29 | } |
| 30 | break; |
| 31 | } |
| 32 | line[len++] = c; |
| 33 | } |
| 34 | line[len] = '\0'; |
| 35 | return len || c >= 0 ? Error::Ok : Error::Eof; |
| 36 | } |
| 37 | |
| 38 | void InputFile::ack(Error status) { |
| 39 | if (status != Error::Ok) { |
no outgoing calls
no test coverage detected