immortal
This commit is contained in:
37
examples/parser_simple.c
Normal file
37
examples/parser_simple.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "../cfg.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
printf("Usage: %s <config>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
FILE* f = fopen(argv[1], "rb");
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
ssize_t s = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
char* contents = malloc(s + 1);
|
||||
fread(contents, 1, s, f);
|
||||
fclose(f);
|
||||
|
||||
contents[s] = 0;
|
||||
|
||||
string arg = string_from_cstr(contents);
|
||||
parsed_config c = config_parse(&arg);
|
||||
|
||||
if (!c.ok) {
|
||||
printf("Error: %s\n", c.err.str);
|
||||
return 1;
|
||||
}
|
||||
|
||||
string str = config_str(&c.c, 0);
|
||||
char* cstr = string_cstr(&str);
|
||||
|
||||
printf("%s\n", cstr);
|
||||
|
||||
free_string(str);
|
||||
free(cstr);
|
||||
free(contents);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user