diff options
author | louie <lshprung@yahoo.com> | 2020-07-11 17:08:41 -0700 |
---|---|---|
committer | louie <lshprung@yahoo.com> | 2020-07-11 17:08:41 -0700 |
commit | 8f36e6816b5d5bd968f28e3c0acb269560d2796f (patch) | |
tree | 221717b1fd6f5a5df8bb0b23187d6f1106275bf0 | |
parent | 8ec8e9d5dd37eac5266f8cd94ce946f23f436ef9 (diff) |
Added hiding of empty groups
-rw-r--r-- | draw.c | 7 | ||||
-rw-r--r-- | entry.c | 8 | ||||
-rw-r--r-- | entry.h | 2 | ||||
-rw-r--r-- | entry.o | bin | 3672 -> 4040 bytes | |||
-rw-r--r-- | group.c | 49 | ||||
-rw-r--r-- | group.h | 4 | ||||
-rw-r--r-- | group.o | bin | 6704 -> 7912 bytes | |||
-rw-r--r-- | read_cfg.c | 1 | ||||
-rw-r--r-- | read_cfg.o | bin | 10136 -> 10136 bytes |
9 files changed, 68 insertions, 3 deletions
@@ -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(); @@ -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); @@ -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); Binary files differ@@ -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; @@ -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); Binary files differ@@ -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(); Binary files differ |