00001 
00002 #ifndef  __JBXL_TINY_JSON_H_
00003 #define  __JBXL_TINY_JSON_H_
00004 
00005 
00024 #include "tools.h"
00025 #include "ttree.h"
00026 #include "jbxl_state.h"
00027 
00028 
00029 
00030 #define  JSON_ANCHOR_NODE    JBXL_STATE_ANCHOR      
00031 #define  JSON_TEMP_NODE             -1              
00032 #define  JSON_BRACKET_NODE           1              
00033 #define  JSON_DATA_NODE              2              
00034 #define  JSON_ARRAY_NODE             3              
00035 #define  JSON_ARRAY_VALUE_NODE       4              
00036 
00037 
00038 
00039 #define  JSON_VALUE_UNRESOLV        -1              
00040 #define  JSON_VALUE_NULL             0              
00041 #define  JSON_VALUE_INT              1              
00042 #define  JSON_VALUE_REAL             2              
00043 #define  JSON_VALUE_BOOL             3              
00044 #define  JSON_VALUE_STR              4              
00045 #define  JSON_VALUE_OBJ              5              
00046 #define  JSON_VALUE_ARRAY            6              
00047 
00048 
00049 #define  JSON_ONELINE_FORMAT         0              
00050 #define  JSON_CRLF_FORMAT            1              
00051 #define  JSON_INDENT_FORMAT          2              
00052 
00053 
00055 
00056 
00057 #define new_json_node()         new_tTree_node()            
00058 #define new_json_anchor_node()  new_tTree_anchor_node()     
00059 #define new_json()              new_tTree_node()            
00060 #define new_json_anchor()       new_tTree_anchor_node()     
00061 #define new_json_anchor_node()  new_tTree_anchor_node()     
00062 #define del_json_anchor(t)      del_tTree_anchor_node((t))  
00063 #define del_json_anchor_node(t) del_tTree_anchor_node((t))  
00064 
00065 #define del_json(j)             del_tTree((j))          
00066 #define del_json_node(j)        del_tTree_node((j))     
00067 #define free_json(j)            free_tTree_node((j))    
00068 #define free_json_node(j)       free_tTree_node((j))    
00069 
00070 
00071 
00157 typedef  tTree  tJson;
00158 
00159 
00160 
00161 
00163 
00164 
00165 tJson*   json_parse(char* pp, int num);                         
00166 tJson*   json_parse_prop(tJson* json, char* pp, int num);       
00167 tJson*   json_parse_seq (tJson* json, char* pp, int num);       
00168 tJson*   json_array_parse(tJson* json, char* pp, int num);      
00169 
00170 tJson*   _json_array_parse(tJson* json, int num);                               
00171 tJson*   _json_parse_term (tJson* json, char* st, char* ed, const char* com);   
00172 
00173 
00175 
00176 
00177 Buffer   json_inverse_parse(tJson* pp, int mode);                                       
00178 Buffer   json_inverse_parse_opt(tJson* pp, const char* crlf, const char* space);        
00179 void     print_json(FILE* fp, tJson* json, int mode);                                   
00180 void     print_json_opt(FILE* fp, tJson* json, const char* crlf, const char* space);    
00181 
00182 void     _json_to_Buffer(tJson* pp, Buffer* buf, const char* crlf, const char* space);  
00183 
00184 #define  print_tJson(f, j)          print_tTree((f), (j))
00185 #define  print_tJson_tree(f, j, s)  print_tTree_tree((f), (j), (s))
00186 
00188 
00189 
00190 tJson*   json_parse_file(const char* fn, int num);                      
00191 
00192 void     json_set_str_val(tJson* json, char* str);                      
00193 void     json_copy_val (tJson* f_json, tJson* t_json);                  
00194 void     json_copy_data(tJson* f_json, tJson* t_json);                  
00195 
00196 void     insert_json_nodes(tJson* parent, tJson* child);
00197 
00198 tJson*   join_json(tJson* parenr, tJson** child);                       
00199 #define  dup_merge_json(p, c)               dup_merge_tTree((p), (c))   
00200 
00201 
00203 
00204 
00205 #define  find_top_json(p, n)                search_top_bracket_json((p), (n))               
00206 #define  find_sister_json(p, n)             search_sister_json((p), (n))                    
00207 #define  find_key_json(p, k)                search_key_json((p), (k), FALSE, 1)             
00208 #define  find_key_child_json(p, k)          search_key_child_json( (p), (k), FALSE)         
00209 #define  find_key_sister_json(p, k)         search_key_sister_json((p), (k), FALSE)         
00210 #define  find_key_json_obj(p, k)            search_key_json_obj((p), (k))                   
00211 #define  find_double_key_json(p, k1, k2)    search_double_key_json((p), (k1), (k2), FALSE)  
00212 
00213 tJson*   search_top_bracket_json(tJson* pp, int nn);                        
00214 tJson*   search_sister_json(tJson* pp, int nn);                             
00215 
00216 tJson*   search_key_json(tJson* pp, char* key, int needval, int nn);        
00217 tJson*   search_key_child_json(tJson* pp, char* key, int needval);          
00218 tJson*   search_key_sister_json(tJson* pp, char* key, int needval);         
00219 tJson*   search_key_json_obj(tJson* pp, char* key, int nn);                 
00220 tJson*   search_double_key_json(tJson* pp, char* key1, char* key2, int needval);  
00221 
00222 tJson*   _search_key_json(tJson* pp, char* key, int need, int* nn);         
00223 tJson*   _search_key_json_obj(tJson* pp, char* key, int* nn);               
00224 int      _json_check_node_bykey(tJson* pp, char* key, int needval, int nn); 
00225 
00226 Buffer   get_json_val(tJson* json);
00227 Buffer   get_key_json_val(tJson* pp, char* key, int nn);                    
00228 Buffer   get_key_sister_json_val(tJson* pp, char* key);                     
00229 Buffer   get_double_key_json_val(tJson* pp, char* key1, char* key2);        
00230 
00231 Buffer   get_Buffer_from_json(tJson* json);
00232 char*    get_string_from_json(tJson* json);                                 
00233 
00234 
00235 tList*   search_all_node_strval_json(tJson* json, char* name, char* val);   
00236 tList*   _search_all_node_strval_json(tList* list, tJson* pp, char* name, char* val);   
00237 
00238 
00239 
00240 #endif  // __JBXL_TINY_JSON_H_
00241