#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <errno.h>
+//#include <errno.h>
#include "../jsmn.c"
+//#define BUFSIZ 2048
+
/*
* A small example of jsmn parsing when JSON structure is known and number of
* tokens is predictable.
size_t z;
jsmn_parser p;
jsmntok_t t[(BUFSIZ/sizeof(jsmntok_t))*2]; /* We expect no more than 128 tokens */
- FILE *fh = fopen("../../../../data/test0.map", "r");
+ FILE *fh = fopen("../../../../data/test.map", "r");
char *json_string = malloc(filesize(fh));
- //memset(json_string, 0, sizeof(*json_string));
- //memset(&p, 0, sizeof(p));
-
- //printf("\n[[[[%d]]]]\n\n", BUFSIZ);
if(fh != NULL)
{
return 3;
}*/
//printf("\n%d\n\n", sizeof(*t));
+ printf("\n%d", sizeof(*t));
printf("\n%d", sizeof(t));
printf("\n%d\n\n", sizeof(t)/sizeof(t[0]));
z = fread(json_string, 1, filesize(fh), fh);
jsmn_init(&p);
r = jsmn_parse(&p, json_string, strlen(json_string), t, sizeof(t)/sizeof(t[0]));
+ //t[(BUFSIZ/sizeof(jsmntok_t))*2+1].type=JSMN_OBJECT;
printf("[\n%s\n]", json_string);
printf("[[%d]]\n",r);
if (r < 0) {
* The output looks like YAML, but I'm not sure if it's really compatible.
*/
+static int jsoneq(const char *json, jsmntok_t *tok, const char *s) {
+ if (tok->type == JSMN_STRING && (int) strlen(s) == tok->end - tok->start &&
+ strncmp(json + tok->start, s, tok->end - tok->start) == 0) {
+ return 0;
+ }
+ return -1;
+}
+
static int dump(const char *js, jsmntok_t *t, size_t count, int indent) {
int i, j, k;
if (count == 0) {
return 1;
} else if (t->type == JSMN_STRING) {
printf("'%.*s'", t->end - t->start, js+t->start);
+ /*if (jsoneq(js, t, "image") == 0) {
+ printf("- image: %.*s\n", t->end-t->start,
+ js + t->start);
+ }*/
return 1;
} else if (t->type == JSMN_OBJECT) {
printf("\n");
j = 0;
for (i = 0; i < t->size; i++) {
- for (k = 0; k < indent; k++) printf(" ");
+ //for (k = 0; k < indent; k++) printf("\t");
j += dump(js, t+1+j, count-j, indent+1);
printf(": ");
j += dump(js, t+1+j, count-j, indent+1);
j = 0;
printf("\n");
for (i = 0; i < t->size; i++) {
- for (k = 0; k < indent-1; k++) printf(" ");
- printf(" - ");
+ //for (k = 0; k < indent-1; k++) printf("\t");
+ printf("\t-");
j += dump(js, t+1+j, count-j, indent+1);
printf("\n");
}
}
} else {
dump(js, tok, p.toknext, 0);
+ //fprintf(stdout, "[[[[%d]]]]\n", sizeof(tok));
printf("[\n%d\n]", jslen);
eof_expected = 1;
}