Re: [Flex-help] EOF handling in flex canners is mysterious to me
flex is a tool for generating scanners
Brought to you by:
wlestes
From: John P. H. <jph...@gm...> - 2014-10-14 12:55:55
|
You should test for EOF only if fread returns 0; If res is positive, you should go with that. Next time you read, you'll see EOF. On 14/10/14 14:33, Will Estes wrote: > static ssize_t custom_input(char *buf, size_t result_max, yyscan_t yyscanner) >>{ >> ssize_t res = fread(buf, 1, result_max, yyget_in(yyscanner)); >> >> if (feof(yyget_in(yyscanner)) || ferror(yyget_in(yyscanner))) >> res = YY_NULL; >> if (yydebug) >> fprintf(stderr, "custom_input(..., %ld, ...) -> %zd\n", result_max, res); >> return res; >>} |