+2008-12-09 Tom Tromey <tromey@redhat.com>
+
+ PR gdb/1815:
+ * cli/cli-decode.c (delete_cmd): Forward declare.
+ (delete_cmd): Now static. Change return type. Remove command
+ from alias chain. Rewrite.
+ (add_cmd): Initialize new fields. Update cmd_pointer on all
+ aliases.
+ (add_alias_cmd): Put command on alias chain.
+ * command.h (delete_cmd): Don't declare.
+ * cli/cli-decode.h (delete_cmd): Don't declare.
+ (struct cmd_list_element) <aliases, alias_chain>: New fields.
+
2008-12-09 Tom Tromey <tromey@redhat.com>
* config.in, configure: Rebuild.
static void undef_cmd_error (char *, char *);
+static struct cmd_list_element *delete_cmd (char *name,
+ struct cmd_list_element **list);
+
static struct cmd_list_element *find_cmd (char *command,
int len,
struct cmd_list_element *clist,
{
struct cmd_list_element *c
= (struct cmd_list_element *) xmalloc (sizeof (struct cmd_list_element));
- struct cmd_list_element *p;
+ struct cmd_list_element *p, *iter;
- delete_cmd (name, list);
+ /* Turn each alias of the old command into an alias of the new
+ command. */
+ c->aliases = delete_cmd (name, list);
+ for (iter = c->aliases; iter; iter = iter->alias_chain)
+ iter->cmd_pointer = c;
if (*list == NULL || strcmp ((*list)->name, name) >= 0)
{
c->hookee_pre = NULL;
c->hookee_post = NULL;
c->cmd_pointer = NULL;
+ c->alias_chain = NULL;
return c;
}
if (old == 0)
{
- delete_cmd (name, list);
+ struct cmd_list_element *aliases = delete_cmd (name, list);
+ /* If this happens, it means a programmer error somewhere. */
+ gdb_assert (!aliases);
return 0;
}
c->allow_unknown = old->allow_unknown;
c->abbrev_flag = abbrev_flag;
c->cmd_pointer = old;
+ c->alias_chain = old->aliases;
+ old->aliases = c;
return c;
}
NULL, NULL);
}
-/* Remove the command named NAME from the command list. */
+/* Remove the command named NAME from the command list. Return the
+ list commands which were aliased to the deleted command. If the
+ command had no aliases, return NULL. */
-void
+static struct cmd_list_element *
delete_cmd (char *name, struct cmd_list_element **list)
{
- struct cmd_list_element *c;
- struct cmd_list_element *p;
+ struct cmd_list_element *iter;
+ struct cmd_list_element **previous_chain_ptr;
+ struct cmd_list_element *aliases = NULL;
+
+ previous_chain_ptr = list;
- while (*list && strcmp ((*list)->name, name) == 0)
+ for (iter = *previous_chain_ptr; iter; iter = *previous_chain_ptr)
{
- if ((*list)->hookee_pre)
- (*list)->hookee_pre->hook_pre = 0; /* Hook slips out of its mouth */
- if ((*list)->hookee_post)
- (*list)->hookee_post->hook_post = 0; /* Hook slips out of its bottom */
- p = (*list)->next;
- xfree (* list);
- *list = p;
+ if (strcmp (iter->name, name) == 0)
+ {
+ if (iter->hookee_pre)
+ iter->hookee_pre->hook_pre = 0;
+ if (iter->hookee_post)
+ iter->hookee_post->hook_post = 0;
+
+ /* Update the link. */
+ *previous_chain_ptr = iter->next;
+
+ aliases = iter->aliases;
+
+ /* If this command was an alias, remove it from the list of
+ aliases. */
+ if (iter->cmd_pointer)
+ {
+ struct cmd_list_element **prevp = &iter->cmd_pointer->aliases;
+ struct cmd_list_element *a = *prevp;
+
+ while (a != iter)
+ {
+ prevp = &a->alias_chain;
+ a = *prevp;
+ }
+ *prevp = iter->alias_chain;
+ }
+
+ xfree (iter);
+
+ /* We won't see another command with the same name. */
+ break;
+ }
+ else
+ previous_chain_ptr = &iter->next;
}
- if (*list)
- for (c = *list; c->next;)
- {
- if (strcmp (c->next->name, name) == 0)
- {
- if (c->next->hookee_pre)
- c->next->hookee_pre->hook_pre = 0; /* hooked cmd gets away. */
- if (c->next->hookee_post)
- c->next->hookee_post->hook_post = 0; /* remove post hook */
- /* :( no fishing metaphore */
- p = c->next->next;
- xfree (c->next);
- c->next = p;
- }
- else
- c = c->next;
- }
+ return aliases;
}
\f
/* Shorthands to the commands above. */
/* Pointer to command that is aliased by this one, so the
aliased command can be located in case it has been hooked. */
struct cmd_list_element *cmd_pointer;
+
+ /* Start of a linked list of all aliases of this command. */
+ struct cmd_list_element *aliases;
+
+ /* Link pointer for aliases on an alias list. */
+ struct cmd_list_element *alias_chain;
};
/* API to the manipulation of command lists. */
extern char **complete_on_enum (const char *enumlist[], char *, char *);
-extern void delete_cmd (char *, struct cmd_list_element **);
-
extern void help_cmd_list (struct cmd_list_element *, enum command_class,
char *, int, struct ui_file *);