Giter VIP home page Giter VIP logo

tomlc99's Introduction

tomlc99

TOML in c99; v0.5.0 compliant.

Usage

Please see the toml.h file for details. What follows is a simple example that parses this config file:

[server]
    host = "www.example.com"
    port = 80

For each config param, the code first extracts a raw value and then convert it to a string or integer depending on context.


    FILE* fp;
    toml_table_t* conf;
    toml_table_t* server;
    const char* raw;
    char* host;
    int64_t port;
    char errbuf[200];

    /* open file and parse */
    if (0 == (fp = fopen(FNAME, "r"))) {
	return handle_error();
    }
    conf = toml_parse_file(fp, errbuf, sizeof(errbuf));
    fclose(fp);
    if (0 == conf) {
	return handle_error();
    }

    /* locate the [server] table */
    if (0 == (server = toml_table_in(conf, "server"))) {
	return handle_error();
    }

    /* extract host config value */
    if (0 == (raw = toml_raw_in(server, "host"))) {
	return handle_error();
    }
    if (toml_rtos(raw, &host)) {
	return handle_error();
    }

    /* extract port config value */
    if (0 == (raw = toml_raw_in(server, "port"))) {
	return handle_error();
    }
    if (toml_rtoi(raw, &port)) {
	return handle_error();
    }

    /* done with conf */
    toml_free(conf);

    /* use host and port */
    do_work(host, port);

    /* clean up */
    free(host);

Building

A normal make suffices. Alternately, you can also simply include the toml.c and toml.h files in your project.

Testing

To test against the standard test set provided by BurntSushi/toml-test:

   % make
   % cd test1
   % bash build.sh   # do this once
   % bash run.sh     # this will run the test suite

To test against the standard test set provided by iarna/toml:

   % make
   % cd test2
   % bash build.sh   # do this once
   % bash run.sh     # this will run the test suite

tomlc99's People

Contributors

bamchoh avatar cktan avatar dvdx avatar iain-anderson avatar miniwoffer avatar obreitwi avatar theakman2 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.