+/* Look up a command whose 'prefixlist' is KEY. Return the command if found,
+ otherwise return NULL. */
+
+static struct cmd_list_element *
+lookup_cmd_for_prefixlist (struct cmd_list_element **key,
+ struct cmd_list_element *list)
+{
+ struct cmd_list_element *p = NULL;
+
+ for (p = list; p != NULL; p = p->next)
+ {
+ struct cmd_list_element *q;
+
+ if (p->prefixlist == NULL)
+ continue;
+ else if (p->prefixlist == key)
+ return p;
+
+ q = lookup_cmd_for_prefixlist (key, *(p->prefixlist));
+ if (q != NULL)
+ return q;
+ }
+
+ return NULL;
+}
+
+static void
+set_cmd_prefix (struct cmd_list_element *c, struct cmd_list_element **list)
+{
+ struct cmd_list_element *p;
+
+ /* Check to see if *LIST contains any element other than C. */
+ for (p = *list; p != NULL; p = p->next)
+ if (p != c)
+ break;
+
+ if (p == NULL)
+ {
+ /* *SET_LIST only contains SET. */
+ p = lookup_cmd_for_prefixlist (list, setlist);
+
+ c->prefix = p ? (p->cmd_pointer ? p->cmd_pointer : p) : p;
+ }
+ else
+ c->prefix = p->prefix;
+}
+