]> 4ch.mooo.com Git - 16.git/commitdiff
jsmn far and near ... wwww
authorsparky4 <sparky4@cock.li>
Thu, 11 Jun 2015 16:27:51 +0000 (11:27 -0500)
committersparky4 <sparky4@cock.li>
Thu, 11 Jun 2015 16:27:51 +0000 (11:27 -0500)
modified:   Project 16.bfproject
modified:   makefile
modified:   src/lib/jsmn/jsmn.c
modified:   src/lib/jsmn/jsmn.h
new file:   src/lib/jsmn/jsmnfar.c
new file:   src/lib/jsmn/jsmnfar.h

Project 16.bfproject
makefile
src/lib/jsmn/jsmn.c
src/lib/jsmn/jsmn.h
src/lib/jsmn/jsmnfar.c [new file with mode: 0644]
src/lib/jsmn/jsmnfar.h [new file with mode: 0644]

index 0b00c5af1f48c7495023fa114b1b4e08d987151a..4e486aca813e8009f8463c34a0d4bdebbffd0f06 100644 (file)
@@ -2,32 +2,30 @@ c2e.convert_special: 0
 e2c.convert_num: 0
 openfiles: /dos/z/16/doc/project.txt:138:0:0:
 openfiles: /dos/z/16/src/palettec.c:179:0:0:
-openfiles: /dos/z/16/src/pcxtest.c:1431:2127:0:
-openfiles: /dos/z/16/src/scroll.c:3841:2952:0:
+openfiles: /dos/z/16/src/pcxtest.c:1431:1432:0:
+openfiles: /dos/z/16/src/scroll.c:3894:3527:0:
 openfiles: /dos/z/16/src/fmemtest.c:150:0:0:
-openfiles: /dos/z/16/src/emmtest.c:732:160:0:
+openfiles: /dos/z/16/src/emmtest.c:732:0:0:
 openfiles: /dos/z/16/src/emsdump.c:456:0:0:
 openfiles: /dos/z/16/src/maptest.c:69:0:0:
-openfiles: /dos/z/16/src/maptest0.c:253:85:0:
+openfiles: /dos/z/16/src/maptest0.c:445:0:0:
 openfiles: /dos/z/16/src/test.c:0:0:0:
 openfiles: /dos/z/16/src/test2.c:0:0:0:
 openfiles: /dos/z/16/src/lib/planar.h:602:0:0:
 openfiles: /dos/z/16/src/lib/PLANAR.C:0:0:0:
 openfiles: /dos/z/16/src/lib/bitmap.c:0:0:0:
-openfiles: /dos/z/16/src/lib/bitmap.h:0:0:0:
+openfiles: /dos/z/16/src/lib/bitmap.h:453:0:0:
 openfiles: /dos/z/16/src/lib/dos_kb.c:0:0:0:
 openfiles: /dos/z/16/src/lib/dos_kb.h:0:0:0:
 openfiles: /dos/z/16/src/lib/modex16.c:444:0:0:
 openfiles: /dos/z/16/src/lib/modex16.h:0:0:0:
 openfiles: /dos/z/16/src/lib/mapread.c:4790:4435:0:
-openfiles: /dos/z/16/src/lib/mapread.h:285:23:0:
-openfiles: /dos/z/16/src/lib/jsmn/jsmn.c:4073:3697:0:
-openfiles: /dos/z/16/src/lib/jsmn/jsmn.h:1635:826:0:
+openfiles: /dos/z/16/src/lib/mapread.h:285:0:0:
 openfiles: /dos/z/16/src/lib/exmm/memory.c:496:0:0:
 openfiles: /dos/z/16/src/lib/exmm/memory.h:0:0:0:
 openfiles: /dos/z/16/src/lib/exmm/emmsize.h:0:0:0:
 openfiles: /dos/z/16/src/lib/exmm/emmret.h:0:0:0:
-openfiles: /dos/z/16/makefile:2267:2340:1:
+openfiles: /dos/z/16/makefile:3079:248:1:
 openfiles: /dos/z/16/src/lib/types.h:165:0:0:
 snr_recursion_level: 0
 convertcolumn_horizontally: 0
