if (n->ops->display_short)
n->ops->display_short(n);
else
- printf("------ %s\n", n->prompt);
+ printf("------ %s\n", n->prompt);
}
/* Print a detailed view of the node. */
{
const char *nodetype;
char value[MAX_VALUE_SIZE];
+ char default_value[MAX_VALUE_SIZE];
const char *quote = "";
if (n->ops->display_long) {
return;
}
- value[0] = '\0'; /* XXX get_value */
nodetype = confnode_get_type_str(n);
printf("%s <%s>\n", nodetype, n->name);
printf(" path ");
if (n->flags & CONFNODE_F_QUOTE_VALUE)
quote = "\"";
+
+ /* display real value */
+ if (confnode_get_value(n, value, sizeof(value)) < 0)
+ snprintf(value, sizeof(value), "invalid");
printf(" value %s%s%s\n", quote, value, quote);
- printf(" wanted %s%s%s\n", quote, n->value, quote);
- printf(" default %s%s%s\n", quote, n->default_value, quote);
+
+ /* display user value */
+ if (!strcmp(n->value, ""))
+ printf(" user NONE\n");
+ else
+ printf(" user %s%s%s\n", quote, n->value, quote);
+
+ /* display default value */
+ confnode_get_default_strvalue(n, default_value, MAX_VALUE_SIZE);
+ printf(" default %s%s%s\n", quote, default_value, quote);
+
+ /* check and display deps */
confnode_check_deps(n, 1);
}
{
char buf[BUFSIZ];
- printf("choice %s ", n->name);
+ printf("choice -> %s ", n->name);
if (confnode_get_value(n, buf, sizeof(buf)) >= 0) {
if (strlen(buf) > MAX_DISP_SIZE) {
buf[MAX_DISP_SIZE-3] = '.';
c = '*';
}
- printf("[%c] %s: %s\n", c, n->name, n->prompt);
+ printf("[%c] %s: %s\n", c, n->name, n->prompt);
}
/* register the node type */
c = '*';
}
- printf("[%c] %s: %s\n", c, n->name, n->prompt);
+ printf("[%c] %s: %s\n", c, n->name, n->prompt);
}
/* register the node type */
#include "confnode.h"
static int confnode_intconfig_new(struct confnode *n, const struct line *line);
+static int confnode_intconfig_strvalue_to_boolvalue(const struct confnode *n,
+ const char *strvalue);
static int confnode_intconfig_set_user_strvalue(struct confnode *n,
const char *strvalue);
static int confnode_intconfig_get_user_strvalue(const struct confnode *n, char *buf,
.add_attr = NULL, /* XXX range, displayhex */
.close_dir = NULL,
.dotconfig_write = NULL,
- .strvalue_to_boolvalue = NULL,
+ .strvalue_to_boolvalue = confnode_intconfig_strvalue_to_boolvalue,
.set_user_strvalue = confnode_intconfig_set_user_strvalue,
.get_user_strvalue = confnode_intconfig_get_user_strvalue,
.set_default_strvalue = confnode_intconfig_set_default_strvalue,
return 0;
}
+/* Convert string value into a boolean value (mainly used for
+ * dependancies). Return -1 on error, else return the boolean value (0
+ * or 1). */
+static int confnode_intconfig_strvalue_to_boolvalue(const struct confnode *n,
+ const char *strvalue)
+{
+ char *end = NULL;
+ int val;
+
+ /* XXX support hex and bin */
+ val = strtoul(strvalue, &end, 0);
+ if ((strvalue[0] == '\0') || (end == NULL) || (*end != '\0'))
+ return -1;
+ return val;
+}
+
/* Set the string value of the node n. Return 0 on success, or -1 if
* the value cannot be set. */
static int confnode_intconfig_set_user_strvalue(struct confnode *n,
/* Print a one-line summary of the node. Used in case of 'ls'. */
static void confnode_intconfig_display_short(const struct confnode *n)
{
- int val;
- val = confnode_get_value(n, NULL, 0);
- printf("[%4d] %s: %s\n", val, n->name, n->prompt);
+#define INTBUFLEN 10
+ char buf[INTBUFLEN];
+
+ memset(buf, 0, sizeof(buf));
+
+ buf[0] = '[';
+ confnode_get_value(n, buf, 0);
+ confnode_get_value(n, &buf[1], INTBUFLEN-1);
+ if (strlen(buf) == INTBUFLEN-1) { /* buffer full */
+ buf[INTBUFLEN-4] = '.';
+ buf[INTBUFLEN-3] = '.';
+ buf[INTBUFLEN-2] = '\0';
+ }
+ strcat(buf, "]");
+
+ while (strlen(buf) < sizeof(buf) - 1)
+ strcat(buf, " ");
+
+ printf("%s %s: %s\n", buf, n->name, n->prompt);
}
/* register the node type */
/* Print a one-line summary of the node. Used in case of 'ls'. */
static void confnode_menu_display_short(const struct confnode *n)
{
- printf(" -> %s: %s\n", n->name, n->prompt);
+ printf(" -> %s: %s\n", n->name, n->prompt);
}
/* Print a detailed view of the node. */
printf(" path ");
conf_display_path(n);
printf(" \"%s\"\n", n->prompt);
- printf(" no value\n");
}
/* register the node type */
c = '*';
}
- printf("[%c] -> %s: %s\n", c, n->name, n->prompt);
+ printf("[%c] -> %s: %s\n", c, n->name, n->prompt);
}
/* register the node type */
/* Print a one-line summary of the node. Used in case of 'ls'. */
static void confnode_strconfig_display_short(const struct confnode *n)
{
- /* just display prompt */
- printf(" %s\n", n->prompt);
+#define STRBUFLEN 10
+ char buf[STRBUFLEN];
+
+ memset(buf, 0, sizeof(buf));
+
+ buf[0] = '"';
+ confnode_get_value(n, &buf[1], STRBUFLEN-1);
+ if (strlen(buf) == STRBUFLEN-1) { /* buffer full */
+ buf[STRBUFLEN-4] = '.';
+ buf[STRBUFLEN-3] = '.';
+ buf[STRBUFLEN-2] = '\0';
+ }
+ strcat(buf, "\"");
+
+ while (strlen(buf) < sizeof(buf) - 1)
+ strcat(buf, " ");
+
+ printf("%s %s: %s\n", buf, n->name, n->prompt);
}
/* register the node type */