fixed a feeding loop bug in bin/t03.c

This commit is contained in:
hyung-hwan 2020-06-17 09:51:20 +00:00
parent 61d1f8abd9
commit e98b3a37c0

View File

@ -153,14 +153,18 @@ int main (int argc, char* argv[])
mio_json_setinstcb (json, on_json_inst, MIO_NULL);
rem = 0;
while (!feof(stdin))
while (!feof(stdin) || rem > 0)
{
int x;
size_t size = fread(&buf[rem], 1, sizeof(buf) - rem, stdin);
if (size <= 0) break;
size_t size;
if (!feof(stdin))
{
size = fread(&buf[rem], 1, sizeof(buf) - rem, stdin);
if (size <= 0) break;
}
else size = 0;
if ((x = mio_json_feed(json, buf, size + rem, &rem, 1)) <= -1)
{
@ -168,6 +172,12 @@ int main (int argc, char* argv[])
break;
}
if (x > 0)
{
/* document completed */
mio_logbfmt (mio, MIO_LOG_STDOUT, "\n-----------------------------------\n");
}
//printf ("--> x %d input %d left-over %d\n", (int)x, (int)size, (int)rem);
if (rem > 0) memcpy (buf, &buf[size - rem], rem);
}