1 INI file是配置文件,保存的是数据,主要是系统或者软件的配置信息。
Iniparser则是对INI file的解析或者操作(get,set,delete 等等)。
下面分别就INI file的文件格式和Iniparser提供的APIs进行说明。
2、INI file
Properties(Keys)
INI 每个 name=value
Sections
Keys 在 一个 [section]
最终是用section:key来定位一个
Case insensitivity
section
Comments
注释是以分 开头的
; comment line
3、Iniparser
iniParser: stand-alone ini parser library in ANSI C
可以通过该 站访问iniparser的主页http://ndevilla.free.fr/iniparser/
你也可以通过github下载source code tree
git clone http://github.com/ndevilla/iniparser.git
iniparser iniparser是针对INI INI file之前介绍过,我觉得INI file里面的保存的数据最重要的就是key了,而key有两部分组成,名称 所以需要用section:key来定位一个key.
iniparser ├──
dictionary.h里面声明了一些直接解析 iniparser.h里面声明了一些提供用户操作的 需要说明的是iniparser.h里面的
iniparser.h
Functions
int
iniparser_getnsec (dictionary *d)
Get number of sections in a dictionary.
char *
iniparser_getsecname (dictionary *d, int n)
Get name for section n in a dictionary.
void
iniparser_dump_ini (dictionary *d, FILE *f)
Save a dictionary to a loadable ini file.
void
iniparser_dumpsection_ini (dictionary *d, char *s, FILE *f)
Save a dictionary section to a loadable ini file.
void
iniparser_dump (dictionary *d, FILE *f)
Dump a dictionary to an opened file pointer.
int
iniparser_getsecnkeys (dictionary *d, char *s)
Get the number of keys in a section of a dictionary.
char **
iniparser_getseckeys (dictionary *d, char *s)
Get the number of keys in a section of a dictionary.
char *
iniparser_getstring (dictionary *d, const char *key, char *def)
Get the string associated to a key.
int
iniparser_getint (dictionary *d, const char *key, int notfound)
Get the string associated to a key, convert to an int.
double
iniparser_getdouble (dictionary *d, const char *key, double notfound)
Get the string associated to a key, convert to a double.
int
iniparser_getboolean (dictionary *d, const char *key, int notfound)
Get the string associated to a key, convert to a boolean.
int
iniparser_set (dictionary *ini, const char *entry, const char *val)
Set an entry in a dictionary.
void
iniparser_unset (dictionary *ini, const char *entry)
Delete an entry in a dictionary.
int
iniparser_find_entry (dictionary *ini, const char *entry)
Finds out if a given entry exists in a dictionary.
dictionary *
iniparser_load (const char *ininame)
Parse an ini file and return an allocated dictionary object.
void
iniparser_freedict (dictionary *d)
Free all memory associated to an ini dictionary.
参考资料:
INI file from wiki
实例:
1 $ gcc -fPIC -c dictionary.c iniparser.c
$ gcc -shared -o libiniparser.so dictionary.o iniparser.o -lc
3、编写调用
-
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!
dictionary.h里面声明了一些直接解析 iniparser.h里面声明了一些提供用户操作的 需要说明的是iniparser.h里面的
iniparser.h
Functions
int
iniparser_getnsec (dictionary *d)
Get number of sections in a dictionary.
char *
iniparser_getsecname (dictionary *d, int n)
Get name for section n in a dictionary.
void
iniparser_dump_ini (dictionary *d, FILE *f)
Save a dictionary to a loadable ini file.
void
iniparser_dumpsection_ini (dictionary *d, char *s, FILE *f)
Save a dictionary section to a loadable ini file.
void
iniparser_dump (dictionary *d, FILE *f)
Dump a dictionary to an opened file pointer.
int
iniparser_getsecnkeys (dictionary *d, char *s)
Get the number of keys in a section of a dictionary.
char **
iniparser_getseckeys (dictionary *d, char *s)
Get the number of keys in a section of a dictionary.
char *
iniparser_getstring (dictionary *d, const char *key, char *def)
Get the string associated to a key.
int
iniparser_getint (dictionary *d, const char *key, int notfound)
Get the string associated to a key, convert to an int.
double
iniparser_getdouble (dictionary *d, const char *key, double notfound)
Get the string associated to a key, convert to a double.
int
iniparser_getboolean (dictionary *d, const char *key, int notfound)
Get the string associated to a key, convert to a boolean.
int
iniparser_set (dictionary *ini, const char *entry, const char *val)
Set an entry in a dictionary.
void
iniparser_unset (dictionary *ini, const char *entry)
Delete an entry in a dictionary.
int
iniparser_find_entry (dictionary *ini, const char *entry)
Finds out if a given entry exists in a dictionary.
dictionary *
iniparser_load (const char *ininame)
Parse an ini file and return an allocated dictionary object.
void
iniparser_freedict (dictionary *d)
Free all memory associated to an ini dictionary.
参考资料:
INI file from wiki
实例:
1 $ gcc -fPIC -c dictionary.c iniparser.c
$ gcc -shared -o libiniparser.so dictionary.o iniparser.o -lc
3、编写调用
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!