summaryrefslogtreecommitdiff
path: root/lib/command.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/command.c')
-rw-r--r--lib/command.c55
1 files changed, 45 insertions, 10 deletions
diff --git a/lib/command.c b/lib/command.c
index 5ca4a0fda9..18a28f57c0 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -715,6 +715,41 @@ cmd_variable_complete (struct cmd_token *token, const char *arg, vector comps)
vector_free(tmpcomps);
}
+#define AUTOCOMP_INDENT 5
+
+char *
+cmd_variable_comp2str(vector comps, unsigned short cols, const char nl[])
+{
+ size_t bsz = 16;
+ char *buf = XCALLOC(MTYPE_TMP, bsz);
+ int lc = AUTOCOMP_INDENT;
+ size_t cs = AUTOCOMP_INDENT;
+ size_t nllen = strlen(nl);
+ size_t itemlen;
+ snprintf(buf, bsz, "%*s", AUTOCOMP_INDENT, "");
+ for (size_t j = 0; j < vector_active (comps); j++)
+ {
+ char *item = vector_slot (comps, j);
+ itemlen = strlen(item);
+
+ if (cs + itemlen + nllen + AUTOCOMP_INDENT + 2 >= bsz)
+ buf = XREALLOC(MTYPE_TMP, buf, (bsz *= 2));
+
+ if (lc + itemlen + 1 >= cols)
+ {
+ cs += snprintf(&buf[cs], bsz - cs, "%s%*s", nl, AUTOCOMP_INDENT, "");
+ lc = AUTOCOMP_INDENT;
+ }
+
+ size_t written = snprintf(&buf[cs], bsz - cs, "%s ", item);
+ lc += written;
+ cs += written;
+ XFREE (MTYPE_COMPLETION, item);
+ vector_set_index (comps, j, NULL);
+ }
+ return buf;
+}
+
void
cmd_variable_handler_register (const struct cmd_variable_handler *cvh)
{
@@ -1150,7 +1185,7 @@ DEFUN (config_terminal,
else
{
vty_outln (vty, "VTY configuration is locked by other VTY");
- return CMD_WARNING;
+ return CMD_WARNING_CONFIG_FAILED;
}
return CMD_SUCCESS;
}
@@ -1722,7 +1757,7 @@ DEFUN (config_hostname,
if (!isalpha((int) word->arg[0]))
{
vty_outln (vty, "Please specify string starting with alphabet");
- return CMD_WARNING;
+ return CMD_WARNING_CONFIG_FAILED;
}
return cmd_hostname_set (word->arg);
@@ -1763,7 +1798,7 @@ DEFUN (config_password,
{
vty_outln (vty,
"Please specify string starting with alphanumeric");
- return CMD_WARNING;
+ return CMD_WARNING_CONFIG_FAILED;
}
if (host.password)
@@ -1812,7 +1847,7 @@ DEFUN (config_enable_password,
else
{
vty_outln (vty, "Unknown encryption type.");
- return CMD_WARNING;
+ return CMD_WARNING_CONFIG_FAILED;
}
}
@@ -1820,7 +1855,7 @@ DEFUN (config_enable_password,
{
vty_outln (vty,
"Please specify string starting with alphanumeric");
- return CMD_WARNING;
+ return CMD_WARNING_CONFIG_FAILED;
}
if (host.enable)
@@ -2134,14 +2169,14 @@ set_log_file(struct vty *vty, const char *fname, int loglevel)
if (getcwd (cwd, MAXPATHLEN) == NULL)
{
zlog_err ("config_log_file: Unable to alloc mem!");
- return CMD_WARNING;
+ return CMD_WARNING_CONFIG_FAILED;
}
if ( (p = XMALLOC (MTYPE_TMP, strlen (cwd) + strlen (fname) + 2))
== NULL)
{
zlog_err ("config_log_file: Unable to alloc mem!");
- return CMD_WARNING;
+ return CMD_WARNING_CONFIG_FAILED;
}
sprintf (p, "%s/%s", cwd, fname);
fullpath = p;
@@ -2157,7 +2192,7 @@ set_log_file(struct vty *vty, const char *fname, int loglevel)
if (!ret)
{
vty_out (vty, "can't open logfile %s\n", fname);
- return CMD_WARNING;
+ return CMD_WARNING_CONFIG_FAILED;
}
if (host.logfile)
@@ -2371,7 +2406,7 @@ cmd_banner_motd_file (const char *file)
host.motdfile = XSTRDUP (MTYPE_HOST, file);
}
else
- success = CMD_WARNING;
+ success = CMD_WARNING_CONFIG_FAILED;
return success;
}
@@ -2390,7 +2425,7 @@ DEFUN (banner_motd_file,
if (cmd == CMD_ERR_NO_FILE)
vty_out (vty, "%s does not exist", filename);
- else if (cmd == CMD_WARNING)
+ else if (cmd == CMD_WARNING_CONFIG_FAILED)
vty_out (vty, "%s must be in %s", filename, SYSCONFDIR);
return cmd;