int main() { int c; int frag; char stamp[TIMESTAMP]; char line[MAXLINE]; size_t len; frag = -1; for (;;) { c = getc(stdin); if (feof(stdin)) { break; } timestamp(stamp); ungetc(c, stdin); while (fgets(line, MAXLINE, stdin) != NULL) { if (ferror(stdin)) { fputs(stamp, stderr); fputs(" ERROR: error encountered while reading line.\n", stderr); return 5; } len = strlen(line); if (line[len - 1] != '\n' || frag >= 0) { frag++; } writejson(stdout, stamp, line, len, frag); if (line[len - 1] == '\n') { frag = -1; break; } } if (ferror(stdout)) { fputs(stamp, stderr); fputs(" ERROR: error encountered while writing line.\n", stderr); return 5; } if (feof(stdin)) { break; } } return 0; }
void writer::output (json::value const& value) { impl_->markstarted(); writejson (value, impl_->getoutput()); }