首页 > 其他 > 详细

Linux下用C读取配置文件。类似ini这样。

时间:2014-03-09 05:51:26      阅读:897      评论:0      收藏:0      [点我收藏+]

Introduction
ccl is the customizable configuration library, a collection of functions for application programmers wishing to interface with user-editable configuration files containing key/value pairs.

ccl is customizable because it allows the comment, key/value, and string literal delimiters to be programatically specified at runtime.

ccl is designed to be simple and portable; it has a small interface consisting of five functions and is written in ANSI/ISO C. ccl uses avl‘s implemenation of binary search trees for backend storage.
 

Download
ccl is available via ftp from http://files.sbooth.org/.
 

Documentation
You can browse the library‘s contents by using the navigation bar at the top of this page. A good starting point is the globals page.
 

Example
An example is the best way to understand how ccl works. A configuration file named example.conf might contain:

## Sample configuration file
Desktop-Picture = /usr/images/earth.jpg
Position = Centered
"Background Color" = Black


The following code demonstrates how to parse and access this file using ccl:

bubuko.com,布布扣
#include "ccl/ccl.h"

struct ccl_t config;
const struct ccl_pair_t *iter;

/* Set configuration file details */
config.comment_char = #;
config.sep_char = =;
config.str_char = ";

/* Parse the file */
ccl_parse(&config, "example.conf");

/* Iterate through all key/value pairs */
while((iter = ccl_iterate(&config)) != 0) {
printf("(%s,%s)n", iter->key, iter->value);
}

/* Clean up */
ccl_release(&config);
bubuko.com,布布扣

 


When compiled, the snippet above produces the output

(Background Color,Black)
(Desktop-Picture,/usr/images/earth.jpg)
(Position,Centered)

Linux下用C读取配置文件。类似ini这样。,布布扣,bubuko.com

Linux下用C读取配置文件。类似ini这样。

原文:http://www.cnblogs.com/dieangel/p/3588294.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!