@@ -40,10 +38,10 @@ view_left_panel: 0
 default_mime_type: text/plain
 e2c.convert_xml: 1
 c2e.convert_iso: 0
-opendir: file:///dos/z/16/src/lib/exmm
+opendir: file:///dos/z/16/src/lib
 wrap_text_default: 0
 bookmarks_filename_mode: 1
-ssearch_text: long
+ssearch_text: fprintf
 snr_casesens: 0
 view_blocks: 1
 name: Project 16
@@ -64,43 +62,45 @@ charmap_block: 1
 recent_files: file:///dos/z/rbaka.c
 recent_files: file:///dos/z/baka.c
 recent_files: file:///dos/z/bakac.c
-recent_files: file:///dos/z/16/doc/project.txt
-recent_files: file:///dos/z/16/src/test.c
-recent_files: file:///dos/z/16/src/test2.c
 recent_files: file:///dos/z/16/src/lib/xms.c
 recent_files: file:///dos/z/16/src/lib/xms.h
+recent_files: file:///dos/z/16/src/lib/ems.c
+recent_files: file:///dos/z/16/src/lib/lib_head.h
+recent_files: file:///dos/z/16/src/emm.c
+recent_files: file:///dos/z/16/src/far.c
+recent_files: file:///dos/z/16/src/emstest.c
+recent_files: file:///dos/z/16/src/lib/exmm/x.bat
+recent_files: file:///dos/z/16/makefile
+recent_files: file:///dos/z/16/doc/project.txt
 recent_files: file:///dos/z/16/src/palettec.c
+recent_files: file:///dos/z/16/src/emmtest.c
+recent_files: file:///dos/z/16/src/emsdump.c
+recent_files: file:///dos/z/16/src/maptest.c
 recent_files: file:///dos/z/16/src/pcxtest.c
-recent_files: file:///dos/z/16/src/lib/bitmap.h
-recent_files: file:///dos/z/16/src/lib/ems.c
+recent_files: file:///dos/z/16/src/fmemtest.c
+recent_files: file:///dos/z/16/src/maptest0.c
+recent_files: file:///dos/z/16/src/test.c
+recent_files: file:///dos/z/16/src/test2.c
+recent_files: file:///dos/z/16/src/scroll.c
 recent_files: file:///dos/z/16/src/lib/planar.h
 recent_files: file:///dos/z/16/src/lib/PLANAR.C
-recent_files: file:///dos/z/16/src/lib/bitmap.c
-recent_files: file:///dos/z/16/src/scroll.c
 recent_files: file:///dos/z/16/src/lib/dos_kb.c
-recent_files: file:///dos/z/16/src/lib/types.h
 recent_files: file:///dos/z/16/src/lib/dos_kb.h
-recent_files: file:///dos/z/16/src/lib/lib_head.h
+recent_files: file:///dos/z/16/src/lib/mapread.h
+recent_files: file:///dos/z/16/src/lib/bitmap.c
+recent_files: file:///dos/z/16/src/lib/bitmap.h
 recent_files: file:///dos/z/16/src/lib/modex16.h
 recent_files: file:///dos/z/16/src/lib/modex16.c
-recent_files: file:///dos/z/16/src/lib/mapread.h
-recent_files: file:///dos/z/16/src/lib/mapread.c
 recent_files: file:///dos/z/16/src/lib/jsmn/jsmn.c
+recent_files: file:///dos/z/16/src/lib/mapread.c
 recent_files: file:///dos/z/16/src/lib/jsmn/jsmn.h
-recent_files: file:///dos/z/16/src/maptest0.c
-recent_files: file:///dos/z/16/src/maptest.c
-recent_files: file:///dos/z/16/makefile
-recent_files: file:///dos/z/16/src/emm.c
-recent_files: file:///dos/z/16/src/far.c
-recent_files: file:///dos/z/16/src/emstest.c
-recent_files: file:///dos/z/16/src/lib/exmm/x.bat
-recent_files: file:///dos/z/16/src/fmemtest.c
-recent_files: file:///dos/z/16/src/lib/exmm/emmret.h
 recent_files: file:///dos/z/16/src/lib/exmm/emmsize.h
+recent_files: file:///dos/z/16/src/lib/exmm/emmret.h
 recent_files: file:///dos/z/16/src/lib/exmm/memory.h
