From: Olivier Matz Date: Fri, 24 Dec 2010 12:16:18 +0000 (+0100) Subject: genconf: fix dotconfig_write methods X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=c1a42a41a1218dc8adcb52246cb4d67c0264e8b3;p=libcmdline.git genconf: fix dotconfig_write methods Signed-off-by: Olivier Matz --- diff --git a/src/genconf/confnode_menu.c b/src/genconf/confnode_menu.c index 63bd6c5..844eb32 100644 --- a/src/genconf/confnode_menu.c +++ b/src/genconf/confnode_menu.c @@ -107,13 +107,9 @@ static int confnode_menu_close_dir(struct confnode *parent, static int confnode_menu_dotconfig_write(const struct confnode *n, FILE *f) { const struct confnode *c; - int val; - val = confnode_get_value(n, NULL, 0); - if (val < 0) + if (fprintf(f, "#\n# -- %s\n#\n", n->prompt) < 0) return -1; - if (val == 0) - return 0; TAILQ_FOREACH(c, &n->children, next) { if (confnode_dotconfig_write(c, f) < 0) diff --git a/src/genconf/confnode_menuconfig.c b/src/genconf/confnode_menuconfig.c index 545d1b6..99e5b17 100644 --- a/src/genconf/confnode_menuconfig.c +++ b/src/genconf/confnode_menuconfig.c @@ -42,6 +42,7 @@ static int confnode_menuconfig_new(struct confnode *n, const struct line *line); static int confnode_menuconfig_close_dir(struct confnode *parent, const struct line *line); +static int confnode_menuconfig_dotconfig_write(const struct confnode *n, FILE *f); static int confnode_menuconfig_set_user_strvalue(struct confnode *n, const char *strvalue); static int confnode_menuconfig_get_user_strvalue(const struct confnode *n, char *buf, @@ -59,7 +60,7 @@ static struct confnode_type confnode_menuconfig = { .free = NULL, .add_attr = NULL, .close_dir = confnode_menuconfig_close_dir, - .dotconfig_write = NULL, + .dotconfig_write = confnode_menuconfig_dotconfig_write, .strvalue_to_boolvalue = NULL, .set_user_strvalue = confnode_menuconfig_set_user_strvalue, .get_user_strvalue = confnode_menuconfig_get_user_strvalue, @@ -109,6 +110,36 @@ static int confnode_menuconfig_close_dir(struct confnode *parent, return -1; } +/* write config value in file f in a dotconfig-like manner. Return 0 + * on success. */ +static int confnode_menuconfig_dotconfig_write(const struct confnode *n, FILE *f) +{ + const struct confnode *c; + int val; + + if (fprintf(f, "#\n# -- %s\n#\n", n->prompt) < 0) + return -1; + + val = confnode_get_value(n, NULL, 0); + if (val < 0) + return -1; + + if (val == 0) { + if (fprintf(f, "# CONFIG_%s is not set\n", n->name) < 0) + return -1; + return 0; + } + + if (fprintf(f, "CONFIG_%s=y\n", n->name) < 0) + return -1; + + TAILQ_FOREACH(c, &n->children, next) { + if (confnode_dotconfig_write(c, f) < 0) + return -1; + } + return 0; +} + /* Set the string value of the node n. Return 0 on success, or -1 if * the value cannot be set. */ static int confnode_menuconfig_set_user_strvalue(struct confnode *n,