summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouie <lshprung@yahoo.com>2020-12-24 17:21:09 -0800
committerlouie <lshprung@yahoo.com>2020-12-24 17:21:09 -0800
commit3a5c33f7379796dfddfbf187f0fb54ddde11131f (patch)
tree99affc533c34d25ad8148bb465fb921a373f48af
parenta7c48cdd187c23b51e9aac54f4abbdb5c7c24a6f (diff)
Improved default configuration, fixed addR
-rw-r--r--docs/tml-config.5.gzbin2330 -> 2330 bytes
-rw-r--r--read_cfg.c144
-rw-r--r--read_cfg.obin20544 -> 27576 bytes
-rwxr-xr-xtmlbin47040 -> 51168 bytes
4 files changed, 125 insertions, 19 deletions
diff --git a/docs/tml-config.5.gz b/docs/tml-config.5.gz
index e8a61c2..797abc9 100644
--- a/docs/tml-config.5.gz
+++ b/docs/tml-config.5.gz
Binary files differ
diff --git a/read_cfg.c b/read_cfg.c
index 8625e87..5f479c4 100644
--- a/read_cfg.c
+++ b/read_cfg.c
@@ -34,6 +34,7 @@ void handle_fname(char *path, char *group, bool recurs, bool force, char *name,
void addme(char *path, char *group, bool force, char *name);
char *autoAlias(char *path);
int search_ch(char *str, char c);
+int search_last_ch(char *str, char c);
int wild_cmp(char *wild, char *literal);
char *strip_quotes(char *str);
void error_mes(int ln, char *message);
@@ -243,33 +244,103 @@ void mkconfig_wizard(char *path){
//write to file (in Windows, executing a file will open it in its default application)
#if defined _WIN32 || defined _WIN64
- fprintf(fp, "# This file was auto-generated by tml. See docs/tml-config.md or tml-config(5) for documentation\n"
+ fprintf(fp, "# This file was auto-generated by tml. See docs\\tml-config.md or tml-config(5) for documentation\n"
"# By default, no launcher is specified for any group. When no launcher is specified on the Windows build of tml, media files will be opened with their default application.\n"
"# It is generally recommended to specify a launcher for groups containing media files using the \"setLauncher\" command\n\n"
"# Recursively add files from %s%cMusic%c to Music group\n"
- "addGroup Music\n"
- "addR %s%cMusic%c* Music\n\n"
- "# Recursively add files from %s%cPictures%c to Pictures group\n"
- "addGroup Pictures\n"
- "addR %s%cPictures%c* Pictures\n\n"
- "# Recursively add files from %s%cVideos%c to Videos group\n"
- "addGroup Videos\n"
- "addR %s%cVideos%c* Videos", home, sep, sep, home, sep, sep, home, sep, sep, home, sep, sep, home, sep, sep, home, sep, sep);
+ "addGroup Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.aac Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.aiff Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.alac Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.au Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.flac Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.m4a Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.mp3 Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.ogg Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.pcm Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.wav Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.wma Music\n\n", home, sep, sep);
+ fprintf(fp, "# Recursively add files from %s%cPictures%c to Pictures group\n"
+ "addGroup Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.epi Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.eps Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.eps2 Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.eps3 Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.epsf Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.epsi Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.ept Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.gif Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.gfa Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.giff Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.jpeg Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.jpg Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.png Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.svg Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.svgz Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.tif Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.tiff Pictures\n\n", home, sep, sep);
+ fprintf(fp, "# Recursively add files from %s%cVideos%c to Videos group\n"
+ "addGroup Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.asf Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.avi Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.flv Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.mk3d Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.mkv Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.mov Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.mp4 Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.qt Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.webm Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.wmv Videos\n", home, sep, sep);
#else
fprintf(fp, "# This file was auto-generated by tml. See docs/tml-config.md or tml-config(5) for documentation\n"
"# The default launcher is set to \"xdg-open\" which will open files based on the relevant default application set through xdg\n\n"
"# Recursively add files from %s%cMusic%c to Music group\n"
"addGroup Music\n"
- "setLauncher Music xdg-open\n"
- "addR %s%cMusic%c* Music\n\n"
- "# Recursively add files from %s%cPictures%c to Pictures group\n"
+ "setLauncher Music xdg-open\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.aac Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.aiff Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.alac Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.au Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.flac Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.m4a Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.mp3 Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.ogg Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.pcm Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.wav Music\n", home, sep, sep);
+ fprintf(fp, "addR %s%cMusic%c*.wma Music\n\n", home, sep, sep);
+ fprintf(fp, "# Recursively add files from %s%cPictures%c to Pictures group\n"
"addGroup Pictures\n"
- "setLauncher Pictures xdg-open\n"
- "addR %s%cPictures%c* Pictures\n\n"
- "# Recursively add files from %s%cVideos%c to Videos group\n"
+ "setLauncher Pictures xdg-open\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.epi Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.eps Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.eps2 Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.eps3 Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.epsf Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.epsi Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.ept Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.gif Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.gfa Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.giff Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.jpeg Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.jpg Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.png Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.svg Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.svgz Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.tif Pictures\n", home, sep, sep);
+ fprintf(fp, "addR %s%cPictures%c*.tiff Pictures\n\n", home, sep, sep);
+ fprintf(fp, "# Recursively add files from %s%cVideos%c to Videos group\n"
"addGroup Videos\n"
- "setLauncher Videos xdg-open\n"
- "addR %s%cVideos%c* Videos", home, sep, sep, home, sep, sep, home, sep, sep, home, sep, sep, home, sep, sep, home, sep, sep);
+ "setLauncher Videos xdg-open\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.asf Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.avi Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.flv Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.mk3d Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.mkv Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.mov Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.mp4 Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.qt Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.webm Videos\n", home, sep, sep);
+ fprintf(fp, "addR %s%cVideos%c*.wmv Videos\n", home, sep, sep);
#endif
fclose(fp);
@@ -531,6 +602,7 @@ void handle_fname(char *path, char *group, bool recurs, bool force, char *name,
char auto_name[BUF_LEN];
int plen = strlen(path);
char *dirname;
+ char *local_arg; //for use in addR
DIR *dp;
struct dirent *fname;
int i;
@@ -574,14 +646,24 @@ void handle_fname(char *path, char *group, bool recurs, bool force, char *name,
//Windows cannot tell file types (TODO), so just add relatively indiscriminantly
if(!(wild_cmp(&arg_cpy[i+1], fname->d_name))) addme(relative_path_cpy, group, force, name);
+ //if the recursive option was specified, run handle_fname on this directory, but for security reasons, do not consider directories that start with a '.'
+ else if(recurs && fname->d_name[0] != '.'){
+ i = search_last_ch(arg_cpy, sep);
+ local_arg = &arg_cpy[i+1];
+ strcat(relative_path_cpy, &sep);
+ strcat(relative_path_cpy, local_arg);
+ handle_fname(relative_path_cpy, group, 1, 0, NULL, ln);
+ }
#else
//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))) addme(relative_path_cpy, group, force, name);
//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, "/*");
+ i = search_last_ch(arg_cpy, sep);
+ local_arg = &arg_cpy[i+1];
+ strcat(relative_path_cpy, &sep);
+ strcat(relative_path_cpy, local_arg);
handle_fname(relative_path_cpy, group, 1, 0, NULL, ln);
}
#endif
@@ -591,6 +673,17 @@ void handle_fname(char *path, char *group, bool recurs, bool force, char *name,
closedir(dp);
}
+#if defined _WIN32 || defined _WIN64
+ //directory is not real, report error to the user
+ else if(!recurs){
+ error_p = malloc(sizeof(char) * 1024);
+ sprintf(error_p, "\"%s\" bad path", dirname);
+ error_mes(ln, error_p);
+ free(error_p);
+ //printf("Error: \"%s\" bad path\n", dirname);
+ }
+ }
+#else
//directory is not real, report error to the user
else{
error_p = malloc(sizeof(char) * 1024);
@@ -600,6 +693,7 @@ void handle_fname(char *path, char *group, bool recurs, bool force, char *name,
//printf("Error: \"%s\" bad path\n", dirname);
}
}
+#endif
//path is not real, report error to the user
else{
@@ -709,6 +803,18 @@ int search_ch(char *str, char c){
return -1;
}
+int search_last_ch(char *str, char c){
+ int i = 0;
+ int last_i = -1;
+
+ while(str[i] != '\0'){
+ if(str[i] == c) last_i = i;
+ i++;
+ }
+
+ return last_i;
+}
+
//return 0 if match, 1 if not
//TODO only supports one wildcard per entry
int wild_cmp(char *wild, char *literal){
diff --git a/read_cfg.o b/read_cfg.o
index 95b5bbb..927e85b 100644
--- a/read_cfg.o
+++ b/read_cfg.o
Binary files differ
diff --git a/tml b/tml
index da376e3..91c46cc 100755
--- a/tml
+++ b/tml
Binary files differ