| 931 | } |
| 932 | |
| 933 | static int ply_read_word(p_ply ply) { |
| 934 | size_t t = 0; |
| 935 | assert(ply && ply->fp && ply->io_mode == PLY_READ); |
| 936 | /* skip leading blanks */ |
| 937 | while (1) { |
| 938 | t = strspn(BFIRST(ply), " \n\r\t"); |
| 939 | /* check if all buffer was made of blanks */ |
| 940 | if (t >= BSIZE(ply)) { |
| 941 | if (!BREFILL(ply)) { |
| 942 | ply_ferror(ply, "Unexpected end of file"); |
| 943 | return 0; |
| 944 | } |
| 945 | } else break; |
| 946 | } |
| 947 | BSKIP(ply, t); |
| 948 | /* look for a space after the current word */ |
| 949 | t = strcspn(BFIRST(ply), " \n\r\t"); |
| 950 | /* if we didn't reach the end of the buffer, we are done */ |
| 951 | if (t < BSIZE(ply)) { |
| 952 | ply_finish_word(ply, t); |
| 953 | return ply_check_word(ply); |
| 954 | } |
| 955 | /* otherwise, try to refill buffer */ |
| 956 | if (!BREFILL(ply)) { |
| 957 | /* if we reached the end of file, try to do with what we have */ |
| 958 | ply_finish_word(ply, t); |
| 959 | return ply_check_word(ply); |
| 960 | /* ply_ferror(ply, "Unexpected end of file"); */ |
| 961 | /* return 0; */ |
| 962 | } |
| 963 | /* keep looking from where we left */ |
| 964 | t += strcspn(BFIRST(ply) + t, " \n\r\t"); |
| 965 | /* check if the token is too large for our buffer */ |
| 966 | if (t >= BSIZE(ply)) { |
| 967 | ply_ferror(ply, "Token too large"); |
| 968 | return 0; |
| 969 | } |
| 970 | /* we are done */ |
| 971 | ply_finish_word(ply, t); |
| 972 | return ply_check_word(ply); |
| 973 | } |
| 974 | |
| 975 | static void ply_finish_word(p_ply ply, size_t size) { |
| 976 | ply->buffer_token = ply->buffer_first; |
no test coverage detected