/************************************************************************* > File Name: Cfg.h > Author: zhoulin > Created Time: Wed 16 Mar 2016 06:17:27 PM CST ************************************************************************/ 项目需要,有时候需要读取配置文件,大多以kv的方式。该小程序仅仅是读取字符,控制字符和空白行,空白字符是不读取的。 #ifndef _Cfg_H #define WORD "=" typedef struct _Item { void *K; void *V; struct _Item *Next; }Item; typedef struct _Node { int Size; char *Base; struct _Node *Next; struct _Item *iHead; }Node; typedef struct _Cfg { int Size; struct _Node *nHead; }Cfg; Cfg *CfgNew(const char *path); Node *GetNodeByBase(char *base,Cfg *cfg); char *GetValByKey(char *base,char *key,Cfg *Cfg); int CfgFree(Cfg *cfg); #define _Cfg_H #endif
/************************************************************************* > File Name: Cfg.c > Author: zhoulin > Created Time: Wed 16 Mar 2016 06:31:46 PM CST ************************************************************************/ #include "cfg.h" #include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #define bufSize 1024 char *trimSp(char *buf) { char tbuf[bufSize] = {'