- /*****************************
- writed by zhangliang
- email: liangzhws@foxmail.com
- date:2016/6/19
- *****************************/
- /*************************
- data model
- CFG----------
- \\-----------
- | cg_count |
- CFGNODE----->| cn_count |
- | next |---
- | node_name | \\
- | \\0 | \\
- | key | |
- | \\0 | |
- | value | |
- | key | |
- | \\0 | |
- | value | |
- . /
- . /
- . _ /
- CFGNODE----->| cn_count |<
- | next |----> NULL
- | node_name |
- | \\0 |
- .
- .
- .
- *************************/
- #ifndef _CFG_H_
- #define _CFG_H_ 1
- typedef struct ConfigNode {
- int cn_count;
- struct ConfigNode * next;
- char cn_buf[];
- }ConfigNode_t,* CFGNODE;
- typedef struct Config {
- int cg_count;
- char cg_buf[];
- }Config_t, * CFG;
- /**
- @name: readConfig
- @function: init CFGfrom config file
- @param1: #const char * fileptr# file path
- @return: #CFG# return null is failure ,other is success
- */
- CFG readConfig(const char * fileptr);
- /**
- @name: closeConfig
- @function: destory CFG
- @param1: #CFG cgptr# CFGobject
- @return: #void#
- */
- void closeConfig(CFG cgptr);
- /**
- @name: getConfigNode
- @function: get the node from config_t object
- @param1: #const CFG* cgptr# CFGobject;
- @param2: #char * nameptr# node's name
- @return: #CFGNODE*# return null is the node not exist in config, other return the config_node object
- */
- CFGNODE getConfigNode(const CFG cgptr, const char * nameptr);
- /**
- @name: getConfigField
- @function: get the value of key from config_node object
- @param1: #CFGNODE cnptr# config_node object
- @param2: #const char * keyptr# key's name
- */
- char * getConfigField(CFGNODE cnptr, const char * keyptr);
- /**
- @name: getConfigNodeField
- @function: get the value of key from config object
- @param1: #CFG cgptr# CFGobject
- @param2: #const char * nodeptr# node's name
- @param3: #const char * keyptr# key's name
- @return: #char * # return NULL is means the node not exist or the value is empty, other is value
- */
- char * getConfigNodeField(const CFG cgptr, const char * nodeptr, const char * keyptr);
- /**
- */
- #endif /* _CFG_H_ */
- //该片段来自于http://www.codesnippet.cn/detail/1507201513086.html
来源: http://www.codesnippet.cn/detail/1507201513086.html