? quagga-0.97.4.tar.gz.asc ? tools/ztraceroute Index: lib/command.c =================================================================== RCS file: /var/cvsroot/quagga/lib/command.c,v retrieving revision 1.31 diff -u -r1.31 command.c --- lib/command.c 2 Jan 2005 18:51:01 -0000 1.31 +++ lib/command.c 4 Jan 2005 18:02:44 -0000 @@ -32,6 +32,11 @@ #include "vty.h" #include "command.h" +/* commands which are intended to be hidden from user normally */ +#define CMD_IS_HIDDEN(cmd_element) \ + ((cmd_element)->attr == CMD_ATTR_HIDDEN \ + || (cmd_element)->attr == CMD_ATTR_DEPRECATED) + /* Command vector which includes some level of command lists. Normally each daemon maintains each own cmdvec. */ vector cmdvec; @@ -222,20 +227,18 @@ vector descvec; struct cmd_element *cmd_element; - for (i = 0; i < vector_max (cmdvec); i++) - if ((cnode = vector_slot (cmdvec, i)) != NULL) - { - vector cmd_vector = cnode->cmd_vector; - qsort (cmd_vector->index, cmd_vector->max, sizeof (void *), cmp_node); - - for (j = 0; j < vector_max (cmd_vector); j++) - if ((cmd_element = vector_slot (cmd_vector, j)) != NULL) - { - descvec = vector_slot (cmd_element->strvec, - vector_max (cmd_element->strvec) - 1); - qsort (descvec->index, descvec->max, sizeof (void *), cmp_desc); - } - } + VECTOR_LOOP (cmdvec, cnode, i) + { + vector cmd_vector = cnode->cmd_vector; + qsort (cmd_vector->index, cmd_vector->max, sizeof (void *), cmp_node); + + VECTOR_LOOP (cmd_vector, cmd_element, j) + { + descvec = vector_slot (cmd_element->strvec, + vector_max (cmd_element->strvec) - 1); + qsort (descvec->index, descvec->max, sizeof (void *), cmp_desc); + } + } } /* Breaking up string into each command piece. I assume given @@ -300,9 +303,8 @@ if (!v) return; - for (i = 0; i < vector_max (v); i++) - if ((cp = vector_slot (v, i)) != NULL) - XFREE (MTYPE_STRVEC, cp); + VECTOR_LOOP (v, cp, i) + XFREE (MTYPE_STRVEC, cp); vector_free (v); } @@ -1128,104 +1130,103 @@ match_type = no_match; /* If command and cmd_element string does not match set NULL to vector */ - for (i = 0; i < vector_max (v); i++) - if ((cmd_element = vector_slot (v, i)) != NULL) - { - if (index >= vector_max (cmd_element->strvec)) - vector_slot (v, i) = NULL; - else - { - unsigned int j; - int matched = 0; - - descvec = vector_slot (cmd_element->strvec, index); - - for (j = 0; j < vector_max (descvec); j++) - { - desc = vector_slot (descvec, j); - str = desc->cmd; - - if (CMD_VARARG (str)) - { - if (match_type < vararg_match) - match_type = vararg_match; - matched++; - } - else if (CMD_RANGE (str)) - { - if (cmd_range_match (str, command)) - { - if (match_type < range_match) - match_type = range_match; - - matched++; - } - } + VECTOR_LOOP (v, cmd_element, i) + { + if (index >= vector_max (cmd_element->strvec)) + vector_slot (v, i) = NULL; + else + { + unsigned int j; + int matched = 0; + + descvec = vector_slot (cmd_element->strvec, index); + + for (j = 0; j < vector_max (descvec); j++) + { + desc = vector_slot (descvec, j); + str = desc->cmd; + + if (CMD_VARARG (str)) + { + if (match_type < vararg_match) + match_type = vararg_match; + matched++; + } + else if (CMD_RANGE (str)) + { + if (cmd_range_match (str, command)) + { + if (match_type < range_match) + match_type = range_match; + + matched++; + } + } #ifdef HAVE_IPV6 - else if (CMD_IPV6 (str)) - { - if (cmd_ipv6_match (command)) - { - if (match_type < ipv6_match) - match_type = ipv6_match; - - matched++; - } - } - else if (CMD_IPV6_PREFIX (str)) - { - if (cmd_ipv6_prefix_match (command)) - { - if (match_type < ipv6_prefix_match) - match_type = ipv6_prefix_match; - - matched++; - } - } + else if (CMD_IPV6 (str)) + { + if (cmd_ipv6_match (command)) + { + if (match_type < ipv6_match) + match_type = ipv6_match; + + matched++; + } + } + else if (CMD_IPV6_PREFIX (str)) + { + if (cmd_ipv6_prefix_match (command)) + { + if (match_type < ipv6_prefix_match) + match_type = ipv6_prefix_match; + + matched++; + } + } #endif /* HAVE_IPV6 */ - else if (CMD_IPV4 (str)) - { - if (cmd_ipv4_match (command)) - { - if (match_type < ipv4_match) - match_type = ipv4_match; - - matched++; - } - } - else if (CMD_IPV4_PREFIX (str)) - { - if (cmd_ipv4_prefix_match (command)) - { - if (match_type < ipv4_prefix_match) - match_type = ipv4_prefix_match; - matched++; - } - } - else - /* Check is this point's argument optional ? */ - if (CMD_OPTION (str) || CMD_VARIABLE (str)) - { - if (match_type < extend_match) - match_type = extend_match; - matched++; - } - else if (strncmp (command, str, strlen (command)) == 0) - { - if (strcmp (command, str) == 0) - match_type = exact_match; - else - { - if (match_type < partly_match) - match_type = partly_match; - } - matched++; - } - } - if (! matched) - vector_slot (v, i) = NULL; - } - } + else if (CMD_IPV4 (str)) + { + if (cmd_ipv4_match (command)) + { + if (match_type < ipv4_match) + match_type = ipv4_match; + + matched++; + } + } + else if (CMD_IPV4_PREFIX (str)) + { + if (cmd_ipv4_prefix_match (command)) + { + if (match_type < ipv4_prefix_match) + match_type = ipv4_prefix_match; + matched++; + } + } + else + /* Check is this point's argument optional ? */ + if (CMD_OPTION (str) || CMD_VARIABLE (str)) + { + if (match_type < extend_match) + match_type = extend_match; + matched++; + } + else if (strncmp (command, str, strlen (command)) == 0) + { + if (strcmp (command, str) == 0) + match_type = exact_match; + else + { + if (match_type < partly_match) + match_type = partly_match; + } + matched++; + } + } + if (! matched) + vector_slot (v, i) = NULL; + } + } return match_type; } @@ -1243,98 +1244,97 @@ match_type = no_match; /* If command and cmd_element string does not match set NULL to vector */ - for (i = 0; i < vector_max (v); i++) - if ((cmd_element = vector_slot (v, i)) != NULL) - { - /* If given index is bigger than max string vector of command, - set NULL*/ - if (index >= vector_max (cmd_element->strvec)) - vector_slot (v, i) = NULL; - else - { - unsigned int j; - int matched = 0; - - descvec = vector_slot (cmd_element->strvec, index); - - for (j = 0; j < vector_max (descvec); j++) - { - desc = vector_slot (descvec, j); - str = desc->cmd; - - if (CMD_VARARG (str)) - { - if (match_type < vararg_match) - match_type = vararg_match; - matched++; - } - else if (CMD_RANGE (str)) - { - if (cmd_range_match (str, command)) - { - if (match_type < range_match) - match_type = range_match; - matched++; - } - } + VECTOR_LOOP (v, cmd_element, i) + { + /* If given index is bigger than max string vector of command, + set NULL*/ + if (index >= vector_max (cmd_element->strvec)) + vector_slot (v, i) = NULL; + else + { + unsigned int j; + int matched = 0; + + descvec = vector_slot (cmd_element->strvec, index); + + for (j = 0; j < vector_max (descvec); j++) + { + desc = vector_slot (descvec, j); + str = desc->cmd; + + if (CMD_VARARG (str)) + { + if (match_type < vararg_match) + match_type = vararg_match; + matched++; + } + else if (CMD_RANGE (str)) + { + if (cmd_range_match (str, command)) + { + if (match_type < range_match) + match_type = range_match; + matched++; + } + } #ifdef HAVE_IPV6 - else if (CMD_IPV6 (str)) - { - if (cmd_ipv6_match (command) == exact_match) - { - if (match_type < ipv6_match) - match_type = ipv6_match; - matched++; - } - } - else if (CMD_IPV6_PREFIX (str)) - { - if (cmd_ipv6_prefix_match (command) == exact_match) - { - if (match_type < ipv6_prefix_match) - match_type = ipv6_prefix_match; - matched++; - } - } + else if (CMD_IPV6 (str)) + { + if (cmd_ipv6_match (command) == exact_match) + { + if (match_type < ipv6_match) + match_type = ipv6_match; + matched++; + } + } + else if (CMD_IPV6_PREFIX (str)) + { + if (cmd_ipv6_prefix_match (command) == exact_match) + { + if (match_type < ipv6_prefix_match) + match_type = ipv6_prefix_match; + matched++; + } + } #endif /* HAVE_IPV6 */ - else if (CMD_IPV4 (str)) - { - if (cmd_ipv4_match (command) == exact_match) - { - if (match_type < ipv4_match) - match_type = ipv4_match; - matched++; - } - } - else if (CMD_IPV4_PREFIX (str)) - { - if (cmd_ipv4_prefix_match (command) == exact_match) - { - if (match_type < ipv4_prefix_match) - match_type = ipv4_prefix_match; - matched++; - } - } - else if (CMD_OPTION (str) || CMD_VARIABLE (str)) - { - if (match_type < extend_match) - match_type = extend_match; - matched++; - } - else - { - if (strcmp (command, str) == 0) - { - match_type = exact_match; - matched++; - } - } - } - if (! matched) - vector_slot (v, i) = NULL; - } - } - return match_type; + else if (CMD_IPV4 (str)) + { + if (cmd_ipv4_match (command) == exact_match) + { + if (match_type < ipv4_match) + match_type = ipv4_match; + matched++; + } + } + else if (CMD_IPV4_PREFIX (str)) + { + if (cmd_ipv4_prefix_match (command) == exact_match) + { + if (match_type < ipv4_prefix_match) + match_type = ipv4_prefix_match; + matched++; + } + } + else if (CMD_OPTION (str) || CMD_VARIABLE (str)) + { + if (match_type < extend_match) + match_type = extend_match; + matched++; + } + else + { + if (strcmp (command, str) == 0) + { + match_type = exact_match; + matched++; + } + } + } + if (! matched) + vector_slot (v, i) = NULL; + } + } +return match_type; } /* Check ambiguous match */ @@ -1349,88 +1349,86 @@ vector descvec; struct desc *desc; - for (i = 0; i < vector_max (v); i++) - if ((cmd_element = vector_slot (v, i)) != NULL) - { - int match = 0; - - descvec = vector_slot (cmd_element->strvec, index); - - for (j = 0; j < vector_max (descvec); j++) - { - enum match_type ret; - - desc = vector_slot (descvec, j); - str = desc->cmd; - - switch (type) - { - case exact_match: - if (! (CMD_OPTION (str) || CMD_VARIABLE (str)) - && strcmp (command, str) == 0) - match++; - break; - case partly_match: - if (! (CMD_OPTION (str) || CMD_VARIABLE (str)) - && strncmp (command, str, strlen (command)) == 0) - { - if (matched && strcmp (matched, str) != 0) - return 1; /* There is ambiguous match. */ - else - matched = str; - match++; - } - break; - case range_match: - if (cmd_range_match (str, command)) - { - if (matched && strcmp (matched, str) != 0) - return 1; - else - matched = str; - match++; - } - break; + VECTOR_LOOP (v, cmd_element, i) + { + int match = 0; + + descvec = vector_slot (cmd_element->strvec, index); + + VECTOR_LOOP (descvec, desc, j) + { + enum match_type ret; + + str = desc->cmd; + + switch (type) + { + case exact_match: + if (! (CMD_OPTION (str) || CMD_VARIABLE (str)) + && strcmp (command, str) == 0) + match++; + break; + case partly_match: + if (! (CMD_OPTION (str) || CMD_VARIABLE (str)) + && strncmp (command, str, strlen (command)) == 0) + { + if (matched && strcmp (matched, str) != 0) + return 1; /* There is ambiguous match. */ + else + matched = str; + match++; + } + break; + case range_match: + if (cmd_range_match (str, command)) + { + if (matched && strcmp (matched, str) != 0) + return 1; + else + matched = str; + match++; + } + break; #ifdef HAVE_IPV6 - case ipv6_match: - if (CMD_IPV6 (str)) - match++; - break; - case ipv6_prefix_match: - if ((ret = cmd_ipv6_prefix_match (command)) != no_match) - { - if (ret == partly_match) - return 2; /* There is incomplete match. */ - - match++; - } - break; + case ipv6_match: + if (CMD_IPV6 (str)) + match++; + break; + case ipv6_prefix_match: + if ((ret = cmd_ipv6_prefix_match (command)) != no_match) + { + if (ret == partly_match) + return 2; /* There is incomplete match. */ + + match++; + } + break; #endif /* HAVE_IPV6 */ - case ipv4_match: - if (CMD_IPV4 (str)) - match++; - break; - case ipv4_prefix_match: - if ((ret = cmd_ipv4_prefix_match (command)) != no_match) - { - if (ret == partly_match) - return 2; /* There is incomplete match. */ - - match++; - } - break; - case extend_match: - if (CMD_OPTION (str) || CMD_VARIABLE (str)) - match++; - break; - case no_match: - default: - break; - } - } - if (! match) - vector_slot (v, i) = NULL; - } + case ipv4_match: + if (CMD_IPV4 (str)) + match++; + break; + case ipv4_prefix_match: + if ((ret = cmd_ipv4_prefix_match (command)) != no_match) + { + if (ret == partly_match) + return 2; /* There is incomplete match. */ + + match++; + } + break; + case extend_match: + if (CMD_OPTION (str) || CMD_VARIABLE (str)) + match++; + break; + case no_match: + default: + break; + } + } + if (! match) + vector_slot (v, i) = NULL; + } return 0; } @@ -1565,20 +1563,21 @@ 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 = { "", "" }; /* Set index. */ - index = vector_max (vline) - 1; - + if ((index = vector_max (vline)) > 0) + index -= 1; + /* Make copy vector of current node's command vector. */ cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node)); @@ -1587,9 +1586,8 @@ /* Filter commands. */ /* Only words precedes current word will be checked in this loop. */ - for (i = 0; i < index; i++) + VECTOR_LOOP (vline, command, i) { - command = vector_slot (vline, i); match = cmd_filter_by_completion (command, cmd_vector, i); if (match == vararg_match) @@ -1598,17 +1596,16 @@ vector descvec; unsigned int j, k; - for (j = 0; j < vector_max (cmd_vector); j++) - if ((cmd_element = vector_slot (cmd_vector, j)) != NULL) - { - descvec = vector_slot (cmd_element->strvec, - vector_max (cmd_element->strvec) - 1); - for (k = 0; k < vector_max (descvec); k++) - { - struct desc *desc = vector_slot (descvec, k); - vector_set (matchvec, desc); - } - } + VECTOR_LOOP (cmd_vector, cmd_element, j) + { + descvec = vector_slot (cmd_element->strvec, + vector_max (cmd_element->strvec) - 1); + for (k = 0; k < vector_max (descvec); k++) + { + struct desc *desc = vector_slot (descvec, k); + vector_set (matchvec, desc); + } + } vector_set (matchvec, &desc_cr); vector_free (cmd_vector); @@ -1639,44 +1636,43 @@ match = cmd_filter_by_completion (command, cmd_vector, index); /* Make description vector. */ - for (i = 0; i < vector_max (cmd_vector); i++) - if ((cmd_element = vector_slot (cmd_vector, i)) != NULL) - { - const char *string = NULL; - vector strvec = cmd_element->strvec; - - /* if command is NULL, index may be equal to vector_max */ - if (command && index >= vector_max (strvec)) - vector_slot (cmd_vector, i) = NULL; - else - { - /* Check if command is completed. */ - if (command == NULL && index == vector_max (strvec)) - { - string = ""; - if (! desc_unique_string (matchvec, string)) - vector_set (matchvec, &desc_cr); - } - else - { - unsigned int j; - vector descvec = vector_slot (strvec, index); - struct desc *desc; - - for (j = 0; j < vector_max (descvec); j++) - { - desc = vector_slot (descvec, j); - string = cmd_entry_function_desc (command, desc->cmd); - if (string) - { - /* Uniqueness check */ - if (! desc_unique_string (matchvec, string)) - vector_set (matchvec, desc); - } - } - } - } - } + VECTOR_LOOP (cmd_vector, cmd_element, i) + { + const char *string = NULL; + vector strvec = cmd_element->strvec; + + /* if command is NULL, index may be equal to vector_max */ + if (command && index >= vector_max (strvec)) + vector_slot (cmd_vector, i) = NULL; + else + { + /* Check if command is completed. */ + if (command == NULL && index == vector_max (strvec)) + { + string = ""; + if (! desc_unique_string (matchvec, string)) + vector_set (matchvec, &desc_cr); + } + else + { + unsigned int j; + vector descvec = vector_slot (strvec, index); + struct desc *desc; + + for (j = 0; j < vector_max (descvec); j++) + { + desc = vector_slot (descvec, j); + string = cmd_entry_function_desc (command, desc->cmd); + if (string) + { + /* Uniqueness check */ + if (! desc_unique_string (matchvec, string)) + vector_set (matchvec, desc); + } + } + } + } + } vector_free (cmd_vector); if (vector_slot (matchvec, 0) == NULL) @@ -1718,8 +1714,7 @@ vty->node = onode; return ret; } - - + return cmd_describe_command_real (vline, vty, status); } @@ -1761,26 +1756,27 @@ 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 ( (index = vector_max (vline)) > 0) + index -= 1; + /* First, filter by preceeding command string */ - for (i = 0; i < index; i++) + VECTOR_LOOP (vline, command, 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); @@ -1806,31 +1802,28 @@ matchvec = vector_init (INIT_MATCHVEC_SIZE); /* Now we got into completion */ - for (i = 0; i < vector_max (cmd_vector); i++) - if ((cmd_element = vector_slot (cmd_vector, i)) != NULL) - { - const char *string; - vector strvec = cmd_element->strvec; - - /* Check field length */ - if (index >= vector_max (strvec)) - vector_slot (cmd_vector, i) = NULL; - else - { - unsigned int j; - - descvec = vector_slot (strvec, index); - for (j = 0; j < vector_max (descvec); j++) - { - desc = vector_slot (descvec, j); - - if ((string = cmd_entry_function (vector_slot (vline, index), - desc->cmd))) - if (cmd_unique_string (matchvec, string)) - vector_set (matchvec, XSTRDUP (MTYPE_TMP, string)); - } - } - } + VECTOR_LOOP (cmd_vector, cmd_element, i) + { + const char *string; + vector strvec = cmd_element->strvec; + + /* Check field length */ + if (index >= vector_max (strvec)) + vector_slot (cmd_vector, i) = NULL; + else + { + unsigned int j; + + descvec = vector_slot (strvec, index); + VECTOR_LOOP (descvec, desc, j) + { + if ((string = cmd_entry_function (vector_slot (vline, index), + desc->cmd))) + if (cmd_unique_string (matchvec, string)) + vector_set (matchvec, XSTRDUP (MTYPE_TMP, string)); + } + } + } /* We don't need cmd_vector any more. */ vector_free (cmd_vector); @@ -2014,24 +2007,21 @@ matched_count = 0; incomplete_count = 0; - for (i = 0; i < vector_max (cmd_vector); i++) - if (vector_slot (cmd_vector,i) != NULL) - { - cmd_element = vector_slot (cmd_vector,i); - - if (match == vararg_match || index >= cmd_element->cmdsize) - { - matched_element = cmd_element; + VECTOR_LOOP (cmd_vector, cmd_element, i) + { + if (match == vararg_match || index >= cmd_element->cmdsize) + { + matched_element = cmd_element; #if 0 - printf ("DEBUG: %s\n", cmd_element->string); + printf ("DEBUG: %s\n", cmd_element->string); #endif - matched_count++; - } - else - { - incomplete_count++; - } - } + matched_count++; + } + else + { + incomplete_count++; + } + } /* Finish of using cmd_vector. */ vector_free (cmd_vector); @@ -2163,12 +2153,10 @@ /* Make copy of command element */ cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node)); - for (index = 0; index < vector_max (vline); index++) + VECTOR_LOOP (vline, command, index) { int ret; - command = vector_slot (vline, index); - match = cmd_filter_by_string (vector_slot (vline, index), cmd_vector, index); @@ -2193,19 +2181,17 @@ matched_element = NULL; matched_count = 0; incomplete_count = 0; - for (i = 0; i < vector_max (cmd_vector); i++) - if (vector_slot (cmd_vector,i) != NULL) - { - cmd_element = vector_slot (cmd_vector,i); - - if (match == vararg_match || index >= cmd_element->cmdsize) - { - matched_element = cmd_element; - matched_count++; - } - else - incomplete_count++; - } + + VECTOR_LOOP (cmd_vector, cmd_element, i) + { + if (match == vararg_match || index >= cmd_element->cmdsize) + { + matched_element = cmd_element; + matched_count++; + } + else + incomplete_count++; + } /* Finish of using cmd_vector. */ vector_free (cmd_vector); @@ -2481,10 +2467,10 @@ struct cmd_node *cnode = vector_slot (cmdvec, vty->node); struct cmd_element *cmd; - for (i = 0; i < vector_max (cnode->cmd_vector); i++) - if ((cmd = vector_slot (cnode->cmd_vector, i)) != NULL) - vty_out (vty, " %s%s", cmd->string, - VTY_NEWLINE); + VECTOR_LOOP (cnode->cmd_vector, cmd, i) + if (!CMD_IS_HIDDEN(cmd)) + vty_out (vty, " %s%s", cmd->string, VTY_NEWLINE); + return CMD_SUCCESS; } Index: lib/command.h =================================================================== RCS file: /var/cvsroot/quagga/lib/command.h,v retrieving revision 1.13 diff -u -r1.13 command.h --- lib/command.h 7 Dec 2004 15:39:32 -0000 1.13 +++ lib/command.h 4 Jan 2005 18:02:45 -0000 @@ -121,7 +121,7 @@ enum { - CMD_ATTR_DEPRECATED, + CMD_ATTR_DEPRECATED = 1, CMD_ATTR_HIDDEN, }; Index: lib/vector.h =================================================================== RCS file: /var/cvsroot/quagga/lib/vector.h,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 vector.h --- lib/vector.h 13 Dec 2002 20:15:29 -0000 1.1.1.1 +++ lib/vector.h 4 Jan 2005 18:02:45 -0000 @@ -39,6 +39,13 @@ #define vector_slot(V,I) ((V)->index[(I)]) #define vector_max(V) ((V)->max) +/* for iterating through a vector + * Note that a trailling else will break this macro! + */ +#define VECTOR_LOOP(vector, node, i) \ + for ((i) = 0; (i) < vector_max ((vector)); i++) \ + if ( ((node) = vector_slot ((vector),i)) != NULL) + /* Prototypes. */ vector vector_init (unsigned int size); void vector_ensure (vector v, unsigned int num);