summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouie <lshprung@yahoo.com>2020-07-23 19:55:21 -0700
committerlouie <lshprung@yahoo.com>2020-07-23 19:55:21 -0700
commit315a106170bfec5815cf7e8e281295b5e30f4d08 (patch)
treed37a4ce3cf6c800cc05a053c455c4073aec5863a
parentbafa9232b86fb2214819e77a1c477a5f9538d3f2 (diff)
Added most of what is needed for compatability with Windows
-rw-r--r--draw.c76
-rw-r--r--read_cfg.c22
-rw-r--r--read_cfg.obin10256 -> 10424 bytes
3 files changed, 80 insertions, 18 deletions
diff --git a/draw.c b/draw.c
index a3f8a87..b0f829f 100644
--- a/draw.c
+++ b/draw.c
@@ -1,7 +1,14 @@
+//Windows Compatability
+#if defined _WIN32 || defined _WIN64
+#include <ncurses/ncurses.h>
+#else
#include <ncurses.h>
+#endif
+
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include "entry.h"
#include "group.h"
#include "read_cfg.h"
@@ -17,6 +24,7 @@ void update_col(int mode, int hl_where); //0 = last, 1 = first; 0 = GROUP, 1 = E
void switch_col();
void trav_col(int dir); //0 = down, 1 = up
char *get_launch();
+void win_launch();
char *compat_convert(char *path, int mode);
static int width;
@@ -116,12 +124,18 @@ int main(int argc, char **argv){
trav_col(1);
break;
+ //FIXME Windows issue calling system() while in an ncurses instance. For Windows, call execl() instead
case 10: //enter key
+#if defined _WIN32 || defined _WIN64
+ win_launch();
+#else
full_command = get_launch();
system(full_command);
+#endif
+ refresh();
break;
- default:
+ case 'q':
endwin();
return 0;
@@ -358,6 +372,8 @@ void trav_col(int dir){
return;
}
+//TODO this looks ugly with all the #ifdefs...
+//FIXME account for how Windows does things: ""program.exe" [flags] "file""
char *get_launch(){
char *program = get_gprog(g[g_hover]);
char *flags = get_gflags(g[g_hover]);
@@ -365,38 +381,70 @@ char *get_launch(){
bool force = get_eforce(e[e_hover]);
int mode = get_compmode();
char *full_command = malloc(sizeof(char) * BUF_LEN);
- bool quote_flag_p = (program[0] == '"' ? false : true);
- bool quote_flag_f = (flags[0] == '"' ? false : true);
- bool quote_flag_e = (path[0] == '"' ? false : true);
full_command[0] = '\0';
+#if defined _WIN32 || defined _WIN64
+ //format correctly for Windows
+ strcat(full_command, "\"");
+#endif
+
//if the entry is an executable file (doesn't have a launcher)
if(!(strcmp(program, "./"))){
- if(quote_flag_e) strcat(full_command, "\"");
+ strcat(full_command, "\"");
strcat(full_command, path);
- if(quote_flag_e) strcat(full_command, "\"");
- return full_command;
+ strcat(full_command, "\"");
}
else{
//if the entry is not forced and compatability mode is on, run it through the converter function
if(mode != 0 && !force) path = compat_convert(path, mode);
- if(quote_flag_p) strcat(full_command, "\"");
+ strcat(full_command, "\"");
strcat(full_command, program);
- if(quote_flag_p) strcat(full_command, "\"");
+ strcat(full_command, "\"");
if(flags[0] !='\0'){
strcat(full_command, " ");
- if(quote_flag_f) strcat(full_command, "\"");
+ strcat(full_command, "\"");
strcat(full_command, flags);
- if(quote_flag_f) strcat(full_command, "\"");
+ strcat(full_command, "\"");
}
strcat(full_command, " ");
- if(quote_flag_e) strcat(full_command, "\"");
+ strcat(full_command, "\"");
strcat(full_command, path);
- if(quote_flag_e) strcat(full_command, "\"");
- return full_command;
+ strcat(full_command, "\"");
}
+
+#if defined _WIN32 || defined _WIN64
+ //format correctly for Windows
+ strcat(full_command, "\"");
+#endif
+
+ return full_command;
+
+}
+
+//FIXME issue with flags, some flags simply do not work (yet!)
+void win_launch(){
+ char *program = get_gprog(g[g_hover]);
+ char *flags = get_gflags(g[g_hover]);
+ char *path = get_epath(e[e_hover]);
+ char quoted_path[BUF_LEN];
+ char quoted_program[BUF_LEN];
+
+ quoted_path[0] = '\0';
+ strcat(quoted_path, "\"");
+ strcat(quoted_path, path);
+ strcat(quoted_path, "\"");
+
+ quoted_program[0] = '\0';
+ strcat(quoted_program, "\"");
+ strcat(quoted_program, program);
+ strcat(quoted_program, "\"");
+
+ if(!(strcmp(program, "./"))) execl(path, quoted_path, NULL);
+ else execl(program, quoted_program, flags, quoted_path, NULL);
+
+ return;
}
char *compat_convert(char *path, int mode){
diff --git a/read_cfg.c b/read_cfg.c
index 92f0b06..b55904a 100644
--- a/read_cfg.c
+++ b/read_cfg.c
@@ -33,6 +33,13 @@ int compmode = 0;
//set to true to automatically try to create a human readable name for an entry
bool hr = false;
+#if defined _WIN32 || defined _WIN64
+//for Windows Compatability, this will be '\\' (otherwise '/')
+char sep = '\\';
+#else
+char sep = '/';
+#endif
+
void cfg_interp(char *path){
FILE *fp;
char buffer[BUF_LEN];
@@ -156,14 +163,14 @@ void check_line(char *buffer){
//set a group's launcher (this requires pulling down the existing groups and finding the one that args[1] mentions)
if(!(strcmp(args[0], "setLauncher"))){
//assert that a matching group was found
- if(i < g_count) set_gprog(g[i], args[2]);
+ if(i < g_count) set_gprog(g[i], strip_quotes(args[2]));
else printf("Error: Group \"%s\" does not exist\n", args[1]);
}
//set a group's launcher flags (like ./program -f file for fullscreen)
else if(!(strcmp(args[0], "setFlags"))){
//assert that a matching group was found
- if(i < g_count) set_gflags(g[i], args[2]);
+ if(i < g_count) set_gflags(g[i], strip_quotes(args[2]));
else printf("Error: Group \"%s\" does not exist\n", args[1]);
}
@@ -213,7 +220,7 @@ void handle_fname(char *path, char *group, bool recurs, bool force, char *name){
i = search_ch(full_path_cpy, '*');
if(i > -1){
//look for a directory
- while(full_path_cpy[i] != '/' && (i >= 0)){
+ while(full_path_cpy[i] != sep && (i >= 0)){
i--;
}
dirname = full_path_cpy;
@@ -228,6 +235,11 @@ void handle_fname(char *path, char *group, bool recurs, bool force, char *name){
strcat(relative_path_cpy, dirname);
strcat(relative_path_cpy, fname->d_name);
+#if defined _WIN32 || defined _WIN64
+ //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);
+
+#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);
@@ -237,6 +249,8 @@ void handle_fname(char *path, char *group, bool recurs, bool force, char *name){
strcat(relative_path_cpy, "/*");
handle_fname(relative_path_cpy, group, 1, 0, NULL);
}
+#endif
+
}
closedir(dp);
@@ -289,7 +303,7 @@ char *autoAlias(char *path){
bool stop = false; //stop when you don't want to add a series of chars to the output
//get to the relative path name
- rpath = strrchr(path, '/');
+ rpath = strrchr(path, sep);
if(rpath == NULL) rpath = path;
else rpath++;
diff --git a/read_cfg.o b/read_cfg.o
index 8392136..0d0af5a 100644
--- a/read_cfg.o
+++ b/read_cfg.o
Binary files differ