8 #include "expression.h"
9 #include "parser_common.h"
10 #include "conf_parser.h"
12 #include "conf_htable.h"
14 int dotconfig_parse_line(const char *line)
22 /* copy line in a writable buffer */
23 buf[sizeof(buf) - 1] = '\0';
24 strncpy(buf, line, sizeof(buf) - 1);
27 while (*s != '\0' && isspace(*s))
29 /* nothing to do, empty line */
33 /* skip the first "#", expecting "is not set" */
37 while (*s != '\0' && isspace(*s))
39 /* nothing to do, empty line */
44 /* get node name, ignore invalid names */
46 if (strncmp("CONFIG_", nodename, strlen("CONFIG_")))
48 nodename += strlen("CONFIG_");
50 while (*s != '\0' && *s != wait_char)
58 /* find the node in the conf htable */
59 opt = conf_htable_lookup(nodename);
61 printf("ignore unknown symbol <%s>\n", nodename);
67 /* "is not set" -> "n" */
68 if (wait_char == ' ') {
69 if (strcmp(s, "is not set\n"))
77 /* erase the cariage return */
78 while (*s != '\0' && *s != '\n') {
79 if (*s == '"' && *(s-1) != '\\') {
88 /* set its value in the conf tree */
89 if (confnode_set_user_strvalue(opt, optval) < 0) {
90 printf("cannot assign value to node <%s>: %s\n", nodename, optval);
98 int dotconfig_read(const char *filename, struct confnode *conf)
104 f = fopen(filename, "r");
106 printf("cannot find file <%s>\n", filename);
109 while (fgets(buf, sizeof(buf), f) != NULL) {
111 if (dotconfig_parse_line(buf) < 0) {
122 int dotconfig_write(const char *filename, const struct confnode *conf)
125 const struct confnode *c;
127 f = fopen(filename, "w");
129 printf("cannot open file <%s>\n", filename);
133 /* dump all the children of root node */
134 TAILQ_FOREACH(c, &conf->children, next) {
135 confnode_dotconfig_write(c, f);