Pivot to simpler approach. Passes JSONTestSuite
This commit is contained in:
39
src/validate.cpp
Normal file
39
src/validate.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "callbacks.h"
|
||||
#include "parser3.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s <path>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
int fd = open(argv[1], O_RDONLY);
|
||||
if (fd == -1) {
|
||||
perror("open");
|
||||
return 1;
|
||||
}
|
||||
auto c = noopCallbacks();
|
||||
parser3::Parser3 parser(&c, nullptr);
|
||||
for (;;) {
|
||||
char buf[1024];
|
||||
int l = read(fd, buf, sizeof(buf));
|
||||
if (l == -1) {
|
||||
perror("read");
|
||||
return 1;
|
||||
}
|
||||
switch (parser.parse(buf, l)) {
|
||||
case parser3::S_OK:
|
||||
return 0;
|
||||
case parser3::S_AGAIN:
|
||||
continue;
|
||||
case parser3::S_REJECT:
|
||||
case parser3::S_OVERFLOW:
|
||||
return 1;
|
||||
}
|
||||
if (l == 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user