Giter VIP home page Giter VIP logo

config's Introduction

config

This is a c module for parsing an ini style configuration file. To use the library, include config.h in your program and call the function config_parse() with the full path and name of the file to parse and a callback function to call whenever a key = value assignment is parsed. The function will return an error code, defined in config.h. The default in the makefile is to use clang for compilation and linking. To use gcc, do something like cc=gcc ld=gcc make.

Configuration files can have optional sections that are defined inside section delimiter characters (default is '[' and ']'). See the "CONSTANTS" section of config.c for default delimiter, comment and assignment characters.

[section name]

If no section is defined, the callback function will receive a NULL in the section argument. Section names are a little less restricted than keys and can contain whitespace.

Assignments are made in the configuration using the assignment operator (default is '='). Each assignment must have a key and a value.

key = value

Values can be delimited by enclosing them in the delimiter character (default '"').

key = "delimited value"

If a value is not delimited, there are some restrictions on what it can contain. It can't have whitespace in it, comments or newlines.

Keys also have these limitations and cannot be delimited.

The callback function supplied to the config_parse function will be called with the currently active section name (if any, otherwise NULL), the current key and the value assigned to that key. The current line number can be retrieved using the config_get_line_number() function. Line numbers start at 1. The section, key and value passed to the callback are allocated and freed by the config module, internally. If any of those need to be preserved, the application code will have to allocate an appropriate sized block and copy the values from the pointers passed to the handler function into the application's allocated memory as the pointers will be invalid as soon as the handler function returns. The callback function can return its own error code (a code greater than CONFIG_ERROR_COUNT) to indicate a problem particular to the application.

The module also supplies a function config_get_error_string() that can be used to get descriptive text for any error returned by the config_parse() function. If the error code passed to this function is >= CONFIG_ERROR_COUNT, the text returned will be "Unknown error".

See the included test.c and test.ini for example usage. Run make to build the example program from test.c and run it from the command line to see how the library behaves with the supplied test.ini.

There are no limits on line lengths in the config file, nor length limits for sections, keys or values.

[email protected]

config's People

Contributors

yoppeh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.