49#define DEFAULT_CHUNK_SIZE 60
96 bool run_chunk_ranges =
false;
101 bool need_strings =
false;
110 while ((
c =
getopt(argc, argv,
"r:c:os")) != -1)
115 run_chunk_ranges =
true;
118 chunk_size = strtou64(
optarg, NULL, 10);
148 if ((json_file = fopen(testfile,
PG_BINARY_R)) == NULL)
149 pg_fatal(
"error opening input: %m");
151 if (
fstat(fileno(json_file), &statbuf) != 0)
152 pg_fatal(
"error statting input: %m");
161 off_t bytes_left = statbuf.
st_size;
162 size_t to_read = chunk_size;
174 if (bytes_left < to_read)
175 to_read = bytes_left;
177 n_read = fread(buff, 1, to_read, json_file);
178 if (n_read < to_read)
179 pg_fatal(
"error reading input file: %d", ferror(json_file));
189 bytes_left -= n_read;
228 if (run_chunk_ranges)
233 }
while (run_chunk_ranges && (--chunk_size > 0));
365 for (p =
str; *p; p++)
391 if ((
unsigned char) *p <
' ')
406 fprintf(stderr,
" -c chunksize size of piece fed to parser (default 64)\n");
407 fprintf(stderr,
" -o set JSONLEX_CTX_OWNS_TOKENS for leak checking\n");
408 fprintf(stderr,
" -s do semantic processing\n");
static void cleanup(void)
#define fprintf(file, fmt, msg)
JsonParseErrorType pg_parse_json_incremental(JsonLexContext *lex, const JsonSemAction *sem, const char *json, size_t len, bool is_last)
JsonLexContext * makeJsonLexContextIncremental(JsonLexContext *lex, int encoding, bool need_escapes)
void setJsonLexContextOwnsTokens(JsonLexContext *lex, bool owned_by_context)
const JsonSemAction nullSemAction
char * json_errdetail(JsonParseErrorType error, JsonLexContext *lex)
void freeJsonLexContext(JsonLexContext *lex)
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 bool lex_owns_tokens
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)