]> 4ch.mooo.com Git - 16.git/commitdiff
modified: src/lib/jsmn/example/MAPTEST.EXE
authorsparky4 <sparky4@cock.li>
Mon, 23 Mar 2015 05:10:01 +0000 (00:10 -0500)
committersparky4 <sparky4@cock.li>
Mon, 23 Mar 2015 05:10:01 +0000 (00:10 -0500)
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

src/lib/jsmn/example/MAPTEST.EXE
src/lib/jsmn/example/MAPTEST2.EXE
src/lib/jsmn/example/maptest
src/lib/jsmn/example/maptest.c
src/lib/jsmn/example/maptest2
src/lib/jsmn/example/maptest2.c

index 4b6028638dbaf6330f5f02b625e99549f49c5b4d..f3a71677a6e6303602c6ab88a0ac826735d3e091 100644 (file)
Binary files a/src/lib/jsmn/example/MAPTEST.EXE and b/src/lib/jsmn/example/MAPTEST.EXE differ
index bb07fc7fca4b69e0cce8283e709f522a9ea14ec6..af8cb79d15f86e3094b4cd0047a84c6da54fcec5 100644 (file)
Binary files a/src/lib/jsmn/example/MAPTEST2.EXE and b/src/lib/jsmn/example/MAPTEST2.EXE differ
index 4825f5a13c4b4be5121bcbb2247d070adce6eba2..a72fa7f9f215fdb940dac204d401a2f9b47f1db2 100644 (file)
Binary files a/src/lib/jsmn/example/maptest and b/src/lib/jsmn/example/maptest differ
index 597b0001fa86cac2db3e437f22ee368f59347279..7cceabb8ea2e7494d470f68aa45ab01a2ac30bf8 100644 (file)
@@ -1,9 +1,11 @@
 #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.
@@ -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) {
index 4a861d3b24e7cd478e7058d2dd0b58dd5ab37c80..b35d6cda5896f7c70dbe3f8daebafd7dba399b23 100644 (file)
Binary files a/src/lib/jsmn/example/maptest2 and b/src/lib/jsmn/example/maptest2 differ
index 6e18a40d54fb5cbd981074d6eb10f1b83f2d6c35..8d4fec246beb2b2ceb55550452abd56266a2f9e5 100644 (file)
@@ -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;
                }