summaryrefslogtreecommitdiff
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
parent8ec8e9d5dd37eac5266f8cd94ce946f23f436ef9 (diff)
Added hiding of empty groups
-rw-r--r--draw.c7
-rw-r--r--entry.c8
-rw-r--r--entry.h2
-rw-r--r--entry.obin3672 -> 4040 bytes
-rw-r--r--group.c49
-rw-r--r--group.h4
-rw-r--r--group.obin6704 -> 7912 bytes
-rw-r--r--read_cfg.c1
-rw-r--r--read_cfg.obin10136 -> 10136 bytes
9 files changed, 68 insertions, 3 deletions
diff --git a/draw.c b/draw.c
index 96b4525..a3f8a87 100644
--- a/draw.c
+++ b/draw.c
@@ -48,8 +48,11 @@ int main(int argc, char **argv){
//Fill Groups
cfg_interp(cfg_path); //read the contents of the cfg file
- g = get_groups(); //retrieve results of previous function
- g_count = get_gcount(g); //retrieve number of groups in g
+
+ //Remove Empty Groups from the Array
+ clean_groups();
+ g = get_groups(); //retrieve results of cfg_interp
+ g_count = get_gcount(g); //retrieve number of groups in g (only do this after removing empty groups)
initscr();
cbreak();
diff --git a/entry.c b/entry.c
index 7431b64..a74f18e 100644
--- a/entry.c
+++ b/entry.c
@@ -17,10 +17,13 @@ typedef struct entry{
} ENTRY;
ENTRY *create_entry(char *new_name, char *new_path, bool force);
+void entry_rm(ENTRY *e);
ENTRY *entry_add_last(ENTRY *tail, ENTRY *add);
ENTRY **get_entries(ENTRY *head, int count);
char *get_ename(ENTRY *e);
char *get_epath(ENTRY *e);
+bool get_eforce(ENTRY *e);
+void entry_debug(ENTRY *trav);
ENTRY *create_entry(char *new_name, char *new_path, bool force){
ENTRY *new;
@@ -35,6 +38,11 @@ ENTRY *create_entry(char *new_name, char *new_path, bool force){
return new;
}
+void entry_rm(ENTRY *e){
+ assert(e != NULL);
+ free(e);
+}
+
ENTRY *entry_add_last(ENTRY *tail, ENTRY *add){
assert(add != NULL);
diff --git a/entry.h b/entry.h
index b70462c..6bc6163 100644
--- a/entry.h
+++ b/entry.h
@@ -5,6 +5,8 @@ typedef struct entry ENTRY;
ENTRY *create_entry(char *new_name, char *new_path, bool force);
+void entry_rm(ENTRY *e);
+
ENTRY *entry_add_last(ENTRY *tail, ENTRY *add);
ENTRY **get_entries(ENTRY *head, int count);
diff --git a/entry.o b/entry.o
index ad68585..d013914 100644
--- a/entry.o
+++ b/entry.o
Binary files differ
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;
diff --git a/group.h b/group.h
index 2dc18b9..38a33f8 100644
--- a/group.h
+++ b/group.h
@@ -7,6 +7,10 @@ GROUP *create_group(char *new_name);
void group_add(char *gname, ENTRY *addme);
+void group_rm(GROUP *g);
+
+void clean_groups();
+
GROUP **get_groups();
char *get_gname(GROUP *g);
diff --git a/group.o b/group.o
index e3c006f..2b1b6e1 100644
--- a/group.o
+++ b/group.o
Binary files differ
diff --git a/read_cfg.c b/read_cfg.c
index 52eb26c..c97b62c 100644
--- a/read_cfg.c
+++ b/read_cfg.c
@@ -134,7 +134,6 @@ void check_line(char *buffer){
else printf("Error: Unknown Compatability Mode Argument \"%s\"\n", args[1]);
}
- //TODO fix this so it can give an error that it doesn't recognize args[0]
else{
//remaining possibilities involve args[1] being a char* referring to a group
g = get_groups();
diff --git a/read_cfg.o b/read_cfg.o
index 540a909..322ba03 100644
--- a/read_cfg.o
+++ b/read_cfg.o
Binary files differ