ZEDA  1.6.18
zeda_ztk.h
Go to the documentation of this file.
1 /* ZEDA - Elementary Data and Algorithms
2  * Copyright (C) 1998 Tomomichi Sugihara (Zhidao)
3  */
9 #ifndef __ZEDA_ZTK_H__
10 #define __ZEDA_ZTK_H__
11 
13 #ifndef __KERNEL__
14 
15 #include <zeda/zeda_strlist.h>
16 
18 
19 /* ********************************************************** *//* ******************************************************* */
27 typedef struct _zFileStack{
28  char *pathname;
29  FILE *fp;
30  struct _zFileStack *prev;
31 } zFileStack;
32 
33 /* initialize a file stack. */
35 
36 /* check if the given file is already in a file stack, and if not,
37  * open the file and push it. */
39 
40 /* pop the latest file from a file stack. */
42 
43 /* destroy a file stack. */
45 
46 /* ********************************************************** *//* ******************************************************* */
50 typedef struct{
51  char *key;
53 } ZTKKeyField;
54 
55 /* print out a key field of ZTK format. */
56 __EXPORT void ZTKKeyFieldFPrint(FILE *fp, ZTKKeyField *kf);
57 
58 /* ********************************************************** *//* ******************************************************* */
63 
64 /* insert a new key field of ZTK format to a list. */
66 
67 /* destroy a list of key fields of ZTK format. */
69 
70 /* ********************************************************** *//* ******************************************************* */
74 typedef struct{
75  char *tag;
77 } ZTKTagField;
78 
79 /* print out a tagged field of ZTK format (for debug). */
80 __EXPORT void ZTKTagFieldFPrint(FILE *fp, ZTKTagField *tf);
81 
82 /* ********************************************************** *//* ******************************************************* */
87 
88 /* insert a new tagged field of ZTK format to a list. */
90 
91 /* destroy a list of tagged fields of ZTK format. */
93 
94 /* print out a list of tagged fields of ZTK format (for debug). */
96 
97 /* ********************************************************** *//* ******************************************************* */
101 typedef struct{
107 } ZTK;
108 
110 __EXPORT ZTK *ZTKInit(ZTK *ztk);
111 
113 __EXPORT void ZTKDestroy(ZTK *ztk);
114 
116 __EXPORT bool ZTKParseFP(ZTK *ztk, FILE *fp);
117 
119 __EXPORT bool ZTKParse(ZTK *ztk, char *path);
120 
122 __EXPORT int ZTKCountTag(ZTK *ztk, const char *tag);
123 
125 __EXPORT int ZTKCountKey(ZTK *ztk, const char *key);
126 
128 #define ZTKValPtr(ztk) (ztk)->val_cp
129 
130 #define ZTKVal(ztk) ( (ztk)->val_cp ? (ztk)->val_cp->data : "" )
131 
136 #define ZTKValCmp(ztk,str) ( strcmp( ZTKVal(ztk), str ) == 0 )
137 
139 #define ZTKKey(ztk) ( (ztk)->kf_cp ? (ztk)->kf_cp->data.key : "" )
140 
145 #define ZTKKeyCmp(ztk,str) ( strcmp( ZTKKey(ztk), str ) == 0 )
146 
148 #define ZTKTag(ztk) ( (ztk)->tf_cp ? (ztk)->tf_cp->data.tag : "" )
149 
154 #define ZTKTagCmp(ztk,str) ( strcmp( ZTKTag(ztk), str ) == 0 )
155 
157 #define ZTKRewind(ztk) ZTKTagRewind( ztk )
158 
160 __EXPORT int ZTKInt(ZTK *ztk);
162 __EXPORT double ZTKDouble(ZTK *ztk);
163 
165 __EXPORT void ZTKFPrint(FILE *fp, ZTK *ztk);
166 #define ZTKPrint(ztk) ZTKFPrint( stdout, ztk )
167 
168 /* ********************************************************** *//* ******************************************************* */
172 typedef struct{
173  char *str;
174  int num;
175  void *(* _eval)(void *, int, void *, ZTK *);
176  void (* _fprint)(FILE *, int, void *);
177 } ZTKPrp;
178 
179 /* evaluate a key field of a ZTK format processor based on a ZTK property. */
180 __EXPORT void *_ZTKEvalKey(void *obj, void *arg, ZTK *ztk, ZTKPrp prp[], int num);
181 #define ZTKEvalKey(obj,arg,ztk,prp) _ZTKEvalKey( obj, arg, ztk, prp, sizeof(prp)/sizeof(ZTKPrp) )
182 
183 /* print out a key field of a ZTK format processor based on a ZTK property. */
184 __EXPORT void _ZTKPrpKeyFPrint(FILE *fp, void *obj, ZTKPrp prp[], int num);
185 #define ZTKPrpKeyFPrint(fp,obj,prp) _ZTKPrpKeyFPrint( fp, obj, prp, sizeof(prp)/sizeof(ZTKPrp) )
186 
187 /* evaluate a tag field of a ZTK format processor based on a ZTK property. */
188 __EXPORT void *_ZTKEvalTag(void *obj, void *arg, ZTK *ztk, ZTKPrp prp[], int num);
189 #define ZTKEvalTag(obj,arg,ztk,prp) _ZTKEvalTag( obj, arg, ztk, prp, sizeof(prp)/sizeof(ZTKPrp) )
190 
191 /* print out a tag field of a ZTK format processor based on a ZTK property. */
192 __EXPORT void _ZTKPrpTagFPrint(FILE *fp, void *obj, ZTKPrp prp[], int num);
193 #define ZTKPrpTagFPrint(fp,obj,prp) _ZTKPrpTagFPrint( fp, obj, prp, sizeof(prp)/sizeof(ZTKPrp) )
194 
196 
197 #endif /* __KERNEL__ */
198 
199 #endif /* __ZEDA_ZTK_H__ */
char * str
Definition: zeda_ztk.h:173
int num
Definition: zeda_ztk.h:174
tagged field of ZTK format.
Definition: zeda_ztk.h:74
zFileStack * zFileStackPush(zFileStack *head, char *pathname)
void ZTKTagFieldFPrint(FILE *fp, ZTKTagField *tf)
ZTKKeyFieldListCell * ZTKKeyRewind(ZTK *ztk)
rewind the list of key fields of the current tagged field in a tag-and-key list of a ZTK format proce...
ZTKKeyFieldListCell * kf_cp
Definition: zeda_ztk.h:105
zStrList vallist
Definition: zeda_ztk.h:52
void ZTKFPrint(FILE *fp, ZTK *ztk)
print out ZTK to a file.
bool ZTKParse(ZTK *ztk, char *path)
scan a file and parse it into a tag-and-key list of a ZTK format processor.
double ZTKDouble(ZTK *ztk)
retrieve a real value from the current key field of the current tagged field in a tag-and-key list of...
list of tagged fields of ZTK format.
#define __END_DECLS
Definition: zeda_defs.h:30
int ZTKInt(ZTK *ztk)
retrieve an integer value from the current key field of the current tagged field in a tag-and-key lis...
FILE * fp
Definition: zeda_ztk.h:29
ZTKTagFieldListCell * ZTKTagFieldListNew(char buf[])
int ZTKCountTag(ZTK *ztk, const char *tag)
count the number of tagged fields with a specified tag in a tag-and-key list of a ZTK format processo...
zStrListCell * ZTKValRewind(ZTK *ztk)
rewind the list of value strings of the current key field of the current tagged field in a tag-and-ke...
void ZTKKeyFieldFPrint(FILE *fp, ZTKKeyField *kf)
zStrListCell * ZTKValNext(ZTK *ztk)
move to the next value string in the current key field of the current tagged field in a tag-and-key l...
bool ZTKParseFP(ZTK *ztk, FILE *fp)
scan and parse a file stream into a tag-and-key list of a ZTK format processor.
Definition: zeda_ztk.h:27
ZTKKeyFieldListCell * ZTKKeyNext(ZTK *ztk)
move to the next key field of the current tagged field in a tag-and-key list of a ZTK format processo...
ZTKTagFieldListCell * ZTKTagRewind(ZTK *ztk)
rewind the list of tagged field in a tag-and-key list of a ZTK format processor.
Definition: zeda_ztk.h:62
ZTKKeyFieldList kflist
Definition: zeda_ztk.h:76
char * pathname
Definition: zeda_ztk.h:28
void ZTKDestroy(ZTK *ztk)
destroy a ZTK format processor.
int ZTKCountKey(ZTK *ztk, const char *key)
count the number of key fields with a specified key of the current tagged field in a tag-and-key list...
zStrListCell * val_cp
Definition: zeda_ztk.h:106
void ZTKTagFieldListDestroy(ZTKTagFieldList *list)
a list of key fields of ZTK format.
void zFileStackDestroy(zFileStack *head)
file stack.
char * key
Definition: zeda_ztk.h:51
struct _zFileStack * prev
Definition: zeda_ztk.h:30
zFileStack * zFileStackPop(zFileStack *head)
void ZTKKeyFieldListDestroy(ZTKKeyFieldList *list)
struct _zFileStack zFileStack
#define __BEGIN_DECLS
Definition: zeda_defs.h:26
properties of a class described by a set of tag/key string and call-back functions.
Definition: zeda_ztk.h:172
ZTKKeyFieldListCell * ZTKKeyFieldListNew(ZTKKeyFieldList *list, char *key)
ZTK * ZTKInit(ZTK *ztk)
initialize a ZTK format processor.
void ZTKTagFieldListFPrint(FILE *fp, ZTKTagFieldList *list)
ZTKTagFieldListCell * ZTKTagNext(ZTK *ztk)
move to the next tagged field in a tag-and-key list of a ZTK format processor.
void * _ZTKEvalTag(void *obj, void *arg, ZTK *ztk, ZTKPrp prp[], int num)
#define zListClass(list_t, cell_t, data_t)
generate bidirectional ring list class.
Definition: zeda_list.h:48
zFileStack fs
Definition: zeda_ztk.h:102
Definition: zeda_strlist.h:23
void zFileStackInit(zFileStack *stack)
ZTKTagFieldListCell * tf_cp
Definition: zeda_ztk.h:104
void * _ZTKEvalKey(void *obj, void *arg, ZTK *ztk, ZTKPrp prp[], int num)
#define __EXPORT
Definition: zeda_compat.h:32
key field of ZTK format.
Definition: zeda_ztk.h:50
Definition: zeda_ztk.h:86
ZTK format processor.
Definition: zeda_ztk.h:101
char * tag
Definition: zeda_ztk.h:75
ZTKTagFieldList tflist
Definition: zeda_ztk.h:103
void _ZTKPrpKeyFPrint(FILE *fp, void *obj, ZTKPrp prp[], int num)
void _ZTKPrpTagFPrint(FILE *fp, void *obj, ZTKPrp prp[], int num)
Definition: zeda_strlist.h:23