+recent_files: file:///dos/z/16/src/lib/types.h
 recent_files: file:///dos/z/16/src/lib/exmm/memory.c
 snr_replacetype: 0
-savedir: file:///dos/z/16
+savedir: file:///dos/z/16/src/lib/jsmn
 spell_check_default: 1
 spell_insert_entities: 0
 last_filefilter: 
@@ -110,21 +110,21 @@ snr_escape_chars: 0
 htmlbar_view: 0
 spell_lang: en
 ssearch_dotmatchall: 0
-searchlist: num_tokens
-searchlist: *
-searchlist:  *
-searchlist:  malloc
-searchlist: malloc
-searchlist: alloc)(
 searchlist: alloc(
 searchlist: alloc (
 searchlist: parse(
-searchlist: i 
+searchlist: i
 searchlist: parser->toknext
 searchlist: toknext
 searchlist: int
 searchlist: countlong
 searchlist: long
+searchlist: farhuge
+searchlist: arhuge
+searchlist: rhuge
+searchlist: huge
+searchlist: ++++
+searchlist: fprintf
 autocomplete: 1
 outputb_show_all_output: 0
 bookmarks_show_mode: 0
index 0e4f6711342cad597706665e2964865439dbcf5c..556b3f869048f9740d2d830239895c7d74b01837 100644 (file)
--- a/makefile
+++ b/makefile
@@ -2,7 +2,7 @@
 #-zk0 = kanji support~\r
 #-zkl = current codepage\r
 \r
-CFLAGS=-zkl -wo -x -mc# -mh# -zdp# -zp16 -zq\r
+CFLAGS=-zkl -wo -x## -mc# -zdp# -zp16 -zq\r
 OFLAGS=-ot -ox -ob -oh -or# -om -ol -ol+\r
 FLAGS=-0 -d2 $(OFLAGS) $(CFLAGS)\r
 REMOVECOMMAND=del\r
@@ -94,7 +94,10 @@ lib_head.obj: $(SRCLIB)lib_head.h $(SRCLIB)lib_head.c
        wcl $(FLAGS) -c $(SRCLIB)lib_head.c\r
 \r
 jsmn.obj: $(JSMNLIB)jsmn.h $(JSMNLIB)jsmn.c\r
-       wcl $(FLAGS) -c $(JSMNLIB)jsmn.c\r
+       wcl $(FLAGS) -c $(JSMNLIB)jsmn.c
+
+farjsmn.obj: $(JSMNLIB)farjsmn.h $(JSMNLIB)farjsmn.c\r
+       wcl $(FLAGS) -c $(JSMNLIB)farjsmn.c\r
 
 memory.obj: $(EXMMLIB)memory.h $(EXMMLIB)memory.c\r
        wcl $(FLAGS) -c $(EXMMLIB)memory.c
index d79f9a5ddb447d96d494d363ca62d7ae7f0b8e3c..a0f4f69c6710939fefb2c4d04cbfa5b0e5a19946 100644 (file)
@@ -1,14 +1,13 @@
 #include <stdlib.h>
-#include <stdio.h>     //fprintf for noisy debugging wwww
 
 #include "jsmn.h"
 
 /**
  * Allocates a fresh unused token from the token pull.
  */
-static jsmntok_t huge *jsmn_alloc_token(jsmn_parser huge *parser,
-               jsmntok_t huge *tokens, size_t num_tokens) {
-       jsmntok_t huge *tok;
+static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser,
+               jsmntok_t *tokens, size_t num_tokens) {
+       jsmntok_t *tok;
        if (parser->toknext >= num_tokens) {
                return NULL;
        }
@@ -24,7 +23,7 @@ static jsmntok_t huge *jsmn_alloc_token(jsmn_parser huge *parser,
 /**
  * Fills token type and boundaries.
  */
-static void jsmn_fill_token(jsmntok_t huge *token, jsmntype_t type,
+static void jsmn_fill_token(jsmntok_t *token, jsmntype_t type,
                             int start, int end) {
        token->type = type;
        token->start = start;
@@ -35,9 +34,9 @@ static void jsmn_fill_token(jsmntok_t huge *token, jsmntype_t type,
 /**
  * Fills next available token with JSON primitive.
  */
-static jsmnerr_t jsmn_parse_primitive(jsmn_parser huge *parser, const char huge *js,
-               size_t len, jsmntok_t huge *tokens, size_t num_tokens) {
-       jsmntok_t huge *token;
+static jsmnerr_t jsmn_parse_primitive(jsmn_parser *parser, const char *js,
+               size_t len, jsmntok_t *tokens, size_t num_tokens) {
+       jsmntok_t *token;
        int start;
 
        start = parser->pos;
@@ -84,9 +83,9 @@ found:
 /**
  * Filsl next token with JSON string.
  */
-static jsmnerr_t jsmn_parse_string(jsmn_parser huge *parser, const char huge *js,
-               size_t len, jsmntok_t huge *tokens, size_t num_tokens) {
-       jsmntok_t huge *token;
+static jsmnerr_t jsmn_parse_string(jsmn_parser *parser, const char *js,
+               size_t len, jsmntok_t *tokens, size_t num_tokens) {
+       jsmntok_t *token;
 
        int start = parser->pos;
 
@@ -151,21 +150,17 @@ static jsmnerr_t jsmn_parse_string(jsmn_parser huge *parser, const char huge *js
 /**
  * Parse JSON string and fill tokens.
  */
-jsmnerr_t jsmn_parse(jsmn_parser huge *parser, const char huge *js, size_t len,
-               jsmntok_t huge *tokens, unsigned int num_tokens) {
+jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
+               jsmntok_t *tokens, unsigned int num_tokens) {
        jsmnerr_t r;
        int i;
-       jsmntok_t huge *token;
+       jsmntok_t *token;
        int count = 0;
-       static unsigned long pee=0;
 
        for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
                char c;
                jsmntype_t type;
 
-fprintf(stdout, "pee=%lu       count=%u        i=%d    nt=%u\n", pee, count, i, num_tokens);
-pee++;
-
                c = js[parser->pos];
                switch (c) {
                        case '{': case '[':
@@ -269,7 +264,7 @@ pee++;
                        case 't': case 'f': case 'n' :
                                /* And they must not be keys of the object */
                                if (tokens != NULL) {
-                                       jsmntok_t huge *t = &tokens[parser->toksuper];
+                                       jsmntok_t *t = &tokens[parser->toksuper];
                                        if (t->type == JSMN_OBJECT ||
                                                        (t->type == JSMN_STRING && t->size != 0)) {
                                                return JSMN_ERROR_INVAL;
@@ -308,7 +303,7 @@ pee++;
  * Creates a new parser based over a given  buffer with an array of tokens
  * available.
  */
-void jsmn_init(jsmn_parser huge *parser) {
+void jsmn_init(jsmn_parser *parser) {
        parser->pos = 0;
        parser->toknext = 0;
        parser->toksuper = -1;
index fe27ed0d31e6933ea95f3ed2333654a5f43b9dc7..95fb2cabd4d8b0769adafa28f10ca12f252b9724 100644 (file)
@@ -3,8 +3,6 @@
 
 #include <stddef.h>
 
-#define JSMN_PARENT_LINKS
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -61,14 +59,14 @@ typedef struct {
 /**
  * Create JSON parser over an array of tokens
  */
-void jsmn_init(jsmn_parser huge *parser);
+void jsmn_init(jsmn_parser *parser);
 
 /**
  * Run JSON parser. It parses a JSON data string into and array of tokens, each describing
  * a single JSON object.
  */
-jsmnerr_t jsmn_parse(jsmn_parser huge *parser, const char huge *js, size_t len,
-               jsmntok_t huge *tokens, unsigned int num_tokens);
+jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
+               jsmntok_t *tokens, unsigned int num_tokens);
 
 #ifdef __cplusplus
 }
diff --git a/src/lib/jsmn/jsmnfar.c b/src/lib/jsmn/jsmnfar.c
new file mode 100644 (file)
index 0000000..d79f9a5
--- /dev/null
@@ -0,0 +1,316 @@
+#include <stdlib.h>
+#include <stdio.h>     //fprintf for noisy debugging wwww
+
+#include "jsmn.h"
+
+/**
+ * Allocates a fresh unused token from the token pull.
+ */
+static jsmntok_t huge *jsmn_alloc_token(jsmn_parser huge *parser,
+               jsmntok_t huge *tokens, size_t num_tokens) {
+       jsmntok_t huge *tok;
+       if (parser->toknext >= num_tokens) {
+               return NULL;
+       }
+       tok = &tokens[parser->toknext++];
+       tok->start = tok->end = -1;
+       tok->size = 0;
+#ifdef JSMN_PARENT_LINKS
+       tok->parent = -1;
+#endif
+       return tok;
+}
+
+/**
+ * Fills token type and boundaries.
+ */
+static void jsmn_fill_token(jsmntok_t huge *token, jsmntype_t type,
+                            int start, int end) {
+       token->type = type;
+       token->start = start;
+       token->end = end;
+       token->size = 0;
+}
+
+/**
+ * Fills next available token with JSON primitive.
+ */
+static jsmnerr_t jsmn_parse_primitive(jsmn_parser huge *parser, const char huge *js,
+               size_t len, jsmntok_t huge *tokens, size_t num_tokens) {
+       jsmntok_t huge *token;
+       int start;
+
+       start = parser->pos;
+
+       for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+               switch (js[parser->pos]) {
+#ifndef JSMN_STRICT
+                       /* In strict mode primitive must be followed by "," or "}" or "]" */
+                       case ':':
+#endif
+                       case '\t' : case '\r' : case '\n' : case ' ' :
+                       case ','  : case ']'  : case '}' :
+                               goto found;
+               }
+               if (js[parser->pos] < 32 || js[parser->pos] >= 127) {
+                       parser->pos = start;
+                       return JSMN_ERROR_INVAL;
+               }
+       }
+#ifdef JSMN_STRICT
+       /* In strict mode primitive must be followed by a comma/object/array */
+       parser->pos = start;
+       return JSMN_ERROR_PART;
+#endif
+
+found:
+       if (tokens == NULL) {
+               parser->pos--;
+               return 0;
+       }
+       token = jsmn_alloc_token(parser, tokens, num_tokens);
+       if (token == NULL) {
+               parser->pos = start;
+               return JSMN_ERROR_NOMEM;
+       }
+       jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos);
+#ifdef JSMN_PARENT_LINKS
+       token->parent = parser->toksuper;
+#endif
+       parser->pos--;
+       return 0;
+}
+
+/**
+ * Filsl next token with JSON string.
+ */
+static jsmnerr_t jsmn_parse_string(jsmn_parser huge *parser, const char huge *js,
+               size_t len, jsmntok_t huge *tokens, size_t num_tokens) {
+       jsmntok_t huge *token;
+
+       int start = parser->pos;
+
+       parser->pos++;
+
+       /* Skip starting quote */
+       for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+               char c = js[parser->pos];
+
+               /* Quote: end of string */
+               if (c == '\"') {
+                       if (tokens == NULL) {
+                               return 0;
+                       }
+                       token = jsmn_alloc_token(parser, tokens, num_tokens);
+                       if (token == NULL) {
+                               parser->pos = start;
+                               return JSMN_ERROR_NOMEM;
+                       }
+                       jsmn_fill_token(token, JSMN_STRING, start+1, parser->pos);
+#ifdef JSMN_PARENT_LINKS
+                       token->parent = parser->toksuper;
+#endif
+                       return 0;
+               }
+
+               /* Backslash: Quoted symbol expected */
+               if (c == '\\' && parser->pos + 1 < len) {
+                       int i;
+                       parser->pos++;
+                       switch (js[parser->pos]) {
+                               /* Allowed escaped symbols */
+                               case '\"': case '/' : case '\\' : case 'b' :
+                               case 'f' : case 'r' : case 'n'  : case 't' :
+                                       break;
+                               /* Allows escaped symbol \uXXXX */
+                               case 'u':
+                                       parser->pos++;
+                                       for(i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0'; i++) {
+                                               /* If it isn't a hex character we have an error */
+                                               if(!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */
+                                                                       (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */
+                                                                       (js[parser->pos] >= 97 && js[parser->pos] <= 102))) { /* a-f */
+                                                       parser->pos = start;
+                                                       return JSMN_ERROR_INVAL;
+                                               }
+                                               parser->pos++;
+                                       }
+                                       parser->pos--;
+                                       break;
+                               /* Unexpected symbol */
+                               default:
+                                       parser->pos = start;
+                                       return JSMN_ERROR_INVAL;
+                       }
+               }
+       }
+       parser->pos = start;
+       return JSMN_ERROR_PART;
+}
+
+/**
+ * Parse JSON string and fill tokens.
+ */
+jsmnerr_t jsmn_parse(jsmn_parser huge *parser, const char huge *js, size_t len,
+               jsmntok_t huge *tokens, unsigned int num_tokens) {
+       jsmnerr_t r;
+       int i;
+       jsmntok_t huge *token;
+       int count = 0;
+       static unsigned long pee=0;
+
+       for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+               char c;
+               jsmntype_t type;
+
+fprintf(stdout, "pee=%lu       count=%u        i=%d    nt=%u\n", pee, count, i, num_tokens);
+pee++;
+
+               c = js[parser->pos];
+               switch (c) {
+                       case '{': case '[':
+                               count++;
+                               if (tokens == NULL) {
+                                       break;
+                               }
+                               token = jsmn_alloc_token(parser, tokens, num_tokens);
+                               if (token == NULL)
+                                       return JSMN_ERROR_NOMEM;
+                               if (parser->toksuper != -1) {
+                                       tokens[parser->toksuper].size++;
+#ifdef JSMN_PARENT_LINKS
+                                       token->parent = parser->toksuper;
+#endif
+                               }
+                               token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
+                               token->start = parser->pos;
+                               parser->toksuper = parser->toknext - 1;
+                               break;
+                       case '}': case ']':
+                               if (tokens == NULL)
+                                       break;
+                               type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
+#ifdef JSMN_PARENT_LINKS
+                               if (parser->toknext < 1) {
+                                       return JSMN_ERROR_INVAL;
+                               }
+                               token = &tokens[parser->toknext - 1];
+                               for (;;) {
+                                       if (token->start != -1 && token->end == -1) {
+                                               if (token->type != type) {
+                                                       return JSMN_ERROR_INVAL;
+                                               }
+                                               token->end = parser->pos + 1;
+                                               parser->toksuper = token->parent;
+                                               break;
+                                       }
+                                       if (token->parent == -1) {
+                                               break;
+                                       }
+                                       token = &tokens[token->parent];
+                               }
+#else
+                               for (i = parser->toknext - 1; i >= 0; i--) {
+                                       token = &tokens[i];
+                                       if (token->start != -1 && token->end == -1) {
+                                               if (token->type != type) {
+                                                       return JSMN_ERROR_INVAL;
+                                               }
+                                               parser->toksuper = -1;
+                                               token->end = parser->pos + 1;
+                                               break;
+                                       }
+                               }
+                               /* Error if unmatched closing bracket */
+                               if (i == -1) return JSMN_ERROR_INVAL;
+                               for (; i >= 0; i--) {
+                                       token = &tokens[i];
+                                       if (token->start != -1 && token->end == -1) {
+                                               parser->toksuper = i;
+                                               break;
+                                       }
+                               }
+#endif
+                               break;
+                       case '\"':
+                               r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
+                               if (r < 0) return r;
+                               count++;
+                               if (parser->toksuper != -1 && tokens != NULL)
+                                       tokens[parser->toksuper].size++;
+                               break;
+                       case '\t' : case '\r' : case '\n' : case ' ':
+                               break;
+                       case ':':
+                               parser->toksuper = parser->toknext - 1;
+                               break;
+                       case ',':
+                               if (tokens != NULL &&
+                                               tokens[parser->toksuper].type != JSMN_ARRAY &&
+                                               tokens[parser->toksuper].type != JSMN_OBJECT) {
+#ifdef JSMN_PARENT_LINKS
+                                       parser->toksuper = tokens[parser->toksuper].parent;
+#else
+                                       for (i = parser->toknext - 1; i >= 0; i--) {
+                                               if (tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT) {
+                                                       if (tokens[i].start != -1 && tokens[i].end == -1) {
+                                                               parser->toksuper = i;
+                                                               break;
+                                                       }
+                                               }
+                                       }
+#endif
+                               }
+                               break;
+#ifdef JSMN_STRICT
+                       /* In strict mode primitives are: numbers and booleans */
+                       case '-': case '0': case '1' : case '2': case '3' : case '4':
+                       case '5': case '6': case '7' : case '8': case '9':
+                       case 't': case 'f': case 'n' :
+                               /* And they must not be keys of the object */
+                               if (tokens != NULL) {
+                                       jsmntok_t huge *t = &tokens[parser->toksuper];
+                                       if (t->type == JSMN_OBJECT ||
+                                                       (t->type == JSMN_STRING && t->size != 0)) {
+                                               return JSMN_ERROR_INVAL;
+                                       }
+                               }
+#else
+                       /* In non-strict mode every unquoted value is a primitive */
+                       default:
+#endif
+                               r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
+                               if (r < 0) return r;
+                               count++;
+                               if (parser->toksuper != -1 && tokens != NULL)
+                                       tokens[parser->toksuper].size++;
+                               break;
+
+#ifdef JSMN_STRICT
+                       /* Unexpected char in strict mode */
+                       default:
+                               return JSMN_ERROR_INVAL;
+#endif
+               }
+       }
+
+       for (i = parser->toknext - 1; i >= 0; i--) {
+               /* Unmatched opened object or array */
+               if (tokens[i].start != -1 && tokens[i].end == -1) {
+                       return JSMN_ERROR_PART;
+               }
+       }
+
+       return count;
+}
+
+/**
+ * Creates a new parser based over a given  buffer with an array of tokens
+ * available.
+ */
+void jsmn_init(jsmn_parser huge *parser) {
+       parser->pos = 0;
+       parser->toknext = 0;
+       parser->toksuper = -1;
+}
+
diff --git a/src/lib/jsmn/jsmnfar.h b/src/lib/jsmn/jsmnfar.h
new file mode 100644 (file)
index 0000000..fe27ed0
--- /dev/null
@@ -0,0 +1,77 @@
+#ifndef __JSMN_H_
+#define __JSMN_H_
+
+#include <stddef.h>
+
+#define JSMN_PARENT_LINKS
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * JSON type identifier. Basic types are:
+ *     o Object
+ *     o Array
+ *     o String
+ *     o Other primitive: number, boolean (true/false) or null
+ */
+typedef enum {
+       JSMN_PRIMITIVE = 0,
+       JSMN_OBJECT = 1,
+       JSMN_ARRAY = 2,
+       JSMN_STRING = 3
+} jsmntype_t;
+
+typedef enum {
+       /* Not enough tokens were provided */
+       JSMN_ERROR_NOMEM = -1,
+       /* Invalid character inside JSON string */
+       JSMN_ERROR_INVAL = -2,
+       /* The string is not a full JSON packet, more bytes expected */
+       JSMN_ERROR_PART = -3
+} jsmnerr_t;
+
+/**
+ * JSON token description.
+ * @param              type    type (object, array, string etc.)
+ * @param              start   start position in JSON data string
+ * @param              end             end position in JSON data string
+ */
+typedef struct {
+       jsmntype_t type;
+       int start;
+       int end;
+       int size;
+#ifdef JSMN_PARENT_LINKS
+       int parent;
+#endif
+} jsmntok_t;
+
+/**
+ * JSON parser. Contains an array of token blocks available. Also stores
+ * the string being parsed now and current position in that string
+ */
+typedef struct {
+       unsigned int pos; /* offset in the JSON string */
+       unsigned int toknext; /* next token to allocate */
+       int toksuper; /* superior token node, e.g parent object or array */
+} jsmn_parser;
+
+/**
+ * Create JSON parser over an array of tokens
+ */
+void jsmn_init(jsmn_parser huge *parser);
+
+/**
+ * Run JSON parser. It parses a JSON data string into and array of tokens, each describing
+ * a single JSON object.
+ */
+jsmnerr_t jsmn_parse(jsmn_parser huge *parser, const char huge *js, size_t len,
+               jsmntok_t huge *tokens, unsigned int num_tokens);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __JSMN_H_ */