Skip to content

Commit 2ff3bc4

Browse files
committed
UI: fix debuggee launch
1 parent f2fc4c4 commit 2ff3bc4

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/platform/sdl/main.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static struct option OPTIONS[] = {
5252
{0, 0, 0, 0}
5353
};
5454

55-
const char *g_appPath;
55+
char g_appPath[OS_PATHNAME_SIZE + 1];
5656
int g_debugPort = 4000;
5757

5858
void appLog(const char *format, ...) {
@@ -209,6 +209,22 @@ void printKeywords() {
209209
}
210210
}
211211

212+
void setupAppPath(const char *path) {
213+
g_appPath[0] = '\0';
214+
if (path[0] == '/' || (path[1] == ':' && path[2] == '/')) {
215+
// full path or C:/
216+
strcpy(g_appPath, path);
217+
} else {
218+
// relative path
219+
char cwd[OS_PATHNAME_SIZE + 1];
220+
cwd[0] = '\0';
221+
getcwd(cwd, sizeof(cwd) - 1);
222+
strcat(g_appPath, cwd);
223+
strcat(g_appPath, "/");
224+
strcat(g_appPath, path);
225+
}
226+
}
227+
212228
void showHelp() {
213229
fprintf(stdout,
214230
"SmallBASIC version %s - kw:%d, pc:%d, fc:%d, ae:%d I=%d N=%d\n\n",
@@ -229,10 +245,10 @@ void showHelp() {
229245
int main(int argc, char* argv[]) {
230246
logEntered();
231247

248+
setupAppPath(argv[0]);
232249
opt_command[0] = '\0';
233250
opt_verbose = false;
234251
opt_quiet = true;
235-
g_appPath = argv[0];
236252

237253
char *fontFamily = NULL;
238254
char *runFile = NULL;

src/platform/sdl/syswm.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#define DEFAULT_FONT_SIZE 12
1313
#define DEFAULT_FONT_SIZE_PTS 11
1414

15-
extern const char *g_appPath;
15+
extern char g_appPath[];
1616
extern int g_debugPort;
1717

1818
#if defined(_Win32)
@@ -54,6 +54,7 @@ void launchDebug(const char *file) {
5454

5555
#else
5656
#include <unistd.h>
57+
#include <errno.h>
5758

5859
void loadIcon(SDL_Window *window) {
5960
}
@@ -73,7 +74,10 @@ void launchDebug(const char *file) {
7374
case 0:
7475
// child process
7576
sprintf(port, "-p %d", g_debugPort);
76-
execl(g_appPath, g_appPath, port, "-d", file, (char *)0);
77+
if (execl(g_appPath, g_appPath, port, "-d", file, (char *)0) == -1) {
78+
fprintf(stderr, "exec failed %s\n", strerror(errno));
79+
exit(1);
80+
}
7781
break;
7882
default:
7983
// parent process - continue

src/ui/system.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ void System::showMenu() {
731731
_systemMenu[index++] = MENU_RUN;
732732
_systemMenu[index++] = MENU_DEBUG;
733733
_systemMenu[index++] = MENU_OUTPUT;
734-
} else {
734+
} else if (isRunning()) {
735735
items->add(new String("Cut"));
736736
items->add(new String("Copy"));
737737
items->add(new String("Paste"));

0 commit comments

Comments
 (0)