From f9227cef5bcbe9f3a3fe3487ed1cc358cff37932 Mon Sep 17 00:00:00 2001
From: louie <lshprung@yahoo.com>
Date: Wed, 23 Dec 2020 18:20:46 -0800
Subject: Fixed Windows configuration auto-generation, added new setLauncherRaw
 option

---
 draw.c             |  11 ++++++-----
 draw.o             | Bin 19712 -> 19720 bytes
 group.c            |  13 +++++++++++++
 group.h            |   4 ++++
 group.o            | Bin 8216 -> 8672 bytes
 history/history.db | Bin 0 -> 12288 bytes
 read_cfg.c         |  22 ++++++++++++----------
 read_cfg.o         | Bin 20400 -> 20608 bytes
 tml                | Bin 46960 -> 47080 bytes
 9 files changed, 35 insertions(+), 15 deletions(-)
 create mode 100644 history/history.db

diff --git a/draw.c b/draw.c
index 7e58d23..c4d00c8 100644
--- a/draw.c
+++ b/draw.c
@@ -437,7 +437,7 @@ char *get_launch(){
 	char *program = get_gprog(g[g_hover]);
 	char *flags = get_gflags(g[g_hover]);
 	char *path = get_epath(e[e_hover]);
-	bool force = get_eforce(e[e_hover]);
+	bool quotes = get_gquotes(g[g_hover]);
 	char *full_command = malloc(sizeof(char) * BUF_LEN);
 
 	full_command[0] = '\0';
@@ -450,9 +450,9 @@ char *get_launch(){
 	}
 
 	else{
-		strcat(full_command, "\"");
+		if(quotes) strcat(full_command, "\"");
 		strcat(full_command, program);
-		strcat(full_command, "\"");
+		if(quotes) strcat(full_command, "\"");
 		if(flags[0] !='\0'){
 			strcat(full_command, " ");
 			strcat(full_command, flags);
@@ -472,6 +472,7 @@ void win_launch(){
 	char *program = get_gprog(g[g_hover]);
 	char *flags = get_gflags(g[g_hover]);
 	char *path = get_epath(e[e_hover]);
+	bool quotes = get_gquotes(g[g_hover]);
 	char file[BUF_LEN];
 	char params[BUF_LEN];
 
@@ -485,9 +486,9 @@ void win_launch(){
 	}
 
 	else{
-		strcat(file, "\"");
+		if(quotes) strcat(file, "\"");
 		strcat(file, program);
-		strcat(file, "\"");
+		if(quotes) strcat(file, "\"");
 
 		params[0] = '\0';
 		if(flags[0] != '\0'){
diff --git a/draw.o b/draw.o
index 5aee7fc..e831fce 100644
Binary files a/draw.o and b/draw.o differ
diff --git a/group.c b/group.c
index 821adf3..a34556f 100644
--- a/group.c
+++ b/group.c
@@ -17,6 +17,7 @@ typedef struct group{
 	struct entry *tail;
 	struct group *next;
 	int entry_count;
+	bool launcher_quotes; //set by a group option whether or not the launcher should be wrapped by quotes
 } GROUP;
 
 GROUP *create_group(char *new_name);
@@ -32,6 +33,8 @@ void set_gflags(GROUP *g, char *p);
 ENTRY *get_ghead(GROUP *g);
 int get_ecount(GROUP *g);
 void set_ecount(GROUP *g, int new_count); //for use in hiding entries
+void set_gquotes(GROUP *g, bool b);
+bool get_gquotes(GROUP *g);
 int get_gcount();
 void group_debug(); //debug function to output all groups
 
@@ -50,6 +53,7 @@ GROUP *create_group(char *new_name){
 	new->tail = NULL;
 	new->next = NULL;
 	new->entry_count = 0;
+	new->launcher_quotes = true;
 
 	group_count++;
 	return new;
@@ -228,6 +232,15 @@ void set_ecount(GROUP *g, int new_count){
 	g->entry_count = new_count;
 }
 
+void set_gquotes(GROUP *g, bool b){
+	assert(g != NULL);
+	g->launcher_quotes = b;
+}
+
+bool get_gquotes(GROUP *g){
+	return g->launcher_quotes;
+}
+
 int get_gcount(){
 	return group_count;
 }
diff --git a/group.h b/group.h
index e29107c..03db702 100644
--- a/group.h
+++ b/group.h
@@ -29,6 +29,10 @@ int get_ecount(GROUP *g);
 
 void set_ecount(GROUP *g, int new_count);
 
+void set_gquotes(GROUP *g, bool b);
+
+bool get_gquotes(GROUP *g);
+
 int get_gcount();
 
 void group_debug();
diff --git a/group.o b/group.o
index e8f6ea5..3279e7f 100644
Binary files a/group.o and b/group.o differ
diff --git a/history/history.db b/history/history.db
new file mode 100644
index 0000000..5398ed4
Binary files /dev/null and b/history/history.db differ
diff --git a/read_cfg.c b/read_cfg.c
index 9235108..019b3a4 100644
--- a/read_cfg.c
+++ b/read_cfg.c
@@ -12,7 +12,7 @@
 #include "group.h"
 #define BUF_LEN 1024 //maybe move this line to the header file
 #define MAX_ARGS 5
-#define OPTION_CNT 13
+#define OPTION_CNT 14
 
 //public
 #if defined _WIN32 || defined _WIN64
@@ -135,7 +135,8 @@ void cfg_interp(char *path){
 	options[9] = "hideFile";
 	options[10] = "setFlags";
 	options[11] = "setLauncher";
-	options[12] = "sort";
+	options[12] = "setLauncherRaw";
+	options[13] = "sort";
 
 	//Read each line of "config"
 	while(fgets(buffer, BUF_LEN, fp)){
@@ -240,22 +241,19 @@ void mkconfig_wizard(char *path){
 		exit(1);
 	}
 
-	//write to file (in Windows, launch an application with the default launcher by invoking "start")
-	//FIXME at the moment, this WILL NOT WORK. I need to add an option to set launcher without quotes
+	//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"
-	"# Please note that the launcher \"start\" is a built-in Windows command to launch a file with the default application\n\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"
-	"setLauncher Music start\n"
 	"addR %s%cMusic%c* Music\n\n"
 	"# Recursively add files from %s%cPictures%c to Pictures group\n"
 	"addGroup Pictures\n"
-	"setLauncher Pictures start\n"
 	"addR %s%cPictures%c* Pictures\n\n"
 	"# Recursively add files from %s%cVideos%c to Videos group\n"
 	"addGroup Videos\n"
-	"setLauncher Videos start\n"
 	"addR %s%cVideos%c* Videos", home, sep, sep, home, sep, sep, home, sep, sep, home, sep, sep, home, sep, sep, 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"
@@ -459,6 +457,7 @@ void check_line(char *buffer, char **options, int ln){
 				break;
 
 			case 11: //setLauncher
+			case 12: //setLauncherRaw
 				//args[1] is referring to a group
 				g = get_groups();
 				g_count = get_gcount();
@@ -470,7 +469,10 @@ void check_line(char *buffer, char **options, int ln){
 
 				//set a group's launcher (this requires pulling down the existing groups and finding the one that args[1] mentions)
 				//assert that a matching group was found
-				if(i < g_count) set_gprog(g[i], strip_quotes(args[2]));
+				if(i < g_count){
+					set_gprog(g[i], strip_quotes(args[2]));
+					if(search_res == 12) set_gquotes(g[i], false); //FIXME don't forget to change this line if adding more options!!!
+				}
 				else{
 					error_p = malloc(sizeof(char) * 1024);
 					sprintf(error_p, "Group \"%s\" does not exist", args[1]);
@@ -479,7 +481,7 @@ void check_line(char *buffer, char **options, int ln){
 				}
 				break;
 
-			case 12: //sort
+			case 13: //sort
 				if(!(strcmp(args[1], "on"))) sort = true;
 				else if(!(strcmp(args[1], "off"))) sort = false;
 				break;
diff --git a/read_cfg.o b/read_cfg.o
index 3efc7b8..3102795 100644
Binary files a/read_cfg.o and b/read_cfg.o differ
diff --git a/tml b/tml
index e13f80b..9d9584a 100755
Binary files a/tml and b/tml differ
-- 
cgit