diff options
author | louie <lshprung@yahoo.com> | 2020-07-13 15:09:01 -0700 |
---|---|---|
committer | louie <lshprung@yahoo.com> | 2020-07-13 15:09:01 -0700 |
commit | 40a6bba7765b661303ed0e1e6f6f7319e344ce08 (patch) | |
tree | d5e99caeb36c6bb9300a43efd1a11201534499ea | |
parent | 2d08a7dbceac846f54cba6b0b75b0de1542df707 (diff) |
Fixed entry deletion, added addR option
-rw-r--r-- | entry.c | 18 | ||||
-rw-r--r-- | entry.h | 4 | ||||
-rw-r--r-- | entry.o | bin | 4040 -> 4256 bytes | |||
-rw-r--r-- | group.c | 7 | ||||
-rw-r--r-- | group.o | bin | 7960 -> 7792 bytes | |||
-rw-r--r-- | read_cfg.c | 15 | ||||
-rw-r--r-- | read_cfg.o | bin | 10136 -> 10464 bytes |
7 files changed, 34 insertions, 10 deletions
@@ -17,7 +17,8 @@ typedef struct entry{ } ENTRY; ENTRY *create_entry(char *new_name, char *new_path, bool force); -void entry_rm(ENTRY *e); +void entry_rm(ENTRY *e, ENTRY *prev); +void clear_entries(ENTRY *head); ENTRY *entry_add_last(ENTRY *tail, ENTRY *add); ENTRY **get_entries(ENTRY *head, int count); char *get_ename(ENTRY *e); @@ -38,11 +39,24 @@ ENTRY *create_entry(char *new_name, char *new_path, bool force){ return new; } -void entry_rm(ENTRY *e){ +void entry_rm(ENTRY *e, ENTRY *prev){ assert(e != NULL); + if(prev != NULL) prev->next = e->next; //maintain linked structure free(e); } +void clear_entries(ENTRY *head){ + ENTRY *temp; + + while(head != NULL){ + temp = head; + head = head->next; + free(temp); + } + + return; +} + ENTRY *entry_add_last(ENTRY *tail, ENTRY *add){ assert(add != NULL); @@ -5,7 +5,9 @@ typedef struct entry ENTRY; ENTRY *create_entry(char *new_name, char *new_path, bool force); -void entry_rm(ENTRY *e); +void entry_rm(ENTRY *e, ENTRY *prev); + +void clear_entries(ENTRY *head); ENTRY *entry_add_last(ENTRY *tail, ENTRY *add); @@ -113,14 +113,9 @@ void group_add(char *gname, ENTRY *addme){ } 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]); - } + clear_entries(g->head); - free(e); free(g); group_count--; return; Binary files differ@@ -69,8 +69,8 @@ void cfg_interp(char *path){ return; } +//TODO consider implementing binary tree search instead of if, elseif, elseif, etc. //TODO add support for "addR" recursive adding -//TODO add support for "addName" option for adding and aliasing on the same line //TODO add support for "alias" option //TODO add support for "hide" option void check_line(char *buffer){ @@ -118,10 +118,16 @@ void check_line(char *buffer){ //TODO add potential dash functions //TODO add sorting functionality else if(!(strcmp(args[0], "add"))) handle_fname(args[1], args[2], 0, 0, NULL); + //force add entry to a group: first arg is the file(s), second arg is the group to add to else if(!(strcmp(args[0], "addF"))) handle_fname(args[1], args[2], 0, 1, NULL); + + //recursively add: that is, also search directories in the given path + else if(!(strcmp(args[0], "addR"))) handle_fname(args[1], args[2], 1, 0, NULL); + //add entry to a group: first arg is the name, second arg is the file, and third arg is the group to add to else if(!(strcmp(args[0], "addName"))) handle_fname(args[2], args[3], 0, 0, args[1]); + //same as addName, but with force on else if(!(strcmp(args[0], "addNameF"))) handle_fname(args[2], args[3], 0, 1, args[1]); @@ -245,6 +251,13 @@ void handle_fname(char *path, char *group, bool recurs, bool force, char *name){ else new = create_entry(relative_path_cpy, relative_path_cpy, force); if(new != NULL) group_add(group, new); } + + //if the recursive option was specified and the path is a directory, run handle_fname on this directory, but for security reasons, do not consider directories that start with a '.' + //FIXME this may still need some work... + else if(recurs && fname->d_type == DT_DIR && fname->d_name[0] != '.'){ + strcat(relative_path_cpy, "/*"); + handle_fname(relative_path_cpy, group, 1, 0, NULL); + } } closedir(dp); Binary files differ |