From: sparky4 Date: Mon, 23 Mar 2015 05:10:01 +0000 (-0500) Subject: modified: src/lib/jsmn/example/MAPTEST.EXE X-Git-Url: http://4ch.mooo.com/gitweb/?a=commitdiff_plain;h=a731fa2dda47dfd29c48dc0b3486837179474c44;p=16.git modified: src/lib/jsmn/example/MAPTEST.EXE modified: src/lib/jsmn/example/MAPTEST2.EXE modified: src/lib/jsmn/example/maptest modified: src/lib/jsmn/example/maptest.c modified: src/lib/jsmn/example/maptest2 modified: src/lib/jsmn/example/maptest2.c --- diff --git a/src/lib/jsmn/example/MAPTEST.EXE b/src/lib/jsmn/example/MAPTEST.EXE index 4b602863..f3a71677 100644 Binary files a/src/lib/jsmn/example/MAPTEST.EXE and b/src/lib/jsmn/example/MAPTEST.EXE differ diff --git a/src/lib/jsmn/example/MAPTEST2.EXE b/src/lib/jsmn/example/MAPTEST2.EXE index bb07fc7f..af8cb79d 100644 Binary files a/src/lib/jsmn/example/MAPTEST2.EXE and b/src/lib/jsmn/example/MAPTEST2.EXE differ diff --git a/src/lib/jsmn/example/maptest b/src/lib/jsmn/example/maptest index 4825f5a1..a72fa7f9 100644 Binary files a/src/lib/jsmn/example/maptest and b/src/lib/jsmn/example/maptest differ diff --git a/src/lib/jsmn/example/maptest.c b/src/lib/jsmn/example/maptest.c index 597b0001..7cceabb8 100644 --- a/src/lib/jsmn/example/maptest.c +++ b/src/lib/jsmn/example/maptest.c @@ -1,9 +1,11 @@ #include #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. @@ -38,12 +40,8 @@ int main() { 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) { @@ -53,6 +51,7 @@ int main() { 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); @@ -67,6 +66,7 @@ int main() { 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) { diff --git a/src/lib/jsmn/example/maptest2 b/src/lib/jsmn/example/maptest2 index 4a861d3b..b35d6cda 100644 Binary files a/src/lib/jsmn/example/maptest2 and b/src/lib/jsmn/example/maptest2 differ diff --git a/src/lib/jsmn/example/maptest2.c b/src/lib/jsmn/example/maptest2.c index 6e18a40d..8d4fec24 100644 --- a/src/lib/jsmn/example/maptest2.c +++ b/src/lib/jsmn/example/maptest2.c @@ -9,6 +9,14 @@ * 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) { @@ -19,12 +27,16 @@ static int dump(const char *js, jsmntok_t *t, size_t count, int indent) { 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); @@ -35,8 +47,8 @@ static int dump(const char *js, jsmntok_t *t, size_t count, int indent) { 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"); } @@ -106,6 +118,7 @@ again: } } else { dump(js, tok, p.toknext, 0); + //fprintf(stdout, "[[[[%d]]]]\n", sizeof(tok)); printf("[\n%d\n]", jslen); eof_expected = 1; }