Skip to content

Commit 4aefbc6

Browse files
committed
UI: fix crash with online command when site down
1 parent 161cc2c commit 4aefbc6

File tree

9 files changed

+83
-11
lines changed

9 files changed

+83
-11
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Fix debugger launch in linux build
33
Fix editor variable handling
44
Fix image drawing
5+
Fix PAINT infinite loop
6+
Fix keyboard handling for non-us keymaps
7+
Fix Ctrl+Home editor keystroke handler
8+
Fix crash with online command if site is down
59

610
2015-10-20
711
Fix LET when assigning a value to a MAP/ARRAY field

documentation/build_kwp.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,15 @@ int main(int argc, char *argv[]) {
240240
fprintf(stdout, " const char *package;\n");
241241
fprintf(stdout, " const char *keyword;\n");
242242
fprintf(stdout, " const char *signature;\n");
243+
fprintf(stdout, " const char *nodeId;\n");
243244
fprintf(stdout, " const char *help;\n");
244245
fprintf(stdout, "} keyword_help[] = {\n");
245246

246247
int max_keyword_len = 0;
247248
List_each(HelpItem *, it, helpItems) {
248249
HelpItem *item = (*it);
249-
fprintf(stdout, "{\"%s\",\"%s\",\"%s\",\"%s\"},\n", item->package,
250-
item->keyword, item->signature, item->help);
250+
fprintf(stdout, "{\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"},\n", item->package,
251+
item->keyword, item->signature, item->id, item->help);
251252
int len = strlen(item->keyword);
252253
if (len > max_keyword_len) {
253254
max_keyword_len = len;

src/common/fs_socket_client.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int sockcl_open(dev_file_t *f) {
1818
int port;
1919
char server[129];
2020

21-
// open "SOCL:smallbasic.sf.net:80" as #1
21+
// open "SOCL:smallbasic.sf.net:80" as #1
2222
// open "SOCL:80" as #2
2323
f->drv_dw[0] = 1;
2424
p = strchr(f->name + 5, ':');
@@ -132,7 +132,10 @@ int http_read(dev_file_t *f, var_t *var_p) {
132132

133133
while (1) {
134134
int bytes = net_read(f->handle, (char *) rxbuff, sizeof(rxbuff));
135-
if (bytes == 0) {
135+
if (bytes == -1) {
136+
httpOK = 0;
137+
break;
138+
} else if (bytes == 0) {
136139
break; // no more data
137140
}
138141
// assumes http header < 1024 bytes

src/platform/sdl/editor.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
#include "common/sbapp.h"
1212
#include "ui/system.h"
1313
#include "ui/textedit.h"
14+
#include "platform/sdl/syswm.h"
15+
16+
void onlineHelp(const char *nodeId) {
17+
if (nodeId != NULL) {
18+
char path[100];
19+
sprintf(path, "http://smallbasic.sf.net/?q=node/%s", nodeId);
20+
browseFile(path);
21+
} else {
22+
browseFile("http://smallbasic.sourceforge.net/");
23+
}
24+
}
1425

1526
void System::editSource(strlib::String &loadPath) {
1627
logEntered();
@@ -90,7 +101,6 @@ void System::editSource(strlib::String &loadPath) {
90101
}
91102

92103
switch (event.key) {
93-
case SB_KEY_F(2):
94104
case SB_KEY_F(3):
95105
case SB_KEY_F(8):
96106
case SB_KEY_F(10):
@@ -131,6 +141,10 @@ void System::editSource(strlib::String &loadPath) {
131141
helpWidget->createKeywordIndex();
132142
helpWidget->show();
133143
break;
144+
case SB_KEY_F(2):
145+
redraw = false;
146+
onlineHelp(widget->getNodeId());
147+
break;
134148
case SB_KEY_F(5):
135149
saveFile(editWidget, loadPath);
136150
_output->setStatus("Debug. F6=Step, F7=Continue, Esc=Close");

src/platform/sdl/syswm.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ void launchDebug(const char *file) {
5757
}
5858
}
5959

60+
#if defined(WIN32)
61+
#include <windows.h>
62+
#include <fltk/Window.h>
63+
#include <fltk/win32.h>
64+
#endif
65+
66+
void browseFile(const char *url) {
67+
SDL_SysWMinfo wminfo;
68+
SDL_VERSION(&wminfo.version);
69+
if (SDL_GetWindowWMInfo(window, &wminfo) == 1) {
70+
HWND hwnd = wminfo.info.win.window;
71+
ShellExecute(hwnd, "open", url, 0, 0, SW_SHOWNORMAL);
72+
}
73+
}
74+
6075
#else
6176
#include <unistd.h>
6277
#include <errno.h>
@@ -90,4 +105,19 @@ void launchDebug(const char *file) {
90105
}
91106
}
92107

108+
void browseFile(const char *url) {
109+
if (fork() == 0) {
110+
fclose(stderr);
111+
fclose(stdin);
112+
fclose(stdout);
113+
execlp("htmlview", "htmlview", url, NULL);
114+
execlp("google-chrome", "google-chrome", url, NULL);
115+
execlp("chromium-browser", "chromium-browser", url, NULL);
116+
execlp("firefox", "firefox", url, NULL);
117+
execlp("mozilla", "mozilla", url, NULL);
118+
// exit in case exec failed
119+
::exit(0);
120+
}
121+
}
122+
93123
#endif

src/platform/sdl/syswm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
void loadIcon(SDL_Window *window);
1515
int getStartupFontSize(SDL_Window *window);
1616
void launchDebug(const char *file);
17+
void browseFile(const char *url);
1718

1819
#endif

src/ui/system.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,13 +412,16 @@ char *System::loadResource(const char *fileName) {
412412
_output->setStatus("Loading...");
413413
_output->redraw();
414414
if (dev_fopen(handle, fileName, 0)) {
415-
http_read(f, var_p);
416-
int len = var_p->v.p.size;
417-
buffer = (char *)malloc(len + 1);
418-
memcpy(buffer, var_p->v.p.ptr, len);
419-
buffer[len] = '\0';
415+
if (http_read(f, var_p) == 0) {
416+
systemPrint("\nfailed to read %s\n", fileName);
417+
} else {
418+
int len = var_p->v.p.size;
419+
buffer = (char *)malloc(len + 1);
420+
memcpy(buffer, var_p->v.p.ptr, len);
421+
buffer[len] = '\0';
422+
}
420423
} else {
421-
systemPrint("\nfailed to open %s", fileName);
424+
systemPrint("\nfailed to open %s\n", fileName);
422425
}
423426
_output->setStatus(NULL);
424427
dev_fclose(handle);

src/ui/textedit.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,21 @@ char *TextEditInput::getSelection(int *start, int *end) {
12211221
return result;
12221222
}
12231223

1224+
const char *TextEditInput::getNodeId() {
1225+
char *selection = getWordBeforeCursor();
1226+
const char *result = NULL;
1227+
int len = selection != NULL ? strlen(selection) : 0;
1228+
if (len > 0) {
1229+
for (int i = 0; i < keyword_help_len && !result; i++) {
1230+
if (strcasecmp(selection, keyword_help[i].keyword) == 0) {
1231+
result = keyword_help[i].nodeId;
1232+
}
1233+
}
1234+
}
1235+
free(selection);
1236+
return result;
1237+
}
1238+
12241239
char *TextEditInput::getWordBeforeCursor() {
12251240
char *result;
12261241
if (_state.select_start == _state.select_end) {

src/ui/textedit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ struct TextEditInput : public FormEditInput {
106106
bool isDirty() { return _dirty && _state.undostate.undo_point > 0; }
107107
void setDirty(bool dirty) { _dirty = dirty; }
108108
void resize(int w, int h) { _width = w; _height = h; }
109+
const char *getNodeId();
109110
char *getWordBeforeCursor();
110111
bool replaceNext(const char *text);
111112
int getCompletions(StringList *list, int max);

0 commit comments

Comments
 (0)