5 static int dump(const char *js, jsmntok_t *t, size_t count, int indent) {
10 if (t->type == JSMN_PRIMITIVE) {
11 printf("%.*s", t->end - t->start, js+t->start);
13 } else if (t->type == JSMN_STRING) {
14 printf("'%.*s'", t->end - t->start, js+t->start);
16 } else if (t->type == JSMN_OBJECT) {
19 for (i = 0; i < t->size; i++) {
20 for (k = 0; k < indent; k++) printf(" ");
21 j += dump(js, t+1+j, count-j, indent+1);
23 j += dump(js, t+1+j, count-j, indent+1);
27 } else if (t->type == JSMN_ARRAY) {
30 for (i = 0; i < t->size; i++) {
31 for (k = 0; k < indent-1; k++) printf(" ");
33 j += dump(js, t+1+j, count-j, indent+1);
44 long int save_pos, size_of_file;
47 fseek(fp, 0L, SEEK_END);
48 size_of_file = ftell(fp);
49 fseek(fp, save_pos, SEEK_SET);
54 int loadmap(char *mn/*, map_t *map*/)
60 jsmntok_t *tok = NULL;
61 size_t tokcount, file_s;
63 FILE *fh = fopen(mn, "r");
68 file_s = filesize(fh);
71 fprintf(stderr, "malloc(): errno = %d", 2);
75 if(fread(js, 1, file_s, fh) != file_s){
76 fprintf(stderr, "Map read error");
82 tokcount = jsmn_parse(&p, js, file_s, NULL, 0);
83 tok = malloc(tokcount*sizeof(jsmntok_t));
84 jsmn_parse(&p, js, file_s, tok, tokcount);
86 fprintf(stdout, "running dump~\n");
88 dump(js, tok, p.toknext, 0);
100 loadmap("../../data/0es0.map");