Hash :
2cfb1381
Author :
Thomas de Grivel
Date :
2021-12-30T11:58:28
WIP parser
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
/*
* kv - key value text file format
*
* Copyright 2022 Thomas de Grivel
*/
#include <stdio.h>
#include <stdlib.h>
#include <kv.h>
typedef struct kv_paths s_kv_paths;
struct kv_paths {
s_kv_path *k;
const char *v;
size_t vsz;
s_kv_paths *next;
};
int on_kv (s_buffer *b, const char *v, size_t vsz)
{
(void) b;
(void) v;
(void) vsz;
printf("--- v: %s\n", v);
return 0;
}
int read_file (const char *path, s_kv_paths *keys)
{
FILE *fp = fopen(path, "rb");
s_buffer b;
if (buffer_init(&b, path, fp, keys) ||
kv_parse(&b, on_kv) ||
buffer_close(&b))
return -1;
return 0;
}
s_kv_paths *kv_paths_new (s_kv_path *k, s_kv_paths *next)
{
s_kv_paths *keys = calloc(sizeof(s_kv_paths), 1);
if (keys) {
keys->k = k;
keys->next = next;
}
return keys;
}
s_kv_paths * read_keys (FILE *fp)
{
(void) fp;
return NULL;
}
int main (int argc, char **argv)
{
s_kv_paths *keys = read_keys(stdin);
while (--argc > 0)
read_file(*++argv, keys);
return 0;
}