/*
- $Id: command.c,v 1.43 2005/03/09 13:42:23 paul Exp $
+ $Id: command.c,v 1.44 2005/03/14 17:35:52 paul Exp $
Command interpreter routine for virtual terminal [aka TeletYpe]
Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
if ((cnode = vector_slot (cmdvec, i)) != NULL)
{
vector cmd_vector = cnode->cmd_vector;
- qsort (cmd_vector->index, cmd_vector->max, sizeof (void *), cmp_node);
+ qsort (cmd_vector->index, vector_max (cmd_vector),
+ sizeof (void *), cmp_node);
for (j = 0; j < vector_max (cmd_vector); j++)
- if ((cmd_element = vector_slot (cmd_vector, j)) != NULL)
+ if ((cmd_element = vector_slot (cmd_vector, j)) != NULL
+ && vector_max (cmd_element->strvec))
{
descvec = vector_slot (cmd_element->strvec,
vector_max (cmd_element->strvec) - 1);
- qsort (descvec->index, descvec->max, sizeof (void *), cmp_desc);
+ qsort (descvec->index, vector_max (descvec),
+ sizeof (void *), cmp_desc);
}
}
}
unsigned int i;
int size = 0;
vector descvec;
+ struct desc *desc;
for (i = 0; i < vector_max (strvec); i++)
+ if ((descvec = vector_slot (strvec, i)) != NULL)
{
- descvec = vector_slot (strvec, i);
-
- if (vector_max (descvec) == 1)
+ if ((vector_max (descvec)) == 1
+ && (desc = vector_slot (descvec, 0)) != NULL)
{
- struct desc *desc = vector_slot (descvec, 0);
-
if (desc->cmd == NULL || CMD_OPTION (desc->cmd))
return size;
else
descvec = vector_slot (cmd_element->strvec, index);
for (j = 0; j < vector_max (descvec); j++)
+ if ((desc = vector_slot (descvec, j)))
{
- desc = vector_slot (descvec, j);
str = desc->cmd;
if (CMD_VARARG (str))
descvec = vector_slot (cmd_element->strvec, index);
for (j = 0; j < vector_max (descvec); j++)
+ if ((desc = vector_slot (descvec, j)))
{
- desc = vector_slot (descvec, j);
str = desc->cmd;
if (CMD_VARARG (str))
descvec = vector_slot (cmd_element->strvec, index);
for (j = 0; j < vector_max (descvec); j++)
+ if ((desc = vector_slot (descvec, j)))
{
enum match_type ret;
- desc = vector_slot (descvec, j);
str = desc->cmd;
switch (type)
static vector
cmd_describe_command_real (vector vline, struct vty *vty, int *status)
{
- int i;
+ unsigned int i;
vector cmd_vector;
#define INIT_MATCHVEC_SIZE 10
vector matchvec;
struct cmd_element *cmd_element;
- int index;
+ unsigned int index;
int ret;
enum match_type match;
char *command;
static struct desc desc_cr = { "<cr>", "" };
/* Set index. */
+ if (vector_max (vline) == 0)
+ {
+ *status = CMD_ERR_NO_MATCH;
+ return NULL;
+ }
+ else
index = vector_max (vline) - 1;
/* Make copy vector of current node's command vector. */
/* Filter commands. */
/* Only words precedes current word will be checked in this loop. */
for (i = 0; i < index; i++)
+ if ((command = vector_slot (vline, i)))
{
- command = vector_slot (vline, i);
match = cmd_filter_by_completion (command, cmd_vector, i);
if (match == vararg_match)
unsigned int j, k;
for (j = 0; j < vector_max (cmd_vector); j++)
- if ((cmd_element = vector_slot (cmd_vector, j)) != NULL)
+ if ((cmd_element = vector_slot (cmd_vector, j)) != NULL
+ && (vector_max (cmd_element->strvec)))
{
descvec = vector_slot (cmd_element->strvec,
vector_max (cmd_element->strvec) - 1);
struct desc *desc;
for (j = 0; j < vector_max (descvec); j++)
+ if ((desc = vector_slot (descvec, j)))
{
- desc = vector_slot (descvec, j);
string = cmd_entry_function_desc (command, desc->cmd);
if (string)
{
static char **
cmd_complete_command_real (vector vline, struct vty *vty, int *status)
{
- int i;
+ unsigned int i;
vector cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node));
#define INIT_MATCHVEC_SIZE 10
vector matchvec;
struct cmd_element *cmd_element;
- int index = vector_max (vline) - 1;
+ unsigned int index;
char **match_str;
struct desc *desc;
vector descvec;
char *command;
int lcd;
+ if (vector_max (vline) == 0)
+ {
+ *status = CMD_ERR_NO_MATCH;
+ return NULL;
+ }
+ else
+ index = vector_max (vline) - 1;
+
/* First, filter by preceeding command string */
for (i = 0; i < index; i++)
+ if ((command = vector_slot (vline, i)))
{
enum match_type match;
int ret;
- command = vector_slot (vline, i);
-
/* First try completion match, if there is exactly match return 1 */
match = cmd_filter_by_completion (command, cmd_vector, i);
/* Now we got into completion */
for (i = 0; i < vector_max (cmd_vector); i++)
- if ((cmd_element = vector_slot (cmd_vector, i)) != NULL)
+ if ((cmd_element = vector_slot (cmd_vector, i)))
{
const char *string;
vector strvec = cmd_element->strvec;
descvec = vector_slot (strvec, index);
for (j = 0; j < vector_max (descvec); j++)
+ if ((desc = vector_slot (descvec, j)))
{
- desc = vector_slot (descvec, j);
-
- if ((string = cmd_entry_function (vector_slot (vline, index),
+ if ((string =
+ cmd_entry_function (vector_slot (vline, index),
desc->cmd)))
if (cmd_unique_string (matchvec, string))
vector_set (matchvec, XSTRDUP (MTYPE_TMP, string));
/* Execute command by argument vline vector. */
static int
-cmd_execute_command_real (vector vline, struct vty *vty, struct cmd_element **cmd)
+cmd_execute_command_real (vector vline, struct vty *vty,
+ struct cmd_element **cmd)
{
unsigned int i;
unsigned int index;
cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node));
for (index = 0; index < vector_max (vline); index++)
+ if ((command = vector_slot (vline, index)))
{
int ret;
- command = vector_slot (vline, index);
-
match = cmd_filter_by_completion (command, cmd_vector, index);
if (match == vararg_match)
incomplete_count = 0;
for (i = 0; i < vector_max (cmd_vector); i++)
- if (vector_slot (cmd_vector,i) != NULL)
+ if ((cmd_element = vector_slot (cmd_vector, i)))
{
- cmd_element = vector_slot (cmd_vector,i);
-
if (match == vararg_match || index >= cmd_element->cmdsize)
{
matched_element = cmd_element;
return (*matched_element->func) (matched_element, vty, argc, argv);
}
-
int
cmd_execute_command (vector vline, struct vty *vty, struct cmd_element **cmd,
int vtysh) {
cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node));
for (index = 0; index < vector_max (vline); index++)
+ if ((command = vector_slot (vline, index)))
{
int ret;
- command = vector_slot (vline, index);
-
match = cmd_filter_by_string (vector_slot (vline, index),
cmd_vector, index);