From 1008c6e563a29000653016fd25ce24f0c8a78df7 Mon Sep 17 00:00:00 2001 From: louie Date: Fri, 10 Jul 2020 17:37:36 -0700 Subject: Added addName and addNameF as config options --- read_cfg.c | 25 ++++++++++++++++++------- read_cfg.o | Bin 9504 -> 10072 bytes 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/read_cfg.c b/read_cfg.c index a5327fe..de75f64 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, bool recurs, bool force); +void handle_fname(char *path, char *group, bool recurs, bool force, char *name); char *autoAlias(char *path); int search_ch(char *str, char c); int wild_cmp(char *wild, char *literal); @@ -70,6 +70,7 @@ void cfg_interp(char *path){ } //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){ @@ -116,8 +117,13 @@ 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 sorting functionality - 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); + 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); + //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]); //create a new group else if(!(strcmp(args[0], "addGroup"))) group_add(args[1], NULL); @@ -166,7 +172,8 @@ int get_compmode(){ } //TODO augment to involve recurs -void handle_fname(char *path, char *group, bool recurs, bool force){ +//TODO could use some cleanup... +void handle_fname(char *path, char *group, bool recurs, bool force, char *name){ ENTRY *new; char *search; //pointer for traversing path char full_path_cpy[BUF_LEN]; @@ -195,7 +202,8 @@ void handle_fname(char *path, char *group, bool recurs, bool force){ //don't check that the path arg is valid if(force){ - if(hr){ + if(name != NULL) new = create_entry(name, full_path_cpy); + else if(hr){ strcpy(auto_name, autoAlias(full_path_cpy)); new = create_entry(auto_name, full_path_cpy); } @@ -228,8 +236,10 @@ void handle_fname(char *path, char *group, bool recurs, bool force){ //check if path is a file (and not a directory/symlink/etc.) and regex matches if(fname->d_type == DT_REG && !(wild_cmp(&arg_cpy[i+1], fname->d_name))){ + //check if a name was given as argument + if(name != NULL) new = create_entry(name, relative_path_cpy); //check if autoAlias is on. If it is, go to the autoAlias function - if(hr){ + else if(hr){ strcpy(auto_name, autoAlias(relative_path_cpy)); new = create_entry(auto_name, relative_path_cpy); } @@ -252,7 +262,8 @@ void handle_fname(char *path, char *group, bool recurs, bool force){ //file name is okay //FIXME does not take into account whether the argument is a file (could be a directory, symlink, etc.) else{ - if(hr){ + if(name != NULL) new = create_entry(name, full_path_cpy); + else if(hr){ strcpy(auto_name, autoAlias(full_path_cpy)); new = create_entry(auto_name, full_path_cpy); } diff --git a/read_cfg.o b/read_cfg.o index 5a2d5a3..18e631c 100644 Binary files a/read_cfg.o and b/read_cfg.o differ -- cgit