add normalizepath_cstr()
[rofl0r-libulz.git] / examples / iniparser_test.c
blobbb35a047a633e05b5d5b67e8abb19f00632b6a7a
1 #include <stdio.h>
2 #include "stringptr.h"
3 #include "../include/iniparser.h"
5 // gcc -Wall -Wextra -g iniparser_test.c stringptr.c iniparser.c -o iniparser_test
7 int main(void) {
8 ini_section sec;
9 stringptr result;
10 stringptr* ini = stringptr_copy(SPLITERAL("[main]\nfoo=bar\nbar=baz\n[section1]\nbaz=blah\nblah=foo\n"));
11 // we need stringptr_copy since stringptr_linesplit modifies the buffer. which would segfault using a literal.
12 stringptrlist* lines = stringptr_linesplit(ini);
14 sec = iniparser_get_section(lines, SPLITERAL("main"));
15 iniparser_getvalue(lines, &sec, SPLITERAL("bar"), &result);
17 printf("[main] bar=%s, size=%d\n", result.ptr, (int) result.size);
20 sec = iniparser_get_section(lines, SPLITERAL("section1"));
21 iniparser_getvalue(lines, &sec, SPLITERAL("blah"), &result);
23 printf("blah=%s, size=%d\n", result.ptr, (int) result.size);
25 stringptr_free(ini);
26 free(lines);
28 return 0;