Skip to content

Commit

Permalink
Merge pull request #89 from chrisws/0_12_18
Browse files Browse the repository at this point in the history
0 12 18
  • Loading branch information
chrisws authored Mar 15, 2020
2 parents a6db1a0 + abec24a commit 2ddcb5b
Show file tree
Hide file tree
Showing 22 changed files with 180 additions and 61 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2020-02-13 (0.12.18)
Fix path for HOME constant

2020-02-08 (0.12.18)
SDL: fix issue #81 - numlock handling
FLTK: added live editing menu item
COMMON: increase stack size to 1024

2019-12-21 (0.12.17)
SDL: fix issue #81 - numlock handling

Expand Down
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ release:
ndk-stack:
adb logcat | ${NDK}/ndk-stack -sym src/platform/android/obj/local/armeabi

appImage:
~/apps/linuxdeploy-x86_64.AppImage --appdir=AppDir --executable=./src/platform/fltk/sbasici && \
~/apps/appimagetool-x86_64.AppImage AppDir
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
dnl
dnl Configure script for SmallBASIC
dnl
dnl Copyright(C) 2001-2019 Chris Warren-Smith.
dnl Copyright(C) 2001-2020 Chris Warren-Smith.
dnl
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.17])
AC_INIT([smallbasic], [0.12.18])
AC_CONFIG_SRCDIR([configure.ac])

AC_CANONICAL_TARGET
Expand Down
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
smallbasic (0.12.18) unstable; urgency=low
* Various see web site

-- Chris Warren-Smith <[email protected]> Wed, 05 Feb 2020 09:45:25 +1000

smallbasic (0.12.17) unstable; urgency=low
* Various see web site

