Skip to content

Commit 33c50c8

Browse files
author
Chris Warren-Smith
committed
FLATPAK: handle external execute error line
1 parent 403463e commit 33c50c8

12 files changed

Lines changed: 67 additions & 14 deletions

File tree

src/platform/android/jni/runtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct Runtime : public System {
8686

8787
private:
8888
void editSource(String loadPath, bool restoreOnExit) override;
89-
void externalExecute(const char *bas) const override {}
89+
int externalExecute(const char *bas) const override { return 0;}
9090

9191
bool _keypadActive;
9292
bool _hasFocus;

src/platform/emcc/runtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct Runtime : public System {
2222
char *getClipboardText();
2323
int getFontSize() { return _output->getFontSize(); }
2424
void editSource(String loadPath, bool restoreOnExit) override;
25-
void externalExecute(const char *bas) const override {}
25+
int externalExecute(const char *bas) const override { return 0;}
2626
void enableCursor(bool enabled) {}
2727
int handle(int event);
2828
char *loadResource(const char *fileName);

src/platform/fltk/runtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct Runtime : public System {
2121
int ask(const char *title, const char *prompt, bool cancel=true);
2222
void browseFile(const char *url);
2323
void editSource(String loadPath, bool restoreOnExit) override {}
24-
void externalExecute(const char *bas) const override {}
24+
int externalExecute(const char *bas) const override { return 0;}
2525
char *getClipboardText();
2626
int getFontSize() { return _output->getFontSize(); }
2727
void enableCursor(bool enabled);

src/platform/sdl/editor.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ void Runtime::editSource(String loadPath, bool restoreOnExit) {
267267
_output->setStatus(!gsb_last_errmsg[0] ? "Error" : gsb_last_errmsg);
268268
}
269269
}
270+
} else if (editWidget->getErrorAtLine() != -1) {
271+
String message("Error at line: ");
272+
message.append(editWidget->getErrorAtLine());
273+
_output->setStatus(message);
274+
editWidget->setCursorRow(editWidget->getErrorAtLine() - 1);
275+
editWidget->setErrorAtLine(-1);
270276
} else {
271277
statusMessage.update(editWidget, _output, true);
272278
}

src/platform/sdl/runtime.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ void Runtime::exportRun(const char *file) const {
262262
SDL_RaiseWindow(_window);
263263
}
264264

265-
void Runtime::externalExecute(const char *bas) const {
266-
launchConsole(bas);
265+
int Runtime::externalExecute(const char *bas) const {
266+
return launchConsole(bas);
267267
}
268268

269269
bool Runtime::toggleFullscreen() {

src/platform/sdl/runtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct Runtime final : System {
6464

6565
private:
6666
void editSource(String loadPath, bool restoreOnExit) override;
67-
void externalExecute(const char *bas) const override;
67+
int externalExecute(const char *bas) const override;
6868

6969
bool _fullscreen;
7070
SDL_Rect _windowRect{};

src/platform/sdl/syswm.cpp

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ static void launch(const char *command, const char *file) {
6565
}
6666
}
6767

68-
void launchConsole(const char *file) {
68+
int launchConsole(const char *file) {
6969
launch("sbasic", file);
70+
return 0;
7071
}
7172

7273
void launchDebug(const char *file) {
@@ -99,10 +100,16 @@ void browseFile(SDL_Window *window, const char *url) {
99100
}
100101

101102
#else
102-
#include <unistd.h>
103103
#include <errno.h>
104+
#include <fcntl.h>
104105
#include <limits.h>
105106
#include <spawn.h>
107+
#include <sys/wait.h>
108+
#include <unistd.h>
109+
110+
#include <SDL3/SDL_events.h>
111+
#include <SDL3/SDL_timer.h>
112+
106113
#include "icon.h"
107114
#include "lib/lodepng/lodepng.h"
108115

@@ -140,15 +147,48 @@ static void launch(const char *command, const char *argument, const char *file)
140147
char *argv[] = {(char *)command, (char *)argument, (char *)file, nullptr};
141148
int status = posix_spawnp(&pid, command, nullptr, nullptr, argv, environ);
142149
if (status != 0) {
143-
fprintf(stderr, "exec failed [%d] %s\n", status, command);
150+
fprintf(stderr, "%s failed [%s]\n", command, strerror(status));
144151
}
145152
}
146153

147154
//
148155
// invoke sbasic console build to run external GUI based modules
149156
//
150-
void launchConsole(const char *file) {
151-
launch("sbasic", "", file);
157+
int launchConsole(const char *file) {
158+
pid_t pid;
159+
char *argv[] = {(char*)"sbasic", (char *)file, nullptr};
160+
int status = posix_spawnp(&pid, "sbasic", nullptr, nullptr, argv, environ);
161+
if (status != 0) {
162+
fprintf(stderr, "sbasic failed [%s]\n", strerror(status));
163+
return 1;
164+
}
165+
166+
bool running = true;
167+
int result = 0;
168+
while (running) {
169+
SDL_Event event;
170+
while (SDL_PollEvent(&event)) {
171+
if (event.type == SDL_EVENT_QUIT) {
172+
kill(pid, SIGTERM);
173+
running = false;
174+
break;
175+
}
176+
}
177+
int wait_status;
178+
pid_t wait_result = waitpid(pid, &wait_status, WNOHANG);
179+
if (wait_result > 0) {
180+
running = false;
181+
if (WIFEXITED(wait_status)) {
182+
// normal exit
183+
result = WEXITSTATUS(wait_status);
184+
} else if (WIFSIGNALED(wait_status)) {
185+
// crashed
186+
result = -1;
187+
}
188+
}
189+
SDL_Delay(16);
190+
}
191+
return result;
152192
}
153193

154194
//

src/platform/sdl/syswm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
void browseFile(SDL_Window *window, const char *url);
1515
int getStartupFontSize(SDL_Window *window);
16-
void launchConsole(const char *file);
16+
int launchConsole(const char *file);
1717
void launchDebug(const char *file);
1818
void launchExec(const char *file);
1919
void loadIcon(SDL_Window *window);

src/ui/system.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ bool System::execute(const char *bas) {
176176
String path(bas);
177177
saveFile(_editor, path);
178178
}
179-
externalExecute(bas);
179+
int result = externalExecute(bas);
180+
if (_editor != nullptr && result > 0) {
181+
_editor->setErrorAtLine(result);
182+
}
180183
}
181184

182185
if (_editor == nullptr) {

src/ui/system.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct System {
7777
static bool setParentPath();
7878

7979
virtual void editSource(strlib::String loadPath, bool restoreOnExit) = 0;
80-
virtual void externalExecute(const char *bas) const = 0;
80+
virtual int externalExecute(const char *bas) const = 0;
8181
bool execute(const char *bas);
8282
MAEvent getNextEvent() { return processEvents(1); }
8383
uint32_t getModifiedTime() const;

0 commit comments

Comments
 (0)