aboutsummaryrefslogtreecommitdiff
path: root/lib/include
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-10-10 11:28:46 +0200
committerDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-10-10 16:45:11 +0200
commit24c90b7700e18d0668799f8f343bc854a42dea20 (patch)
tree224d9b5e81a46e27f354c6975fc3fa4cd1f1fb79 /lib/include
parent7b647eefef00afb6104e84fae2a2fbf0481d4364 (diff)
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 <david.oberhollenzer@tele2.at>
Diffstat (limited to 'lib/include')
-rw-r--r--lib/include/libcfg.h29
1 files changed, 7 insertions, 22 deletions
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 <stdbool.h>
#include <stddef.h>
+#include <stdio.h>
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);
@@ -111,15 +105,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 '<keyword> [arguments...]' lines.
The cfgobj and flags are passed to the callback in the params array.