From 40a6bba7765b661303ed0e1e6f6f7319e344ce08 Mon Sep 17 00:00:00 2001 From: louie Date: Mon, 13 Jul 2020 15:09:01 -0700 Subject: Fixed entry deletion, added addR option --- read_cfg.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'read_cfg.c') 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); -- cgit