diff options
author | Ali Gholami Rudi <aliqrudi@gmail.com> | 2008-10-18 08:05:15 +0330 |
---|---|---|
committer | Shawn <sabetts@juicebox.(none)> | 2008-10-19 00:36:59 -0700 |
commit | 03f8bba45a8d1b0236731b4aece52795c0bc1326 (patch) | |
tree | faa91e25968a66eda5764711da715f2dc0a51bf3 | |
parent | 9ec3e80ad828e3eb35ce800b78fa73176d0d7c02 (diff) | |
download | ratpoison-03f8bba45a8d1b0236731b4aece52795c0bc1326.zip |
disallow duplicate group names
-rw-r--r-- | src/actions.c | 8 | ||||
-rw-r--r-- | src/group.c | 5 | ||||
-rw-r--r-- | src/group.h | 2 |
3 files changed, 11 insertions, 4 deletions
diff --git a/src/actions.c b/src/actions.c index 292ffc4..c977075 100644 --- a/src/actions.c +++ b/src/actions.c @@ -1916,7 +1916,7 @@ find_group (char *str) return group; } - group = groups_find_group_by_name (str); + group = groups_find_group_by_name (str, 0); return group; } @@ -4845,6 +4845,8 @@ cmd_gother (int interactive, struct cmdarg **args) cmdret * cmd_gnew (int interactive, struct cmdarg **args) { + if (groups_find_group_by_name (ARG_STRING (0), 1)) + return cmdret_new (RET_FAILURE, "gnew: group already exists"); set_current_group (group_add_new_group (ARG_STRING(0))); return cmdret_new (RET_SUCCESS, NULL); } @@ -4852,6 +4854,8 @@ cmd_gnew (int interactive, struct cmdarg **args) cmdret * cmd_gnewbg (int interactive, struct cmdarg **args) { + if (groups_find_group_by_name (ARG_STRING (0), 1)) + return cmdret_new (RET_FAILURE, "gnewbg: group already exists"); group_add_new_group (ARG_STRING(0)); return cmdret_new (RET_SUCCESS, NULL); } @@ -4859,6 +4863,8 @@ cmd_gnewbg (int interactive, struct cmdarg **args) cmdret * cmd_grename (int interactive, struct cmdarg **args) { + if (groups_find_group_by_name (ARG_STRING (0), 1)) + return cmdret_new (RET_FAILURE, "grename: duplicate group name"); group_rename (rp_current_group, ARG_STRING(0)); return cmdret_new (RET_SUCCESS, NULL); } diff --git a/src/group.c b/src/group.c index 1c4329b..5246b33 100644 --- a/src/group.c +++ b/src/group.c @@ -139,7 +139,7 @@ group_last_group (void) } rp_group * -groups_find_group_by_name (char *s) +groups_find_group_by_name (char *s, int exact_match) { rp_group *cur; @@ -147,7 +147,8 @@ groups_find_group_by_name (char *s) { if (cur->name) { - if (str_comp (s, cur->name, strlen (s))) + if ((!exact_match && str_comp (s, cur->name, strlen (s))) || + (exact_match && !strcmp (cur->name, s))) return cur; } } diff --git a/src/group.h b/src/group.h index 176e4ee..364100f 100644 --- a/src/group.h +++ b/src/group.h @@ -41,7 +41,7 @@ void groups_unmap_window (rp_window *win); rp_window *group_prev_window (rp_group *g, rp_window *win); rp_window *group_next_window (rp_group *g, rp_window *win); -rp_group *groups_find_group_by_name (char *s); +rp_group *groups_find_group_by_name (char *s, int exact_match); rp_group *groups_find_group_by_number (int n); rp_group *groups_find_group_by_window (rp_window *win); rp_group *groups_find_group_by_group (rp_group *g); |