Expand Down
17 changes: 10 additions & 7 deletions src/common/brun.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,14 @@ void exec_setup_predefined_variables() {
if (getenv("HOME_DIR")) {
strlcpy(homedir, getenv("HOME_DIR"), sizeof(homedir));
}
#else
#if defined(_Win32)
#elif defined(_Win32)
if (getenv("HOMEPATH")) {
strlcpy(homedir, getenv("HOMEPATH"), sizeof(homedir));
if (getenv("HOMEDRIVE")) {
strlcpy(homedir, getenv("HOMEDRIVE"), sizeof(homedir));
strlcat(homedir, getenv("HOMEPATH"), sizeof(homedir));
} else {
strlcpy(homedir, getenv("HOMEPATH"), sizeof(homedir));
}
} else {
GetModuleFileName(NULL, homedir, sizeof(homedir) - 1);
char *p = strrchr(homedir, '\\');
Expand All @@ -295,12 +299,11 @@ void exec_setup_predefined_variables() {
strcpy(homedir, "/tmp/");
}
#endif
// don't end with trailing slash
int l = strlen(homedir);
if (homedir[l - 1] != OS_DIRSEP) {
homedir[l] = OS_DIRSEP;
homedir[l + 1] = '\0';
if (homedir[l - 1] == OS_DIRSEP) {
homedir[l - 1] = '\0';
}
#endif
setsysvar_str(SYSVAR_HOME, homedir);
}

Expand Down
3 changes: 2 additions & 1 deletion src/common/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ int sys_search_path(const char *path, const char *file, char *retbuf) {
if (getenv("HOME")) {
strlcpy(cur_path, getenv("HOME"), sizeof(cur_path));
} else {
strlcpy(cur_path, getenv("HOMEPATH"), sizeof(cur_path));
strlcpy(cur_path, getenv("HOMEDRIVE"), sizeof(cur_path));
strlcat(cur_path, getenv("HOMEPATH"), sizeof(cur_path));
}
strlcat(cur_path, "/", sizeof(cur_path));
strlcat(cur_path, old_path, sizeof(cur_path));
Expand Down
2 changes: 1 addition & 1 deletion src/common/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ extern "C" {
#define SB_KEYWORD_SIZE 128
#define SB_SOURCELINE_SIZE 65536 // compiler
#define SB_TEXTLINE_SIZE 8192 // RTL
#define SB_EXEC_STACK_SIZE 512 // executor's stack size
#define SB_EXEC_STACK_SIZE 1024 // executor's stack size
#define SB_EVAL_STACK_SIZE 16 // evaluation stack size
#define SB_KW_NONE_STR "Nil"

Expand Down
2 changes: 1 addition & 1 deletion src/languages/messages.en.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
#define ERR_MISSING_LP "Missing '('"
#define ERR_PARFMT "Parameters count/format error (%s)"
#define ERR_BYREF "Parameter %d cannot BYREF"
#define ERR_BAD_FILE_HANDLE "VFS: Bad file number (Use OPEN)"
#define ERR_BAD_FILE_HANDLE "Invalid file number (Use OPEN)"
#define ERR_SEP_FMT "No separator found (missing %s)"
#define ERR_POLY "Parsing polyline: type mismatch (element: %d, info: %d)"
#define ERR_CRITICAL_MISSING_FUNC "Unsupported built-in function call %ld, please report this bug"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/jsmn
Submodule jsmn updated 1 files
+1 −1 README.md
2 changes: 1 addition & 1 deletion src/lib/lodepng
2 changes: 1 addition & 1 deletion src/lib/miniaudio
5 changes: 3 additions & 2 deletions src/platform/android/app/src/main/assets/main.bas
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ func mk_scratch()
result = true
catch e
local wnd = window()
wnd.alert("Failed to create scratch file: " + e)
logprint e
wnd.alert("Failed to create: " + scratch_file)
end try
else
result = true
Expand Down Expand Up @@ -119,7 +120,7 @@ sub do_about()
color 7
print "Version "; sbver
print
print "Copyright (c) 2002-2019 Chris Warren-Smith"
print "Copyright (c) 2002-2020 Chris Warren-Smith"
print "Copyright (c) 1999-2006 Nicholas Christopoulos" + chr(10)

local bn_home
Expand Down
2 changes: 1 addition & 1 deletion src/platform/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "com.github.ben-manes:gradle-versions-plugin:0.22.0"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/fltk/HelpView.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
const char *aboutText =
"<b>About SmallBASIC...</b><br><br>"
"Version " SB_STR_VER "<br>"
"Copyright (c) 2002-2019 Chris Warren-Smith.<br><br>"
"Copyright (c) 2002-2020 Chris Warren-Smith.<br><br>"
"Copyright (c) 2000-2006 Nicholas Christopoulos.<br><br>"
"<a href=https://smallbasic.github.io>"
"https://smallbasic.github.io</a><br><br>"
Expand Down
27 changes: 20 additions & 7 deletions src/platform/fltk/MainWindow.cxx
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,6 +9,7 @@
#include <config.h>
#include <FL/fl_ask.H>
#include <FL/Fl_PNG_Image.H>
#include <FL/fl_utf8.h>
#include "platform/fltk/MainWindow.h"
#include "platform/fltk/EditorWidget.h"
#include "platform/fltk/HelpView.h"
Expand Down Expand Up @@ -524,6 +525,16 @@ void MainWindow::run_selection(Fl_Widget *w, void *eventData) {
}
}

/**
* run the active program in sbasicg
*/
void MainWindow::run_live(Fl_Widget *w, void *eventData) {
EditorWidget *editWidget = getEditor();
if (editWidget) {
launchExec(editWidget->getFilename());
}
}

/**
* callback for editor-plug-in plug-ins. we assume the target
* program will be changing the contents of the editor buffer
Expand Down Expand Up @@ -871,6 +882,7 @@ bool initialise(int argc, char **argv) {
char path[PATH_MAX];
getHomeDir(path, sizeof(path), false);
dev_setenv("BAS_HOME", path);
setAppName(argv[0]);

wnd = new MainWindow(800, 650);

Expand Down Expand Up @@ -977,12 +989,13 @@ MainWindow::MainWindow(int w, int h) :

scanPlugIns(m);

m->add("&Program/&Run", FL_F+9, run_cb);
m->add("&Program/_&Run Selection", FL_F+8, run_selection_cb);
m->add("&Program/&Break", FL_CTRL + 'b', run_break_cb);
m->add("&Program/_&Restart", FL_CTRL + 'r', restart_run_cb);
m->add("&Program/&Command", FL_F+10, set_options_cb);
m->add("&Program/Online Samples", 0, run_samples_cb);
m->add("&Run/&Run", FL_F+9, run_cb);
m->add("&Run/&Live Editing", FL_F+8, run_live_cb);
m->add("&Run/_&Selection", FL_F+7, run_selection_cb);
m->add("&Run/&Break", FL_CTRL + 'b', run_break_cb);
m->add("&Run/_&Restart", FL_CTRL + 'r', restart_run_cb);
m->add("&Run/&Command", FL_F+10, set_options_cb);
m->add("&Run/Online Samples", 0, run_samples_cb);
m->add("&Help/&Help Contents", FL_F+1, help_contents_cb);
m->add("&Help/_&Context Help", FL_F+2, help_contents_brief_cb);
m->add("&Help/&Program Help", FL_F+11, help_app_cb);
Expand Down
3 changes: 2 additions & 1 deletion src/platform/fltk/MainWindow.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -138,6 +138,7 @@ struct MainWindow : public BaseWindow {
CALLBACK_METHOD(run_samples);
CALLBACK_METHOD(run_break);
CALLBACK_METHOD(run_selection);
CALLBACK_METHOD(run_live);
CALLBACK_METHOD(save_file_as);
CALLBACK_METHOD(set_options);
CALLBACK_METHOD(set_theme);
Expand Down
76 changes: 72 additions & 4 deletions src/platform/fltk/utils.cxx
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
// 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
//

#include <config.h>
#if !defined(_Win32)
#include "config.h"

#if defined(_Win32)
#include <windows.h>
#include <shellapi.h>
#else
#include <sys/socket.h>
#include <unistd.h>
#include <errno.h>
#endif
#include <stdint.h>
#include "lib/str.h"
#include "utils.h"
#include "platform/fltk/utils.h"
#include "ui/utils.h"

#define RX_BUFFER_SIZE 1024
#if defined(_Win32)
static char appName[OS_PATHNAME_SIZE + 1];
#endif

Fl_Color get_color(int argb) {
// Fl_Color => 0xrrggbbii
Expand Down Expand Up @@ -232,3 +242,61 @@ void vsncat(char *buffer, size_t size, ...) {
}
va_end(args);
}

void setAppName(const char *path) {
#if defined(_Win32)
appName[0] = '\0';
if (path[0] == '/' ||
(path[1] == ':' && ((path[2] == '\\') || path[2] == '/'))) {
// full path or C:/
strlcpy(appName, path, sizeof(appName));
} else {
// relative path
char cwd[OS_PATHNAME_SIZE + 1];
cwd[0] = '\0';
getcwd(cwd, sizeof(cwd) - 1);
strlcpy(appName, cwd, sizeof(appName));
strlcat(appName, "/", sizeof(appName));
strlcat(appName, path, sizeof(appName));
}
const auto file = "sbasici.exe";
char *exe = strstr(appName, file);
if (exe) {
strcpy(exe, "sbasicg.exe");
}
#endif
}

#if defined(_Win32)
void launchExec(const char *file) {
STARTUPINFO info = {sizeof(info)};
PROCESS_INFORMATION processInfo;
char cmd[MAX_PATH];
sprintf(cmd, "\"%s\" -x \"%s\"", appName, file);
appLog(cmd);
if (!CreateProcess(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo)) {
appLog("failed to start %d %s %s\n", GetLastError(), appName, cmd);
}
}
#else
void launchExec(const char *file) {
pid_t pid = fork();
auto app = "/usr/bin/sbasicg";

switch (pid) {
case -1:
// failed
break;
case 0:
// child process
if (execl(app, app, "-x", file, (char *)0) == -1) {
fprintf(stderr, "exec failed [%s] %s\n", strerror(errno), app);
exit(1);
}
break;
default:
// parent process - continue
break;
}
}
#endif
2 changes: 2 additions & 0 deletions src/platform/fltk/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,7 @@ Fl_Font get_font(const char *name);
void getHomeDir(char *fileName, size_t size, bool appendSlash = true);
bool cacheLink(dev_file_t *df, char *localFile, size_t size);
void vsncat(char *buffer, size_t size, ...);
void launchExec(const char *file);
void setAppName(const char *path);

#endif
15 changes: 15 additions & 0 deletions src/platform/sdl/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ bool g_returnToLine;
struct StatusMessage {
explicit StatusMessage(TextEditInput *editor) :
_dirty(editor->isDirty()),
_insert(true),
_row(editor->getRow()),
_col(editor->getCol()) {
}
Expand Down Expand Up @@ -61,6 +62,9 @@ struct StatusMessage {
.append(",")
.append(editor->getCol())
.append(") ");
if (!_insert) {
message.append("Ovwrt");
}
int digits = snprintf(NULL, 0, "%d%d",
editor->getRow(), editor->getCol());
int spaces = 6 - digits;
Expand Down Expand Up @@ -93,7 +97,12 @@ struct StatusMessage {
_dirty = !editor->isDirty();
}

void setInsert() {
_insert = !_insert;
}

bool _dirty;
bool _insert;
int _row;
int _col;
String _fileName;
Expand Down Expand Up @@ -379,6 +388,12 @@ void System::editSource(String loadPath, bool restoreOnExit) {
helpWidget->createCompletionHelp();
helpWidget->show();
break;
case SB_KEY_INSERT:
statusMessage.setInsert();
widget->edit(event.key, sw, charWidth);
statusMessage.update(editWidget, _output, true);
redraw = true;
break;
case SB_KEY_CTRL('v'):
case SB_KEY_SHIFT(SB_KEY_INSERT):
text = getClipboardText();
Expand Down
8 changes: 1 addition & 7 deletions src/platform/sdl/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@
const int keymap[][2] = {
{SDLK_RETURN, SB_KEY_ENTER},
{SDLK_ESCAPE, SB_KEY_ESCAPE},
{SDLK_KP_PERIOD, SB_KEY_KP_DEL},
{SDLK_KP_ENTER, SB_KEY_KP_ENTER},
{SDLK_KP_DIVIDE, SB_KEY_KP_DIV},
{SDLK_KP_MULTIPLY, SB_KEY_KP_MUL},
{SDLK_KP_MINUS, SB_KEY_KP_MINUS},
{SDLK_KP_PLUS, SB_KEY_KP_PLUS},
{SDLK_KP_EQUALS, '='},
{SDLK_KP_ENTER, SB_KEY_ENTER},
{SDLK_TAB, SB_KEY_TAB},
{SDLK_BACKSPACE, SB_KEY_BACKSPACE},
{SDLK_DELETE, SB_KEY_DELETE},
Expand Down
Loading

0 comments on commit 2ddcb5b

Please sign in to comment.