summaryrefslogtreecommitdiff
path: root/group.c
diff options
context:
space:
mode:
authorlouie <lshprung@yahoo.com>2020-07-11 17:08:41 -0700
committerlouie <lshprung@yahoo.com>2020-07-11 17:08:41 -0700
commit8f36e6816b5d5bd968f28e3c0acb269560d2796f (patch)
tree221717b1fd6f5a5df8bb0b23187d6f1106275bf0 /group.c
parent8ec8e9d5dd37eac5266f8cd94ce946f23f436ef9 (diff)
Added hiding of empty groups
Diffstat (limited to 'group.c')
-rw-r--r--group.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/group.c b/group.c
index 9c1736c..36d0df3 100644
--- a/group.c
+++ b/group.c
@@ -20,6 +20,8 @@ typedef struct group{
GROUP *create_group(char *new_name);
void group_add(char *gname, ENTRY *addme);
+void group_rm(GROUP *g);
+void clean_groups(); //remove empty groups from linked list
GROUP **get_groups();
char *get_gname(GROUP *g);
char *get_gprog(GROUP *g);
@@ -110,6 +112,53 @@ void group_add(char *gname, ENTRY *addme){
return;
}
+void group_rm(GROUP *g){
+ ENTRY **e = get_entries(g->head, g->entry_count);
+ int i;
+
+ for(i = 0; i < g->entry_count; i++){
+ entry_rm(e[i]);
+ }
+
+ free(e);
+ free(g);
+ group_count--;
+ return;
+}
+
+void clean_groups(){
+ GROUP *dummy_head;
+ GROUP *trav;
+ GROUP *hold;
+
+ if(group_count == 0){
+ printf("Error: no groups!\n");
+ exit(0);
+ }
+
+ else{
+ dummy_head = create_group("dummy");
+ dummy_head->next = groups_head;
+ trav = dummy_head;
+
+ while(trav != NULL){
+ //found empty group for removal
+ if(trav->next != NULL && trav->next->entry_count < 1){
+ printf("Omitting empty group \"%s\"\n", trav->next->name);
+ hold = trav->next;
+ trav->next = trav->next->next;
+ group_rm(hold);
+ }
+ else trav = trav->next;
+ }
+ }
+
+ group_rm(dummy_head);
+ return;
+
+}
+
+
GROUP **get_groups(){
GROUP **arr = malloc(sizeof(GROUP *) * group_count);
GROUP *trav = groups_head;