Skip to content

Commit b9aa056

Browse files
authored
Merge pull request #177 from chrisws/12_26
12 26
2 parents dc61154 + c3d0c17 commit b9aa056

File tree

13 files changed

+187
-39
lines changed

13 files changed

+187
-39
lines changed

ChangeLog

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
2023-01-20 (12.26)
2+
COMMON: Fixed DIM lower bound
3+
COMMON: RGB and RGBF now clamp parameters
4+
COMMON: Fix for BIN and changes to return values of POLYCENT and POLYAREA
5+
6+
2023-01-09 (12.26)
7+
COMMON: INPUT #F; now supports up to 64 parameters
8+
COMMON: Implemented STATMEDIAN() to calculate the median of a data sample in statistics.
9+
COMMON: Implemented STATSTD() to calculate standard deviation
10+
11+
2023-01-09 (12.26)
12+
COMMON: Fix printing chr(0) into a file or network interface
13+
14+
2022-11-13 (12.26)
15+
COMMON: Fix line-chart line drawing to use current foreground color
16+
117
2022-11-13 (12.25)
218
ANDROID: Updated file manager web UI:
319
- Implemented delete command

Makefile.am

+98
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,101 @@ ndk-stack:
6767
appImage:
6868
~/apps/linuxdeploy-x86_64.AppImage --appdir=AppDir --executable=./src/platform/fltk/sbasici && \
6969
~/apps/appimagetool-x86_64.AppImage AppDir
70+
71+
EXTRA_DIST = \
72+
src/languages/chars.en.h \
73+
src/languages/keywords.en.c \
74+
src/languages/messages.en.h \
75+
src/include/module.h \
76+
src/include/osd.h \
77+
src/include/var.h \
78+
src/include/var_map.h \
79+
src/lib/jsmn/jsmn.h \
80+
src/lib/lodepng/lodepng.cpp \
81+
src/lib/lodepng/lodepng.h \
82+
src/lib/miniaudio/miniaudio.h \
83+
src/lib/stb/stb_textedit.h \
84+
src/platform/android/Makefile.am \
85+
src/platform/android/app/src/main/assets/main.bas \
86+
src/platform/android/app/src/main/assets/samples/welcome.bas \
87+
src/platform/android/jni/Android.mk \
88+
src/platform/android/jni/Application.mk \
89+
src/platform/android/jni/common/Android.mk \
90+
src/platform/android/jni/display.cpp \
91+
src/platform/android/jni/display.h \
92+
src/platform/android/jni/freetype/Android.mk \
93+
src/platform/android/jni/main.cpp \
94+
src/platform/android/jni/runtime.cpp \
95+
src/platform/android/jni/runtime.h \
96+
src/platform/android/webui/package.json \
97+
src/platform/android/webui/src/App.js \
98+
src/platform/android/webui/src/index.js \
99+
src/platform/console/Makefile.am \
100+
src/platform/console/decomp.c \
101+
src/platform/console/device.cpp \
102+
src/platform/console/image.cpp \
103+
src/platform/console/input.cpp \
104+
src/platform/console/io.github.smallbasic.appdata.xml \
105+
src/platform/console/io.github.smallbasic.desktop \
106+
src/platform/console/main.cpp \
107+
src/platform/emcc/Makefile.am \
108+
src/platform/emcc/canvas.cpp \
109+
src/platform/emcc/canvas.h \
110+
src/platform/emcc/icon.h \
111+
src/platform/emcc/keymap.h \
112+
src/platform/emcc/main.cpp \
113+
src/platform/emcc/main_bas.h \
114+
src/platform/emcc/runtime.cpp \
115+
src/platform/emcc/runtime.h \
116+
src/platform/emcc/sbasic.html \
117+
src/platform/emcc/shell.html \
118+
src/platform/fltk/BasicEditor.cxx \
119+
src/platform/fltk/BasicEditor.h \
120+
src/platform/fltk/EditorWidget.cxx \
121+
src/platform/fltk/EditorWidget.h \
122+
src/platform/fltk/FileWidget.cxx \
123+
src/platform/fltk/FileWidget.h \
124+
src/platform/fltk/HelpView.cxx \
125+
src/platform/fltk/HelpView.h \
126+
src/platform/fltk/HelpWidget.cxx \
127+
src/platform/fltk/HelpWidget.h \
128+
src/platform/fltk/MainWindow.cxx \
129+
src/platform/fltk/MainWindow.h \
130+
src/platform/fltk/Makefile.am \
131+
src/platform/fltk/Profile.cxx \
132+
src/platform/fltk/Profile.h \
133+
src/platform/fltk/TtyWidget.cxx \
134+
src/platform/fltk/TtyWidget.h \
135+
src/platform/fltk/build_kwp.cxx \
136+
src/platform/fltk/display.cxx \
137+
src/platform/fltk/display.h \
138+
src/platform/fltk/icon.h \
139+
src/platform/fltk/io.github.smallbasic.appdata.xml \
140+
src/platform/fltk/io.github.smallbasic.desktop \
141+
src/platform/fltk/kwp.h \
142+
src/platform/fltk/runtime.cxx \
143+
src/platform/fltk/runtime.h \
144+
src/platform/fltk/utils.cxx \
145+
src/platform/fltk/utils.h \
146+
src/platform/fltk/win.rc \
147+
src/platform/sdl/Makefile.am \
148+
src/platform/sdl/display.cpp \
149+
src/platform/sdl/display.h \
150+
src/platform/sdl/editor.cpp \
151+
src/platform/sdl/icon.h \
152+
src/platform/sdl/io.github.smallbasic.appdata.xml \
153+
src/platform/sdl/io.github.smallbasic.desktop \
154+
src/platform/sdl/keymap.h \
155+
src/platform/sdl/main.cpp \
156+
src/platform/sdl/main_bas.h \
157+
src/platform/sdl/runtime.cpp \
158+
src/platform/sdl/runtime.h \
159+
src/platform/sdl/settings.cpp \
160+
src/platform/sdl/settings.h \
161+
src/platform/sdl/syswm.cpp \
162+
src/platform/sdl/syswm.h \
163+
src/platform/sdl/win.rc \
164+
src/platform/web/Makefile.am \
165+
src/platform/web/canvas.cpp \
166+
src/platform/web/canvas.h \
167+
src/platform/web/main.cpp

