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)
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,
.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,
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,