It should start with ? for a command that is an abbreviation
or with * for a command that most users don't need to know about.
- Add this command to command list *LIST. */
+ Add this command to command list *LIST.
+
+ Returns a pointer to the added command (not necessarily the head
+ of *LIST). */
struct cmd_list_element *
add_cmd (name, class, fun, doc, list)
{
register struct cmd_list_element *c
= (struct cmd_list_element *) xmalloc (sizeof (struct cmd_list_element));
+ struct cmd_list_element *p;
delete_cmd (name, list);
- c->next = *list;
+
+ if (*list == NULL || STRCMP ((*list)->name, name) >= 0)
+ {
+ c->next = *list;
+ *list = c;
+ }
+ else
+ {
+ p = *list;
+ while (p->next && STRCMP (p->next->name, name) <= 0)
+ {
+ p = p->next;
+ }
+ c->next = p->next;
+ p->next = c;
+ }
+
c->name = name;
c->class = class;
c->function.cfunc = fun;
c->user_commands = NULL;
c->hookee = NULL;
c->cmd_pointer = NULL;
- *list = c;
+
return c;
}
}
/* Where SETCMD has already been added, add the corresponding show
- command to LIST and return a pointer to it. */
+ command to LIST and return a pointer to the added command (not
+ necessarily the head of LIST). */
struct cmd_list_element *
add_show_from_set (setcmd, list)
struct cmd_list_element *setcmd;
{
struct cmd_list_element *showcmd =
(struct cmd_list_element *) xmalloc (sizeof (struct cmd_list_element));
+ struct cmd_list_element *p;
memcpy (showcmd, setcmd, sizeof (struct cmd_list_element));
delete_cmd (showcmd->name, list);
else
fprintf_unfiltered (gdb_stderr, "GDB internal error: Bad docstring for set command\n");
- showcmd->next = *list;
- *list = showcmd;
+ if (*list == NULL || STRCMP ((*list)->name, showcmd->name) >= 0)
+ {
+ showcmd->next = *list;
+ *list = showcmd;
+ }
+ else
+ {
+ p = *list;
+ while (p->next && STRCMP (p->next->name, showcmd->name) <= 0)
+ {
+ p = p->next;
+ }
+ showcmd->next = p->next;
+ p->next = showcmd;
+ }
+
return showcmd;
}
}
else if (c == (struct cmd_list_element *) -1)
{
- /* We've gotten this far properley, but the next step
+ /* We've gotten this far properly, but the next step
is ambiguous. We need to set the result list to the best
we've found (if an inferior hasn't already set it). */
if (result_list != NULL)
q = (char *) alloca (p - *line + 1);
strncpy (q, *line, p - *line);
- q[p-*line] = '\0';
+ q[p - *line] = '\0';
undef_cmd_error (cmdtype, q);
}
}