X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fjsmn%2Fexample%2Fmaptest.c;h=7cceabb8ea2e7494d470f68aa45ab01a2ac30bf8;hb=f1605e99959acfb32b36ae875601fc14dd670742;hp=2fdf04e0871f9f91f236a99ba1041fd4604e8213;hpb=bf902b62d6e987635b367d151934e3c0d07bc44b;p=16.git diff --git a/src/lib/jsmn/example/maptest.c b/src/lib/jsmn/example/maptest.c old mode 100644 new mode 100755 index 2fdf04e0..7cceabb8 --- a/src/lib/jsmn/example/maptest.c +++ b/src/lib/jsmn/example/maptest.c @@ -1,8 +1,11 @@ #include #include #include +//#include #include "../jsmn.c" +//#define BUFSIZ 2048 + /* * A small example of jsmn parsing when JSON structure is known and number of * tokens is predictable. @@ -35,18 +38,26 @@ int main() { int i; int r; size_t z; - //char json_s[8192]; jsmn_parser p; - jsmntok_t t[2048]; /* We expect no more than 128 tokens */ + jsmntok_t t[(BUFSIZ/sizeof(jsmntok_t))*2]; /* We expect no more than 128 tokens */ FILE *fh = fopen("../../../../data/test.map", "r"); - char *json_string = malloc(filesize(fh)); - //memset(json_string, 0, sizeof(*json_string)); if(fh != NULL) { + /*t = malloc(2048); + if (t == NULL) { + fprintf(stderr, "malloc(): errno=%d\n", errno); + 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); - printf("[[%d]]\n", z); + //char json_s[2048]; + fclose(fh); fh = NULL; + printf("[%d]\n", z); json_string[z] = '\0'; // we can now close the file //printf("]%s[\n", json_s); @@ -54,10 +65,10 @@ int main() { //printf("[[%s]]\n", json_string); 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); - r = jsmn_parse(&p, json_string, filesize(fh), t, sizeof(t)/sizeof(t[0])); - fclose(fh); fh = NULL; - //printf("[\n%s\n]", json_string); + printf("[[%d]]\n",r); if (r < 0) { printf("Failed to parse JSON: %d\n", r); return 1; @@ -98,8 +109,8 @@ int main() { } i += t[i+1].size + 1; } else { - printf("Unexpected key: %.*s\n", t[i].end-t[i].start, - json_string + t[i].start); + /*printf("Unexpected key: %.*s\n", t[i].end-t[i].start, + json_string + t[i].start);*/ } }