| 988 | } |
| 989 | |
| 990 | static int ply_read_line(p_ply ply) { |
| 991 | const char *end = NULL; |
| 992 | assert(ply && ply->fp && ply->io_mode == PLY_READ); |
| 993 | /* look for a end of line */ |
| 994 | end = strchr(BFIRST(ply), '\n'); |
| 995 | /* if we didn't reach the end of the buffer, we are done */ |
| 996 | if (end) { |
| 997 | ply->buffer_token = ply->buffer_first; |
| 998 | BSKIP(ply, end - BFIRST(ply)); |
| 999 | *BFIRST(ply) = '\0'; |
| 1000 | BSKIP(ply, 1); |
| 1001 | return ply_check_line(ply); |
| 1002 | } else { |
| 1003 | end = ply->buffer + BSIZE(ply); |
| 1004 | /* otherwise, try to refill buffer */ |
| 1005 | if (!BREFILL(ply)) { |
| 1006 | ply_ferror(ply, "Unexpected end of file"); |
| 1007 | return 0; |
| 1008 | } |
| 1009 | } |
| 1010 | /* keep looking from where we left */ |
| 1011 | end = strchr(end, '\n'); |
| 1012 | /* check if the token is too large for our buffer */ |
| 1013 | if (!end) { |
| 1014 | ply_ferror(ply, "Token too large"); |
| 1015 | return 0; |
| 1016 | } |
| 1017 | /* we are done */ |
| 1018 | ply->buffer_token = ply->buffer_first; |
| 1019 | BSKIP(ply, end - BFIRST(ply)); |
| 1020 | *BFIRST(ply) = '\0'; |
| 1021 | BSKIP(ply, 1); |
| 1022 | return ply_check_line(ply); |
| 1023 | } |
| 1024 | |
| 1025 | static int ply_read_chunk(p_ply ply, void *anybuffer, size_t size) { |
| 1026 | char *buffer = (char *) anybuffer; |
no test coverage detected