Skip to content

Commit 614b70a

Browse files
committed
FLTK: set correct path to sbasicg.exe
1 parent 78f0080 commit 614b70a

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/platform/fltk/MainWindow.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,7 @@ bool initialise(int argc, char **argv) {
882882
char path[PATH_MAX];
883883
getHomeDir(path, sizeof(path), false);
884884
dev_setenv("BAS_HOME", path);
885+
setAppName(argv[0]);
885886

886887
wnd = new MainWindow(800, 650);
887888

src/platform/fltk/utils.cxx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include "ui/utils.h"
2323

2424
#define RX_BUFFER_SIZE 1024
25+
#if defined(_Win32)
26+
static char appName[OS_PATHNAME_SIZE + 1];
27+
#endif
2528

2629
Fl_Color get_color(int argb) {
2730
// Fl_Color => 0xrrggbbii
@@ -240,16 +243,38 @@ void vsncat(char *buffer, size_t size, ...) {
240243
va_end(args);
241244
}
242245

246+
void setAppName(const char *path) {
247+
#if defined(_Win32)
248+
appName[0] = '\0';
249+
if (path[0] == '/' ||
250+
(path[1] == ':' && ((path[2] == '\\') || path[2] == '/'))) {
251+
// full path or C:/
252+
strlcpy(appName, path, sizeof(appName));
253+
} else {
254+
// relative path
255+
char cwd[OS_PATHNAME_SIZE + 1];
256+
cwd[0] = '\0';
257+
getcwd(cwd, sizeof(cwd) - 1);
258+
strlcpy(appName, cwd, sizeof(appName));
259+
strlcat(appName, "/", sizeof(appName));
260+
strlcat(appName, path, sizeof(appName));
261+
}
262+
const auto file = "sbasici.exe";
263+
char *exe = strstr(appName, file);
264+
if (exe) {
265+
strcpy(exe, "sbasicg.exe");
266+
}
267+
#endif
268+
}
243269

244270
#if defined(_Win32)
245271
void launchExec(const char *file) {
246272
STARTUPINFO info = {sizeof(info)};
247273
PROCESS_INFORMATION processInfo;
248274
char cmd[1024];
249-
auto app = "./sbasicg.exe";
250-
sprintf(cmd, "%s -x %s", app, file);
251-
if (!CreateProcess(app, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo)) {
252-
appLog("failed to start %d %s %s\n", GetLastError(), app, cmd);
275+
sprintf(cmd, " -x %s", file);
276+
if (!CreateProcess(appName, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo)) {
277+
appLog("failed to start %d %s %s\n", GetLastError(), appName, cmd);
253278
}
254279
}
255280
#else

src/platform/fltk/utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ void getHomeDir(char *fileName, size_t size, bool appendSlash = true);
5757
bool cacheLink(dev_file_t *df, char *localFile, size_t size);
5858
void vsncat(char *buffer, size_t size, ...);
5959
void launchExec(const char *file);
60+
void setAppName(const char *path);
6061

6162
#endif

0 commit comments

Comments
 (0)