Introduction
Introduction Statistics Contact Development Disclaimer Help
rename TYPE_* to JSON_TYPE_* - json2tsv - JSON to TSV converter
git clone git://git.codemadness.org/json2tsv
Log
Files
Refs
README
LICENSE
---
commit e569792c8bc41e19f1702ae57bbfbebc9fc64bff
parent cc245b50c91a1d3b3618773f289a3d4bb670df75
Author: Hiltjo Posthuma <[email protected]>
Date: Sun, 29 Dec 2019 18:34:39 +0100
rename TYPE_* to JSON_TYPE_*
Diffstat:
M json.c | 20 ++++++++++----------
M json.h | 12 ++++++------
M json2tsv.c | 7 ++++---
3 files changed, 20 insertions(+), 19 deletions(-)
---
diff --git a/json.c b/json.c
@@ -121,7 +121,7 @@ handlechr:
expect = EXPECT_VALUE;
break;
case '"':
- nodes[depth].type = TYPE_STRING;
+ nodes[depth].type = JSON_TYPE_STRING;
escape = 0;
len = 0;
while (1) {
@@ -221,11 +221,11 @@ escchr:
nodes[depth].index = 0;
if (c == '[') {
- nodes[depth].type = TYPE_ARRAY;
+ nodes[depth].type = JSON_TYPE_ARRAY;
expect = EXPECT_ARRAY_VALUE;
} else if (c == '{') {
iskey = 1;
- nodes[depth].type = TYPE_OBJECT;
+ nodes[depth].type = JSON_TYPE_OBJECT;
expect = EXPECT_OBJECT_STRING;
}
@@ -240,8 +240,8 @@ escchr:
case ']':
case '}':
if (!depth ||
- (c == ']' && nodes[depth - 1].type != TYPE_ARRAY) ||
- (c == '}' && nodes[depth - 1].type != TYPE_OBJECT))
+ (c == ']' && nodes[depth - 1].type != JSON_TYPE_ARR…
+ (c == '}' && nodes[depth - 1].type != JSON_TYPE_OBJ…
JSON_INVALID(); /* unbalanced nodes */
nodes[--depth].index++;
@@ -252,7 +252,7 @@ escchr:
JSON_INVALID(); /* unbalanced nodes */
nodes[depth - 1].index++;
- if (nodes[depth - 1].type == TYPE_OBJECT) {
+ if (nodes[depth - 1].type == JSON_TYPE_OBJECT) {
iskey = 1;
expect = EXPECT_STRING;
} else {
@@ -262,7 +262,7 @@ escchr:
case 't': /* true */
if (GETNEXT() != 'r' || GETNEXT() != 'u' || GETNEXT() …
JSON_INVALID();
- nodes[depth].type = TYPE_BOOL;
+ nodes[depth].type = JSON_TYPE_BOOL;
cb(nodes, depth + 1, "true");
expect = EXPECT_END;
break;
@@ -270,19 +270,19 @@ escchr:
if (GETNEXT() != 'a' || GETNEXT() != 'l' || GETNEXT() …
GETNEXT() != 'e')
JSON_INVALID();
- nodes[depth].type = TYPE_BOOL;
+ nodes[depth].type = JSON_TYPE_BOOL;
cb(nodes, depth + 1, "false");
expect = EXPECT_END;
break;
case 'n': /* null */
if (GETNEXT() != 'u' || GETNEXT() != 'l' || GETNEXT() …
JSON_INVALID();
- nodes[depth].type = TYPE_NULL;
+ nodes[depth].type = JSON_TYPE_NULL;
cb(nodes, depth + 1, "null");
expect = EXPECT_END;
break;
default: /* number */
- nodes[depth].type = TYPE_NUMBER;
+ nodes[depth].type = JSON_TYPE_NUMBER;
p = 0;
pri[p++] = c;
expect = EXPECT_END;
diff --git a/json.h b/json.h
@@ -1,12 +1,12 @@
#include <stdint.h>
enum JSONType {
- TYPE_ARRAY = 'a',
- TYPE_OBJECT = 'o',
- TYPE_STRING = 's',
- TYPE_BOOL = 'b',
- TYPE_NULL = '?',
- TYPE_NUMBER = 'n'
+ JSON_TYPE_ARRAY = 'a',
+ JSON_TYPE_OBJECT = 'o',
+ JSON_TYPE_STRING = 's',
+ JSON_TYPE_BOOL = 'b',
+ JSON_TYPE_NULL = '?',
+ JSON_TYPE_NUMBER = 'n'
};
enum JSONError {
diff --git a/json2tsv.c b/json2tsv.c
@@ -43,12 +43,13 @@ processnode(struct json_node *nodes, size_t depth, const ch…
printvalue(nodes[i].name);
if (i + 1 == depth &&
- (nodes[i].type == TYPE_OBJECT || nodes[i].type == TYPE_ARR…
+ (nodes[i].type == JSON_TYPE_OBJECT ||
+ nodes[i].type == JSON_TYPE_ARRAY))
continue;
- if (nodes[i].type == TYPE_OBJECT) {
+ if (nodes[i].type == JSON_TYPE_OBJECT) {
putchar('.');
- } else if (nodes[i].type == TYPE_ARRAY) {
+ } else if (nodes[i].type == JSON_TYPE_ARRAY) {
if (nflag) {
printf("[%zu]", nodes[i].index);
} else {
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.