summaryrefslogtreecommitdiff
path: root/src/actions.c
diff options
context:
space:
mode:
authorsabetts <sabetts>2002-01-24 10:58:20 +0000
committersabetts <sabetts>2002-01-24 10:58:20 +0000
commitcb02a04e74094b5ab59e438145f33b0a61fd5fa4 (patch)
tree909a922cfb2a900d2dc1098473c8a832e14a78b3 /src/actions.c
parent15afe7617bf51dcdf7b74e3bb996ae632387924e (diff)
downloadratpoison-cb02a04e74094b5ab59e438145f33b0a61fd5fa4.zip
* src/actions.c (find_alias_index): new function
(cmd_alias): When an alias is already in the alias list, replace it with the new alias. * src/events.c (configure_request): do not send a synthetic configure notify event.
Diffstat (limited to 'src/actions.c')
-rw-r--r--src/actions.c46
1 files changed, 36 insertions, 10 deletions
diff --git a/src/actions.c b/src/actions.c
index 17fe2b1..2aadf38 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -2324,10 +2324,25 @@ cmd_defbarpadding (int interactive, void *data)
return NULL;
}
+/* Search the alias table for a match. If a match is found, return its
+ index into the table. Otherwise return -1. */
+static int
+find_alias_index (char *name)
+{
+ int i;
+
+ for (i=0; i<alias_list_last; i++)
+ if (!strcmp (name, alias_list[i].name))
+ return i;
+
+ return -1;
+}
+
char *
cmd_alias (int interactive, void *data)
{
char *name, *alias;
+ int index;
if (data == NULL)
{
@@ -2335,12 +2350,7 @@ cmd_alias (int interactive, void *data)
return NULL;
}
- if (alias_list_last >= alias_list_size)
- {
- alias_list_size *= 2;
- alias_list = xrealloc (alias_list, sizeof (cmd_alias) * alias_list_size);
- }
-
+ /* Parse out the arguments. */
name = strtok (data, " ");
alias = strtok (NULL, "\0");
@@ -2349,10 +2359,26 @@ cmd_alias (int interactive, void *data)
message (" alias: Two arguments required ");
return NULL;
}
-
- alias_list[alias_list_last].name = xstrdup (name);
- alias_list[alias_list_last].alias = xstrdup (alias);
- alias_list_last++;
+
+ /* Are we updating an existing alias, or creating a new one? */
+ index = find_alias_index (name);
+ if (index >= 0)
+ {
+ free (alias_list[index].alias);
+ alias_list[index].alias = xstrdup (alias);
+ }
+ else
+ {
+ if (alias_list_last >= alias_list_size)
+ {
+ alias_list_size *= 2;
+ alias_list = xrealloc (alias_list, sizeof (cmd_alias) * alias_list_size);
+ }
+
+ alias_list[alias_list_last].name = xstrdup (name);
+ alias_list[alias_list_last].alias = xstrdup (alias);
+ alias_list_last++;
+ }
return NULL;
}