configure.ac

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dnl This program is distributed under the terms of the GPL v2.0
77
dnl Download the GNU Public License (GPL) from www.gnu.org
88
dnl
99

10-
AC_INIT([smallbasic], [12.25])
10+
AC_INIT([smallbasic], [12.26])
1111
AC_CONFIG_SRCDIR([configure.ac])
1212

1313
AC_CANONICAL_TARGET
@@ -17,7 +17,6 @@ AM_MAINTAINER_MODE
1717

1818
AC_PROG_CXX
1919
AM_PROG_CC_C_O
20-
AC_HEADER_STDC
2120
AC_PROG_RANLIB
2221
PKG_PROG_PKG_CONFIG
2322

documentation/sbasic_ref.csv

+6-4
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,12 @@ Math,function,SGN,756,"SGN (x)","Sign of x (+1 for positive, -1 for negative and
237237
Math,function,SIN,757,"SIN (x)","Sine."
238238
Math,function,SINH,758,"SINH (x)","Sine."
239239
Math,function,SQR,759,"SQR (x)","Square root of x."
240-
Math,function,STATMEAN,760,"STATMEAN (...)","Arithmetical mean."
241-
Math,function,STATMEANDEV,761,"STATMEANDEV (...)","Mean deviation."
242-
Math,function,STATSPREADP,762,"STATSPREADS (...)","Sample spread."
243-
Math,function,STATSPREADS,763,"STATSPREADP (...)","Population spread."
240+
Math,function,STATMEAN,760,"STATMEAN (...)","Arithmetical mean (average). "
241+
Math,function,STATMEANDEV,761,"STATMEANDEV (...)","Mean absolute deviation around arithmetic mean."
242+
Math,function,STATMEDIAN,1801,"STATMEDIAN (...)","The median of a finite list of numbers is the ""middle"" number, when those numbers are listed in order from smallest to ..."
243+
Math,function,STATSPREADP,762,"STATSPREADP (...)","Biased sample variance."
244+
Math,function,STATSPREADS,763,"STATSPREADS (...)","Unbiased sample variance."
245+
Math,function,STATSTD,1800,"STATSTD (...)","(Corrected sample) standard deviation."
244246
Math,function,SUM,764,"SUM (...)","Sum of value."
245247
Math,function,SUMSQ,765,"SUMSQ (...)","Sum of square value."
246248
Math,function,TAN,766,"TAN (x)","Tangent."

