Skip to content
No description, website, or topics provided.
C
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
env
.gitignore
LICENSE
README
changelist.txt
gs.h
main.c
settings.cfg

README

--------------------------------------------------------------------------------
 Introduction
--------------------------------------------------------------------------------

This is my configuration file preprocessor.
It reads a yaml-esque human-readable configuration file and outputs C code that
you `#include' into your C program.

Here's an example:

settings.cfg:
+------------------------------------------------------------------------------+
|type: monster                                                                 |
|name: Bruce                                                                   |
|attributes:                                                                   |
|        color: brown                                                          |
|        class: barbarian                                                      |
|        damage: Maximum!                                                      |
|game_speed: 0.5                                                               |
+------------------------------------------------------------------------------+

shell:
+------------------------------------------------------------------------------+
|> gscfg settings.cfg --struct-name monster_cfg --style snake_case             |
+------------------------------------------------------------------------------+

Now include settings.c in your C program:
+------------------------------------------------------------------------------+
|#include "settings.c"                                                         |
|#include <stdio.h>                                                            |
|                                                                              |
|void                                                                          |
|main()                                                                        |
|{                                                                             |
|        monster_cfg cfg;                                                      |
|        monster_cfg_init(&cfg);                                               |
|        if(monster_cfg_has_key(&cfg, "attributes.color"))                     |
|        {                                                                     |
|                printf("Monster is the color: %s\n",                          |
|                       monster_cfg_get(&cfg, "attributes.color"));            |
|        }                                                                     |
|        printf("Monster is a: %s\n", cfg.attributes.class);                   |
|}                                                                             |
+------------------------------------------------------------------------------+

--------------------------------------------------------------------------------
 Setup, Building and Running
--------------------------------------------------------------------------------

> git clone https://GrooveStomp@bitbucket.org/GrooveStomp/gscfg.git
> cd gscfg
> source env/shell
> build
> ./gscfg --help

--------------------------------------------------------------------------------
 Motivation
--------------------------------------------------------------------------------

For a side project I wanted to use a really lightweight library for reading
config files. Preferrably this library would not use dynamic allocations and
would give me an in-memory structure to interact with.

I never did find something to fully satisfy my needs, but I did find some
almost-there libraries that might work for you:

- minIni
  * http://www.compuphase.com/minini.htm
  * Very small, easy to include in a project and works as you expect.
    The only downside is that it constantly interacts with the OS for file IO
    to interact with the config file.

- libyaml
  * http://pyyaml.org/wiki/LibYAML
  * I didn't even bother trying to hook this up. The interface does not look
    intuitive and it's nowhere near as lightweight as minIni.

- MessagePack
  * http://msgpack.org/
  * Not really a good fit for what I want.  I want config files in human-
    readable format, but MessagePack is about converting human-readable JSON-
    like data into binary form. To use this I'd have to read the config file,
    write it to a MessagePack object in memory, then read from it.
  * https://github.com/camgunz/cmp looks really lightweight and easy to use.
  * I may end up just using this.

- Tiny Config File Parser (TCFP)
  * https://sourceforge.net/projects/tcfp/
  * Small, easy to embed. I actually was using this but struggled to have it
    actually read data from my config file as expected. Probably user error.
    It also does dynamic allocations with malloc and is in a very early
    pre-alpha state.

--------------------------------------------------------------------------------
 License
--------------------------------------------------------------------------------

See LICENSE.
Terms of license copied from Handmade Hero.
These may change in the future.
Note: Much of my code is comes from work I do in my `practice' code repo, and
all of that code is CC BY 4.0.
You can’t perform that action at this time.