diff options
author | louie <lshprung@yahoo.com> | 2020-07-06 11:00:47 -0700 |
---|---|---|
committer | louie <lshprung@yahoo.com> | 2020-07-06 11:00:47 -0700 |
commit | 762fc562b23b5b85ae4a19021679b5895bfb339d (patch) | |
tree | 9270fe7601e907fc3d7b475d08198c97316b91a1 | |
parent | 9c291ae862c7568b9a2ed4ac3e958a4e1eb79fc1 (diff) |
Created a basic autoAlias system
-rw-r--r-- | read_cfg.c | 54 | ||||
-rw-r--r-- | read_cfg.o | bin | 7088 -> 8232 bytes |
2 files changed, 52 insertions, 2 deletions
@@ -18,6 +18,7 @@ int get_compmode(); //private void handle_fname(char *path, char *group); +char *autoAlias(char *path); int search_ch(char *str, char c); int wild_cmp(char *wild, char *literal); @@ -27,6 +28,9 @@ int compmode = 0; //1 -> WSL //maybe more later? +//set to true to automatically try to create a human readable name for an entry +bool hr = false; + void cfg_interp(){ FILE *fp; char buffer[BUF_LEN]; @@ -101,6 +105,11 @@ void check_line(char *buffer){ i++; } + if(!(strcmp(args[0], "autoAlias"))){ + if(!(strcmp(args[1], "on"))) hr = true; + else if(!(strcmp(args[1], "off"))) hr = false; + } + //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 @@ -153,6 +162,7 @@ void handle_fname(char *path, char *group){ char *search; //pointer for traversing path char path_cpy[BUF_LEN]; char arg_cpy[BUF_LEN]; + char auto_name[BUF_LEN]; int plen = strlen(path); char *dirname; DIR *dp; @@ -188,7 +198,12 @@ void handle_fname(char *path, char *group){ //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))){ - new = create_entry(path_cpy, path_cpy); + //check if autoAlias is on. If it is, go to the autoAlias function + if(hr){ + strcpy(auto_name, autoAlias(path_cpy)); + new = create_entry(auto_name, path_cpy); + } + else new = create_entry(path_cpy, path_cpy); if(new != NULL) group_add(group, new); } } @@ -202,7 +217,11 @@ void handle_fname(char *path, char *group){ //file name is okay else{ - new = create_entry(path, path); + if(hr){ + strcpy(auto_name, autoAlias(path)); + new = create_entry(auto_name, path); + } + else new = create_entry(path, path); if(new != NULL){ group_add(group, new); } @@ -214,6 +233,37 @@ void handle_fname(char *path, char *group){ return; } +//TODO figure out how to trim the extensions of files off +char *autoAlias(char *path){ + char *hr_name = malloc(sizeof(char) * BUF_LEN); + char *p = hr_name; + char *rpath; //necessary so as not to touch the actual path + + //get to the relative path name + if(compmode) rpath = strrchr(path, '\\'); + else rpath = strrchr(path, '/'); + rpath++; + + while(*rpath != '\0'){ + switch(*rpath){ + case '-': + case '_': + *p = ' '; + break; + + default: + *p = *rpath; + } + *rpath++; + *p++; + } + + //close the name + *p = '\0'; + + return hr_name; +} + int search_ch(char *str, char c){ int i = 0; |