From 23e40384f796beb2c14b86b6ef23dc25b6785d9b Mon Sep 17 00:00:00 2001 From: Olof Hagsand Date: Mon, 13 Nov 2017 17:11:31 +0000 Subject: [PATCH] JSON negative number patch --- CHANGELOG.md | 2 +- lib/src/clixon_json.c | 17 +++++++---------- lib/src/clixon_json_parse.l | 2 +- lib/src/clixon_xml.c | 3 ++- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 253bc24d..5eeaf5c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ * When user callbacks such as statedata() call returns -1, clixon_backend no longer silently exits. Instead a log is printed and an RPC error is returned. -* Added Floating point support to JSON +* Added Floating point and negative number support to JSON * Restconf: http cookie sent as attribute in rpc restconf_post operations to backend. * Added option CLICON_CLISPEC_FILE as complement to CLICON_CLISPEC_DIR to specify single CLI specification file, not only directory containing files. diff --git a/lib/src/clixon_json.c b/lib/src/clixon_json.c index 496151de..265c80f8 100644 --- a/lib/src/clixon_json.c +++ b/lib/src/clixon_json.c @@ -632,7 +632,7 @@ json_parse_str(char *str, * Example compile: gcc -g -o json -I. -I../clixon ./clixon_json.c -lclixon -lcligen * Example run: - echo "" | xml + echo '{"foo": -23}' | ./json */ #if 0 /* Test program */ @@ -643,20 +643,17 @@ usage(char *argv0) exit(0); } -#define BUFLEN 1024 /* Size of xml read buffer */ int main(int argc, char **argv) { cxobj *xt; cxobj *xc; cbuf *cb = cbuf_new(); - int maxbuf = BUFLEN; - char *xmlbuf = NULL; - char *buf = NULL; - int i; - int c; - int len; - FILE *f = stdin; + char *buf = NULL; + int i; + int c; + int len; + FILE *f = stdin; if (argc != 1){ usage(argv[0]); @@ -689,7 +686,7 @@ main(int argc, char **argv) return -1; xc = NULL; while ((xc = xml_child_each(xt, xc, -1)) != NULL) { - xmltree2cbuf(cb, xc, 0); /* dump data structures */ + xmltree2cbuf(cb, xc, 0); /* dump data structures */ //clicon_xml2cbuf(cb, xc, 0, 1); /* print xml */ } fprintf(stdout, "%s", cbuf_get(cb)); diff --git a/lib/src/clixon_json_parse.l b/lib/src/clixon_json_parse.l index d864c655..7e0252ad 100644 --- a/lib/src/clixon_json_parse.l +++ b/lib/src/clixon_json_parse.l @@ -100,7 +100,7 @@ exp ({integer}|{real})[eE][+-]{integer} null { return J_NULL; } false { return J_FALSE; } true { return J_TRUE; } -({integer}|{real}|{exp}) { clixon_json_parselval.string = strdup(yytext); return J_NUMBER;} +\-?({integer}|{real}|{exp}) { clixon_json_parselval.string = strdup(yytext); return J_NUMBER;} . { return -1; } \" { BEGIN(START); return J_DQ; } \\ { BEGIN(ESCAPE); } diff --git a/lib/src/clixon_xml.c b/lib/src/clixon_xml.c index 7a0cdc33..2149c409 100644 --- a/lib/src/clixon_xml.c +++ b/lib/src/clixon_xml.c @@ -1104,7 +1104,8 @@ xmltree2cbuf(cbuf *cb, for (i=0; i