[PATCH] disallow duplicate group names

Ali Gholami Rudi <[email protected]>
Newsgroups gmane.comp.window-managers.ratpoison.devel
Message-ID <[email protected]>
---
 src/actions.c |    6 ++++++
 src/group.c   |   13 +++++++++++++
 src/group.h   |    1 +
 3 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/src/actions.c b/src/actions.c
index 292ffc4..80e5690 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -4845,6 +4845,8 @@ cmd_gother (int interactive, struct cmdarg **args)
 cmdret *
 cmd_gnew (int interactive, struct cmdarg **args)
 {
+  if (groups_get_group_by_name (ARG_STRING (0)))
+    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_get_group_by_name (ARG_STRING (0)))
+    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_get_group_by_name (ARG_STRING (0)))
+    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..b79a0fc 100644
--- a/src/group.c
+++ b/src/group.c
@@ -156,6 +156,19 @@ groups_find_group_by_name (char *s)
 }
 
 rp_group *
+groups_get_group_by_name (char *s)
+{
+  rp_group *cur;
+
+  list_for_each_entry (cur, &rp_groups, node)
+    {
+      if (cur->name && !strcmp(s, cur->name))
+	return cur;
+    }
+  return NULL;
+}
+
+rp_group *
 groups_find_group_by_number (int n)
 {
   rp_group *cur;
diff --git a/src/group.h b/src/group.h
index 176e4ee..046aa58 100644
--- a/src/group.h
+++ b/src/group.h
@@ -42,6 +42,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_get_group_by_name (char *s);
 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);
-- 
1.6.0.2.307.gc427.dirty
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.