samples/distro-examples/tests/stream-files.bas

+25
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,29 @@ end
3939
dirwalk "./", "*.cpp" use walker(x)
4040
if (!has_main) then throw "dirwalk error"
4141

42+
' allow reading and writing of chr(0)
43+
open "output.dat" for output as #F
44+
for x = 0 to 255
45+
print #F, chr(x);
46+
next
47+
close #F
4248

49+
open "output.dat" for input as #1
50+
for x = 0 to 255
51+
d = input(1, 1)
52+
if asc(d) != x then throw "Invalid file read " + d + " <> " + x
53+
next
54+
close #1
55+
56+
' INPUT #F; now supports up to 64 parameters
57+
open "./output.dat" for output as #2
58+
print #2, "1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16"
59+
close #2
60+
open "./output.dat" for input as #2
61+
dim v[0 to 15]
62+
input #2; v[0], "|", v[1], "|", v[2], "|", v[3], "|", &
63+
v[4], "|", v[5], "|", v[6], "|", v[7], "|", &
64+
v[8], "|", v[9], "|", v[10],"|", v[11],"|", &
65+
v[12],"|", v[13],"|", v[14],"|", v[15],"|"
66+
close #2
67+
if v != [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] then throw "invalid input"

src/common/Makefile.am

-14
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@ endif
1212

1313
AM_CPPFLAGS = -I$(abs_top_builddir)/src -DPACKAGE_LIB_DIR=\""$(pkglibdir)"\"
1414

15-
EXTRA_DIST = \
16-
../languages/chars.en.h \
17-
../languages/keywords.en.c \
18-
../languages/messages.en.h \
19-
../include/module.h \
20-
../include/osd.h \
21-
../include/var.h \
22-
../include/var_map.h \
23-
../lib/jsmn/jsmn.h \
24-
../lib/lodepng/lodepng.cpp \
25-
../lib/lodepng/lodepng.h \
26-
../lib/miniaudio/miniaudio.h \
27-
../lib/stb/stb_textedit.h
28-
2915
noinst_LIBRARIES = libsb_common.a
3016

3117
libsb_common_a_SOURCES = \

src/common/blib.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ void cmd_input(int input) {
704704

705705
// get list of parameters
706706
par_t *ptable = NULL;
707-
int pcount = par_getpartable(&ptable, ",;");
707+
int pcount = par_getpartable(&ptable, ",;", input == PV_FILE ? MAX_PARAMS_FILE : MAX_PARAMS);
708708
if (pcount == 0) {
709709
rt_raise(ERR_INPUT_NO_VARS);
710710
}
@@ -813,7 +813,7 @@ void cmd_input(int input) {
813813
// (,)
814814
char *p;
815815
if (pcount == 1) {
816-
p = (inp_p + strlen(inp_p));
816+
p = (inp_p + (!inp_p ? 0 : strlen(inp_p)));
817817
} else {
818818
p = q_strstr(inp_p, ((next_is_const) ? v_getstr(ptable[cur_par_idx].var) : ","), "\"\"");
819819
}
@@ -830,7 +830,7 @@ void cmd_input(int input) {
830830
}
831831
} else {
832832
v_input2var(inp_p, par->var);
833-
inp_p = (inp_p + strlen(inp_p)); // go to '\0'
833+
inp_p = (inp_p + (!inp_p ? 0 : strlen(inp_p))); // go to '\0'
834834
input_is_finished = 1;
835835
}
836836
}

