19 #define NAN strtod("NaN",0) 27 if(1 != fread(&c,1,1,f)) {
29 if(count==0)
return 0;
30 mc_error(
"EOF after %d bytes were read.\n", count);
33 mc_error(
"Reading error: %s\n", strerror(errno));
37 mc_error(
"Malformed JSON object. (read %d bytes).\n", count);
50 size_t buf_size = 100000;
51 char *
buf = (
char*) malloc(buf_size);
57 if( ((
size_t)count) > buf_size - 2) {
59 char * new_buf = realloc(buf, buf_size);
61 mc_error(
"Having read %d bytes, cannot allocate a block of size %d.",
69 if(1 != fread(&c,1,1,f)) {
71 if(count==0) { free(buf);
return 0; }
72 mc_error(
"EOF while %d were read: \n\t'%.*s'. \n", count, count, buf);
75 mc_error(
"Reading error: %s\n", strerror(errno));
78 if(count==0 && isspace(c))
continue;
84 mc_error(
"Malformed JSON object: \n'%.*s'\n", count, buf);
110 mc_error(
"Malformed JSON object: \n'%.*s'\n", len, str);
142 mc_error(
"I expected at least %d elements, got %d. \nArray: '%s'\n",
149 int i;
for(i=0;i<n;i++) {
182 mc_error(
"I expected at least %d elements, got %d. \nArray: '%s'\n",
203 int i;
for(i=0;i<n;i++) {
211 int i;
for(i=0;i<n;i++) {
226 mc_error(
"I was looking for a int, instead got '%s'.\n",
287 strncpy(dest_string,
"<string not found>", max_len);
char * json_object_get_string(struct json_object *this)
int json_object_array_length(struct json_object *this)
int jo_read_string(JO jo, const char *name, char *dest_string, size_t max_len)
double json_object_get_double(struct json_object *this)
const char * json_write(JO jo)
struct json_object * json_object_object_get(struct json_object *this, const char *key)
enum json_tokener_error err
struct json_object * json_object_new_double(double d)
int json_object_is_type(struct json_object *this, int type)
void jo_add_int_array(JO root, const char *name, const int *v, int n)
int jo_read_double(JO jo, const char *name, double *p)
void json_tokener_free(struct json_tokener *tok)
int json_object_get_int(struct json_object *this)
int json_stream_skip(FILE *f)
void mc_error(const char *msg,...)
int json_object_array_add(struct json_object *this, struct json_object *val)
struct json_object * json_tokener_parse_len(const char *str, int len)
JO jo_new_double_array(const double *v, int n)
int json_to_int(JO jo, int *ptr)
int JSON_checker_finished()
const char * json_object_to_json_string(struct json_object *this)
int JSON_checker_push(int b)
struct json_object * json_object_new_array()
void jo_add_string(JO root, const char *name, const char *v)
double convert_to_double(JO jo)
int json_to_double(JO jo, double *ptr)
int jo_read_double_array(JO s, const char *name, double *p, int n, double when_null)
void jo_add_double_array(JO root, const char *name, const double *v, int n)
struct json_object * json_tokener_parse_ex(struct json_tokener *tok, const char *str, int len)
struct json_object * json_object_new_int(int i)
JO json_parse(const char *str)
void jo_add_double(JO root, const char *name, double v)
JO json_read_stream(FILE *f)
struct json_tokener * json_tokener_new()
int jo_read_from_double_array(JO jo, double *p, int n, double when_null)
struct json_object * json_object_array_get_idx(struct json_object *this, int idx)
int jo_read_int_array(JO s, const char *name, int *p, int n, int when_null)
int jo_read_int(JO jo, const char *name, int *p)
void jo_add_int(JO root, const char *name, int v)
JO jo_double_or_null(double v)
int jo_has_field(JO s, const char *name)
JO jo_new_int_array(const int *v, int n)