summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouie <lshprung@yahoo.com>2020-07-13 15:09:01 -0700
committerlouie <lshprung@yahoo.com>2020-07-13 15:09:01 -0700
commit40a6bba7765b661303ed0e1e6f6f7319e344ce08 (patch)
treed5e99caeb36c6bb9300a43efd1a11201534499ea
parent2d08a7dbceac846f54cba6b0b75b0de1542df707 (diff)
Fixed entry deletion, added addR option
-rw-r--r--entry.c18
-rw-r--r--entry.h4
-rw-r--r--entry.obin4040 -> 4256 bytes
-rw-r--r--group.c7
-rw-r--r--group.obin7960 -> 7792 bytes
-rw-r--r--read_cfg.c15
-rw-r--r--read_cfg.obin10136 -> 10464 bytes
7 files changed, 34 insertions, 10 deletions
diff --git a/entry.c b/entry.c
index a74f18e..d455f6b 100644
--- a/entry.c
+++ b/entry.c
@@ -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);
diff --git a/entry.h b/entry.h
index 6bc6163..bcefc04 100644
--- a/entry.h
+++ b/entry.h
@@ -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);
diff --git a/entry.o b/entry.o
index d013914..e9344db 100644
--- a/entry.o
+++ b/entry.o
Binary files differ
diff --git a/group.c b/group.c
index e1ca5a1..7697e96 100644
--- a/group.c
+++ b/group.c
@@ -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;
diff --git a/group.o b/group.o
index 9b89789..469076d 100644
--- a/group.o
+++ b/group.o
Binary files differ
diff --git a/read_cfg.c b/read_cfg.c
index c97b62c..25f4d78 100644
--- a/read_cfg.c
+++ b/read_cfg.c
@@ -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);
diff --git a/read_cfg.o b/read_cfg.o
index 322ba03..2849c09 100644
--- a/read_cfg.o
+++ b/read_cfg.o
Binary files differ