src/common/blib_func.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,7 @@ void cmd_intN(long funcCode, var_t *r) {
19381938
// i <- RGB(r,g,b)
19391939
// i <- RGBF(r,g,b)
19401940
case kwRGB:
1941-
case kwRGBF:
1941+
case kwRGBF: {
19421942
var_num_t rc, gc, bc;
19431943

19441944
par_massget("FFF", &rc, &gc, &bc);
@@ -1955,7 +1955,7 @@ void cmd_intN(long funcCode, var_t *r) {
19551955

19561956
r->v.i = -r->v.i;
19571957
break;
1958-
1958+
}
19591959
default:
19601960
rt_raise("Unsupported built-in function call %ld", funcCode);
19611961
}

src/common/pproc.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
#define PV_STRING 3
3333
#define PV_NET 4
3434

35+
#define MAX_PARAMS_FILE 64
36+
#define MAX_PARAMS 8
37+
3538
#if defined(__cplusplus)
3639
extern "C" {
3740
#endif
@@ -285,7 +288,7 @@ void par_skip(void);
285288
* @return on success the number of the parameters; otherwise -1
286289
* @see par_freepartable, par_massget
287290
*/
288-
int par_getpartable(par_t **ptable_pp, const char *valid_sep);
291+
int par_getpartable(par_t **ptable_pp, const char *valid_sep, unsigned max_items);
289292

290293
/**
291294
* @ingroup par

src/common/proc.c

+28-10
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include <limits.h>
1616
#include <dirent.h>
1717

18-
#define MAX_PARAM 8
19-
2018
/*
2119
* returns the last-modified time of the file
2220
*
@@ -165,6 +163,25 @@ void pv_write_str(char *str, var_t *vp) {
165163
}
166164
}
167165

166+
void pv_write_str_var(var_t *var, int method, intptr_t handle) {
167+
switch (method) {
168+
case PV_FILE:
169+
dev_fwrite((int)handle, (byte *)var->v.p.ptr, var->v.p.length - 1);
170+
break;
171+
case PV_LOG:
172+
lwrite(var->v.p.ptr);
173+
break;
174+
case PV_STRING:
175+
pv_write_str(var->v.p.ptr, (var_t *)handle);
176+
break;
177+
case PV_NET:
178+
net_send((socket_t)handle, (const char *)var->v.p.ptr, var->v.p.length - 1);
179+
break;
180+
default:
181+
dev_print(var->v.p.ptr);
182+
}
183+
}
184+
168185
/*
169186
* Write string to output device
170187
*/
@@ -206,7 +223,7 @@ void pv_writevar(var_t *var, int method, intptr_t handle) {
206223
pv_write(tmpsb, method, handle);
207224
break;
208225
case V_STR:
209-
pv_write(var->v.p.ptr, method, handle);
226+
pv_write_str_var(var, method, handle);
210227
break;
211228
case V_ARRAY:
212229
case V_MAP:
@@ -881,15 +898,16 @@ void par_freepartable(par_t **ptable_pp, int pcount) {
881898
* YOU MUST FREE THAT TABLE BY USING par_freepartable()
882899
* IF THERE IS NO ERROR, CALL TO par_freepartable IS NOT NEEDED
883900
*/
884-
int par_getpartable(par_t **ptable_pp, const char *valid_sep) {
901+
int par_getpartable(par_t **ptable_pp, const char *valid_sep, unsigned max_items) {
885902
bcip_t ofs;
886903
char vsep[8];
887904

888905
// initialize
889906
var_t *par = NULL;
890907
byte last_sep = 0;
891908
int pcount = 0;
892-
par_t *ptable = *ptable_pp = malloc(sizeof(par_t) * MAX_PARAM);
909+
910+
par_t *ptable = *ptable_pp = malloc(sizeof(par_t) * max_items);
893911

894912
if (valid_sep) {
895913
strlcpy(vsep, valid_sep, sizeof(vsep));
@@ -935,9 +953,9 @@ int par_getpartable(par_t **ptable_pp, const char *valid_sep) {
935953
if (code_isvar()) {
936954
// push parameter
937955
ptable[pcount].var = code_getvarptr();
938-
if (++pcount == MAX_PARAM) {
956+
if (++pcount == max_items) {
939957
par_freepartable(ptable_pp, pcount);
940-
err_parfmt(__FILE__);
958+
err_parfmt(ERR_PARAM_TOO_MANY);
941959
return -1;
942960
}
943961
break;
@@ -955,9 +973,9 @@ int par_getpartable(par_t **ptable_pp, const char *valid_sep) {
955973
// push parameter
956974
ptable[pcount].var = par;
957975
ptable[pcount].flags = PAR_BYVAL;
958-
if (++pcount == MAX_PARAM) {
976+
if (++pcount == max_items) {
959977
par_freepartable(ptable_pp, pcount);
960-
err_parfmt(__FILE__);
978+
err_parfmt(ERR_PARAM_TOO_MANY);
961979
return -1;
962980
}
963981
} else {
@@ -1028,7 +1046,7 @@ int par_massget_type_check(char fmt, par_t *par) {
10281046
int par_massget(const char *fmt, ...) {
10291047
// get ptable
10301048
par_t *ptable;
1031-
int pcount = par_getpartable(&ptable, NULL);
1049+
int pcount = par_getpartable(&ptable, NULL, MAX_PARAMS);
10321050
if (pcount == -1) {
10331051
free(ptable);
10341052
return -1;

src/languages/messages.en.h

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
#define ERR_ARRAY_RANGE "Array: Index '%d' out of range. (Max = %d)"
158158
#define ERR_TYPE "Type mismatch"
159159
#define ERR_PARAM "Invalid parameter"
160+
#define ERR_PARAM_TOO_MANY "Too many parameters"
160161
#define ERR_NO_ARGS "Function takes no arguments"
161162
#define EVAL_VAR_IS_ARRAY "Expr/RT: Variable is an array"
162163
#define EVAL_VAR_IS_NOT_ARRAY "Expr/RT: Variable is NOT an array (Use DIM)"

src/platform/android/app/src/main/assets/main.bas

+2-2
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ sub listFiles(byref frm, path, sortDir, byref basList)
397397
endif
398398
if (abbr) then
399399
bn = mk_bn(path + name, name, txtcol)
400-
bn.type = iff(lower(right(name, 4)) == ".bas", "link", "label")
400+
bn.type = iff(!is_android || lower(right(name, 4)) == ".bas", "link", "label")
401401
if (bn.type == "label") then bn.color = colText
402402
if (!node.dir) then bn.isExit = true
403403
else
@@ -407,7 +407,7 @@ sub listFiles(byref frm, path, sortDir, byref basList)
407407
lab = name
408408
endif
409409
bn = mk_bn(path + name, lab, txtcol)
410-
bn.type = iff(lower(right(name, 4)) == ".bas", "link", "label")
410+
bn.type = iff(!is_android || lower(right(name, 4)) == ".bas", "link", "label")
411411
if (bn.type == "label") then bn.color = colText
412412
if (!node.dir) then bn.isExit = true
413413
frm.inputs << bn

0 commit comments

Comments
 (0)