genconf: enhance short and long display of confnodes
[libcmdline.git] / src / genconf / confnode_strconfig.c
index c6dbcd2..40975c8 100644 (file)
@@ -150,8 +150,24 @@ static const char *confnode_strconfig_get_type_str(const struct confnode *n)
 /* 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 */