From 24c90b7700e18d0668799f8f343bc854a42dea20 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 10 Oct 2018 11:28:46 +0200 Subject: Configuration parser cleanup - Do a getline() & process in rdline instead of doing a read per character and feeding it through a state machine. - Move splitkv to rdcfg.c, the only place where it is used Signed-off-by: David Oberhollenzer --- lib/include/libcfg.h | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) (limited to 'lib/include/libcfg.h') diff --git a/lib/include/libcfg.h b/lib/include/libcfg.h index 8096f1b..95f91a8 100644 --- a/lib/include/libcfg.h +++ b/lib/include/libcfg.h @@ -20,23 +20,16 @@ #include #include +#include typedef struct { - int fd; /* input file descriptor */ - const char *argstr; /* if not NULL, read from this instead */ - const char *filename; /* input file name */ size_t lineno; /* current line number */ - - size_t i; /* buffer offset */ - char buffer[256]; /* current line, null-terminated */ + FILE *fp; + char *line; int argc; const char *const *argv; - - bool string; /* inside a string? */ - bool escape; /* reading an escape sequence? */ - bool comment; /* inside a comment */ } rdline_t; typedef struct { @@ -63,6 +56,8 @@ typedef struct { void rdline_init(rdline_t *t, int fd, const char *filename, int argc, const char *const *argv); +void rdline_cleanup(rdline_t *t); + /* Read from file until end-of-file or a line feed is encountered. @@ -84,9 +79,8 @@ void rdline_init(rdline_t *t, int fd, const char *filename, outside the bounds set by argc, processing fails. On success, the argv value is inserted and processed as described above. - A '%' character can be escaped by writing '%%' or, if inside - a double quite string, by writing \%. - - An attempt to use such an indexed argument inside an argument - expansion, results in failure. + a double quoted string, by writing \%. + - Arguments are pasted as is. Substitution is not recursive. - If the resulting line is empty, processing is restarted. */ int rdline(rdline_t *t); @@ -110,15 +104,6 @@ int unescape(char *src); */ int pack_argv(char *str); -/* - Split the current input line into a space seperted keyword - (alphabetical characters only) and a value (the rest of the line). - - If errors are encounted, prints a diagnostic message to stderr and - returns -1. On success, zero is returned. - */ -int splitkv(rdline_t *rd, char **k, char **v); - /* Parse a configuration file containing ' [arguments...]' lines. The cfgobj and flags are passed to the callback in the params array. -- cgit v1.2.3