29 #include <sys/types.h>
40 #define DEFAULT_CHUNK_SIZE 60
76 main(
int argc,
char **argv)
90 bool need_strings =
false;
94 while ((
c =
getopt(argc, argv,
"c:s")) != -1)
127 if ((json_file = fopen(testfile,
PG_BINARY_R)) == NULL)
128 pg_fatal(
"error opening input: %m");
130 if (
fstat(fileno(json_file), &statbuf) != 0)
131 pg_fatal(
"error statting input: %m");
139 if (bytes_left < chunk_size)
140 chunk_size = bytes_left;
142 n_read = fread(buff, 1, chunk_size, json_file);
143 if (n_read < chunk_size)
144 pg_fatal(
"error reading input file: %d", ferror(json_file));
154 bytes_left -= n_read;
305 for (p =
str; *p; p++)
331 if ((
unsigned char) *p <
' ')
346 fprintf(stderr,
" -c chunksize size of piece fed to parser (default 64)n");
347 fprintf(stderr,
" -s do semantic processing\n");
#define strtou64(str, endptr, base)
char * pg_strdup(const char *in)
JsonParseErrorType pg_parse_json_incremental(JsonLexContext *lex, const JsonSemAction *sem, const char *json, size_t len, bool is_last)
char * json_errdetail(JsonParseErrorType error, JsonLexContext *lex)
const JsonSemAction nullSemAction
JsonLexContext * makeJsonLexContextIncremental(JsonLexContext *lex, int encoding, bool need_escapes)
void pg_logging_init(const char *argv0)
int getopt(int nargc, char *const *nargv, const char *ostr)
PGDLLIMPORT char * optarg
StringInfo makeStringInfo(void)
void resetStringInfo(StringInfo str)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
void appendStringInfoString(StringInfo str, const char *s)
void initStringInfo(StringInfo str)
#define appendStringInfoCharMacro(str, ch)
json_struct_action object_start
static void usage(const char *progname)
static JsonParseErrorType do_object_field_start(void *state, char *fname, bool isnull)
int main(int argc, char **argv)
static JsonParseErrorType do_array_element_end(void *state, bool isnull)
static JsonParseErrorType do_array_element_start(void *state, bool isnull)
static JsonParseErrorType do_object_end(void *state)
static JsonParseErrorType do_scalar(void *state, char *token, JsonTokenType tokentype)
#define DEFAULT_CHUNK_SIZE
static JsonParseErrorType do_array_start(void *state)
static JsonParseErrorType do_object_start(void *state)
static JsonParseErrorType do_array_end(void *state)
static JsonParseErrorType do_object_field_end(void *state, char *fname, bool isnull)
static void escape_json(StringInfo buf, const char *str)