44#define DEFAULT_CHUNK_SIZE 60
96 bool need_strings =
false;
101 while ((
c =
getopt(argc, argv,
"c:os")) != -1)
106 chunk_size = strtou64(
optarg, NULL, 10);
138 if ((json_file = fopen(testfile,
PG_BINARY_R)) == NULL)
139 pg_fatal(
"error opening input: %m");
141 if (
fstat(fileno(json_file), &statbuf) != 0)
142 pg_fatal(
"error statting input: %m");
150 if (bytes_left < chunk_size)
151 chunk_size = bytes_left;
153 n_read = fread(buff, 1, chunk_size, json_file);
154 if (n_read < chunk_size)
155 pg_fatal(
"error reading input file: %d", ferror(json_file));
165 bytes_left -= n_read;
327 for (p =
str; *p; p++)
353 if ((
unsigned char) *p <
' ')
368 fprintf(stderr,
" -c chunksize size of piece fed to parser (default 64)\n");
369 fprintf(stderr,
" -o set JSONLEX_CTX_OWNS_TOKENS for leak checking\n");
370 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)