From 03fff71fa937d385a2b260d58443fb81ce303fb2 Mon Sep 17 00:00:00 2001 From: louie Date: Fri, 10 Jul 2020 17:23:52 -0700 Subject: Removed unnecessary checks from create_entry, added addF option^C --- entry.c | 17 +---------------- entry.o | Bin 3888 -> 3336 bytes read_cfg.c | 25 ++++++++++++++++++++----- read_cfg.o | Bin 9024 -> 9504 bytes 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/entry.c b/entry.c index b7c240c..c47b5d7 100644 --- a/entry.c +++ b/entry.c @@ -22,26 +22,11 @@ char *get_epath(ENTRY *e); ENTRY *create_entry(char *new_name, char *new_path){ ENTRY *new; - char adjusted_path[BUF_LEN]; - - //double check if file exists - if(access(new_path, F_OK) == -1){ - //try to adjust the path, in case of lingering quotes - strcpy(adjusted_path, &new_path[1]); - adjusted_path[strlen(adjusted_path)-1] = '\0'; - - if(access(adjusted_path, F_OK) == -1){ - printf("Error: Invalid File Name \"%s\"\n", new_path); - return NULL; - } - } - - else strcpy(adjusted_path, new_path); new = malloc(sizeof(ENTRY)); strcpy(new->name, new_name); - strcpy(new->path, adjusted_path); + strcpy(new->path, new_path); new->next = NULL; return new; diff --git a/entry.o b/entry.o index ce61e81..1fd4495 100644 Binary files a/entry.o and b/entry.o differ diff --git a/read_cfg.c b/read_cfg.c index b8d90fb..a5327fe 100644 --- a/read_cfg.c +++ b/read_cfg.c @@ -17,7 +17,7 @@ void check_line(char *buffer); int get_compmode(); //private -void handle_fname(char *path, char *group); +void handle_fname(char *path, char *group, bool recurs, bool force); char *autoAlias(char *path); int search_ch(char *str, char c); int wild_cmp(char *wild, char *literal); @@ -69,6 +69,9 @@ void cfg_interp(char *path){ return; } +//TODO add support for "addR" recursive adding +//TODO add support for "alias" option +//TODO add support for "hide" option void check_line(char *buffer){ char *delims = " \t\n"; char *tok = strtok(buffer, delims); @@ -112,9 +115,9 @@ void check_line(char *buffer){ //add entry(ies) to a group: first arg is the file(s), second arg is the group to add to //TODO add potential dash functions - //TODO add support for "-R" recursive adding //TODO add sorting functionality - else if(!(strcmp(args[0], "add"))) handle_fname(args[1], args[2]); + else if(!(strcmp(args[0], "add"))) handle_fname(args[1], args[2], 0, 0); + else if(!(strcmp(args[0], "addF"))) handle_fname(args[1], args[2], 0, 1); //create a new group else if(!(strcmp(args[0], "addGroup"))) group_add(args[1], NULL); @@ -162,7 +165,8 @@ int get_compmode(){ return compmode; } -void handle_fname(char *path, char *group){ +//TODO augment to involve recurs +void handle_fname(char *path, char *group, bool recurs, bool force){ ENTRY *new; char *search; //pointer for traversing path char full_path_cpy[BUF_LEN]; @@ -189,9 +193,20 @@ void handle_fname(char *path, char *group){ } else strcpy(full_path_cpy, path); + //don't check that the path arg is valid + if(force){ + if(hr){ + strcpy(auto_name, autoAlias(full_path_cpy)); + new = create_entry(auto_name, full_path_cpy); + } + else new = create_entry(full_path_cpy, full_path_cpy); + if(new != NULL) group_add(group, new); + } + + //file is not recognized, perhaps it has a wildcard? //TODO finish rewriting a more robust wildcard thingy - if(access(full_path_cpy, F_OK) == -1){ + else if(access(full_path_cpy, F_OK) == -1){ i = search_ch(full_path_cpy, '*'); if(i > -1){ //look for a directory diff --git a/read_cfg.o b/read_cfg.o index 6246fc5..5a2d5a3 100644 Binary files a/read_cfg.o and b/read_cfg.o differ -- cgit