VCOM Linux Driver
Advantech Inc.
Loading...
Searching...
No Matches
jstree_read.h
Go to the documentation of this file.
1#ifndef _JSTREE_READ_H
2#define _JSTREE_READ_H
3
4#include <stdarg.h>
5
6#define PP_RSEQ_N() \
7 127,126,125,124,123,122,121,120, \
8 119,118,117,116,115,114,113,112,111,110, \
9 109,108,107,106,105,104,103,102,101,100, \
10 99,98,97,96,95,94,93,92,91,90, \
11 89,88,87,86,85,84,83,82,81,80, \
12 79,78,77,76,75,74,73,72,71,70, \
13 69,68,67,66,65,64,63,62,61,60, \
14 59,58,57,56,55,54,53,52,51,50, \
15 49,48,47,46,45,44,43,42,41,40, \
16 39,38,37,36,35,34,33,32,31,30, \
17 29,28,27,26,25,24,23,22,21,20, \
18 19,18,17,16,15,14,13,12,11,10, \
19 9,8,7,6,5,4,3,2,1,0
20
21#define PP_ARG_N( \
22 _1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
23 _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
24 _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
25 _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
26 _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
27 _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
28 _61,_62,_63,_64,_65,_66,_67,_68,_69,_70, \
29 _71,_72,_73,_74,_75,_76,_77,_78,_79,_80, \
30 _81,_82,_83,_84,_85,_86,_87,_88,_89,_90, \
31 _91,_92,_93,_94,_95,_96,_97,_98,_99,_100, \
32 _101,_102,_103,_104,_105,_106,_107,_108,_109,_110, \
33 _111,_112,_113,_114,_115,_116,_117,_118,_119,_120, \
34 _121,_122,_123,_124,_125,_126,_127,N,...) N
35
36#define PP_NARG_(...) \
37 PP_ARG_N(__VA_ARGS__)
38
39#define PP_NARG(...) \
40 PP_NARG_(__VA_ARGS__,PP_RSEQ_N())
41
42static inline int _do_jstree_read(int argc, _tree_node *input, _tree_node **output, ...)
43{
44 int loop = argc - 2;
45 int iter;
46 int i;
47 va_list ap;
48 _tree_node * rnode = input;
49
50 argc-= 2;
51
52 if(argc < 0){
53 return -1;
54 }
55
56 i = 0;
57 va_start(ap, output);
58 while( i < loop){
59 char *argv;
60 argv = va_arg(ap, char *);
61 //printf("argv = %s\n", argv);
62 if(rnode == 0){
63 printf("cannot step forward\n");
64 break;
65 }
66
67 if(sscanf(argv, "[%d]", &iter)){
68 // printf("jumping to the %dth node\n", iter);
69 rnode = next_node(rnode, iter);
70 if(rnode == 0){
71 //printf("->[%d]:N/A", iter);
72 break;
73 }else if(rnode->data.type == JSMN_STRING){
74 //printf("->[%d](string): %s", iter, rnode->data.data);
75 if(i + 1 < loop){
76 rnode = rnode->r;
77 if(rnode == 0 ){
78 //printf("cannot move forward");
79 break;
80 }else if(rnode->data.type == JSMN_ARRAY){
81 rnode = rnode->r;
82 // printf("->(array)");
83 }else if(rnode->data.type == JSMN_OBJECT){
84 rnode = rnode->r;
85 // printf("->(object)");
86 }
87 }
88 }else if(rnode->data.type == JSMN_PRIMITIVE){
89 //printf("->[%d](primitive): %s", iter, rnode->data.data);
90 }else if(rnode->data.type == JSMN_OBJECT){
91 //printf("->[%d](object)", iter);
92 rnode = rnode->r;
93 }else if(rnode->data.type == JSMN_ARRAY){
94 //printf("->[%d](array)", iter);
95 rnode = rnode->r;
96 }else{
97 //printf("->[%d]unknonw type %x", iter, rnode->data.type);
98 break;
99 }
100
101 }else{
102
103 //printf("->%s", argv);
104 rnode = find_node(rnode, argv);
105
106 if(rnode == 0){
107 //printf("not found");
108 break;
109 }else if(rnode->r == 0){
110 //printf(":has no child");
111 break;
112 }else if(rnode->r->data.type == JSMN_STRING){
113 //printf("->(string): %s", rnode->r->data.data);
114 rnode = rnode->r;
115 i++;
116 break;
117 }else if(rnode->r->data.type == JSMN_PRIMITIVE){
118 //printf("->(primitive): %s", rnode->r->data.data);
119 rnode = rnode->r;
120 i++;
121 break;
122 }else if(rnode->r->data.type == JSMN_OBJECT){
123 //printf("->(object)");
124 rnode = rnode->r->r;
125 }else if(rnode->r->data.type == JSMN_ARRAY){
126 //printf("->(array)");
127 rnode = rnode->r->r;
128 }else{
129 //printf("child unknonw type %x", rnode->r->data.type);
130 break;
131 }
132 }
133 i++;
134 }
135 //printf("\n");
136 va_end(ap);
137
138 //printf("ret = %d\n",ret);
139
140 *output = rnode;
141
142 return i;
143}
144
145//#define readJSTree(...) _do_jstree_read(PP_NARG(__VA_ARGS__), __VA_ARGS__)
146#define jstree_read(...) _do_jstree_read(PP_NARG(__VA_ARGS__), __VA_ARGS__)
147
148#endif
@ JSMN_PRIMITIVE
Definition jsmn.h:22
@ JSMN_OBJECT
Definition jsmn.h:19
@ JSMN_ARRAY
Definition jsmn.h:20
@ JSMN_STRING
Definition jsmn.h:21
_tree_node * find_node(_tree_node *tree, char *key)
Definition jstree.c:386
_tree_node * next_node(_tree_node *node, int step)
Definition jstree.c:421
int type
Definition jstree.h:4
Definition jstree.h:8
struct _t_treenode * r
Definition jstree.h:11
_treenode_data data
Definition jstree.h:9