From e98b3a37c0a66ece5481ad74714d5b89bbdbf9bf Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 17 Jun 2020 09:51:20 +0000 Subject: [PATCH] fixed a feeding loop bug in bin/t03.c --- mio/bin/t03.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mio/bin/t03.c b/mio/bin/t03.c index 5166591..b237545 100644 --- a/mio/bin/t03.c +++ b/mio/bin/t03.c @@ -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); }