aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 27ced63870bb2c81c10511c9e3f68ad63daa50b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# parcini: a PARser in C for INI files

parcini is a simple parser for INI files somewhat inspired by inih. I made it
because I wanted a somewhat different API from that of inih, and because I was
half-way done when I found about inih.

It was mainly made to serve my needs, so I intend on keeping it super minimal.
Most probably inih or a different library might of more interest/use to you, but
feel free to use my implementation if it fits your use-case as it fits mine.

# License

parcini is released under the terms of the GNU Lesser General Public License,
version 2.1 only. For more information check the LICENSE file.

# Compiling

Just copy the header `include/parcini.h` and source `src/parcini.c` files to
your project. My main goal is to statically link it, so there's no "support" to
use it as a dynamically linked, but feel free to add it yourself.

A compiler with C99 support and a libc with POSIX.1-2008 are required.

The Makefile provided is just for testing purposes. The test(s) can be run
simply by executing `make` from the command-line.

## Compile-time options

Currently only the following compile-time option is available:

* `PARCINI_COMMENT_CHAR`: should be set to the desired character for start of
  comment. Default is `'#'`.

# INI file format

There is no one standard INI file spec, but this implementation does differ some
from most other implementations out there. 

* It expects only three possible value types: integer, boolean and string. 
	- Integers can be signed and should be withing the range of a long int. They
	  are parsed with `strtol()` so more information can be gathered from the
	  respective manual page.
	- Booleans can be represented as `yes`/`no` or `true`/`false`.
	- Strings should be surrounded by `"` quote characters, and can contain
	  quote characters without escaping, since the last quote character is
	  considered the closing one.
* `=` is the delimiter sign for keys and values, e.g. `key = value`
* Any white space (except newline) surrounding the `=` delimiter is ignored.
* Any white space after the end of a value, or the ] of a section is ignored.
Other characters are not ignored and invalidate the line, unless they are
preceded by the comment character.
* A new line means a new key-value, section, or comment/empty line.
* In the default compilation comments start with `#` and can be on their own
line or at the end of key-value and section lines.

## Example INI file

```ini
int=1995
string = "hello world"
bool = yes

# a comment
[section]
key="value" # another comment
```

# Example program

Check out `example/example.c` for an example of a program using parcini. You can
compile it by running `make example`, it will be compiled to
`build/example/example`.

# Questions

I don't expect this piece of code to be used by a lot of people (if any), but if
you have any questions, or maybe even patches, send me an email. You can find my
address and my PGP key on my homepage 
[www.yaroslavps.com](http://www.yaroslavps.com).