From 4a84e599edcc6d9c4cae7e8ca1e60207af757ce5 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Sat, 28 Mar 2020 13:52:16 +1000 Subject: [PATCH 01/36] AUDIO: #90 use latest miniaudio api --- ChangeLog | 3 ++ configure.ac | 2 +- debian/changelog | 5 +++ src/lib/miniaudio | 2 +- src/platform/sdl/runtime.cpp | 1 - src/ui/audio.cpp | 77 +++++++++++++++++++----------------- 6 files changed, 51 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index acf1aaf7..3a880376 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2020-02-13 (0.12.19) + AUDIO: fix integration with latest version of miniaudio library + 2020-02-13 (0.12.18) Fix path for HOME constant diff --git a/configure.ac b/configure.ac index 39b2fb28..68cf0e89 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ dnl This program is distributed under the terms of the GPL v2.0 dnl Download the GNU Public License (GPL) from www.gnu.org dnl -AC_INIT([smallbasic], [0.12.18]) +AC_INIT([smallbasic], [0.12.19]) AC_CONFIG_SRCDIR([configure.ac]) AC_CANONICAL_TARGET diff --git a/debian/changelog b/debian/changelog index c3cd6ba9..26518299 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,8 @@ +smallbasic (0.12.19) unstable; urgency=low + * Various see web site + + -- Chris Warren-Smith Sun, 22 Mar 2020 09:45:25 +1000 + smallbasic (0.12.18) unstable; urgency=low * Various see web site diff --git a/src/lib/miniaudio b/src/lib/miniaudio index df2903a0..4b45e1ef 160000 --- a/src/lib/miniaudio +++ b/src/lib/miniaudio @@ -1 +1 @@ -Subproject commit df2903a0bcaf0126f9ad43d2b1238891b55bc2f6 +Subproject commit 4b45e1ef1bdc43c24e650118dac79fbf36003bfd diff --git a/src/platform/sdl/runtime.cpp b/src/platform/sdl/runtime.cpp index fc882e6e..05418cda 100644 --- a/src/platform/sdl/runtime.cpp +++ b/src/platform/sdl/runtime.cpp @@ -298,7 +298,6 @@ int Runtime::runShell(const char *startupBas, bool runWait, int fontScale, int d _output->setFontSize(fontSize); } - audio_open(); net_init(); diff --git a/src/ui/audio.cpp b/src/ui/audio.cpp index a21f1b38..efe38b58 100644 --- a/src/ui/audio.cpp +++ b/src/ui/audio.cpp @@ -1,6 +1,6 @@ // This file is part of SmallBASIC // -// Copyright(C) 2001-2019 Chris Warren-Smith. +// Copyright(C) 2001-2020 Chris Warren-Smith. // // This program is distributed under the terms of the GPL v2.0 or later // Download the GNU Public License (GPL) from www.gnu.org @@ -32,7 +32,7 @@ struct Sound; static ma_device device; static ma_device_config config; static strlib::Queue queue; -static strlib::Properties cache; +static int queuePos = 0; struct Sound { Sound(int frequency, int millis, int volume); @@ -41,7 +41,7 @@ struct Sound { ma_result construct(const char *path); - ma_sine_wave *_tone; + ma_waveform *_tone; ma_decoder *_decoder; uint32_t _start; uint32_t _duration; @@ -59,8 +59,11 @@ Sound::Sound(int frequency, int millis, int volume) : _decoder(nullptr), _start(0), _duration(millis) { - _tone = (ma_sine_wave *)malloc(sizeof(ma_sine_wave)); - ma_sine_wave_init(volume / 100.0, frequency, DEFAULT_SAMPLE_RATE, _tone); + _tone = (ma_waveform *)malloc(sizeof(ma_waveform)); + ma_waveform_config config = + ma_waveform_config_init(DEFAULT_FORMAT, DEFAULT_CHANNELS, DEFAULT_SAMPLE_RATE, + ma_waveform_type_sine, volume / 100.0, frequency); + ma_waveform_init(&config, _tone); } Sound::~Sound() { @@ -82,20 +85,25 @@ static void data_callback(ma_device *device, void *output, const void *input, ma if (queue.empty()) { usleep(MILLIS_TO_MICROS(10)); } else { - Sound *sound = queue.front(); + queuePos = (queuePos + 1) % queue.size(); + Sound *sound = queue[queuePos]; if (sound->_decoder != nullptr) { // play audio track - ma_decoder_read_pcm_frames(sound->_decoder, output, frameCount); + ma_uint64 framesRead = ma_decoder_read_pcm_frames(sound->_decoder, output, frameCount); + if (framesRead == 0) { + // finished playing + queue.pop(false); + } } else if (sound->_start == 0) { // start new sound sound->_start = dev_get_millisecond_count(); - ma_sine_wave_read_f32(sound->_tone, frameCount, (float*)output); + ma_waveform_read_pcm_frames(sound->_tone, (float *)output, frameCount); } else if (dev_get_millisecond_count() - sound->_start > sound->_duration) { // sound has timed out - queue.pop(sound->_decoder == nullptr); + queue.pop(false); } else { // continue sound - ma_sine_wave_read_f32(sound->_tone, frameCount, (float*)output); + ma_waveform_read_pcm_frames(sound->_tone, (float *)output, frameCount); } } } @@ -122,8 +130,18 @@ static void setup_format(ma_format format, ma_uint32 channels, ma_uint32 sampleR } } +static void device_start() { + if (ma_device__get_state(&device) != MA_STATE_STARTED) { + ma_result result = ma_device_start(&device); + if (result != MA_SUCCESS) { + err_throw("Failed to start audio [%d]", result); + } + } +} + bool audio_open() { setup_config(DEFAULT_FORMAT, DEFAULT_CHANNELS, DEFAULT_SAMPLE_RATE); + queuePos = 0; return (ma_device_init(nullptr, &config, &device) == MA_SUCCESS); } @@ -133,32 +151,19 @@ void audio_close() { } void osd_audio(const char *path) { - Sound *sound = cache.get(path); - if (sound) { + Sound *sound = new Sound(); + ma_result result = sound->construct(path); + if (result != MA_SUCCESS) { + delete sound; + err_throw("Failed to open sound file [%d]", result); + } else { + setup_format(sound->_decoder->outputFormat, + sound->_decoder->outputChannels, + sound->_decoder->outputSampleRate); ma_mutex_lock(&device.lock); queue.push(sound); ma_mutex_unlock(&device.lock); - } else { - sound = new Sound(); - ma_result result = sound->construct(path); - if (result != MA_SUCCESS) { - delete sound; - err_throw("Failed to open sound file [%d]", result); - } else { - setup_format(sound->_decoder->outputFormat, - sound->_decoder->outputChannels, - sound->_decoder->outputSampleRate); - ma_mutex_lock(&device.lock); - queue.push(sound); - cache.put(path, sound); - ma_mutex_unlock(&device.lock); - if (queue.size() == 1) { - result = ma_device_start(&device); - if (result != MA_SUCCESS) { - err_throw("Failed to start audio [%d]", result); - } - } - } + device_start(); } } @@ -180,7 +185,7 @@ void osd_clear_sound_queue() { } queue.removeAll(); - cache.removeAll(); + queuePos = 0; } void osd_sound(int frequency, int millis, int volume, int background) { @@ -190,13 +195,13 @@ void osd_sound(int frequency, int millis, int volume, int background) { ma_mutex_unlock(&device.lock); if (!background) { - ma_device_start(&device); + device_start(); usleep(MILLIS_TO_MICROS(millis)); ma_device_stop(&device); ma_mutex_lock(&device.lock); queue.pop(); ma_mutex_unlock(&device.lock); } else if (queue.size() == 1) { - ma_device_start(&device); + device_start(); } } From 028f94d4e00213bbe629de254c855fa9f0b00bc8 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Tue, 7 Apr 2020 07:08:22 +1000 Subject: [PATCH 02/36] COMMON: implement DEFINEKEY undo #92 --- samples/distro-examples/tests/keymap.bas | 34 ++++++++++++++++++ src/common/blib.c | 14 +++++--- src/common/keymap.c | 46 ++++++++++++++++++++---- src/common/keymap.h | 1 + src/platform/console/Makefile.am | 2 +- 5 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 samples/distro-examples/tests/keymap.bas diff --git a/samples/distro-examples/tests/keymap.bas b/samples/distro-examples/tests/keymap.bas new file mode 100644 index 00000000..603f7fb5 --- /dev/null +++ b/samples/distro-examples/tests/keymap.bas @@ -0,0 +1,34 @@ +sub foo + ? "f" +end + +definekey 2, foo +definekey 1, foo +definekey 1, foo +definekey 1, foo +definekey 1, 1 +definekey 1, 2 +definekey 1, 3 +definekey 1, 2 +definekey 1, 3 +definekey 2, 0 +definekey 2, 0 +definekey 2, 0 +definekey 2, 0 + +definekey asc("x"), foo +definekey asc("x"), foo +definekey asc("y"), foo +definekey asc("z"), foo +definekey asc("f"), foo +definekey asc("x"), 0 +definekey asc("y"), 0 +definekey asc("z"), 0 + +if (instr(sbver, "SDL") <> 0) then + while 1 + ? "."; + delay 10 + wend +endif + diff --git a/src/common/blib.c b/src/common/blib.c index 2825205b..cd2b8d85 100644 --- a/src/common/blib.c +++ b/src/common/blib.c @@ -2835,14 +2835,20 @@ void cmd_definekey(void) { if (!prog_error) { par_getcomma(); - - if (code_peek() != kwTYPE_CALL_UDF) { - err_syntax(kwDEFINEKEY, "%I,%G"); - } else { + switch (code_peek()) { + case kwTYPE_INT: + prog_ip++; + keymap_remove(key, code_getint()); + break; + case kwTYPE_CALL_UDF: keymap_add(key, prog_ip); // skip ahead to avoid immediate call prog_ip += BC_CTRLSZ + 1; + break; + default: + err_syntax(kwDEFINEKEY, "%I,%G"); + break; } } v_free(&var); diff --git a/src/common/keymap.c b/src/common/keymap.c index 351175bb..4edb178f 100644 --- a/src/common/keymap.c +++ b/src/common/keymap.c @@ -30,7 +30,7 @@ struct key_map_s { int key; // key definition }; -key_map_s* keymap = 0; +key_map_s *keymap = 0; /** * Prepare task_t exec.keymap for keymap handling at program init @@ -42,7 +42,7 @@ void keymap_init() { /** * Handler for keymap_free() */ -void keymap_delete(key_map_s* km) { +void keymap_delete(key_map_s *km) { if (km) { keymap_delete(km->next); free(km); @@ -61,13 +61,13 @@ void keymap_free() { * DEFINEKEY command handler to add a keymap */ void keymap_add(uint32_t key, bcip_t ip) { - key_map_s* km = (key_map_s*) malloc(sizeof (key_map_s)); + key_map_s *km = (key_map_s *)malloc(sizeof(key_map_s)); km->next = 0; km->ip = ip; km->key = key; // add the new mapping onto the linked list - key_map_s* head = keymap; + key_map_s *head = keymap; if (!head) { keymap = km; } else { @@ -78,12 +78,44 @@ void keymap_add(uint32_t key, bcip_t ip) { } } +/** + * DEFINEKEY key, 0 + */ +void keymap_remove(uint32_t key, int level) { + key_map_s *head = keymap; + key_map_s *prev = head; + int size = 0; + + while (head) { + if (head->key == key) { + key_map_s *current = head; + prev->next = head->next; + head = head->next; + free(current); + if (current == prev) { + prev = head; + } + if (current == keymap) { + keymap = head; + } + } else { + prev = head; + head = head->next; + size++; + } + } + if (!size) { + keymap = 0; + } +} + + /** * invokes the handler for the given key */ int keymap_invoke(uint32_t key) { int result = 0; - key_map_s* head = keymap; + key_map_s *head = keymap; while (head) { if (head->key == key) { bcip_t ip = prog_ip; // store current ip @@ -175,7 +207,7 @@ void timer_free(timer_s *timer) { } void timer_add(var_num_t interval, bcip_t ip) { - timer_s* timer = (timer_s*) malloc(sizeof (timer_s)); + timer_s *timer = (timer_s *)malloc(sizeof (timer_s)); timer->next = NULL; timer->ip = ip; timer->interval = interval; @@ -195,7 +227,7 @@ void timer_add(var_num_t interval, bcip_t ip) { } void timer_run(uint32_t now) { - timer_s* timer = prog_timer; + timer_s *timer = prog_timer; while (timer) { if (timer->value == 0) { // start timer diff --git a/src/common/keymap.h b/src/common/keymap.h index e8d50d71..8b7c070a 100644 --- a/src/common/keymap.h +++ b/src/common/keymap.h @@ -87,6 +87,7 @@ extern "C" { void keymap_init(); void keymap_free(); void keymap_add(uint32_t key, bcip_t ip); +void keymap_remove(uint32_t key, int level); int keymap_invoke(uint32_t key); int keymap_kbhit(); int keymap_kbpeek(); diff --git a/src/platform/console/Makefile.am b/src/platform/console/Makefile.am index 0e26bd8a..0f44b05f 100644 --- a/src/platform/console/Makefile.am +++ b/src/platform/console/Makefile.am @@ -28,7 +28,7 @@ TEST_DIR=../../../samples/distro-examples/tests UNIT_TESTS=array break byref eval-test iifs matrices metaa ongoto \ uds hash pass1 call_tau short-circuit strings stack-test \ replace-test read-data proc optchk letbug ptr ref \ - trycatch chain stream-files split-join sprint all scope goto + trycatch chain stream-files split-join sprint all scope goto keymap test: ${bin_PROGRAMS} @for utest in $(UNIT_TESTS); do \ From 46b9339b837da8f04471ed890c2258232538b771 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Tue, 7 Apr 2020 07:10:00 +1000 Subject: [PATCH 03/36] UI: added R157 colour theme #94 --- ChangeLog | 3 +++ src/platform/fltk/MainWindow.cxx | 1 + src/ui/textedit.cpp | 8 +++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3a880376..04e87f93 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2020-03-07 (0.12.19) + COMMON: implement DEFINEKEY undo #92 + 2020-02-13 (0.12.19) AUDIO: fix integration with latest version of miniaudio library diff --git a/src/platform/fltk/MainWindow.cxx b/src/platform/fltk/MainWindow.cxx index 8e2f4fc5..bf4bcb18 100644 --- a/src/platform/fltk/MainWindow.cxx +++ b/src/platform/fltk/MainWindow.cxx @@ -974,6 +974,7 @@ MainWindow::MainWindow(int w, int h) : m->add("&View/Theme/&Shian", 0, set_theme_cb, (void *)(intptr_t)2); m->add("&View/Theme/&Atom 1", 0, set_theme_cb, (void *)(intptr_t)3); m->add("&View/Theme/&Atom 2", 0, set_theme_cb, (void *)(intptr_t)4); + m->add("&View/Theme/&R157", 0, set_theme_cb, (void *)(intptr_t)5); m->add("&View/Text Color/_Background", 0, EditorWidget::set_color_cb, (void *)st_background); m->add("&View/Text Color/Text", 0, EditorWidget::set_color_cb, (void *)st_text); m->add("&View/Text Color/Comments", 0, EditorWidget::set_color_cb, (void *)st_comments); diff --git a/src/ui/textedit.cpp b/src/ui/textedit.cpp index ac8c7307..3a1f9df2 100644 --- a/src/ui/textedit.cpp +++ b/src/ui/textedit.cpp @@ -156,6 +156,12 @@ const int atom2[] = { 0x0083f8, 0xff9d00, 0x31ccac, 0xc679dd, 0x0083f8 }; +const int r157[] = { + 0x80dfff, 0xa7aebc, 0xffffff, 0xa7aebc, 0xa7aebc, 0xd0d6e1, + 0x2e3436, 0x888a85, 0x000000, 0x4d483b, 0x000000, 0x576375, + 0xffffff, 0xffc466, 0xffcce0, 0xffff66, 0x0083f8 +}; + int g_user_theme[] = { 0xc8cedb, 0xa7aebc, 0x484f5f, 0xa7aebc, 0xa7aebc, 0x00bb00, 0x2e3436, 0x888a85, 0x000000, 0x4d483b, 0x000000, 0x2b313a, @@ -163,7 +169,7 @@ int g_user_theme[] = { }; const int* themes[] = { - solarized_dark, solarized_light, shian, atom1, atom2, g_user_theme + solarized_dark, solarized_light, shian, atom1, atom2, r157, g_user_theme }; const char *helpText = From fa6328f48b53f9b1f06fe6ac4af1b917eedb3801 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Tue, 7 Apr 2020 07:34:14 +1000 Subject: [PATCH 04/36] COMMON: implement DEFINEKEY undo #92 --- src/common/keymap.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/common/keymap.c b/src/common/keymap.c index 4edb178f..ed4b7c72 100644 --- a/src/common/keymap.c +++ b/src/common/keymap.c @@ -84,7 +84,6 @@ void keymap_add(uint32_t key, bcip_t ip) { void keymap_remove(uint32_t key, int level) { key_map_s *head = keymap; key_map_s *prev = head; - int size = 0; while (head) { if (head->key == key) { @@ -101,15 +100,10 @@ void keymap_remove(uint32_t key, int level) { } else { prev = head; head = head->next; - size++; } } - if (!size) { - keymap = 0; - } } - /** * invokes the handler for the given key */ From 903cad3d478a93f7b03f09a1d07adb270377e98d Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Fri, 24 Apr 2020 06:49:32 +1000 Subject: [PATCH 05/36] BUILD: use pkg-config to check freetype --- ChangeLog | 1 + configure.ac | 18 ++++++++++++------ src/platform/android/build.gradle | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 04e87f93..ded20268 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2020-03-07 (0.12.19) COMMON: implement DEFINEKEY undo #92 + UI: added R157 colour theme #94 2020-02-13 (0.12.19) AUDIO: fix integration with latest version of miniaudio library diff --git a/configure.ac b/configure.ac index 68cf0e89..0da19f80 100644 --- a/configure.ac +++ b/configure.ac @@ -156,8 +156,7 @@ function buildSDL() { AC_MSG_ERROR([libsdl2-dev not installed: configure failed.]) fi - AC_CHECK_PROG(have_freetype2, freetype-config, [yes], [no]) - if test "${have_freetype2}" = "no" ; then + if [ ! pkg-config --cflags freetype2 ]; then AC_MSG_ERROR([libfreetype6-dev not installed: configure failed.]) fi @@ -178,7 +177,7 @@ function buildSDL() { PACKAGE_CFLAGS="${PACKAGE_CFLAGS} -mms-bitfields" PACKAGE_LIBS="${PACKAGE_LIBS} -lwsock32 -lws2_32 -static-libgcc -static-libstdc++" PACKAGE_LIBS="${PACKAGE_LIBS} -Wl,-Bstatic -Wl,-Map=output.map" - PACKAGE_LIBS="${PACKAGE_LIBS} `sdl2-config --static-libs` `freetype-config --libs`" + PACKAGE_LIBS="${PACKAGE_LIBS} `sdl2-config --static-libs` `pkg-config --libs freetype2`" AC_DEFINE(_Win32, 1, [Windows build]) ;; @@ -193,7 +192,7 @@ function buildSDL() { dnl backlinking support for modules PACKAGE_LIBS="${PACKAGE_LIBS} -ldl" PACKAGE_LIBS="${PACKAGE_LIBS} ${FONTCONFIG_LIBS}" - PACKAGE_LIBS="${PACKAGE_LIBS} `sdl2-config --libs` `freetype-config --libs`" + PACKAGE_LIBS="${PACKAGE_LIBS} `sdl2-config --libs` `pkg-config --libs freetype2`" ;; *) @@ -207,10 +206,10 @@ function buildSDL() { dnl backlinking support for modules PACKAGE_LIBS="${PACKAGE_LIBS} -ldl -no-pie" PACKAGE_LIBS="${PACKAGE_LIBS} ${FONTCONFIG_LIBS}" - PACKAGE_LIBS="-static-libgcc ${PACKAGE_LIBS} `sdl2-config --static-libs` `freetype-config --libs`" + PACKAGE_LIBS="-static-libgcc ${PACKAGE_LIBS} `sdl2-config --static-libs` `pkg-config --libs freetype2`" esac - PACKAGE_CFLAGS="${PACKAGE_CFLAGS} `sdl2-config --cflags` `freetype-config --cflags` -fno-exceptions" + PACKAGE_CFLAGS="${PACKAGE_CFLAGS} `sdl2-config --cflags` `pkg-config --cflags freetype2` -fno-exceptions" CXXFLAGS="${CXXFLAGS} -fno-rtti -std=c++11" dnl preconfigured values for SDL build @@ -441,6 +440,13 @@ echo ${TARGET} echo "CFLAGS=${CFLAGS}" echo "CXXFLAGS=${CXXFLAGS}" echo "PACKAGE_LIBS=${PACKAGE_LIBS}" + +if test x$ac_build_sdl = xyes; then + echo + echo "sdl2: `sdl2-config --version`" + echo "freetype: `pkg-config --version freetype2`" +fi + echo if test x$ac_build_dist = xyes; then diff --git a/src/platform/android/build.gradle b/src/platform/android/build.gradle index ae627614..d99c778c 100644 --- a/src/platform/android/build.gradle +++ b/src/platform/android/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.3' + classpath 'com.android.tools.build:gradle:3.6.2' classpath "com.github.ben-manes:gradle-versions-plugin:0.22.0" } } From a3fa35b18330c98035a9f6d80b4582c773dba65e Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Mon, 4 May 2020 12:08:03 +1000 Subject: [PATCH 06/36] COMMON: INPUT crash #99 --- ChangeLog | 4 ++++ configure.ac | 4 ++-- samples/distro-examples/tests/keymap.bas | 1 + samples/distro-examples/tests/output/input.out | 1 + samples/distro-examples/tests/output/keymap.out | 1 + src/common/blib.c | 2 +- src/common/units.c | 17 ++++++----------- src/common/var.c | 5 +++-- src/platform/console/Makefile.am | 2 +- 9 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 samples/distro-examples/tests/output/input.out create mode 100644 samples/distro-examples/tests/output/keymap.out diff --git a/ChangeLog b/ChangeLog index ded20268..e1e6229c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2020-05-04 (0.12.19) + INPUT crash #99 + Fix compile warning with updated gcc + 2020-03-07 (0.12.19) COMMON: implement DEFINEKEY undo #92 UI: added R157 colour theme #94 diff --git a/configure.ac b/configure.ac index 0da19f80..62d53467 100644 --- a/configure.ac +++ b/configure.ac @@ -74,8 +74,8 @@ function checkDebugMode() { AC_MSG_RESULT([$with_debug]) if test "$with_debug" = "yes" || test "$with_debug" = "full" then - CFLAGS="${CFLAGS} -g -O0" - CXXFLAGS="${CXXFLAGS} -g -O0" + CFLAGS="${CFLAGS} -g -O0 -fstack-protector-all" + CXXFLAGS="${CXXFLAGS} -g -O0 -fstack-protector-all" AC_DEFINE(_DEBUG, 1, [debugging build enabled]) fi AC_SUBST(CFLAGS) diff --git a/samples/distro-examples/tests/keymap.bas b/samples/distro-examples/tests/keymap.bas index 603f7fb5..81d45897 100644 --- a/samples/distro-examples/tests/keymap.bas +++ b/samples/distro-examples/tests/keymap.bas @@ -32,3 +32,4 @@ if (instr(sbver, "SDL") <> 0) then wend endif +print "done" diff --git a/samples/distro-examples/tests/output/input.out b/samples/distro-examples/tests/output/input.out new file mode 100644 index 00000000..79627b1d --- /dev/null +++ b/samples/distro-examples/tests/output/input.out @@ -0,0 +1 @@ +1.11111111111111E+74 diff --git a/samples/distro-examples/tests/output/keymap.out b/samples/distro-examples/tests/output/keymap.out new file mode 100644 index 00000000..19f86f49 --- /dev/null +++ b/samples/distro-examples/tests/output/keymap.out @@ -0,0 +1 @@ +done diff --git a/src/common/blib.c b/src/common/blib.c index cd2b8d85..3d68c906 100644 --- a/src/common/blib.c +++ b/src/common/blib.c @@ -751,7 +751,7 @@ void cmd_input(int input) { inps = malloc(SB_TEXTLINE_SIZE + 1); if (prompt.v.p.ptr) { // prime output buffer with prompt text - int prompt_len = strlen(prompt.v.p.ptr); + int prompt_len = v_strlen(&prompt); int len = prompt_len < SB_TEXTLINE_SIZE ? prompt_len : SB_TEXTLINE_SIZE; strncpy(inps, prompt.v.p.ptr, len); inps[len] = 0; diff --git a/src/common/units.c b/src/common/units.c index 87e18f1b..ab21b655 100644 --- a/src/common/units.c +++ b/src/common/units.c @@ -218,18 +218,15 @@ int close_unit(int uid) { * @return 0 on success */ int import_unit(int uid) { - char buf[SB_KEYWORD_SIZE + 1];int i; - if (uid >= 0) { unit_t *u = &units[uid]; if (u->status == unit_loaded) { - for (i = 0; i < u->hdr.sym_count; i++) { - // build the name - // with any path component removed from the name + for (int i = 0; i < u->hdr.sym_count; i++) { + // build the name with any path component removed from the name + char buf[SB_KEYWORD_SIZE + SB_KEYWORD_SIZE + 1]; char *dir_sep = strrchr(u->hdr.base, OS_DIRSEP); sprintf(buf, "%s.%s", - dir_sep ? dir_sep + 1 : u->hdr.base, u->symbols[i].symbol); - + dir_sep ? dir_sep + 1 : u->hdr.base, u->symbols[i].symbol); switch (u->symbols[i].type) { case stt_function: comp_add_external_func(buf, uid | UID_UNIT_BIT); @@ -242,12 +239,10 @@ int import_unit(int uid) { break; }; } - } - else { + } else { return -2; } - } - else { + } else { return -1; } diff --git a/src/common/var.c b/src/common/var.c index 2dfad5ac..aa9983c6 100644 --- a/src/common/var.c +++ b/src/common/var.c @@ -767,15 +767,15 @@ void v_zerostr(var_t *r) { void v_input2var(const char *str, var_t *var) { v_free(var); - if (strlen(str) == 0) { + if (!str || str[0] == '\0') { // no data v_setstr(var, str); } else { - char buf[INT_STR_LEN]; int type; var_int_t lv; var_num_t dv; + char *buf = strdup(str); char *sb = strdup(str); char *np = get_numexpr(sb, buf, &type, &lv, &dv); @@ -787,6 +787,7 @@ void v_input2var(const char *str, var_t *var) { v_setstr(var, str); } free(sb); + free(buf); } } diff --git a/src/platform/console/Makefile.am b/src/platform/console/Makefile.am index 0f44b05f..b18c7530 100644 --- a/src/platform/console/Makefile.am +++ b/src/platform/console/Makefile.am @@ -27,7 +27,7 @@ sbasic_DEPENDENCIES = $(top_srcdir)/src/common/libsb_common.a TEST_DIR=../../../samples/distro-examples/tests UNIT_TESTS=array break byref eval-test iifs matrices metaa ongoto \ uds hash pass1 call_tau short-circuit strings stack-test \ - replace-test read-data proc optchk letbug ptr ref \ + replace-test read-data proc optchk letbug ptr ref input \ trycatch chain stream-files split-join sprint all scope goto keymap test: ${bin_PROGRAMS} From 22de0b979c92bee2f6e1ca96778414ca7d3c127e Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Mon, 4 May 2020 12:09:25 +1000 Subject: [PATCH 07/36] COMMON: INPUT crash #99 --- samples/distro-examples/tests/input.bas | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 samples/distro-examples/tests/input.bas diff --git a/samples/distro-examples/tests/input.bas b/samples/distro-examples/tests/input.bas new file mode 100644 index 00000000..a467bdd5 --- /dev/null +++ b/samples/distro-examples/tests/input.bas @@ -0,0 +1,3 @@ +v = "111111111111111111111111111111111111111111111111111111111111111111111111111" +sinput v; k +print k From dcb1187a5139efc87d2bf71d8d2e95bebde311c5 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Thu, 7 May 2020 08:44:57 +1000 Subject: [PATCH 08/36] COMMON: Fix image.save() to array destination --- ChangeLog | 7 ++-- src/ui/image.cpp | 93 +++++++++++++++++++++++++----------------------- 2 files changed, 54 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index e1e6229c..e9f06d6c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ +2020-05-07 (0.12.19) + COMMON: Fix image.save() to array destination + 2020-05-04 (0.12.19) - INPUT crash #99 - Fix compile warning with updated gcc + COMMON: INPUT crash #99 + COMMON: Fix compile warning with updated gcc 2020-03-07 (0.12.19) COMMON: implement DEFINEKEY undo #92 diff --git a/src/ui/image.cpp b/src/ui/image.cpp index 3b36f0e0..d1d5ec95 100644 --- a/src/ui/image.cpp +++ b/src/ui/image.cpp @@ -38,8 +38,8 @@ void reset_image_cache() { ImageBuffer::ImageBuffer() : _bid(0), - _filename(NULL), - _image(NULL), + _filename(nullptr), + _image(nullptr), _width(0), _height(0) { } @@ -55,8 +55,8 @@ ImageBuffer::ImageBuffer(ImageBuffer &o) : ImageBuffer::~ImageBuffer() { free(_filename); free(_image); - _filename = NULL; - _image = NULL; + _filename = nullptr; + _image = nullptr; } ImageDisplay::ImageDisplay() : Shape(0, 0, 0, 0), @@ -66,7 +66,7 @@ ImageDisplay::ImageDisplay() : Shape(0, 0, 0, 0), _opacity(0), _id(0), _bid(0), - _buffer(NULL) { + _buffer(nullptr) { } ImageDisplay::ImageDisplay(ImageDisplay &o) : Shape(o._x, o._y, o._width, o._height) { @@ -102,7 +102,7 @@ void ImageDisplay::draw(int x, int y, int w, int h, int cw) { } dev_file_t *eval_filep() { - dev_file_t *result = NULL; + dev_file_t *result = nullptr; code_skipnext(); if (code_getnext() == '#') { int handle = par_getint(); @@ -121,7 +121,7 @@ uint8_t *get_image_data(int x, int y, int w, int h) { rc.height = h; int size = w * h * 4; uint8_t *result = (uint8_t *)malloc(size); - if (result != NULL) { + if (result != nullptr) { g_system->getOutput()->redraw(); maGetImageData(HANDLE_SCREEN, result, &rc, w * 4); } @@ -133,7 +133,7 @@ ImageBuffer *load_image(var_int_t x) { int count = par_massget("iii", &y, &w, &h); int width = g_system->getOutput()->getWidth(); int height = g_system->getOutput()->getHeight(); - ImageBuffer *result = NULL; + ImageBuffer *result = nullptr; if (prog_error || count == 0 || count == 2) { err_throw(ERR_PARAM); @@ -146,14 +146,14 @@ ImageBuffer *load_image(var_int_t x) { h = MIN(h, height); } uint8_t* image = get_image_data(x, y, w, h); - if (image == NULL) { + if (image == nullptr) { err_throw(ERR_IMAGE_LOAD, "Failed to load screen image"); } else { result = new ImageBuffer(); result->_bid = ++nextId; result->_width = w; result->_height = h; - result->_filename = NULL; + result->_filename = nullptr; result->_image = image; cache.add(result); } @@ -163,7 +163,7 @@ ImageBuffer *load_image(var_int_t x) { // share image buffer from another image variable ImageBuffer *load_image(var_t *var) { - ImageBuffer *result = NULL; + ImageBuffer *result = nullptr; if (var->type == V_MAP) { int bid = map_get_int(var, IMG_BID, -1); if (bid != -1) { @@ -199,7 +199,7 @@ ImageBuffer *load_image(var_t *var) { result->_bid = ++nextId; result->_width = w; result->_height = h; - result->_filename = NULL; + result->_filename = nullptr; result->_image = image; cache.add(result); } @@ -207,7 +207,7 @@ ImageBuffer *load_image(var_t *var) { } ImageBuffer *load_image(const unsigned char* buffer, int32_t size) { - ImageBuffer *result = NULL; + ImageBuffer *result = nullptr; unsigned w, h; unsigned char *image; unsigned error = 0; @@ -218,7 +218,7 @@ ImageBuffer *load_image(const unsigned char* buffer, int32_t size) { result->_bid = ++nextId; result->_width = w; result->_height = h; - result->_filename = NULL; + result->_filename = nullptr; result->_image = image; cache.add(result); } else { @@ -228,16 +228,16 @@ ImageBuffer *load_image(const unsigned char* buffer, int32_t size) { } ImageBuffer *load_image(dev_file_t *filep) { - ImageBuffer *result = NULL; + ImageBuffer *result = nullptr; List_each(ImageBuffer *, it, cache) { ImageBuffer *next = (*it); - if (next->_filename != NULL && strcmp(next->_filename, filep->name) == 0) { + if (next->_filename != nullptr && strcmp(next->_filename, filep->name) == 0) { result = next; break; } } - if (result == NULL) { + if (result == nullptr) { unsigned w, h; unsigned char *image; unsigned error = 0; @@ -286,13 +286,13 @@ ImageBuffer *load_xpm_image(char **data) { unsigned w, h; unsigned char *image; unsigned error = xpm_decode32(&image, &w, &h, data); - ImageBuffer *result = NULL; + ImageBuffer *result = nullptr; if (!error) { result = new ImageBuffer(); result->_bid = ++nextId; result->_width = w; result->_height = h; - result->_filename = NULL; + result->_filename = nullptr; result->_image = image; cache.add(result); } else { @@ -316,7 +316,7 @@ void cmd_image_show(var_s *self) { var_int_t x, y, z, op; int count = par_massget("iiii", &x, &y, &z, &op); - if (prog_error || image._buffer == NULL || count == 1 || count > 4) { + if (prog_error || image._buffer == nullptr || count == 1 || count > 4) { err_throw(ERR_PARAM); } else { // 0, 2, 3, 4 arguments accepted @@ -358,7 +358,7 @@ void cmd_image_hide(var_s *self) { void cmd_image_save(var_s *self) { unsigned id = map_get_int(self, IMG_BID, -1); - ImageBuffer *image = NULL; + ImageBuffer *image = nullptr; List_each(ImageBuffer *, it, cache) { ImageBuffer *next = (*it); if (next->_bid == id) { @@ -367,8 +367,8 @@ void cmd_image_save(var_s *self) { } } - var_t *array = NULL; - dev_file_t *filep = NULL; + var_t *array = nullptr; + dev_file_t *filep = nullptr; byte code = code_peek(); switch (code) { case kwTYPE_SEP: @@ -380,15 +380,19 @@ void cmd_image_save(var_s *self) { } bool saved = false; - if (!prog_error && image != NULL) { + if (!prog_error && image != nullptr) { int w = image->_width; int h = image->_height; - if (filep != NULL && filep->open_flags == DEV_FILE_OUTPUT) { + if (filep != nullptr && filep->open_flags == DEV_FILE_OUTPUT) { if (!lodepng_encode32_file(filep->name, image->_image, w, h)) { saved = true; } - } else if (array != NULL) { - v_tomatrix(array, h, w); + } else if (array != nullptr) { + v_tomatrix(array, w, h); + // x0 x1 x2 (w=3,h=2) + // y0 rgba rgba rgba ypos=0 + // y1 rgba rgba rgba ypos=12 + // for (int y = 0; y < h; y++) { int yoffs = (4 * y * w); for (int x = 0; x < w; x++) { @@ -430,13 +434,13 @@ void create_image(var_p_t var, ImageBuffer *image) { // loads an image for the form image input type ImageDisplay *create_display_image(var_p_t var, const char *name) { - ImageDisplay *result = NULL; - if (name != NULL && var != NULL) { + ImageDisplay *result = nullptr; + if (name != nullptr && var != nullptr) { dev_file_t file; strlcpy(file.name, name, sizeof(file.name)); file.type = ft_stream; ImageBuffer *buffer = load_image(&file); - if (buffer != NULL) { + if (buffer != nullptr) { result = new ImageDisplay(); result->_buffer = buffer; result->_bid = buffer->_bid; @@ -468,22 +472,23 @@ ImageDisplay *create_display_image(var_p_t var, const char *name) { void screen_dump() { int width = g_system->getOutput()->getWidth(); int height = g_system->getOutput()->getHeight(); - uint8_t* image = get_image_data(0, 0, width, height); - if (image != NULL) { + auto image = get_image_data(0, 0, width, height); + if (image != nullptr) { const char *path = gsb_bas_dir; #if defined(_ANDROID) path = getenv("EXTERNAL_STORAGE"); #endif for (int i = 0; i < 1000; i++) { - char file[OS_PATHNAME_SIZE]; - if (strstr(path, "://") != NULL) { - sprintf(file, "sbasic_dump_%d.png", i); - } else { - sprintf(file, "%ssbasic_dump_%d.png", path, i); + String file; + if (strstr(path, "://") == nullptr) { + file.append(path); } - if (access(file, R_OK) != 0) { - g_system->systemPrint("Saving screen to %s\n", file); - unsigned error = lodepng_encode32_file(file, image, width, height); + file.append("sbasic_dump_"); + file.append(i); + file.append(".png"); + if (access(file.c_str(), R_OK) != 0) { + g_system->systemPrint("Saving screen to %s\n", file.c_str()); + unsigned error = lodepng_encode32_file(file.c_str(), image, width, height); if (error) { g_system->systemPrint("Error: %s\n", lodepng_error_text(error)); } @@ -496,14 +501,14 @@ void screen_dump() { extern "C" void v_create_image(var_p_t var) { var_t arg; - ImageBuffer *image = NULL; - dev_file_t *filep = NULL; + ImageBuffer *image = nullptr; + dev_file_t *filep = nullptr; byte code = code_peek(); switch (code) { case kwTYPE_SEP: filep = eval_filep(); - if (filep != NULL) { + if (filep != nullptr) { image = load_image(filep); } break; @@ -551,7 +556,7 @@ extern "C" void v_create_image(var_p_t var) { break; }; - if (image != NULL) { + if (image != nullptr) { create_image(var, image); } else { err_throw(ERR_BAD_FILE_HANDLE); From 0cc6fdf9422263b084d59ccc3e978e227fad0a17 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Thu, 7 May 2020 18:35:02 +1000 Subject: [PATCH 09/36] UI: fix compile error with newer gcc --- src/ui/system.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ui/system.cpp b/src/ui/system.cpp index 9cbe441a..66fb6677 100644 --- a/src/ui/system.cpp +++ b/src/ui/system.cpp @@ -618,12 +618,12 @@ char *System::readSource(const char *fileName) { } if (buffer != nullptr) { delete [] _programSrc; - int len = strlen(buffer); - _programSrc = new char[len + 1]; - strncpy(_programSrc, buffer, len); - _programSrc[len] = '\0'; + int len = strlen(buffer) + 1; + _programSrc = new char[len]; + memcpy(_programSrc, buffer, len); + _programSrc[len - 1] = '\0'; _srcRendered = false; - systemPrint("Opened: %s %d bytes\n", fileName, len); + systemPrint("Opened: %s %d bytes\n", fileName, len - 1); } return buffer; } From 6bdec13c494ccdb9ddec98be7e223647bac82411 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Sat, 28 Mar 2020 13:52:16 +1000 Subject: [PATCH 10/36] AUDIO: #90 use latest miniaudio api --- ChangeLog | 3 ++ configure.ac | 2 +- debian/changelog | 5 +++ src/lib/miniaudio | 2 +- src/platform/sdl/runtime.cpp | 1 - src/ui/audio.cpp | 77 +++++++++++++++++++----------------- 6 files changed, 51 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index acf1aaf7..3a880376 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2020-02-13 (0.12.19) + AUDIO: fix integration with latest version of miniaudio library + 2020-02-13 (0.12.18) Fix path for HOME constant diff --git a/configure.ac b/configure.ac index ea0dd25e..78da8356 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ dnl This program is distributed under the terms of the GPL v2.0 dnl Download the GNU Public License (GPL) from www.gnu.org dnl -AC_INIT([smallbasic], [0.12.18]) +AC_INIT([smallbasic], [0.12.19]) AC_CONFIG_SRCDIR([configure.ac]) AC_CANONICAL_TARGET diff --git a/debian/changelog b/debian/changelog index c3cd6ba9..26518299 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,8 @@ +smallbasic (0.12.19) unstable; urgency=low + * Various see web site + + -- Chris Warren-Smith Sun, 22 Mar 2020 09:45:25 +1000 + smallbasic (0.12.18) unstable; urgency=low * Various see web site diff --git a/src/lib/miniaudio b/src/lib/miniaudio index df2903a0..4b45e1ef 160000 --- a/src/lib/miniaudio +++ b/src/lib/miniaudio @@ -1 +1 @@ -Subproject commit df2903a0bcaf0126f9ad43d2b1238891b55bc2f6 +Subproject commit 4b45e1ef1bdc43c24e650118dac79fbf36003bfd diff --git a/src/platform/sdl/runtime.cpp b/src/platform/sdl/runtime.cpp index fc882e6e..05418cda 100644 --- a/src/platform/sdl/runtime.cpp +++ b/src/platform/sdl/runtime.cpp @@ -298,7 +298,6 @@ int Runtime::runShell(const char *startupBas, bool runWait, int fontScale, int d _output->setFontSize(fontSize); } - audio_open(); net_init(); diff --git a/src/ui/audio.cpp b/src/ui/audio.cpp index a21f1b38..efe38b58 100644 --- a/src/ui/audio.cpp +++ b/src/ui/audio.cpp @@ -1,6 +1,6 @@ // This file is part of SmallBASIC // -// Copyright(C) 2001-2019 Chris Warren-Smith. +// Copyright(C) 2001-2020 Chris Warren-Smith. // // This program is distributed under the terms of the GPL v2.0 or later // Download the GNU Public License (GPL) from www.gnu.org @@ -32,7 +32,7 @@ struct Sound; static ma_device device; static ma_device_config config; static strlib::Queue queue; -static strlib::Properties cache; +static int queuePos = 0; struct Sound { Sound(int frequency, int millis, int volume); @@ -41,7 +41,7 @@ struct Sound { ma_result construct(const char *path); - ma_sine_wave *_tone; + ma_waveform *_tone; ma_decoder *_decoder; uint32_t _start; uint32_t _duration; @@ -59,8 +59,11 @@ Sound::Sound(int frequency, int millis, int volume) : _decoder(nullptr), _start(0), _duration(millis) { - _tone = (ma_sine_wave *)malloc(sizeof(ma_sine_wave)); - ma_sine_wave_init(volume / 100.0, frequency, DEFAULT_SAMPLE_RATE, _tone); + _tone = (ma_waveform *)malloc(sizeof(ma_waveform)); + ma_waveform_config config = + ma_waveform_config_init(DEFAULT_FORMAT, DEFAULT_CHANNELS, DEFAULT_SAMPLE_RATE, + ma_waveform_type_sine, volume / 100.0, frequency); + ma_waveform_init(&config, _tone); } Sound::~Sound() { @@ -82,20 +85,25 @@ static void data_callback(ma_device *device, void *output, const void *input, ma if (queue.empty()) { usleep(MILLIS_TO_MICROS(10)); } else { - Sound *sound = queue.front(); + queuePos = (queuePos + 1) % queue.size(); + Sound *sound = queue[queuePos]; if (sound->_decoder != nullptr) { // play audio track - ma_decoder_read_pcm_frames(sound->_decoder, output, frameCount); + ma_uint64 framesRead = ma_decoder_read_pcm_frames(sound->_decoder, output, frameCount); + if (framesRead == 0) { + // finished playing + queue.pop(false); + } } else if (sound->_start == 0) { // start new sound sound->_start = dev_get_millisecond_count(); - ma_sine_wave_read_f32(sound->_tone, frameCount, (float*)output); + ma_waveform_read_pcm_frames(sound->_tone, (float *)output, frameCount); } else if (dev_get_millisecond_count() - sound->_start > sound->_duration) { // sound has timed out - queue.pop(sound->_decoder == nullptr); + queue.pop(false); } else { // continue sound - ma_sine_wave_read_f32(sound->_tone, frameCount, (float*)output); + ma_waveform_read_pcm_frames(sound->_tone, (float *)output, frameCount); } } } @@ -122,8 +130,18 @@ static void setup_format(ma_format format, ma_uint32 channels, ma_uint32 sampleR } } +static void device_start() { + if (ma_device__get_state(&device) != MA_STATE_STARTED) { + ma_result result = ma_device_start(&device); + if (result != MA_SUCCESS) { + err_throw("Failed to start audio [%d]", result); + } + } +} + bool audio_open() { setup_config(DEFAULT_FORMAT, DEFAULT_CHANNELS, DEFAULT_SAMPLE_RATE); + queuePos = 0; return (ma_device_init(nullptr, &config, &device) == MA_SUCCESS); } @@ -133,32 +151,19 @@ void audio_close() { } void osd_audio(const char *path) { - Sound *sound = cache.get(path); - if (sound) { + Sound *sound = new Sound(); + ma_result result = sound->construct(path); + if (result != MA_SUCCESS) { + delete sound; + err_throw("Failed to open sound file [%d]", result); + } else { + setup_format(sound->_decoder->outputFormat, + sound->_decoder->outputChannels, + sound->_decoder->outputSampleRate); ma_mutex_lock(&device.lock); queue.push(sound); ma_mutex_unlock(&device.lock); - } else { - sound = new Sound(); - ma_result result = sound->construct(path); - if (result != MA_SUCCESS) { - delete sound; - err_throw("Failed to open sound file [%d]", result); - } else { - setup_format(sound->_decoder->outputFormat, - sound->_decoder->outputChannels, - sound->_decoder->outputSampleRate); - ma_mutex_lock(&device.lock); - queue.push(sound); - cache.put(path, sound); - ma_mutex_unlock(&device.lock); - if (queue.size() == 1) { - result = ma_device_start(&device); - if (result != MA_SUCCESS) { - err_throw("Failed to start audio [%d]", result); - } - } - } + device_start(); } } @@ -180,7 +185,7 @@ void osd_clear_sound_queue() { } queue.removeAll(); - cache.removeAll(); + queuePos = 0; } void osd_sound(int frequency, int millis, int volume, int background) { @@ -190,13 +195,13 @@ void osd_sound(int frequency, int millis, int volume, int background) { ma_mutex_unlock(&device.lock); if (!background) { - ma_device_start(&device); + device_start(); usleep(MILLIS_TO_MICROS(millis)); ma_device_stop(&device); ma_mutex_lock(&device.lock); queue.pop(); ma_mutex_unlock(&device.lock); } else if (queue.size() == 1) { - ma_device_start(&device); + device_start(); } } From 2b3accb1734b90ae7460aca4908835c59d707b25 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Tue, 7 Apr 2020 07:08:22 +1000 Subject: [PATCH 11/36] COMMON: implement DEFINEKEY undo #92 --- samples/distro-examples/tests/keymap.bas | 34 ++++++++++++++++++ src/common/blib.c | 14 +++++--- src/common/keymap.c | 46 ++++++++++++++++++++---- src/common/keymap.h | 1 + src/platform/console/Makefile.am | 2 +- 5 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 samples/distro-examples/tests/keymap.bas diff --git a/samples/distro-examples/tests/keymap.bas b/samples/distro-examples/tests/keymap.bas new file mode 100644 index 00000000..603f7fb5 --- /dev/null +++ b/samples/distro-examples/tests/keymap.bas @@ -0,0 +1,34 @@ +sub foo + ? "f" +end + +definekey 2, foo +definekey 1, foo +definekey 1, foo +definekey 1, foo +definekey 1, 1 +definekey 1, 2 +definekey 1, 3 +definekey 1, 2 +definekey 1, 3 +definekey 2, 0 +definekey 2, 0 +definekey 2, 0 +definekey 2, 0 + +definekey asc("x"), foo +definekey asc("x"), foo +definekey asc("y"), foo +definekey asc("z"), foo +definekey asc("f"), foo +definekey asc("x"), 0 +definekey asc("y"), 0 +definekey asc("z"), 0 + +if (instr(sbver, "SDL") <> 0) then + while 1 + ? "."; + delay 10 + wend +endif + diff --git a/src/common/blib.c b/src/common/blib.c index 2825205b..cd2b8d85 100644 --- a/src/common/blib.c +++ b/src/common/blib.c @@ -2835,14 +2835,20 @@ void cmd_definekey(void) { if (!prog_error) { par_getcomma(); - - if (code_peek() != kwTYPE_CALL_UDF) { - err_syntax(kwDEFINEKEY, "%I,%G"); - } else { + switch (code_peek()) { + case kwTYPE_INT: + prog_ip++; + keymap_remove(key, code_getint()); + break; + case kwTYPE_CALL_UDF: keymap_add(key, prog_ip); // skip ahead to avoid immediate call prog_ip += BC_CTRLSZ + 1; + break; + default: + err_syntax(kwDEFINEKEY, "%I,%G"); + break; } } v_free(&var); diff --git a/src/common/keymap.c b/src/common/keymap.c index 351175bb..4edb178f 100644 --- a/src/common/keymap.c +++ b/src/common/keymap.c @@ -30,7 +30,7 @@ struct key_map_s { int key; // key definition }; -key_map_s* keymap = 0; +key_map_s *keymap = 0; /** * Prepare task_t exec.keymap for keymap handling at program init @@ -42,7 +42,7 @@ void keymap_init() { /** * Handler for keymap_free() */ -void keymap_delete(key_map_s* km) { +void keymap_delete(key_map_s *km) { if (km) { keymap_delete(km->next); free(km); @@ -61,13 +61,13 @@ void keymap_free() { * DEFINEKEY command handler to add a keymap */ void keymap_add(uint32_t key, bcip_t ip) { - key_map_s* km = (key_map_s*) malloc(sizeof (key_map_s)); + key_map_s *km = (key_map_s *)malloc(sizeof(key_map_s)); km->next = 0; km->ip = ip; km->key = key; // add the new mapping onto the linked list - key_map_s* head = keymap; + key_map_s *head = keymap; if (!head) { keymap = km; } else { @@ -78,12 +78,44 @@ void keymap_add(uint32_t key, bcip_t ip) { } } +/** + * DEFINEKEY key, 0 + */ +void keymap_remove(uint32_t key, int level) { + key_map_s *head = keymap; + key_map_s *prev = head; + int size = 0; + + while (head) { + if (head->key == key) { + key_map_s *current = head; + prev->next = head->next; + head = head->next; + free(current); + if (current == prev) { + prev = head; + } + if (current == keymap) { + keymap = head; + } + } else { + prev = head; + head = head->next; + size++; + } + } + if (!size) { + keymap = 0; + } +} + + /** * invokes the handler for the given key */ int keymap_invoke(uint32_t key) { int result = 0; - key_map_s* head = keymap; + key_map_s *head = keymap; while (head) { if (head->key == key) { bcip_t ip = prog_ip; // store current ip @@ -175,7 +207,7 @@ void timer_free(timer_s *timer) { } void timer_add(var_num_t interval, bcip_t ip) { - timer_s* timer = (timer_s*) malloc(sizeof (timer_s)); + timer_s *timer = (timer_s *)malloc(sizeof (timer_s)); timer->next = NULL; timer->ip = ip; timer->interval = interval; @@ -195,7 +227,7 @@ void timer_add(var_num_t interval, bcip_t ip) { } void timer_run(uint32_t now) { - timer_s* timer = prog_timer; + timer_s *timer = prog_timer; while (timer) { if (timer->value == 0) { // start timer diff --git a/src/common/keymap.h b/src/common/keymap.h index e8d50d71..8b7c070a 100644 --- a/src/common/keymap.h +++ b/src/common/keymap.h @@ -87,6 +87,7 @@ extern "C" { void keymap_init(); void keymap_free(); void keymap_add(uint32_t key, bcip_t ip); +void keymap_remove(uint32_t key, int level); int keymap_invoke(uint32_t key); int keymap_kbhit(); int keymap_kbpeek(); diff --git a/src/platform/console/Makefile.am b/src/platform/console/Makefile.am index 0e26bd8a..0f44b05f 100644 --- a/src/platform/console/Makefile.am +++ b/src/platform/console/Makefile.am @@ -28,7 +28,7 @@ TEST_DIR=../../../samples/distro-examples/tests UNIT_TESTS=array break byref eval-test iifs matrices metaa ongoto \ uds hash pass1 call_tau short-circuit strings stack-test \ replace-test read-data proc optchk letbug ptr ref \ - trycatch chain stream-files split-join sprint all scope goto + trycatch chain stream-files split-join sprint all scope goto keymap test: ${bin_PROGRAMS} @for utest in $(UNIT_TESTS); do \ From 00589d459f60a11cb25df26aed73375160f6885c Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Tue, 7 Apr 2020 07:10:00 +1000 Subject: [PATCH 12/36] UI: added R157 colour theme #94 --- ChangeLog | 3 +++ src/platform/fltk/MainWindow.cxx | 1 + src/ui/textedit.cpp | 8 +++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3a880376..04e87f93 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2020-03-07 (0.12.19) + COMMON: implement DEFINEKEY undo #92 + 2020-02-13 (0.12.19) AUDIO: fix integration with latest version of miniaudio library diff --git a/src/platform/fltk/MainWindow.cxx b/src/platform/fltk/MainWindow.cxx index 8e2f4fc5..bf4bcb18 100644 --- a/src/platform/fltk/MainWindow.cxx +++ b/src/platform/fltk/MainWindow.cxx @@ -974,6 +974,7 @@ MainWindow::MainWindow(int w, int h) : m->add("&View/Theme/&Shian", 0, set_theme_cb, (void *)(intptr_t)2); m->add("&View/Theme/&Atom 1", 0, set_theme_cb, (void *)(intptr_t)3); m->add("&View/Theme/&Atom 2", 0, set_theme_cb, (void *)(intptr_t)4); + m->add("&View/Theme/&R157", 0, set_theme_cb, (void *)(intptr_t)5); m->add("&View/Text Color/_Background", 0, EditorWidget::set_color_cb, (void *)st_background); m->add("&View/Text Color/Text", 0, EditorWidget::set_color_cb, (void *)st_text); m->add("&View/Text Color/Comments", 0, EditorWidget::set_color_cb, (void *)st_comments); diff --git a/src/ui/textedit.cpp b/src/ui/textedit.cpp index ac8c7307..3a1f9df2 100644 --- a/src/ui/textedit.cpp +++ b/src/ui/textedit.cpp @@ -156,6 +156,12 @@ const int atom2[] = { 0x0083f8, 0xff9d00, 0x31ccac, 0xc679dd, 0x0083f8 }; +const int r157[] = { + 0x80dfff, 0xa7aebc, 0xffffff, 0xa7aebc, 0xa7aebc, 0xd0d6e1, + 0x2e3436, 0x888a85, 0x000000, 0x4d483b, 0x000000, 0x576375, + 0xffffff, 0xffc466, 0xffcce0, 0xffff66, 0x0083f8 +}; + int g_user_theme[] = { 0xc8cedb, 0xa7aebc, 0x484f5f, 0xa7aebc, 0xa7aebc, 0x00bb00, 0x2e3436, 0x888a85, 0x000000, 0x4d483b, 0x000000, 0x2b313a, @@ -163,7 +169,7 @@ int g_user_theme[] = { }; const int* themes[] = { - solarized_dark, solarized_light, shian, atom1, atom2, g_user_theme + solarized_dark, solarized_light, shian, atom1, atom2, r157, g_user_theme }; const char *helpText = From ee20a654ceb83d32e1186abd7e42e8a2081ef97c Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Tue, 7 Apr 2020 07:34:14 +1000 Subject: [PATCH 13/36] COMMON: implement DEFINEKEY undo #92 --- src/common/keymap.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/common/keymap.c b/src/common/keymap.c index 4edb178f..ed4b7c72 100644 --- a/src/common/keymap.c +++ b/src/common/keymap.c @@ -84,7 +84,6 @@ void keymap_add(uint32_t key, bcip_t ip) { void keymap_remove(uint32_t key, int level) { key_map_s *head = keymap; key_map_s *prev = head; - int size = 0; while (head) { if (head->key == key) { @@ -101,15 +100,10 @@ void keymap_remove(uint32_t key, int level) { } else { prev = head; head = head->next; - size++; } } - if (!size) { - keymap = 0; - } } - /** * invokes the handler for the given key */ From 57544893b7bc49514ba7db1619f43c54039fefcb Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Fri, 24 Apr 2020 06:49:32 +1000 Subject: [PATCH 14/36] BUILD: use pkg-config to check freetype --- ChangeLog | 1 + configure.ac | 7 +++++++ src/platform/android/build.gradle | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 04e87f93..ded20268 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2020-03-07 (0.12.19) COMMON: implement DEFINEKEY undo #92 + UI: added R157 colour theme #94 2020-02-13 (0.12.19) AUDIO: fix integration with latest version of miniaudio library diff --git a/configure.ac b/configure.ac index 78da8356..586068a3 100644 --- a/configure.ac +++ b/configure.ac @@ -441,6 +441,13 @@ echo ${TARGET} echo "CFLAGS=${CFLAGS}" echo "CXXFLAGS=${CXXFLAGS}" echo "PACKAGE_LIBS=${PACKAGE_LIBS}" + +if test x$ac_build_sdl = xyes; then + echo + echo "sdl2: `sdl2-config --version`" + echo "freetype: `pkg-config --version freetype2`" +fi + echo if test x$ac_build_dist = xyes; then diff --git a/src/platform/android/build.gradle b/src/platform/android/build.gradle index ae627614..d99c778c 100644 --- a/src/platform/android/build.gradle +++ b/src/platform/android/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.3' + classpath 'com.android.tools.build:gradle:3.6.2' classpath "com.github.ben-manes:gradle-versions-plugin:0.22.0" } } From c7594f581d0fb6a47e63a03ba7fb858d787d7ce6 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Mon, 4 May 2020 12:08:03 +1000 Subject: [PATCH 15/36] COMMON: INPUT crash #99 --- ChangeLog | 4 ++++ configure.ac | 4 ++-- samples/distro-examples/tests/keymap.bas | 1 + samples/distro-examples/tests/output/input.out | 1 + samples/distro-examples/tests/output/keymap.out | 1 + src/common/blib.c | 2 +- src/common/units.c | 17 ++++++----------- src/common/var.c | 5 +++-- src/platform/console/Makefile.am | 2 +- 9 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 samples/distro-examples/tests/output/input.out create mode 100644 samples/distro-examples/tests/output/keymap.out diff --git a/ChangeLog b/ChangeLog index ded20268..e1e6229c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2020-05-04 (0.12.19) + INPUT crash #99 + Fix compile warning with updated gcc + 2020-03-07 (0.12.19) COMMON: implement DEFINEKEY undo #92 UI: added R157 colour theme #94 diff --git a/configure.ac b/configure.ac index 586068a3..3d15ce02 100644 --- a/configure.ac +++ b/configure.ac @@ -74,8 +74,8 @@ function checkDebugMode() { AC_MSG_RESULT([$with_debug]) if test "$with_debug" = "yes" || test "$with_debug" = "full" then - CFLAGS="${CFLAGS} -g -O0" - CXXFLAGS="${CXXFLAGS} -g -O0" + CFLAGS="${CFLAGS} -g -O0 -fstack-protector-all" + CXXFLAGS="${CXXFLAGS} -g -O0 -fstack-protector-all" AC_DEFINE(_DEBUG, 1, [debugging build enabled]) fi AC_SUBST(CFLAGS) diff --git a/samples/distro-examples/tests/keymap.bas b/samples/distro-examples/tests/keymap.bas index 603f7fb5..81d45897 100644 --- a/samples/distro-examples/tests/keymap.bas +++ b/samples/distro-examples/tests/keymap.bas @@ -32,3 +32,4 @@ if (instr(sbver, "SDL") <> 0) then wend endif +print "done" diff --git a/samples/distro-examples/tests/output/input.out b/samples/distro-examples/tests/output/input.out new file mode 100644 index 00000000..79627b1d --- /dev/null +++ b/samples/distro-examples/tests/output/input.out @@ -0,0 +1 @@ +1.11111111111111E+74 diff --git a/samples/distro-examples/tests/output/keymap.out b/samples/distro-examples/tests/output/keymap.out new file mode 100644 index 00000000..19f86f49 --- /dev/null +++ b/samples/distro-examples/tests/output/keymap.out @@ -0,0 +1 @@ +done diff --git a/src/common/blib.c b/src/common/blib.c index cd2b8d85..3d68c906 100644 --- a/src/common/blib.c +++ b/src/common/blib.c @@ -751,7 +751,7 @@ void cmd_input(int input) { inps = malloc(SB_TEXTLINE_SIZE + 1); if (prompt.v.p.ptr) { // prime output buffer with prompt text - int prompt_len = strlen(prompt.v.p.ptr); + int prompt_len = v_strlen(&prompt); int len = prompt_len < SB_TEXTLINE_SIZE ? prompt_len : SB_TEXTLINE_SIZE; strncpy(inps, prompt.v.p.ptr, len); inps[len] = 0; diff --git a/src/common/units.c b/src/common/units.c index 87e18f1b..ab21b655 100644 --- a/src/common/units.c +++ b/src/common/units.c @@ -218,18 +218,15 @@ int close_unit(int uid) { * @return 0 on success */ int import_unit(int uid) { - char buf[SB_KEYWORD_SIZE + 1];int i; - if (uid >= 0) { unit_t *u = &units[uid]; if (u->status == unit_loaded) { - for (i = 0; i < u->hdr.sym_count; i++) { - // build the name - // with any path component removed from the name + for (int i = 0; i < u->hdr.sym_count; i++) { + // build the name with any path component removed from the name + char buf[SB_KEYWORD_SIZE + SB_KEYWORD_SIZE + 1]; char *dir_sep = strrchr(u->hdr.base, OS_DIRSEP); sprintf(buf, "%s.%s", - dir_sep ? dir_sep + 1 : u->hdr.base, u->symbols[i].symbol); - + dir_sep ? dir_sep + 1 : u->hdr.base, u->symbols[i].symbol); switch (u->symbols[i].type) { case stt_function: comp_add_external_func(buf, uid | UID_UNIT_BIT); @@ -242,12 +239,10 @@ int import_unit(int uid) { break; }; } - } - else { + } else { return -2; } - } - else { + } else { return -1; } diff --git a/src/common/var.c b/src/common/var.c index 2dfad5ac..aa9983c6 100644 --- a/src/common/var.c +++ b/src/common/var.c @@ -767,15 +767,15 @@ void v_zerostr(var_t *r) { void v_input2var(const char *str, var_t *var) { v_free(var); - if (strlen(str) == 0) { + if (!str || str[0] == '\0') { // no data v_setstr(var, str); } else { - char buf[INT_STR_LEN]; int type; var_int_t lv; var_num_t dv; + char *buf = strdup(str); char *sb = strdup(str); char *np = get_numexpr(sb, buf, &type, &lv, &dv); @@ -787,6 +787,7 @@ void v_input2var(const char *str, var_t *var) { v_setstr(var, str); } free(sb); + free(buf); } } diff --git a/src/platform/console/Makefile.am b/src/platform/console/Makefile.am index 0f44b05f..b18c7530 100644 --- a/src/platform/console/Makefile.am +++ b/src/platform/console/Makefile.am @@ -27,7 +27,7 @@ sbasic_DEPENDENCIES = $(top_srcdir)/src/common/libsb_common.a TEST_DIR=../../../samples/distro-examples/tests UNIT_TESTS=array break byref eval-test iifs matrices metaa ongoto \ uds hash pass1 call_tau short-circuit strings stack-test \ - replace-test read-data proc optchk letbug ptr ref \ + replace-test read-data proc optchk letbug ptr ref input \ trycatch chain stream-files split-join sprint all scope goto keymap test: ${bin_PROGRAMS} From de85a6e2ae573185edd36338b15ba29fae1a99b3 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Mon, 4 May 2020 12:09:25 +1000 Subject: [PATCH 16/36] COMMON: INPUT crash #99 --- samples/distro-examples/tests/input.bas | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 samples/distro-examples/tests/input.bas diff --git a/samples/distro-examples/tests/input.bas b/samples/distro-examples/tests/input.bas new file mode 100644 index 00000000..a467bdd5 --- /dev/null +++ b/samples/distro-examples/tests/input.bas @@ -0,0 +1,3 @@ +v = "111111111111111111111111111111111111111111111111111111111111111111111111111" +sinput v; k +print k From 6b62fe38bb87e519f405741dc5ea81c9c0d55276 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Thu, 7 May 2020 08:44:57 +1000 Subject: [PATCH 17/36] COMMON: Fix image.save() to array destination --- ChangeLog | 7 ++-- src/ui/image.cpp | 93 +++++++++++++++++++++++++----------------------- 2 files changed, 54 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index e1e6229c..e9f06d6c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ +2020-05-07 (0.12.19) + COMMON: Fix image.save() to array destination + 2020-05-04 (0.12.19) - INPUT crash #99 - Fix compile warning with updated gcc + COMMON: INPUT crash #99 + COMMON: Fix compile warning with updated gcc 2020-03-07 (0.12.19) COMMON: implement DEFINEKEY undo #92 diff --git a/src/ui/image.cpp b/src/ui/image.cpp index 3b36f0e0..d1d5ec95 100644 --- a/src/ui/image.cpp +++ b/src/ui/image.cpp @@ -38,8 +38,8 @@ void reset_image_cache() { ImageBuffer::ImageBuffer() : _bid(0), - _filename(NULL), - _image(NULL), + _filename(nullptr), + _image(nullptr), _width(0), _height(0) { } @@ -55,8 +55,8 @@ ImageBuffer::ImageBuffer(ImageBuffer &o) : ImageBuffer::~ImageBuffer() { free(_filename); free(_image); - _filename = NULL; - _image = NULL; + _filename = nullptr; + _image = nullptr; } ImageDisplay::ImageDisplay() : Shape(0, 0, 0, 0), @@ -66,7 +66,7 @@ ImageDisplay::ImageDisplay() : Shape(0, 0, 0, 0), _opacity(0), _id(0), _bid(0), - _buffer(NULL) { + _buffer(nullptr) { } ImageDisplay::ImageDisplay(ImageDisplay &o) : Shape(o._x, o._y, o._width, o._height) { @@ -102,7 +102,7 @@ void ImageDisplay::draw(int x, int y, int w, int h, int cw) { } dev_file_t *eval_filep() { - dev_file_t *result = NULL; + dev_file_t *result = nullptr; code_skipnext(); if (code_getnext() == '#') { int handle = par_getint(); @@ -121,7 +121,7 @@ uint8_t *get_image_data(int x, int y, int w, int h) { rc.height = h; int size = w * h * 4; uint8_t *result = (uint8_t *)malloc(size); - if (result != NULL) { + if (result != nullptr) { g_system->getOutput()->redraw(); maGetImageData(HANDLE_SCREEN, result, &rc, w * 4); } @@ -133,7 +133,7 @@ ImageBuffer *load_image(var_int_t x) { int count = par_massget("iii", &y, &w, &h); int width = g_system->getOutput()->getWidth(); int height = g_system->getOutput()->getHeight(); - ImageBuffer *result = NULL; + ImageBuffer *result = nullptr; if (prog_error || count == 0 || count == 2) { err_throw(ERR_PARAM); @@ -146,14 +146,14 @@ ImageBuffer *load_image(var_int_t x) { h = MIN(h, height); } uint8_t* image = get_image_data(x, y, w, h); - if (image == NULL) { + if (image == nullptr) { err_throw(ERR_IMAGE_LOAD, "Failed to load screen image"); } else { result = new ImageBuffer(); result->_bid = ++nextId; result->_width = w; result->_height = h; - result->_filename = NULL; + result->_filename = nullptr; result->_image = image; cache.add(result); } @@ -163,7 +163,7 @@ ImageBuffer *load_image(var_int_t x) { // share image buffer from another image variable ImageBuffer *load_image(var_t *var) { - ImageBuffer *result = NULL; + ImageBuffer *result = nullptr; if (var->type == V_MAP) { int bid = map_get_int(var, IMG_BID, -1); if (bid != -1) { @@ -199,7 +199,7 @@ ImageBuffer *load_image(var_t *var) { result->_bid = ++nextId; result->_width = w; result->_height = h; - result->_filename = NULL; + result->_filename = nullptr; result->_image = image; cache.add(result); } @@ -207,7 +207,7 @@ ImageBuffer *load_image(var_t *var) { } ImageBuffer *load_image(const unsigned char* buffer, int32_t size) { - ImageBuffer *result = NULL; + ImageBuffer *result = nullptr; unsigned w, h; unsigned char *image; unsigned error = 0; @@ -218,7 +218,7 @@ ImageBuffer *load_image(const unsigned char* buffer, int32_t size) { result->_bid = ++nextId; result->_width = w; result->_height = h; - result->_filename = NULL; + result->_filename = nullptr; result->_image = image; cache.add(result); } else { @@ -228,16 +228,16 @@ ImageBuffer *load_image(const unsigned char* buffer, int32_t size) { } ImageBuffer *load_image(dev_file_t *filep) { - ImageBuffer *result = NULL; + ImageBuffer *result = nullptr; List_each(ImageBuffer *, it, cache) { ImageBuffer *next = (*it); - if (next->_filename != NULL && strcmp(next->_filename, filep->name) == 0) { + if (next->_filename != nullptr && strcmp(next->_filename, filep->name) == 0) { result = next; break; } } - if (result == NULL) { + if (result == nullptr) { unsigned w, h; unsigned char *image; unsigned error = 0; @@ -286,13 +286,13 @@ ImageBuffer *load_xpm_image(char **data) { unsigned w, h; unsigned char *image; unsigned error = xpm_decode32(&image, &w, &h, data); - ImageBuffer *result = NULL; + ImageBuffer *result = nullptr; if (!error) { result = new ImageBuffer(); result->_bid = ++nextId; result->_width = w; result->_height = h; - result->_filename = NULL; + result->_filename = nullptr; result->_image = image; cache.add(result); } else { @@ -316,7 +316,7 @@ void cmd_image_show(var_s *self) { var_int_t x, y, z, op; int count = par_massget("iiii", &x, &y, &z, &op); - if (prog_error || image._buffer == NULL || count == 1 || count > 4) { + if (prog_error || image._buffer == nullptr || count == 1 || count > 4) { err_throw(ERR_PARAM); } else { // 0, 2, 3, 4 arguments accepted @@ -358,7 +358,7 @@ void cmd_image_hide(var_s *self) { void cmd_image_save(var_s *self) { unsigned id = map_get_int(self, IMG_BID, -1); - ImageBuffer *image = NULL; + ImageBuffer *image = nullptr; List_each(ImageBuffer *, it, cache) { ImageBuffer *next = (*it); if (next->_bid == id) { @@ -367,8 +367,8 @@ void cmd_image_save(var_s *self) { } } - var_t *array = NULL; - dev_file_t *filep = NULL; + var_t *array = nullptr; + dev_file_t *filep = nullptr; byte code = code_peek(); switch (code) { case kwTYPE_SEP: @@ -380,15 +380,19 @@ void cmd_image_save(var_s *self) { } bool saved = false; - if (!prog_error && image != NULL) { + if (!prog_error && image != nullptr) { int w = image->_width; int h = image->_height; - if (filep != NULL && filep->open_flags == DEV_FILE_OUTPUT) { + if (filep != nullptr && filep->open_flags == DEV_FILE_OUTPUT) { if (!lodepng_encode32_file(filep->name, image->_image, w, h)) { saved = true; } - } else if (array != NULL) { - v_tomatrix(array, h, w); + } else if (array != nullptr) { + v_tomatrix(array, w, h); + // x0 x1 x2 (w=3,h=2) + // y0 rgba rgba rgba ypos=0 + // y1 rgba rgba rgba ypos=12 + // for (int y = 0; y < h; y++) { int yoffs = (4 * y * w); for (int x = 0; x < w; x++) { @@ -430,13 +434,13 @@ void create_image(var_p_t var, ImageBuffer *image) { // loads an image for the form image input type ImageDisplay *create_display_image(var_p_t var, const char *name) { - ImageDisplay *result = NULL; - if (name != NULL && var != NULL) { + ImageDisplay *result = nullptr; + if (name != nullptr && var != nullptr) { dev_file_t file; strlcpy(file.name, name, sizeof(file.name)); file.type = ft_stream; ImageBuffer *buffer = load_image(&file); - if (buffer != NULL) { + if (buffer != nullptr) { result = new ImageDisplay(); result->_buffer = buffer; result->_bid = buffer->_bid; @@ -468,22 +472,23 @@ ImageDisplay *create_display_image(var_p_t var, const char *name) { void screen_dump() { int width = g_system->getOutput()->getWidth(); int height = g_system->getOutput()->getHeight(); - uint8_t* image = get_image_data(0, 0, width, height); - if (image != NULL) { + auto image = get_image_data(0, 0, width, height); + if (image != nullptr) { const char *path = gsb_bas_dir; #if defined(_ANDROID) path = getenv("EXTERNAL_STORAGE"); #endif for (int i = 0; i < 1000; i++) { - char file[OS_PATHNAME_SIZE]; - if (strstr(path, "://") != NULL) { - sprintf(file, "sbasic_dump_%d.png", i); - } else { - sprintf(file, "%ssbasic_dump_%d.png", path, i); + String file; + if (strstr(path, "://") == nullptr) { + file.append(path); } - if (access(file, R_OK) != 0) { - g_system->systemPrint("Saving screen to %s\n", file); - unsigned error = lodepng_encode32_file(file, image, width, height); + file.append("sbasic_dump_"); + file.append(i); + file.append(".png"); + if (access(file.c_str(), R_OK) != 0) { + g_system->systemPrint("Saving screen to %s\n", file.c_str()); + unsigned error = lodepng_encode32_file(file.c_str(), image, width, height); if (error) { g_system->systemPrint("Error: %s\n", lodepng_error_text(error)); } @@ -496,14 +501,14 @@ void screen_dump() { extern "C" void v_create_image(var_p_t var) { var_t arg; - ImageBuffer *image = NULL; - dev_file_t *filep = NULL; + ImageBuffer *image = nullptr; + dev_file_t *filep = nullptr; byte code = code_peek(); switch (code) { case kwTYPE_SEP: filep = eval_filep(); - if (filep != NULL) { + if (filep != nullptr) { image = load_image(filep); } break; @@ -551,7 +556,7 @@ extern "C" void v_create_image(var_p_t var) { break; }; - if (image != NULL) { + if (image != nullptr) { create_image(var, image); } else { err_throw(ERR_BAD_FILE_HANDLE); From 0ae98bb1883b8564b6c11163237e03838ecc2b31 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Thu, 7 May 2020 18:35:02 +1000 Subject: [PATCH 18/36] UI: fix compile error with newer gcc --- src/ui/system.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ui/system.cpp b/src/ui/system.cpp index 9cbe441a..66fb6677 100644 --- a/src/ui/system.cpp +++ b/src/ui/system.cpp @@ -618,12 +618,12 @@ char *System::readSource(const char *fileName) { } if (buffer != nullptr) { delete [] _programSrc; - int len = strlen(buffer); - _programSrc = new char[len + 1]; - strncpy(_programSrc, buffer, len); - _programSrc[len] = '\0'; + int len = strlen(buffer) + 1; + _programSrc = new char[len]; + memcpy(_programSrc, buffer, len); + _programSrc[len - 1] = '\0'; _srcRendered = false; - systemPrint("Opened: %s %d bytes\n", fileName, len); + systemPrint("Opened: %s %d bytes\n", fileName, len - 1); } return buffer; } From dce9be46f2744b75aff7682b65f8315cba669bec Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Sun, 10 May 2020 08:57:30 +1000 Subject: [PATCH 19/36] COMMON: Fix crash when passing non-array to CHART --- ChangeLog | 4 + configure.ac | 2 + src/common/blib_graph.c | 214 +++++++++++++----------------- src/common/smbas.h | 3 + src/platform/android/build.gradle | 2 +- src/platform/sdl/syswm.cpp | 17 ++- src/ui/system.cpp | 2 +- 7 files changed, 116 insertions(+), 128 deletions(-) diff --git a/ChangeLog b/ChangeLog index e9f06d6c..a4301d3c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2020-05-09 (0.12.19) + COMMON: Fix crash when passing non-array to CHART + SDL: show icon in linux build + 2020-05-07 (0.12.19) COMMON: Fix image.save() to array destination diff --git a/configure.ac b/configure.ac index 3d15ce02..f7025078 100644 --- a/configure.ac +++ b/configure.ac @@ -204,6 +204,8 @@ function buildSDL() { PACKAGE_CFLAGS="${PACKAGE_CFLAGS} ${FONTCONFIG_CFLAGS}" + (cd images && xxd -i sb-desktop-128x128.png > ../src/platform/sdl/icon.h) + dnl backlinking support for modules PACKAGE_LIBS="${PACKAGE_LIBS} -ldl -no-pie" PACKAGE_LIBS="${PACKAGE_LIBS} ${FONTCONFIG_LIBS}" diff --git a/src/common/blib_graph.c b/src/common/blib_graph.c index f56ee869..54f1bfe7 100644 --- a/src/common/blib_graph.c +++ b/src/common/blib_graph.c @@ -884,36 +884,35 @@ void cmd_chart_fstr(var_num_t v, char *buf) { } /* - * draw a chart + * draw a chart * - * x1,y1-x2,y2 = the area to draw - * vals = the values - * count = the number of the values - * xvals, xcount = for ruler the xvalues (use NULL for default) - * chart = chart type (1=line chart, 0=bar chart, 5=points) - * marks = marks type (2 & ruler, 1 & marks) + * x1,y1-x2,y2 = the area to draw + * vals = the values + * count = the number of the values + * xvals, xcount = for ruler the xvalues (use NULL for default) + * chart = chart type (1=line chart, 0=bar chart, 5=points) + * marks = marks type (2 & ruler, 1 & marks) */ -void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count, var_num_t *xvals, int xcount, - int chart, int marks) { - int *pts; - int rx1, dx, dy, i; - var_num_t vmin, vmax, lx, ly; +void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count, + var_num_t *xvals, int xcount, int chart, int marks) { + var_num_t lx, ly; char buf[32]; int32_t color = 0; - - rx1 = x1; + int rx1 = x1; // ready dev_settextcolor(0, 15); - pts = (int *) malloc(sizeof(int) * count * 2); + int *pts = (int *) malloc(sizeof(int) * count * 2); - if (marks & 0x2) { // ruler + if (marks & 0x2) { + // ruler x1 += dev_textwidth("00000") + 1; y2 -= (dev_textheight("0") + 1); } if (marks & 0x1) { - if (chart == 1) { // line + if (chart == 1) { + // line x1 += 2; x2 -= 2; y1 += 2; @@ -921,12 +920,13 @@ void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count, var_ } } - dx = (x2 - x1); - dy = (y2 - y1); + int dx = (x2 - x1); + int dy = (y2 - y1); // limits - vmin = vmax = vals[0]; - for (i = 1; i < count; i++) { + var_num_t vmin = vals[0]; + var_num_t vmax = vals[0]; + for (int i = 1; i < count; i++) { if (vmin > vals[i]) { vmin = vals[i]; } @@ -944,22 +944,22 @@ void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count, var_ ly = ((var_num_t) dy) / (vmax - vmin); // calc points - for (i = 0; i < count; i++) { - pts[i * 2] = x1 + i * lx; - pts[i * 2 + 1] = y1 + (dy - ((vals[i] - vmin) * ly)); + for (int i = 0; i < count; i++) { + int x = x1 + i * lx; + int y = y1 + (dy - ((vals[i] - vmin) * ly)); + pts[i * 2] = x > 0 ? x : 0; + pts[i * 2 + 1] = y > 0 ? y : 0; } // draw ruler if (marks & 0x2) { - int fh, fw, n, y, x; - var_num_t v; - // vertical - fh = dev_textheight("0"); - n = dy / (fh * 1.5); + int fh = dev_textheight("0"); + int n = dy / (fh * 1.5); if ((n - 1) > 0) { - for (i = 0; i <= n; i++) { + for (int i = 0; i <= n; i++) { + var_num_t v; if (i == 0) { v = vmin; } @@ -970,8 +970,7 @@ void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count, var_ } cmd_chart_fstr(v, buf); - y = y1 + (dy - ((v - vmin) * ly)); - + int y = y1 + (dy - ((v - vmin) * ly)); if (i != 0) { dev_setxy(rx1 + 1, y + 1, 0); } else { @@ -983,7 +982,7 @@ void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count, var_ } // horizontal - fw = dev_textwidth("000"); + int fw = dev_textwidth("000"); n = -1; if (count <= 24) { if (count * (fw * 1.34) < dx) { @@ -995,7 +994,8 @@ void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count, var_ n = dx / (fw * 1.5); } if ((n - 1) > 0) { - for (i = 0; i < n; i++) { + for (int i = 0; i < n; i++) { + var_num_t v; if (i == 0) { v = 0; } else { @@ -1003,12 +1003,10 @@ void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count, var_ } if (xvals) { // I have xvals - var_num_t x, dx; - var_num_t xmin, xmax; - - xmin = xvals[0]; - xmax = xvals[xcount - 1]; - dx = xmax - xmin; + var_num_t x; + var_num_t xmin = xvals[0]; + var_num_t xmax = xvals[xcount - 1]; + var_num_t dx = xmax - xmin; if (i == 0) { x = xmin; } else if (i == n) { @@ -1022,12 +1020,10 @@ void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count, var_ ftostr(i + 1, buf); } - // buf[3] = '\0'; fw = dev_textwidth(buf); - x = x1 + v * lx; - + int x = x1 + v * lx; if (chart == 1 || chart == 5) { dev_setxy(x - fw, y2 + 1, 0); } else { @@ -1052,32 +1048,29 @@ void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count, var_ // draw switch (chart) { - - case 1: // line chart - case 5: // points + case 1: + case 5: + // line chart + // points if (chart == 5) { - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { dev_setpixel(pts[i * 2], pts[i * 2 + 1]); } } else { - for (i = 1; i < count; i++) { + for (int i = 1; i < count; i++) { dev_line(pts[(i - 1) * 2], pts[(i - 1) * 2 + 1], pts[i * 2], pts[i * 2 + 1]); } } // draw marks if (marks & 0x1) { - for (i = 0; i < count; i++) { - int mx, my; - int fh, fw; - + for (int i = 0; i < count; i++) { cmd_chart_fstr(vals[i], buf); - fw = dev_textwidth(buf); - fh = dev_textheight(buf); - - mx = pts[i * 2] - fw / 2; - my = pts[i * 2 + 1]; + int fw = dev_textwidth(buf); + int fh = dev_textheight(buf); + int mx = pts[i * 2] - fw / 2; + int my = pts[i * 2 + 1]; if (my > (y1 + (y2 - y1) / 2)) { my -= fh; @@ -1090,15 +1083,17 @@ void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count, var_ } dev_setxy(mx, my, 0); dev_print(buf); - dev_rect(pts[i * 2] - 2, pts[i * 2 + 1] - 2, pts[i * 2] + 2, pts[i * 2 + 1] + 2, 1); + dev_rect(pts[i * 2] - 2, pts[i * 2 + 1] - 2, + pts[i * 2] + 2, pts[i * 2 + 1] + 2, 1); } } break; - case 2: // bar chart + case 2: + // bar chart // draw rect color = 0; - for (i = 1; i < count; i++) { + for (int i = 1; i < count; i++) { if (os_color_depth > 2) { dev_setcolor(color); color++; @@ -1112,22 +1107,19 @@ void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count, var_ if (os_color_depth > 2) { dev_setcolor(color); } - dev_rect(pts[(count - 1) * 2], pts[(count - 1) * 2 + 1], pts[(count - 1) * 2] + lx - 1, y2, 1); + dev_rect(pts[(count - 1) * 2], pts[(count - 1) * 2 + 1], + pts[(count - 1) * 2] + lx - 1, y2, 1); // draw marks if (marks & 0x1) { color = 0; - for (i = 0; i < count; i++) { - int mx, my; - int fh, fw; - + for (int i = 0; i < count; i++) { cmd_chart_fstr(vals[i], buf); - fw = dev_textwidth(buf); - fh = dev_textheight(buf); - - mx = pts[i * 2] + lx / 2 - fw / 2; - my = pts[i * 2 + 1]; + int fw = dev_textwidth(buf); + int fh = dev_textheight(buf); + int mx = pts[i * 2] + lx / 2 - fw / 2; + int my = pts[i * 2 + 1]; if (os_color_depth > 2) { if (my - fh >= y1) { @@ -1162,7 +1154,6 @@ void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count, var_ break; }; - // free(pts); } @@ -1170,79 +1161,54 @@ void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count, var_ // CHART // void cmd_chart() { - var_t *var_p, *elem_p; - int i, count; - var_num_t *vals; int32_t prev_fgcolor = dev_fgcolor; int32_t prev_bgcolor = dev_bgcolor; - - // parameters - int chart; - int marks = 0; - int x1 = 0, y1 = 0, x2 = os_graf_mx, y2 = os_graf_my; + int x1 = 0; + int y1 = 0; + int x2 = os_graf_mx; + int y2 = os_graf_my; // chart type - chart = par_getint(); - if (prog_error) - return; - - par_getcomma(); - if (prog_error) - return; + int chart = par_getint(); IF_PROG_ERR_RTN; + par_getcomma(); IF_PROG_ERR_RTN; // array - var_p = par_getvarray(); - if (prog_error) + var_t *var_p = par_getvarray(); IF_PROG_ERR_RTN; + if (!var_p || var_p->type != V_ARRAY) { + err_varisnotarray(); return; - count = v_asize(var_p); + } // optional labels-flag + int marks; if (code_peek() == kwTYPE_SEP) { - par_getcomma(); - if (prog_error) - return; - marks = par_getint(); - if (prog_error) - return; + par_getcomma(); IF_PROG_ERR_RTN; + marks = par_getint(); IF_PROG_ERR_RTN; // optional x1,y1,x2,y2 if (code_peek() == kwTYPE_SEP) { - par_getcomma(); - if (prog_error) - return; - x1 = par_getint(); - if (prog_error) - return; - par_getcomma(); - if (prog_error) - return; - y1 = par_getint(); - if (prog_error) - return; - par_getcomma(); - if (prog_error) - return; - x2 = par_getint(); - if (prog_error) - return; - par_getcomma(); - if (prog_error) - return; - y2 = par_getint(); - if (prog_error) - return; + par_getcomma(); IF_PROG_ERR_RTN; + x1 = par_getint(); IF_PROG_ERR_RTN; + par_getcomma(); IF_PROG_ERR_RTN; + y1 = par_getint(); IF_PROG_ERR_RTN; + par_getcomma(); IF_PROG_ERR_RTN; + x2 = par_getint(); IF_PROG_ERR_RTN; + par_getcomma(); IF_PROG_ERR_RTN; + y2 = par_getint(); IF_PROG_ERR_RTN; } + } else { + marks = 0; } // get array's values - vals = (var_num_t *) malloc(sizeof(var_num_t) * count); - for (i = 0; i < count; i++) { - elem_p = v_elem(var_p, i); + int count = v_asize(var_p); + var_num_t *vals = (var_num_t *) malloc(sizeof(var_num_t) * count); + for (int i = 0; i < count; i++) { + var_t *elem_p = v_elem(var_p, i); if (prog_error) { free(vals); return; } - switch (elem_p->type) { case V_INT: vals[i] = elem_p->v.i; @@ -1260,10 +1226,8 @@ void cmd_chart() { } } - // chart_draw(x1, y1, x2, y2, vals, count, NULL, 0, chart, marks); - // free(vals); dev_settextcolor(prev_fgcolor, prev_bgcolor); } diff --git a/src/common/smbas.h b/src/common/smbas.h index 59823acd..ab463193 100644 --- a/src/common/smbas.h +++ b/src/common/smbas.h @@ -133,6 +133,9 @@ EXTERN char gsb_last_errmsg[SB_ERRMSG_SIZE + 1]; /**< last error message */ #include "common/units.h" #include "common/tasks.h" +#define IF_PROG_ERR_RTN if (ctask->error) { return; } +#define IF_PROG_ERR_BRK if (ctask->error) { break; } + // emulation #define prog_line ctask->line #define comp_line ctask->line diff --git a/src/platform/android/build.gradle b/src/platform/android/build.gradle index d99c778c..95dbb080 100644 --- a/src/platform/android/build.gradle +++ b/src/platform/android/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.6.2' + classpath 'com.android.tools.build:gradle:3.6.3' classpath "com.github.ben-manes:gradle-versions-plugin:0.22.0" } } diff --git a/src/platform/sdl/syswm.cpp b/src/platform/sdl/syswm.cpp index 30189bc6..d9064254 100644 --- a/src/platform/sdl/syswm.cpp +++ b/src/platform/sdl/syswm.cpp @@ -80,9 +80,24 @@ void browseFile(SDL_Window *window, const char *url) { #else #include #include +#include "icon.h" +#include "lib/lodepng/lodepng.h" void loadIcon(SDL_Window *window) { - // handled via smallbasic.desktop + unsigned w, h; + unsigned char *image; + if (!lodepng_decode32(&image, &w, &h, sb_desktop_128x128_png, sb_desktop_128x128_png_len)) { + SDL_Surface *surf = + SDL_CreateRGBSurfaceFrom(image, w, h, + 32, w * 4, + 0x000000ff, + 0x0000ff00, + 0x00ff0000, + 0xff000000); + SDL_SetWindowIcon(window, surf); + SDL_FreeSurface(surf); + free(image); + } } int getStartupFontSize(SDL_Window *window) { diff --git a/src/ui/system.cpp b/src/ui/system.cpp index 66fb6677..de268e4e 100644 --- a/src/ui/system.cpp +++ b/src/ui/system.cpp @@ -623,7 +623,7 @@ char *System::readSource(const char *fileName) { memcpy(_programSrc, buffer, len); _programSrc[len - 1] = '\0'; _srcRendered = false; - systemPrint("Opened: %s %d bytes\n", fileName, len - 1); + systemPrint("Opened: %s %d bytes\n", fileName, len); } return buffer; } From aae73b3fd69c15d4cc50ae26bd9e4096310222e7 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Sun, 10 May 2020 14:46:57 +1000 Subject: [PATCH 20/36] COMMON: Fix ABSMIN/ABSMAX transposed #96 --- ChangeLog | 3 +++ samples/distro-examples/tests/output/all.out | 4 ++-- src/common/blib_func.c | 11 ++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index a4301d3c..d83b766b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2020-05-10 (0.12.19) + Fix ABSMIN/ABSMAX transposed #96 + 2020-05-09 (0.12.19) COMMON: Fix crash when passing non-array to CHART SDL: show icon in linux build diff --git a/samples/distro-examples/tests/output/all.out b/samples/distro-examples/tests/output/all.out index caca2746..9a837c11 100644 --- a/samples/distro-examples/tests/output/all.out +++ b/samples/distro-examples/tests/output/all.out @@ -83,8 +83,8 @@ VIEW: WINDOW: WRITE: ABS:12.2222 -ABSMAX:1 -ABSMIN:9 +ABSMAX:9 +ABSMIN:1 ACOS:nan ACOSH:3.2010898763691 ACOT:0.0811223921009 diff --git a/src/common/blib_func.c b/src/common/blib_func.c index da5e5e80..46938e19 100644 --- a/src/common/blib_func.c +++ b/src/common/blib_func.c @@ -122,19 +122,20 @@ void dar_next(long funcCode, var_t *r, var_t *elem_p) { v_set(r, elem_p); } break; - default: // numeric + default: + // numeric n = v_getval(elem_p); switch (funcCode) { case kwABSMIN: n = fabsl(n); - if (r->v.n < n) { + if (n < r->v.n) { r->v.n = n; } break; case kwABSMAX: n = fabsl(n); - if (r->v.n > n) { + if (n > r->v.n) { r->v.n = n; } break; @@ -145,8 +146,8 @@ void dar_next(long funcCode, var_t *r, var_t *elem_p) { case kwSUMSV: r->v.n += (n * n); break; - } // sw2 - } // sw1 + } + } } /* From 6d95f438a31b3157a2db1d053816ccb44a9c4f4e Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Mon, 11 May 2020 20:06:09 +1000 Subject: [PATCH 21/36] FLTK: Fix compile warnings with updated gcc --- ChangeLog | 7 +++++-- src/platform/fltk/EditorWidget.cxx | 6 +----- src/platform/fltk/MainWindow.cxx | 21 +++++---------------- src/platform/fltk/MainWindow.h | 1 - 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index d83b766b..f4a9b222 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ +2020-05-11 (0.12.19) + FLTK: Fix compile warnings with updated gcc + 2020-05-10 (0.12.19) - Fix ABSMIN/ABSMAX transposed #96 + COMMON: Fix ABSMIN/ABSMAX transposed #96 2020-05-09 (0.12.19) COMMON: Fix crash when passing non-array to CHART @@ -10,7 +13,7 @@ 2020-05-04 (0.12.19) COMMON: INPUT crash #99 - COMMON: Fix compile warning with updated gcc + COMMON: Fix compile warnings with updated gcc 2020-03-07 (0.12.19) COMMON: implement DEFINEKEY undo #92 diff --git a/src/platform/fltk/EditorWidget.cxx b/src/platform/fltk/EditorWidget.cxx index ad0e0899..95d593a9 100644 --- a/src/platform/fltk/EditorWidget.cxx +++ b/src/platform/fltk/EditorWidget.cxx @@ -815,11 +815,7 @@ void EditorWidget::getInput(char *result, int size) { if (wnd->isBreakExec()) { brun_break(); } else { - const char *value = _commandText->value(); - int valueLen = strlen(value); - int len = (valueLen < size) ? valueLen : size; - strncpy(result, value, len); - result[len] = 0; + strlcpy(result, _commandText->value(), size); } setCommand(cmd_find); } diff --git a/src/platform/fltk/MainWindow.cxx b/src/platform/fltk/MainWindow.cxx index bf4bcb18..8cd58b0b 100644 --- a/src/platform/fltk/MainWindow.cxx +++ b/src/platform/fltk/MainWindow.cxx @@ -544,18 +544,19 @@ void MainWindow::editor_plugin(Fl_Widget *w, void *eventData) { if (editWidget) { Fl_Text_Editor *editor = editWidget->getEditor(); char filename[PATH_MAX]; - char path[PATH_MAX]; - strcpy(filename, editWidget->getFilename()); + strlcpy(filename, editWidget->getFilename(), PATH_MAX); if (runMode == edit_state) { if (editWidget->checkSave(false) && filename[0]) { + char path[PATH_MAX]; int pos = editor->insert_position(); int row, col, s1r, s1c, s2r, s2c; editWidget->getRowCol(&row, &col); editWidget->getSelStartRowCol(&s1r, &s1c); editWidget->getSelEndRowCol(&s2r, &s2c); - snprintf(opt_command, sizeof(opt_command), "%s|%d|%d|%d|%d|%d|%d", - filename, row - 1, col, s1r - 1, s1c, s2r - 1, s2c); + strlcpy(opt_command, filename, PATH_MAX); + snprintf(path, sizeof(path), "|%d|%d|%d|%d|%d|%d", row - 1, col, s1r - 1, s1c, s2r - 1, s2c); + strlcat(opt_command, path, PATH_MAX); runMode = run_state; editWidget->runState(rs_run); snprintf(path, sizeof(path), "%s/%s", packageHome, (const char *)eventData); @@ -626,17 +627,6 @@ void MainWindow::load_file(Fl_Widget *w, void *eventData) { //--Startup functions----------------------------------------------------------- -/** - *Adds a plug-in to the menu - */ -void MainWindow::addPlugin(Fl_Menu_Bar *menu, const char *label, const char *filename) { - char path[PATH_MAX]; - snprintf(path, PATH_MAX, "%s/%s", pluginHome, filename); - if (access(path, R_OK) == 0) { - menu->add(label, 0, editor_plugin_cb, strdup(path)); - } -} - /** * scan for recent files */ @@ -952,7 +942,6 @@ MainWindow::MainWindow(int w, int h) : m->add("&File/_Close Others", 0, close_other_tabs_cb); m->add("&File/&Save File", FL_CTRL + 's', EditorWidget::save_file_cb); m->add("&File/_Save File &As", FL_CTRL + FL_SHIFT + 'S', save_file_as_cb); - addPlugin(m, "&File/Publish Online", "publish.bas"); m->add("&File/_Export", FL_CTRL + FL_F+9, export_file_cb); m->add("&File/E&xit", FL_CTRL + 'q', quit_cb); m->add("&Edit/_&Undo", FL_CTRL + 'z', EditorWidget::undo_cb); diff --git a/src/platform/fltk/MainWindow.h b/src/platform/fltk/MainWindow.h index b6d55798..b965da8b 100644 --- a/src/platform/fltk/MainWindow.h +++ b/src/platform/fltk/MainWindow.h @@ -72,7 +72,6 @@ struct MainWindow : public BaseWindow { bool isIdeHidden(); // whether to run without the IDE displayed bool isInteractive(); // whether to run without an interface bool isModal(); // whether a modal gui loop is active - void addPlugin(Fl_Menu_Bar *menu, const char *label, const char *filename); void busyMessage(); int handle(int e); void loadHelp(const char *path); From 221ec0f18b0bd078688e2878323b0a5cd78f761e Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Sun, 24 May 2020 08:15:24 +1000 Subject: [PATCH 22/36] COMMON: fix map crash, fix pahole --- src/common/var_map.c | 2 +- src/ui/image.cpp | 4 ++-- src/ui/image.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/var_map.c b/src/common/var_map.c index cbe6f629..5e9946f2 100644 --- a/src/common/var_map.c +++ b/src/common/var_map.c @@ -90,7 +90,7 @@ int map_length(const var_p_t var_p) { var_p_t map_get(var_p_t base, const char *name) { var_p_t result; - if (base->type == V_MAP) { + if (base != NULL && base->type == V_MAP) { result = hashmap_get(base, name); } else { result = NULL; diff --git a/src/ui/image.cpp b/src/ui/image.cpp index d1d5ec95..af090fed 100644 --- a/src/ui/image.cpp +++ b/src/ui/image.cpp @@ -37,17 +37,17 @@ void reset_image_cache() { } ImageBuffer::ImageBuffer() : - _bid(0), _filename(nullptr), _image(nullptr), + _bid(0), _width(0), _height(0) { } ImageBuffer::ImageBuffer(ImageBuffer &o) : - _bid(o._bid), _filename(o._filename), _image(o._image), + _bid(o._bid), _width(o._width), _height(o._height) { } diff --git a/src/ui/image.h b/src/ui/image.h index 16f5adfb..d7467120 100644 --- a/src/ui/image.h +++ b/src/ui/image.h @@ -17,9 +17,9 @@ struct ImageBuffer { ImageBuffer(ImageBuffer &imageBuffer); virtual ~ImageBuffer(); - unsigned _bid; char *_filename; unsigned char *_image; + unsigned _bid; int _width; int _height; }; From b74ec59c0f063555bdf26a92871c9f5fa5155e88 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Mon, 25 May 2020 21:20:47 +1000 Subject: [PATCH 23/36] ANDROID: complain when samsum keyboard detected --- ChangeLog | 4 ++++ src/common/brun.c | 4 ++-- src/common/units.c | 2 +- src/platform/android/app/build.gradle | 4 ++-- .../java/net/sourceforge/smallbasic/MainActivity.java | 9 ++++++++- .../net/sourceforge/smallbasic/TextToSpeechAdapter.java | 4 ++-- src/platform/android/app/src/main/res/values/strings.xml | 1 + src/ui/system.cpp | 2 +- 8 files changed, 21 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index f4a9b222..a3019cc7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2020-05-11 (0.12.19) + ANDROID: complain when samsung keyboard detected + COMMON: fix compile warnings + 2020-05-11 (0.12.19) FLTK: Fix compile warnings with updated gcc diff --git a/src/common/brun.c b/src/common/brun.c index 58ed89b0..fcf62cc8 100644 --- a/src/common/brun.c +++ b/src/common/brun.c @@ -352,7 +352,7 @@ void cmd_chain(void) { if (var.type == V_STR) { if (access(var.v.p.ptr, R_OK) == 0) { // argument is a file name - int h = open(var.v.p.ptr, O_BINARY | O_RDONLY, 0644); + int h = open(var.v.p.ptr, O_BINARY | O_RDONLY); if (h != -1) { struct stat st; if (fstat(h, &st) == 0) { @@ -1144,7 +1144,7 @@ int brun_create_task(const char *filename, byte *preloaded_bc, int libf) { return search_task(fname); } // open & load - int h = open(fname, O_RDWR | O_BINARY, 0660); + int h = open(fname, O_RDWR | O_BINARY); if (h == -1) { panic("File '%s' not found", fname); } diff --git a/src/common/units.c b/src/common/units.c index ab21b655..a3b19202 100644 --- a/src/common/units.c +++ b/src/common/units.c @@ -147,7 +147,7 @@ int open_unit(const char *file) { } // open unit - h = open(unitname, O_RDWR | O_BINARY, 0660); + h = open(unitname, O_RDWR | O_BINARY); if (h == -1) { return -1; } diff --git a/src/platform/android/app/build.gradle b/src/platform/android/app/build.gradle index 4f2cb966..ef7fd650 100644 --- a/src/platform/android/app/build.gradle +++ b/src/platform/android/app/build.gradle @@ -2,13 +2,13 @@ apply plugin: 'com.android.application' android { // app can use the API features included in this API level and lower. - compileSdkVersion 28 + compileSdkVersion 29 // can override some attributes in main/AndroidManifest.xml defaultConfig { applicationId 'net.sourceforge.smallbasic' minSdkVersion 16 - targetSdkVersion 28 + targetSdkVersion 29 versionCode 39 versionName "0.12.17" resConfigs "en" diff --git a/src/platform/android/app/src/main/java/net/sourceforge/smallbasic/MainActivity.java b/src/platform/android/app/src/main/java/net/sourceforge/smallbasic/MainActivity.java index 95e93a85..cb242e7b 100644 --- a/src/platform/android/app/src/main/java/net/sourceforge/smallbasic/MainActivity.java +++ b/src/platform/android/app/src/main/java/net/sourceforge/smallbasic/MainActivity.java @@ -24,6 +24,7 @@ import android.os.Bundle; import android.os.Environment; import android.os.Handler; +import android.provider.Settings; import android.util.Base64; import android.util.DisplayMetrics; import android.util.Log; @@ -82,7 +83,7 @@ /** * Extends NativeActivity to provide interface methods for runtime.cpp * - * @author chrisws + * @author Chris Warren-Smith */ public class MainActivity extends NativeActivity { private static final String TAG = "smallbasic"; @@ -586,11 +587,17 @@ public void onClick(DialogInterface dialog, int which) {} public void showKeypad(final boolean show) { Log.i(TAG, "showKeypad: " + show); final View view = getWindow().getDecorView(); + final Activity activity = this; runOnUiThread(new Runnable() { public void run() { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { if (show) { + String id = Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); + if ("com.sec.android.inputmethod/.SamsungKeypad".equals(id)) { + String message = getResources().getString(R.string.samsung_keyboard); + Toast.makeText(activity, message, Toast.LENGTH_LONG).show(); + } imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); } else { imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); diff --git a/src/platform/android/app/src/main/java/net/sourceforge/smallbasic/TextToSpeechAdapter.java b/src/platform/android/app/src/main/java/net/sourceforge/smallbasic/TextToSpeechAdapter.java index 0278028d..1ff45944 100644 --- a/src/platform/android/app/src/main/java/net/sourceforge/smallbasic/TextToSpeechAdapter.java +++ b/src/platform/android/app/src/main/java/net/sourceforge/smallbasic/TextToSpeechAdapter.java @@ -1,12 +1,12 @@ package net.sourceforge.smallbasic; -import java.util.Locale; - import android.content.Context; import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech.OnInitListener; import android.util.Log; +import java.util.Locale; + class TextToSpeechAdapter implements OnInitListener { private static final String TAG = "smallbasic"; private final TextToSpeech _tts; diff --git a/src/platform/android/app/src/main/res/values/strings.xml b/src/platform/android/app/src/main/res/values/strings.xml index e31bb091..bb11245f 100644 --- a/src/platform/android/app/src/main/res/values/strings.xml +++ b/src/platform/android/app/src/main/res/values/strings.xml @@ -1,6 +1,7 @@ SmallBASIC + Samsung keyboard not supported. Please use an alternative keyboard.