Skip to content

Commit b3f4c21

Browse files
authored
Merge pull request #72 from chrisws/0_12_13
0 12 13
2 parents 301174d + 4b03c55 commit b3f4c21

File tree

14 files changed

+129
-94
lines changed

14 files changed

+129
-94
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2018-08-08 (0.12.13)
2+
SDL: fix incorrect file loading with ALT+1-9 command
3+
4+
2018-08-08 (0.12.13)
5+
COMMON: fix problem with SEQ command
6+
17
2018-08-08 (0.12.13)
28
ANDROID: remove hardcoded references to "/sdcard" path
39

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ function buildConsole() {
284284
fi
285285

286286
AC_SUBST(BUILD_SUBDIRS)
287+
288+
(cd documentation && g++ -o build_kwp build_kwp.cpp && ./build_kwp > ../src/ui/kwp.h)
287289
}
288290

289291
function buildWeb() {

samples/distro-examples/tests/strings.bas

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,8 @@ end
171171
cmd_str1("")
172172
cmd_str1(0)
173173

174+
expect = [0,0.26179938779915,0.5235987755983,0.78539816339745,1.0471975511966,1.30899693899575,1.5707963267949,1.83259571459405,2.0943951023932,2.35619449019234,2.61799387799149,2.87979326579064,3.14159265358979,3.40339204138894,3.66519142918809,3.92699081698724,4.18879020478639,4.45058959258554,4.71238898038469,4.97418836818384,5.23598775598299,5.49778714378214,5.75958653158129,6.02138591938044,6.28318530717958]
175+
if expect != seq(0, 2*pi, 360/15+1) then throw "SEQ error"
174176

177+
s="Hello\033There"
178+
if (27 != asc(mid(s, 6, 1))) then throw "err"

src/common/blib_func.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2857,18 +2857,17 @@ void cmd_genfunc(long funcCode, var_t *r) {
28572857
//
28582858
case kwSEQ: {
28592859
var_int_t count;
2860-
var_num_t xmin, xmax, dx;
2861-
2860+
var_num_t xmin, xmax;
28622861
par_massget("FFI", &xmin, &xmax, &count);
2863-
28642862
if (!prog_error) {
28652863
// create the array
28662864
if (count > 1) {
28672865
v_toarray1(r, count);
2868-
dx = (xmax - xmin) / (count - 1);
2866+
var_num_t dx = (xmax - xmin) / (count - 1);
2867+
var_num_t x = xmin;
28692868

28702869
// add the entries
2871-
for (int i = 0, x = xmin; i < count; i++, x += dx) {
2870+
for (int i = 0; i < count; i++, x += dx) {
28722871
var_t *elem_p = v_elem(r, i);
28732872
elem_p->type = V_NUM;
28742873
elem_p->v.n = x;

src/common/fs_serial.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ uint32_t serial_length(dev_file_t *f) {
7777
}
7878

7979
#elif defined(_Win32)
80-
typedef int FileHand;
8180

8281
int serial_open(dev_file_t *f) {
8382
DCB dcb;
@@ -114,32 +113,32 @@ int serial_open(dev_file_t *f) {
114113
return 0;
115114
}
116115

117-
f->handle = (FileHand) hCom;
116+
f->handle = (intptr_t)hCom;
118117
return 1;
119118
}
120119

121120
int serial_close(dev_file_t *f) {
122-
CloseHandle((HANDLE) f->handle);
121+
CloseHandle((HANDLE) (intptr_t)f->handle);
123122
f->handle = -1;
124123
return 1;
125124
}
126125

127126
int serial_write(dev_file_t *f, byte *data, uint32_t size) {
128127
DWORD bytes;
129-
f->last_error = !WriteFile((HANDLE) f->handle, data, size, &bytes, NULL);
128+
f->last_error = !WriteFile((HANDLE)(intptr_t)f->handle, data, size, &bytes, NULL);
130129
return bytes;
131130
}
132131

133132
int serial_read(dev_file_t *f, byte *data, uint32_t size) {
134133
DWORD bytes;
135-
f->last_error = !ReadFile((HANDLE) f->handle, data, size, &bytes, NULL);
134+
f->last_error = !ReadFile((HANDLE)(intptr_t)f->handle, data, size, &bytes, NULL);
136135
return bytes;
137136
}
138137

139138
uint32_t serial_length(dev_file_t *f) {
140139
COMSTAT cs;
141140
DWORD de = CE_BREAK;
142-
ClearCommError((HANDLE) f->handle, &de, &cs);
141+
ClearCommError((HANDLE)(intptr_t)f->handle, &de, &cs);
143142
return cs.cbInQue;
144143
}
145144

src/common/scan.c

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3884,6 +3884,26 @@ char *comp_load(const char *file_name) {
38843884
return buf;
38853885
}
38863886

3887+
const char *format_numeric_text(const char *str, char **output) {
3888+
const char *result = str;
3889+
int value = 0;
3890+
int digits = 0;
3891+
3892+
while (isdigit(*str)) {
3893+
value = (value << 3) + (*str - '0');
3894+
digits++;
3895+
str++;
3896+
}
3897+
3898+
if (digits == 3 && value > V_JOIN_LINE && value < 256) {
3899+
**output = value;
3900+
(*output)++;
3901+
result = str;
3902+
}
3903+
3904+
return result;
3905+
}
3906+
38873907
/**
38883908
* format source-code text
38893909
*
@@ -3895,24 +3915,21 @@ char *comp_load(const char *file_name) {
38953915
* returns a newly created string
38963916
*/
38973917
char *comp_format_text(const char *source) {
3898-
const char *p;
3899-
char *ps;
39003918
int quotes = 0;
3901-
char *new_text;
3902-
int sl, last_ch = 0, i;
3903-
char *last_nonsp_ptr;
3919+
int last_ch = 0;
39043920
int adj_line_num = 0;
39053921
int multi_line_string = 0;
39063922
int curley_brace = 0;
39073923
int square_brace = 0;
3924+
int sl = strlen(source);
3925+
char *new_text = malloc(sl + 2);
3926+
char *ps = new_text;
3927+
char *last_nonsp_ptr = new_text;
3928+
const char *p = source;
39083929

3909-
sl = strlen(source);
3910-
new_text = malloc(sl + 2);
39113930
memset(new_text, 0, sl + 2);
3912-
39133931
comp_line = 0;
3914-
p = source;
3915-
last_nonsp_ptr = ps = new_text;
3932+
39163933
while (*p) {
39173934
if (!quotes) {
39183935
switch (*p) {
@@ -3934,7 +3951,7 @@ char *comp_format_text(const char *source) {
39343951
ps++;
39353952
p++;
39363953
} else {
3937-
for (i = 0; i <= adj_line_num; i++) {
3954+
for (int i = 0; i <= adj_line_num; i++) {
39383955
// at least one nl
39393956
*ps++ = '\n';
39403957
}
@@ -4095,6 +4112,9 @@ char *comp_format_text(const char *source) {
40954112
}
40964113
// new line auto-ends the quoted string
40974114
quotes = !quotes;
4115+
} else if (*p == '\\') {
4116+
p = format_numeric_text(p + 1, &ps);
4117+
continue;
40984118
}
40994119
*ps++ = *p++;
41004120
}

src/platform/console/main.cpp

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "config.h"
1111
#include <getopt.h>
1212
#include "common/sbapp.h"
13+
#include "ui/kwp.h"
1314

1415
// decompile handling
1516
extern "C" {
@@ -22,7 +23,6 @@ extern "C" {
2223
void console_init();
2324

2425
static struct option OPTIONS[] = {
25-
{"help", no_argument, NULL, 'h'},
2626
{"verbose", no_argument, NULL, 'v'},
2727
{"keywords", no_argument, NULL, 'k'},
2828
{"no-file-perm", no_argument, NULL, 'f'},
@@ -32,6 +32,7 @@ static struct option OPTIONS[] = {
3232
{"option", optional_argument, NULL, 'o'},
3333
{"cmd", optional_argument, NULL, 'c'},
3434
{"stdin", optional_argument, NULL, '-'},
35+
{"help", optional_argument, NULL, 'h'},
3536
{0, 0, 0, 0}
3637
};
3738

@@ -56,6 +57,35 @@ void show_brief_help() {
5657
fprintf(stdout, "SmallBASIC version %s - use -h for help\n", SB_STR_VER);
5758
}
5859

60+
void command_help(const char *selection) {
61+
bool found = false;
62+
const char *pattern = "%s\033[50D\033[14C%s\n";
63+
for (int i = 0; i < keyword_help_len; i++) {
64+
if (selection[0] == '?' || strcasecmp(selection, keyword_help[i].package) == 0) {
65+
fprintf(stdout, pattern, keyword_help[i].keyword, keyword_help[i].help);
66+
found = true;
67+
}
68+
}
69+
if (!found) {
70+
int len = strlen(selection);
71+
for (int i = 0; i < keyword_help_len; i++) {
72+
if (strncasecmp(selection, keyword_help[i].keyword, len) == 0) {
73+
fprintf(stdout, pattern, keyword_help[i].keyword, keyword_help[i].help);
74+
found = true;
75+
}
76+
}
77+
}
78+
if (!found) {
79+
const char *last_package = NULL;
80+
for (int i = 0; i < keyword_help_len; i++) {
81+
if (last_package == NULL || strcmp(last_package, keyword_help[i].package) != 0) {
82+
fprintf(stdout, "%s\n", keyword_help[i].package);
83+
last_package = keyword_help[i].package;
84+
}
85+
}
86+
}
87+
}
88+
5989
/*
6090
* handles the command "sbasic -pkw"
6191
*/
@@ -205,7 +235,7 @@ bool process_options(int argc, char *argv[], char **runFile, bool *tmpFile) {
205235
bool result = true;
206236
while (result) {
207237
int option_index = 0;
208-
int c = getopt_long(argc, argv, "hvkfxm::s::o:c:", OPTIONS, &option_index);
238+
int c = getopt_long(argc, argv, "vkfxm::s::o:c:h::", OPTIONS, &option_index);
209239
if (c == -1 && !option_index) {
210240
// no more options
211241
for (int i = 1; i < argc; i++) {
@@ -225,7 +255,13 @@ bool process_options(int argc, char *argv[], char **runFile, bool *tmpFile) {
225255
}
226256
switch (c) {
227257
case 'h':
228-
show_help();
258+
if (optarg) {
259+
command_help(optarg);
260+
} else if (argv[optind] != NULL && argv[optind][0] != '-') {
261+
command_help(argv[optind]);
262+
} else {
263+
show_help();
264+
}
229265
result = false;
230266
break;
231267
case 'v':

src/platform/sdl/editor.cpp

Lines changed: 7 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -151,43 +151,6 @@ void exportBuffer(AnsiWidget *out, const char *text, String &dest, String &token
151151
out->setStatus(buffer);
152152
}
153153

154-
void publish(System *system, const char *text, const char *fileName, const char *description) {
155-
String gist = saveGist(text, fileName, description);
156-
if (gist.empty()) {
157-
system->alert("Publish", "Failed to save gist file.");
158-
} else {
159-
String command;
160-
var_t result;
161-
162-
command.append("curl -X POST -d @")
163-
.append(gist)
164-
.append(" https://api.github.com/gists")
165-
.append(" --header \"Content-Type:application/json\"");
166-
v_init(&result);
167-
if (!dev_run(command, &result, 1)) {
168-
system->alert("Publish", "Failed to invoke curl.");
169-
} else {
170-
const char *str = v_str(&result);
171-
const char *field = "html_url";
172-
const char *url = strstr(str, field);
173-
String html;
174-
175-
if (url != NULL) {
176-
const char *q1 = strchr(url + strlen(field) + 2, '\"');
177-
const char *q2 = q1 == NULL ? NULL : strchr(q1 + 1, '\"');
178-
if (q1 != NULL && q2 != NULL) {
179-
html.append(q1 + 1, q2 - q1 - 1);
180-
}
181-
}
182-
if (html.empty()) {
183-
system->alert("Publish", "Failed to publish gist.");
184-
} else {
185-
system->browseFile(html);
186-
}
187-
}
188-
}
189-
}
190-
191154
void System::editSource(String loadPath) {
192155
logEntered();
193156

@@ -209,7 +172,7 @@ void System::editSource(String loadPath) {
209172
String recentFile;
210173
StatusMessage statusMessage(editWidget);
211174
enum InputMode {
212-
kInit, kExportAddr, kExportToken, kCommand, kPublish
175+
kInit, kExportAddr, kExportToken, kCommand
213176
} inputMode = kInit;
214177

215178
_modifiedTime = getModifiedTime();
@@ -298,7 +261,7 @@ void System::editSource(String loadPath) {
298261
case SB_KEY_ESCAPE:
299262
widget = editWidget;
300263
helpWidget->hide();
301-
debugStop();
264+
((Runtime *)this)->debugStop();
302265
break;
303266
case SB_KEY_CTRL('s'):
304267
saveFile(editWidget, loadPath);
@@ -345,15 +308,15 @@ void System::editSource(String loadPath) {
345308
widget = helpWidget;
346309
helpWidget->createMessage();
347310
helpWidget->show();
348-
debugStart(editWidget, loadPath.c_str());
311+
((Runtime *)this)->debugStart(editWidget, loadPath.c_str());
349312
statusMessage._row = editWidget->getRow();
350313
statusMessage._col = editWidget->getCol();
351314
break;
352315
case SB_KEY_F(6):
353-
debugStep(editWidget, helpWidget, false);
316+
((Runtime *)this)->debugStep(editWidget, helpWidget, false);
354317
break;
355318
case SB_KEY_F(7):
356-
debugStep(editWidget, helpWidget, true);
319+
((Runtime *)this)->debugStep(editWidget, helpWidget, true);
357320
break;
358321
case SB_KEY_F(8):
359322
((Runtime *)this)->exportRun(loadPath);
@@ -369,11 +332,6 @@ void System::editSource(String loadPath) {
369332
helpWidget->show();
370333
inputMode = kCommand;
371334
break;
372-
case SB_KEY_F(11):
373-
if (((Runtime *)this)->toggleFullscreen()) {
374-
_output->setStatus("Press F11 to exit full screen.");
375-
}
376-
break;
377335
case SB_KEY_CTRL('h'):
378336
_output->setStatus("Keystroke help. Esc=Close");
379337
widget = helpWidget;
@@ -454,7 +412,8 @@ void System::editSource(String loadPath) {
454412
if (getRecentFile(recentFile, event.key - SB_KEY_ALT('1'))) {
455413
if (loadSource(recentFile.c_str())) {
456414
editWidget->reload(_programSrc);
457-
statusMessage.setFilename(loadPath);
415+
statusMessage.setFilename(recentFile);
416+
statusMessage.update(editWidget, _output, true);
458417
setLoadPath(recentFile);
459418
setWindowTitle(statusMessage._fileName);
460419
loadPath = recentFile;
@@ -501,15 +460,6 @@ void System::editSource(String loadPath) {
501460
widget = editWidget;
502461
helpWidget->hide();
503462
break;
504-
case kPublish:
505-
_output->setStatus("Sending gist...");
506-
_output->redraw();
507-
publish(this, editWidget->getText(), statusMessage._fileName, helpWidget->getText());
508-
inputMode = kInit;
509-
widget = editWidget;
510-
helpWidget->hide();
511-
statusMessage._dirty = !widget->isDirty();
512-
break;
513463
default:
514464
break;
515465
}

0 commit comments

Comments
 (0)