zoukankan      html  css  js  c++  java
  • Linux下用C读取配置文件。类似ini这样。

    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:

    #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);


    When compiled, the snippet above produces the output

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

  • 相关阅读:
    POJ 1981 最大点覆盖问题(极角排序)
    POJ 1286 Pólya定理
    POJ 1830 高斯消元
    HDU 3364 高斯消元
    Educational Codeforces Round 42D. Merge Equals(STL)
    ZOJ 3955:Saddle Point(思维)
    POJ 3301:Texas Trip(计算几何+三分)
    SCUT 125 :笔芯回文(DP)
    ZOJ 3953:Intervals(优先队列+思维)
    Codeforces Gym101097I:Sticks (思维)
  • 原文地址:https://www.cnblogs.com/dieangel/p/3588294.html
Copyright © 2011-2022 走看看