#include #include #include #include "callbacks.h" #include "weaseljson.h" int main(int argc, char **argv) { if (argc < 2) { printf("Usage: %s \n", argv[0]); return 1; } int fd = open(argv[1], O_RDONLY); if (fd == -1) { perror("open"); return 1; } auto c = noopCallbacks(); std::unique_ptr parser{ WeaselJsonParser_create(1024, &c, nullptr), WeaselJsonParser_destroy}; for (;;) { char buf[1024]; int l = read(fd, buf, sizeof(buf)); if (l == -1) { perror("read"); return 1; } switch (WeaselJsonParser_parse(parser.get(), buf, l)) { case WeaselJson_OK: return 0; case WeaselJson_AGAIN: continue; case WeaselJson_REJECT: case WeaselJson_OVERFLOW: return 1; } if (l == 0) { return 1; } } }