diff --git a/ChangeLog b/ChangeLog index 4089a1c7..5563c93d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-09-06 + RTE command renamed THROW + +2014-09-01 + Added try/catch + 2014-08-30 Added reference variable type Fixed HASH var handling with parenthesis diff --git a/configure.ac b/configure.ac index e8c8c608..be987b4d 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.11.14]) +AC_INIT([smallbasic], [0.11.15]) AC_CONFIG_SRCDIR([configure.ac]) AC_CANONICAL_TARGET @@ -34,11 +34,6 @@ AC_ARG_ENABLE(sdl, [ac_build_sdl="yes"], [ac_build_sdl="no"]) -AC_ARG_ENABLE(mosync, - AS_HELP_STRING([--enable-mosync],[build common library for Mosync(default=no)]), - [ac_build_mosync="yes"], - [ac_build_mosync="no"]) - AC_ARG_ENABLE(tizen, AS_HELP_STRING([--enable-tizen],[build common library for Tizen(default=no)]), [ac_build_tizen="yes"], @@ -94,9 +89,6 @@ function checkPCRE() { have_pcre="no" esac - if test x$ac_build_mosync = xyes; then - have_pcre="no" - fi if test x$ac_build_tizen = xyes; then have_pcre="no" fi @@ -175,7 +167,6 @@ function buildFLTK() { AC_DEFINE(USE_CLIB, 1, [Implements clibmgr.]) AC_DEFINE(DEV_EVENTS_OSD, 1, [dev_events() implemented using osd_events().]) AC_DEFINE(IMPL_IMAGE, 1, [Driver implements image commands]) - AC_DEFINE(IMPL_HTML, 1, [Driver implements the html command]) AC_DEFINE(IMPL_DEV_GETS, 1, [Driver implements dev_gets()]) AC_DEFINE(IMPL_DEV_DELAY, 1, [Driver implements dev_delay()]) AC_DEFINE(IMPL_DEV_ENV, 1, [Driver implements dev_env funcs]) @@ -243,55 +234,6 @@ function buildSDL() { (cd ide/android/assets && xxd -i main.bas > ../../../src/platform/sdl/main_bas.h) } -function buildMosync() { - TARGET="Building common library for Mosync." - - defaultConditionals - - AC_DEFINE(_UnixOS, 1, [Building under Unix like systems.]) - AC_DEFINE(HAVE_SEARCH_H, 1, [Found GNU search.h]) - AC_DEFINE(HAVE_TDESTROY, 1, [Found GNU search.h]) - AC_DEFINE(INET_UNSUP, 1, [inet not supported.]) - AC_DEFINE(RUN_UNSUP, 1, [run not supported.]) - AC_DEFINE(SERIAL_UNSUP, 1, [serial not supported.]) - AC_DEFINE(DEV_EVENTS_OSD, 1, [dev_events() implemented using osd_events().]) - AC_DEFINE(IMPL_DEV_READ, 1, [Implement dev_read()]) - AC_DEFINE(IMPL_DEV_GETS, 1, [Driver implements dev_gets()]) - AC_DEFINE(IMPL_DEV_DELAY, 1, [Driver implements dev_delay()]) - AC_DEFINE(IMPL_IMAGE, 1, [Driver implements image commands]) - AC_DEFINE(HAVE_MALLOC_USABLE_SIZE, 0, [Newlib version causes mosync stack panic]) - AC_DEFINE(CPU_BIGENDIAN, 1, [Mosync uses big-endian]) - AC_DEFINE(IMPL_LOG_WRITE, 1, [Driver implements lwrite()]) - AC_DEFINE(NONSTANDARD_PORT, 1, [sys.h should include portdefs.h]) - AC_DEFINE(USE_TERM_IO, 0, [Does not use terminal-io functions.]) - AC_DEFINE(_MOSYNC, 1, [Defined for Mosync build.]) - - dnl Checks for mosync - AC_CHECK_PROG(have_mosync, pipe-tool, [yes], [no]) - - PACKAGE_CFLAGS="-MMD -S -DMAPIP -O2 -MF " - - dnl find out where mosync is installed - win32=no - case "${host_os}" in - *mingw* | pw32* | cygwin*) - win32="yes" - esac - if test $win32 = yes; then - MOSYNC_HOME="`which xgcc | cygpath -m -f - | sed 's/\/bin\/xgcc//'`" - EXTN=".exe" - else - dnl see: http://www.mosync.com/documentation/manualpages/building-mosync-source-linux - MOSYNC_HOME=${MOSYNCDIR} - EXTN="" - fi - AC_SUBST(MOSYNC_HOME) - AC_SUBST(EXTN) - - BUILD_SUBDIRS="src/platform/mosync/common" - AC_SUBST(BUILD_SUBDIRS) -} - function buildTizen() { TARGET="Building common library for Tizen." @@ -426,8 +368,6 @@ elif test x$ac_build_fltk = xyes; then buildFLTK elif test x$ac_build_sdl = xyes; then buildSDL -elif test x$ac_build_mosync = xyes; then - buildMosync elif test x$ac_build_tizen = xyes; then buildTizen elif test x$ac_build_android = xyes; then @@ -451,7 +391,6 @@ src/platform/sdl/Makefile src/platform/cygwin/Makefile src/platform/mingw/Makefile src/platform/unix/Makefile -src/platform/mosync/common/Makefile src/platform/tizen/common/Makefile src/platform/android/Makefile ]) diff --git a/debian/changelog b/debian/changelog index 535a8b67..bd30d069 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,8 @@ +smallbasic (0.11.15) unstable; urgency=low + * RTE renamed THROW + + -- Chris Warren-Smith Sat, 6 Sept 2014 09:45:25 +1000 + smallbasic (0.11.14) unstable; urgency=low * Added reference variable type diff --git a/ide/mosync/.cproject b/ide/mosync/.cproject deleted file mode 100755 index c53acbcd..00000000 --- a/ide/mosync/.cproject +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/ide/mosync/.mosyncproject b/ide/mosync/.mosyncproject deleted file mode 100755 index 80f26756..00000000 --- a/ide/mosync/.mosyncproject +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ide/mosync/.project b/ide/mosync/.project deleted file mode 100755 index a865ca50..00000000 --- a/ide/mosync/.project +++ /dev/null @@ -1,30 +0,0 @@ - - - SmallBASIC - - - - - - com.mobilesorcery.sdk.core.builder - - - - - - com.mobilesorcery.sdk.core.nature - org.eclipse.cdt.core.cnature - org.eclipse.cdt.core.ccnature - - - - 1337251003237 - - 6 - - org.eclipse.ui.ide.multiFilter - 1.0-name-matches-false-true-.*rebuild.build.cpp - - - - diff --git a/ide/mosync/AndroidManifest.xml b/ide/mosync/AndroidManifest.xml deleted file mode 100755 index 41f51366..00000000 --- a/ide/mosync/AndroidManifest.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ide/mosync/workfile.rb b/ide/mosync/workfile.rb deleted file mode 100755 index f50dd7ad..00000000 --- a/ide/mosync/workfile.rb +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/ruby - -# -#./workfile.rb CONFIG="debug" USE_NEWLIB=1 PACK="Android/Android 2.x" -# - -require File.expand_path(ENV['MOSYNCDIR']+'/rules/mosync_exe.rb') - -work = PipeExeWork.new -work.instance_eval do - @SOURCES = ["src/platform/mosync"] - @EXTRA_CPPFLAGS = " -Wno-shadow -Wno-missing-format-attribute -DHAVE_CONFIG_H" - @EXTRA_INCLUDES = [".", "src", "src/platform/mosync/common", "#{mosyncdir}/include/newlib"] - @LIBRARIES = ["mautil", "libsb_common.a"] - @EXTRA_LINKFLAGS = " -datasize=2048576 -heapsize=786432 -stacksize=65536 " - @NAME = "SmallBASIC" -end - -work.invoke - diff --git a/samples/distro-examples/graphics/3dtorus.bas b/samples/distro-examples/graphics/3dtorus.bas old mode 100755 new mode 100644 index f6e97197..e1f735f4 --- a/samples/distro-examples/graphics/3dtorus.bas +++ b/samples/distro-examples/graphics/3dtorus.bas @@ -47,6 +47,7 @@ repeat anglez = (anglez + 1) mod 360 RotateAndProject Model(), anglex, angley, anglez DrawModel Model() , Poly() + SHOWPAGE until end diff --git a/samples/distro-examples/tests/output/ptr.out b/samples/distro-examples/tests/output/ptr.out new file mode 100644 index 00000000..92de1c2f --- /dev/null +++ b/samples/distro-examples/tests/output/ptr.out @@ -0,0 +1,4 @@ +foo: called from ptr @foo +foo: called from ptr p +in bar +in bar diff --git a/samples/distro-examples/tests/output/trycatch.out b/samples/distro-examples/tests/output/trycatch.out new file mode 100644 index 00000000..7f900ba1 --- /dev/null +++ b/samples/distro-examples/tests/output/trycatch.out @@ -0,0 +1,6 @@ +start +inner try +open failed FS(2): NO SUCH FILE OR DIRECTORY +after try +catch by error name +outer after try diff --git a/samples/distro-examples/tests/proc.bas b/samples/distro-examples/tests/proc.bas index 55402210..48e8aaeb 100644 --- a/samples/distro-examples/tests/proc.bas +++ b/samples/distro-examples/tests/proc.bas @@ -9,7 +9,7 @@ next vn()=va() for i=0 to 4 if ( va(i) <> vn(i) ) - rte "array copy error" + throw "array copy error" fi next diff --git a/samples/distro-examples/tests/ptr.bas b/samples/distro-examples/tests/ptr.bas new file mode 100644 index 00000000..cbf4e0dd --- /dev/null +++ b/samples/distro-examples/tests/ptr.bas @@ -0,0 +1,16 @@ +func foo(s) + foo="foo: " + s +end + +sub bar + ? "in bar" +end + +p = @foo +? call(@foo, "called from ptr @foo") +? call(p, "called from ptr p") + +pb = @bar +call pb +call @bar + diff --git a/samples/distro-examples/tests/trycatch.bas b/samples/distro-examples/tests/trycatch.bas new file mode 100644 index 00000000..d3b1684b --- /dev/null +++ b/samples/distro-examples/tests/trycatch.bas @@ -0,0 +1,43 @@ +? "start" +try + ? "inner try" + if (1==1) then + try + catch + ? "should never be printed" + end try + if (2==2) then + try + open "com2000:" AS #1 + try + ? "should never be printed" + catch + ? "should never be printed" + end try + ? "should never be printed" + catch "err" + ? "should never be printed" + catch err + ? "open failed", err + end try + ? "after try + throw "an error has occurred" + ? "should never be printed" + fi + fi + try + ? "should never be printed" + catch + ? "should never be printed" + end try + open "com2000:" AS #1 + ? "should never be printed" +catch "some error that is not thrown" + ? "should never be printed" +catch "an error has occurred" + ? "catch by error name" +end try + +? "outer after try" + + diff --git a/src/common/blib.c b/src/common/blib.c index f3bb63b4..34cb336a 100644 --- a/src/common/blib.c +++ b/src/common/blib.c @@ -893,50 +893,6 @@ void cmd_input(int input) { v_free(&prompt); } -/** - * RTE ... - */ -void cmd_RTE() { - code_t code; - byte last_op = 0, exitf = 0; - var_t var; - - dev_printf("\n\a%s %s:%d: ", WORD_ERROR_AT, prog_file, prog_line); - do { - code = code_peek(); - switch (code) { - case kwTYPE_LINE: - case kwTYPE_EOC: - exitf = 1; - break; - case kwTYPE_SEP: - code_skipnext(); - last_op = code_getnext(); - if (last_op == ',') { - dev_print("\t"); - } - break; - default: - last_op = 0; - v_init(&var); - eval(&var); - if (!prog_error) { - print_var(&var); - } - v_free(&var); - }; - - if (prog_error) { - return; - } - } while (exitf == 0); - - if (last_op == 0) { - dev_print("\n"); - } - prog_error = 0x1000; -} - /** * ON x GOTO|GOSUB ... */ @@ -2906,23 +2862,6 @@ void cmd_exprseq(void) { } } -/** - * HTML html, [title,] [x,y,w,h] - * Display html text - */ -void cmd_html() { - char *html = 0; - char *title = 0; - var_int_t x, y, w, h; - - x = y = w = h = 0; - par_massget("Ssiiii", &html, &title, &x, &y, &w, &h); - if (!prog_error) { - dev_html(html, title, x, y, w, h); - } - pfree2(html, title); -} - /** * IMAGE #handle, index, x, y [,sx,sy [,w,h]] * Display html text @@ -2963,8 +2902,8 @@ void cmd_select() { v_init(expr); eval(expr); - node.x.vfor.var_ptr = expr; - node.x.vfor.flags = 0; + node.x.vcase.var_ptr = expr; + node.x.vcase.flags = 0; node.type = kwSELECT; code_push(&node); } @@ -2992,13 +2931,13 @@ void cmd_case() { return; } - if (node->x.vfor.flags) { + if (node->x.vcase.flags) { // previous case already matches. code_jump(false_ip); } else { // compare select expr with case expr - node->x.vfor.flags = v_compare(node->x.vfor.var_ptr, &var_p) == 0 ? 1 : 0; - code_jump(node->x.vfor.flags ? true_ip : false_ip); + node->x.vcase.flags = v_compare(node->x.vcase.var_ptr, &var_p) == 0 ? 1 : 0; + code_jump(node->x.vcase.flags ? true_ip : false_ip); } v_free(&var_p); @@ -3014,7 +2953,7 @@ void cmd_case_else() { true_ip = code_getaddr(); // default block false_ip = code_getaddr(); // end-select node = code_stackpeek(); - code_jump(node->x.vfor.flags ? false_ip : true_ip); + code_jump(node->x.vcase.flags ? false_ip : true_ip); } /** @@ -3026,10 +2965,10 @@ void cmd_end_select() { code_pop(&node); // if v_new() was string or array release the allocated memory - v_free(node.x.vfor.var_ptr); + v_free(node.x.vcase.var_ptr); // cleanup v_new() - tmp_free(node.x.vfor.var_ptr); + tmp_free(node.x.vcase.var_ptr); code_jump(code_getaddr()); } @@ -3059,3 +2998,14 @@ void cmd_definekey(void) { v_free(&var); } +void cmd_catch() { + addr_t end_try_ip = code_getaddr(); + addr_t outer_catch_ip = code_getaddr(); + + // cleanup the catch address, then skip to end-try + code_jump(end_try_ip); + + // restore outer try/catch level + prog_catch_ip = outer_catch_ip; +} + diff --git a/src/common/blib.h b/src/common/blib.h index 72ac95d9..4d9da71f 100644 --- a/src/common/blib.h +++ b/src/common/blib.h @@ -30,7 +30,6 @@ void cmd_udpret(void); void cmd_crvar(void); void cmd_param(void); int cmd_exit(void); -void cmd_RTE(void); void cmd_let(int); void cmd_dim(int); void cmd_redim(void); @@ -72,6 +71,7 @@ void cmd_poke16(void); void cmd_poke32(void); void cmd_bcopy(void); void cmd_calladr(void); +void cmd_catch(); var_num_t cmd_math1(long funcCode, var_t *arg); var_int_t cmd_imath1(long funcCode, var_t *arg); @@ -167,7 +167,6 @@ void cmd_dirwalk(void); void cmd_bputc(void); void cmd_bload(void); void cmd_bsave(void); -void cmd_html(void); void cmd_image(void); void cmd_definekey(void); diff --git a/src/common/brun.c b/src/common/brun.c index f7a2c2c3..8e4fcddd 100755 --- a/src/common/brun.c +++ b/src/common/brun.c @@ -26,22 +26,7 @@ #include "common/pproc.h" int brun_create_task(const char *filename, mem_t preloaded_bc, int libf); -int exec_close_task(); -void exec_setup_predefined_variables(); -var_t *code_isvar_arridx(var_t *basevar_p); -void code_pop_until(int type); -void code_pop_and_free(stknode_t *node); -stknode_t *code_stackpeek(); void sys_before_comp(); -int sbasic_exec_task(int tid); -int sbasic_recursive_exec(int tid); -void sbasic_exec_prepare(const char *filename); -int sbasic_exec(const char *file); -int sbasic_main(const char *file); -int exec_close(int tid); -int sbasic_exec(const char *file); -void cmd_options(void); -var_t *code_resolve_varptr(var_t *var_p, int until_parens); static dword evt_check_every; static char fileName[OS_FILENAME_SIZE + 1]; @@ -223,7 +208,7 @@ addr_t getarrayidx(var_t *array, var_t **var_hash_val) { IF_ERR_RETURN_0; if (var.type == V_STR || array->type == V_HASH) { - // array elemement is a string or element is addressing a hash + // array element is a string or element is addressing a hash hash_get_value(array, &var, var_hash_val); if (code_peek() == kwTYPE_LEVEL_END) { @@ -315,6 +300,9 @@ var_t *code_getvarptr_arridx(var_t *basevar_p) { * resolve a composite variable reference, eg: ar.ch(0).foo */ var_t *code_resolve_varptr(var_t *var_p, int until_parens) { + if (var_p && var_p->type == V_REF) { + var_p = eval_ref_var(var_p); + } if (var_p) { switch (code_peek()) { case kwTYPE_LEVEL_BEGIN: @@ -734,8 +722,8 @@ static inline void bc_loop_call_proc() { case kwCLS: graph_reset(); break; - case kwRTE: - cmd_RTE(); + case kwTHROW: + cmd_throw(); break; case kwENVIRON: cmd_environ(); @@ -920,9 +908,6 @@ static inline void bc_loop_call_proc() { // end of program prog_error = -1; break; - case kwHTML: - cmd_html(); - break; case kwIMAGE: cmd_image(); break; @@ -1278,6 +1263,16 @@ void bc_loop(int isf) { case kwEXEC: cmd_run(0); break; + case kwTRY: + prog_catch_ip = code_getaddr(); + IF_ERR_BREAK; + continue; + case kwCATCH: + cmd_catch(); + IF_ERR_BREAK; + continue; + case kwENDTRY: + continue; default: rt_raise("SEG:CODE[%d]=%02x", prog_ip, prog_source[prog_ip]); dev_printf("OUT OF ADDRESS SPACE\n"); @@ -1438,18 +1433,14 @@ int brun_create_task(const char *filename, mem_t preloaded_bc, int libf) { cp += sizeof(unit_sym_t); } } - } else if (memcmp(source, "SBEx", 4) == 0) { // load an executable - ; - } else { // signature error + } else if (memcmp(source, "SBEx", 4) == 0) { + // load an executable + } else { + // signature error panic("Wrong bytecode signature"); } - /* - * --------------------- - * build executor's task - * --------------------- - */ - + // build executor's task memcpy(&hdr, cp, sizeof(bc_head_t)); cp += sizeof(bc_head_t); @@ -1495,6 +1486,7 @@ int brun_create_task(const char *filename, mem_t preloaded_bc, int libf) { prog_stack_alloc = SB_EXEC_STACK_SIZE; prog_stack = tmp_alloc(sizeof(stknode_t) * prog_stack_alloc); prog_stack_count = 0; + prog_catch_ip = INVALID_ADDR; // create eval's stack eval_size = 64; @@ -1923,8 +1915,12 @@ int sbasic_exec(const char *file) { int success = 0; int exec_rq = 1; - // setup some default options - opt_pref_width = opt_pref_height = opt_pref_bpp = 0; + // init compile-time options + opt_pref_bpp = 0; + opt_pref_width = 0; + opt_pref_height = 0; + opt_show_page = 0; + if (opt_decomp) { opt_nosave = 1; } diff --git a/src/common/device.c b/src/common/device.c index e473344f..d0972155 100644 --- a/src/common/device.c +++ b/src/common/device.c @@ -697,11 +697,6 @@ void log_printf(const char *format, ...) { #endif } -#ifndef IMPL_HTML -void dev_html(const char *html, const char *title, int x, int y, int w, int h) { -} -#endif - #ifndef IMPL_IMAGE void dev_image(int handle, int index, int x, int y, int sx, int sy, int w, int h) { } diff --git a/src/common/file.c b/src/common/file.c index ab3d3a3a..cd4765d7 100644 --- a/src/common/file.c +++ b/src/common/file.c @@ -451,7 +451,7 @@ int dev_fremove(const char *file) { success = (remove(file) == 0); } if (!success) { - rt_raise(FSERR_ACCESS); + err_throw(FSERR_ACCESS); } return success; } @@ -598,7 +598,6 @@ void dev_mkdir(const char *dir) { /** * removes a directory - * BUG: no drivers supported */ void dev_rmdir(const char *dir) { if (!opt_file_permitted) { @@ -612,7 +611,6 @@ void dev_rmdir(const char *dir) { /** * changes the current directory - * BUG: no drivers supported */ void dev_chdir(const char *dir) { if (chdir(dir) != 0) { diff --git a/src/common/kw.h b/src/common/kw.h index 08dc0ec2..8586f148 100644 --- a/src/common/kw.h +++ b/src/common/kw.h @@ -170,6 +170,9 @@ enum keyword { // line 50 kwCASE, kwCASE_ELSE, kwENDSELECT, + kwTRY, + kwCATCH, + kwENDTRY, kwNULL }; @@ -181,7 +184,6 @@ enum keyword { // line 50 */ enum proc_keywords { kwCLS = 0x100, // 256 (generic keywords) - kwRTE, kwSHELL, kwENVIRON, kwLOCATE, @@ -241,16 +243,14 @@ enum proc_keywords { kwBPUTC, kwBLOAD, kwBSAVE, - kwIMGGET, - kwIMGPUT, kwTIMEHMS, kwEXPRSEQ, kwUNLOADLIB, kwCALLCP, - kwHTML, kwIMAGE, kwDEFINEKEY, kwSHOWPAGE, + kwTHROW, kwNULLPROC }; @@ -405,7 +405,6 @@ enum func_keywords { kwSEQ, kwCBS, kwBCS, - kwLOADLIB, kwCALLCF, kwIMGW, kwIMGH, diff --git a/src/common/pproc.h b/src/common/pproc.h index 9ef7eaef..b427126e 100644 --- a/src/common/pproc.h +++ b/src/common/pproc.h @@ -67,20 +67,11 @@ void eval(var_t *result); /** * @ingroup exec * - * allocate stack for eval(). used only by brun(). + * resolve the variable reference * - * @note avoid to use it - */ -void eval_alloc_stack(void); - -/** - * @ingroup exec - * - * free eval()'s stack. used only by brun(). - * - * @note avoid to use it + * @param var_t */ -void eval_free_stack(void); +var_t *eval_ref_var(var_t *var_p); /** * @ingroup exec @@ -157,8 +148,8 @@ typedef struct { } par_t; /* par_t flags */ -#define PAR_BYVAL 1 -/**< pat_t::flags, parameter was an expression +#define PAR_BYVAL 1 +/**< pat_t::flags, parameter was an expression (var = the temporary copy of the result) @ingroup par */ /** diff --git a/src/common/proc.c b/src/common/proc.c index e265e854..49f0c384 100644 --- a/src/common/proc.c +++ b/src/common/proc.c @@ -336,6 +336,9 @@ void pv_writevar(var_t *var, int method, int handle) { case V_ARRAY: pv_write_array(var, method, handle); break; + case V_REF: + pv_writevar(var->v.ref, method, handle); + break; } } diff --git a/src/common/sberr.c b/src/common/sberr.c index b9ccdcb6..a10c4902 100644 --- a/src/common/sberr.c +++ b/src/common/sberr.c @@ -92,7 +92,7 @@ void err_file(dword code) { *p = to_upper(*p); p++; } - rt_raise(FSERR_FMT, code, buf); + err_throw(FSERR_FMT, code, buf); } void err_stackoverflow(void) { @@ -261,9 +261,7 @@ void inf_done() { #endif } -/** - * the BREAK message - */ +// the BREAK message void inf_break(int pline) { gsb_last_line = pline; gsb_last_error = prog_error; @@ -274,36 +272,78 @@ void inf_break(int pline) { log_printf("\n\033[0m\033[80m\a\033[7m * %s %d * \033[0m\n", WORD_BREAK_AT, pline); } -/** - * if bytecode files are keeped; messages of the compiler why recompile is needed - */ -void inf_comprq_dv() { - if (!opt_quiet) { - dev_print("Recompile: different version\n"); - } else { - dev_print("(ver)\n"); +// assign error to variable or match with next expression +int err_throw_catch(const char *err) { + int caught = 1; + byte code = code_peek(); + + if (code != kwTYPE_EOC && code != kwTYPE_LINE) { + if (code_peek() == kwTYPE_VAR) { + var_t *arg = code_getvarptr(); + v_setstr(arg, err); + } else { + var_t v_catch; + v_init(&v_catch); + eval(&v_catch); + // catch is conditional on matching error + caught = (v_catch.type == V_STR && strstr(err, v_catch.v.p.ptr) != NULL); + v_free(&v_catch); + } + } + return caught; +} + +// throw string +void err_throw_str(const char *err) { + int caught = 0; + if (!prog_error && prog_catch_ip != INVALID_ADDR && prog_catch_ip > prog_ip) { + // position after kwCATCH + code_jump(prog_catch_ip + 1); + // skip "end try" address + code_getaddr(); + // restore outer level + prog_catch_ip = code_getaddr(); + + caught = err_throw_catch(err); + while (!caught && prog_catch_ip != INVALID_ADDR) { + code_jump(prog_catch_ip + 1); + code_getaddr(); + prog_catch_ip = code_getaddr(); + caught = err_throw_catch(err); + } + } + if (!caught) { + prog_error = 0x80; + err_common_msg(WORD_RTE, prog_file, prog_line, err); } } -void inf_comprq_dt() { - if (!opt_quiet) { - dev_print("Recompile: source is newer\n"); - } else { - dev_print("(mod)\n"); +// throw internal error +void err_throw(const char *fmt, ...) { + if (!gsb_last_error) { + va_list ap; + va_start(ap, fmt); + char *err = tmp_alloc(SB_TEXTLINE_SIZE + 1); + vsprintf(err, fmt, ap); + va_end(ap); + err_throw_str(err); + tmp_free(err); } } -void inf_comprq_prq() { - if (!opt_quiet) { - dev_print("Recompile: no binary file\n"); - } else { - dev_print("(bin)\n"); +// throw user error +void cmd_throw() { + var_t v_throw; + v_init(&v_throw); + const char *err = ""; + byte code = code_peek(); + if (code != kwTYPE_EOC && code != kwTYPE_LINE) { + eval(&v_throw); + if (v_throw.type == V_STR) { + err = v_throw.v.p.ptr; + } } + err_throw_str(err); + v_free(&v_throw); } -/** - * Low-battery event/signal - */ -void inf_low_battery() { - dev_print("\n\n\a* ALARM: LOW BATTERY *\a\n\n"); -} diff --git a/src/common/sberr.h b/src/common/sberr.h index 2d61b48e..fb86648d 100644 --- a/src/common/sberr.h +++ b/src/common/sberr.h @@ -72,14 +72,11 @@ void err_ref_var(); #define err_type_mismatch() err_typemismatch() #define err_syntax_error() err_syntax() -// --- inf_xxx: information messages - void inf_done(void); void inf_break(int pline); -void inf_comprq_dv(void); -void inf_comprq_dt(void); -void inf_comprq_prq(void); -void inf_low_battery(void); + +void err_throw(const char *fmt, ...); +void cmd_throw(); #if defined(__cplusplus) } diff --git a/src/common/scan.c b/src/common/scan.c index bad46e80..af3a5792 100644 --- a/src/common/scan.c +++ b/src/common/scan.c @@ -1128,7 +1128,9 @@ void comp_expression(char *expr, byte no_parser) { if (idx == -1) { idx = comp_is_proc(comp_bc_name); } - if (idx != -1) { + if (idx == kwBYREF) { + bc_add_code(&bc, kwBYREF); + } else if (idx != -1) { sc_raise(MSG_STATEMENT_ON_RIGHT, comp_bc_name); } else { // UDF OR VARIABLE @@ -2378,6 +2380,21 @@ void comp_text_line(char *text) { } break; + case kwTRY: + comp_block_level++; + comp_block_id++; + comp_push(comp_prog.count); + bc_add_code(&comp_prog, idx); + bc_add_addr(&comp_prog, 0); + comp_expression(comp_bc_parm, 0); + break; + + case kwCATCH: + comp_push(comp_prog.count); + bc_add_ctrl(&comp_prog, idx, 0, 0); + comp_expression(comp_bc_parm, 0); + break; + case kwELSE: case kwELIF: { int index = 0; @@ -2432,10 +2449,17 @@ void comp_text_line(char *text) { break; case kwEND: - if (strncmp(comp_bc_parm, LCN_IF, 2) == 0 || strncmp(comp_bc_parm, LCN_SELECT, 6) == 0) { - idx = strncmp(comp_bc_parm, LCN_IF, 2) == 0 ? kwENDIF : kwENDSELECT; + if (strncmp(comp_bc_parm, LCN_IF, 2) == 0 || + strncmp(comp_bc_parm, LCN_TRY, 3) == 0 || + strncmp(comp_bc_parm, LCN_SELECT, 6) == 0) { + idx = strncmp(comp_bc_parm, LCN_IF, 2) == 0 ? kwENDIF : + strncmp(comp_bc_parm, LCN_TRY, 3) == 0 ? kwENDTRY : kwENDSELECT; comp_push(comp_prog.count); - bc_add_ctrl(&comp_prog, idx, 0, 0); + if (idx == kwENDTRY) { + bc_add_code(&comp_prog, idx); + } else { + bc_add_ctrl(&comp_prog, idx, 0, 0); + } comp_block_level--; comp_block_id--; } else if (comp_proc_level) { @@ -2578,6 +2602,7 @@ addr_t comp_next_bc_cmd(addr_t ip) { ip++; break; + case kwTRY: case kwRESTORE: case kwGOSUB: case kwTYPE_LINE: @@ -2622,6 +2647,7 @@ addr_t comp_next_bc_cmd(addr_t ip) { case kwCASE: case kwCASE_ELSE: case kwENDSELECT: + case kwCATCH: ip += BC_CTRLSZ; break; @@ -2674,7 +2700,6 @@ addr_t comp_search_bc_stack(addr_t start, code_t code, byte level, bid_t block_i for (i = start; i < comp_sp; i++) { dbt_read(comp_stack, i, &node, sizeof(comp_pass_node_t)); - if (comp_prog.ptr[node.pos] == code) { if (node.level == level && (block_id == -1 || block_id == node.block_id)) { return node.pos; @@ -2704,6 +2729,34 @@ addr_t comp_search_bc_stack_backward(addr_t start, code_t code, byte level, bid_ return INVALID_ADDR; } +/* + * search stack for the next inner catch + */ +addr_t comp_search_inner_catch(addr_t start, byte level) { + addr_t result = INVALID_ADDR; + if (level > 1) { + byte nextLevel = level - 1; + do { + addr_t i; + comp_pass_node_t node; + for (i = start; i < comp_sp; i++) { + dbt_read(comp_stack, i, &node, sizeof(comp_pass_node_t)); + if (node.level == nextLevel) { + if (comp_prog.ptr[node.pos] == kwTRY) { + // next CATCH has own block + break; + } else if (comp_prog.ptr[node.pos] == kwCATCH) { + result = node.pos; + break; + } + } + } + --nextLevel; + } while (result == INVALID_ADDR && nextLevel > 0); + } + return result; +} + /* * inspect the byte-code at the given location */ @@ -2740,7 +2793,7 @@ void print_pass2_stack(addr_t pos, code_t lcode, int level) { for (i = pos + 1; i < comp_sp; i++) { dbt_read(comp_stack, i, &node, sizeof(comp_pass_node_t)); if (comp_prog.ptr[node.pos] == code) { - log_printf("\n%s found on level %d (@%d) instead of %d (@%d+)\n", + log_printf("\n%s found on level %d (@%d) instead of %d (@%d+)\n", cmd, node.level, node.pos, level, pos); cnt++; if (cnt > 3) { @@ -2749,11 +2802,11 @@ void print_pass2_stack(addr_t pos, code_t lcode, int level) { } } } else { - log_printf("\n%s found on level %d (@%d) instead of %d (@%d+)\n", + log_printf("\n%s found on level %d (@%d) instead of %d (@%d+)\n", cmd, level + 1, node.pos, level, pos); } } else { - log_printf("\n%s found on level %d (@%d) instead of %d (@%d+)\n", + log_printf("\n%s found on level %d (@%d) instead of %d (@%d+)\n", cmd, level - 1, node.pos, level, pos); } @@ -2790,7 +2843,7 @@ void print_pass2_stack(addr_t pos, code_t lcode, int level) { csum[cs_idx] = 1; } // info - log_printf("%s%4d: %16s %16s %6d %6d %5d %5d %5d\n", ((i == pos) ? ">>" : " "), + log_printf("%s%4d: %16s %16s %6d %6d %5d %5d %5d\n", ((i == pos) ? ">>" : " "), i, cmd, node.sec, node.pos, node.line, node.level, node.block_id, csum[cs_idx]); } @@ -2890,6 +2943,9 @@ void comp_pass2_scan() { code != kwTYPE_CALL_UDF && code != kwPROC && code != kwFUNC && + code != kwTRY && + code != kwCATCH && + code != kwENDTRY && code != kwTYPE_RET) { // default - calculate true-ip true_ip = comp_search_bc_eoc(node.pos + (BC_CTRLSZ + 1)); @@ -3165,6 +3221,36 @@ void comp_pass2_scan() { return; } break; + + case kwTRY: + true_ip = comp_search_bc_stack(i + 1, kwCATCH, node.level, node.block_id); + if (true_ip == INVALID_ADDR) { + sc_raise(MSG_MISSING_CATCH); + print_pass2_stack(i, kwTRY, node.level); + return; + } + memcpy(comp_prog.ptr + node.pos + 1, &true_ip, ADDRSZ); + break; + + case kwCATCH: + true_ip = comp_search_bc_stack(i + 1, kwENDTRY, node.level, node.block_id); + if (true_ip == INVALID_ADDR) { + sc_raise(MSG_MISSING_ENDTRY); + print_pass2_stack(i, kwENDTRY, node.level); + return; + } + memcpy(comp_prog.ptr + node.pos + 1, &true_ip, ADDRSZ); + + false_ip = comp_search_bc_stack(i + 1, kwCATCH, node.level, node.block_id); + if (false_ip != INVALID_ADDR && false_ip < true_ip) { + // another catch in the same block + memcpy(comp_prog.ptr + node.pos + (ADDRSZ + 1), &false_ip, ADDRSZ); + } else { + // store the address of the next outer catch (or store INVALID_ADDR if not found) + false_ip = comp_search_inner_catch(i + 1, node.level); + memcpy(comp_prog.ptr + node.pos + (ADDRSZ + 1), &false_ip, ADDRSZ); + } + break; }; } @@ -3299,13 +3385,12 @@ void comp_close() { */ char *comp_load(const char *file_name) { char *buf; - int h; strcpy(comp_file_name, file_name); #if defined(IMPL_DEV_READ) buf = dev_read(file_name); #else - h = open(comp_file_name, O_BINARY | O_RDONLY, 0644); + int h = open(comp_file_name, O_BINARY | O_RDONLY, 0644); if (h == -1) { buf = NULL; #if defined(__CYGWIN__) diff --git a/src/common/smbas.h b/src/common/smbas.h index c4ee5411..7ed53c21 100644 --- a/src/common/smbas.h +++ b/src/common/smbas.h @@ -164,6 +164,7 @@ EXTERN char gsb_last_errmsg[SB_ERRMSG_SIZE + 1]; /**< last error message #define prog_symtable ctask->sbe.exec.symtable #define prog_exptable ctask->sbe.exec.exptable #define prog_uds_tab_ip ctask->sbe.exec.uds_tab_ip +#define prog_catch_ip ctask->sbe.exec.catch_ip #define comp_extfunctable ctask->sbe.comp.extfunctable #define comp_extfunccount ctask->sbe.comp.extfunccount #define comp_extfuncsize ctask->sbe.comp.extfuncsize diff --git a/src/common/tasks.h b/src/common/tasks.h index 0e64549e..56844b9b 100644 --- a/src/common/tasks.h +++ b/src/common/tasks.h @@ -148,6 +148,7 @@ typedef struct { bc_lib_rec_t *libtable; /**< import-libraries table */ bc_symbol_rec_t *symtable; /**< import-symbols table */ unit_sym_t *exptable; /**< export-symbols table */ + addr_t catch_ip; /** try/catch ip */ } exec; } sbe; } task_t; diff --git a/src/common/var.h b/src/common/var.h index cd2ed77f..2dede6d3 100644 --- a/src/common/var.h +++ b/src/common/var.h @@ -158,6 +158,14 @@ struct stknode_s { addr_t lcond; /**< result of the last condition */ } vif; + /** + * SELECT CASE + */ + struct { + var_t *var_ptr; + byte flags; + } vcase; + /** * GOSUB */ @@ -193,7 +201,6 @@ struct stknode_s { word vcheck; /**< checks (1=BYVAL ONLY, 3=BYVAL|BYREF, 2=BYREF ONLY) */ var_t *res; /**< variable pointer (for BYVAL this is a clone) */ } param; - } x; }; typedef struct stknode_s stknode_t; diff --git a/src/languages/keywords.en.c b/src/languages/keywords.en.c index 8e85c3ec..a037b700 100644 --- a/src/languages/keywords.en.c +++ b/src/languages/keywords.en.c @@ -90,6 +90,9 @@ struct keyword_s keyword_table[] = { { "WRITE", kwFILEWRITE }, { "INSERT", kwINSERT }, { "DELETE", kwDELETE }, +{ "TRY", kwTRY }, +{ "CATCH", kwCATCH }, +{ "END TRY", kwENDTRY }, /* DEBUG */ { "TRON", kwTRON }, @@ -343,7 +346,6 @@ struct func_keyword_s func_table[] = { { "SEQ", kwSEQ }, { "CBS", kwCBS }, { "BCS", kwBCS }, -{ "LOADLIB", kwLOADLIB }, { "CALL", kwCALLCF }, { "IMAGEW", kwIMGW }, { "IMAGEH", kwIMGH }, @@ -355,7 +357,7 @@ struct func_keyword_s func_table[] = { */ struct proc_keyword_s proc_table[] = { { "CLS", kwCLS }, -{ "RTE", kwRTE }, +{ "THROW", kwTHROW }, { "ENVIRON", kwENVIRON }, { "ENV", kwENVIRON }, { "LOCATE", kwLOCATE }, @@ -414,13 +416,10 @@ struct proc_keyword_s proc_table[] = { { "BPUTC", kwBPUTC }, { "BLOAD", kwBLOAD }, { "BSAVE", kwBSAVE }, -{ "IMGGET", kwIMGGET }, -{ "IMGPUT", kwIMGPUT }, { "TIMEHMS", kwTIMEHMS }, { "EXPRSEQ", kwEXPRSEQ }, { "UNLOADLIB", kwUNLOADLIB }, { "CALL", kwCALLCP }, -{ "HTML", kwHTML }, { "IMAGE", kwIMAGE }, { "DEFINEKEY", kwDEFINEKEY }, { "SHOWPAGE", kwSHOWPAGE }, @@ -483,6 +482,9 @@ struct proc_keyword_s proc_table[] = { #define LCN_END_WRS "END " #define LCN_END_WNL "END\n" #define LCN_SHOWPAGE "SHOWPAGE" +#define LCN_TRY "TRY" +#define LCN_CATCH "CATCH" +#define LCN_END_TRY "END TRY" /* system variables */ #define LCN_SV_OSNAME "OSNAME" diff --git a/src/languages/messages.en.h b/src/languages/messages.en.h index 09539950..2da9b676 100644 --- a/src/languages/messages.en.h +++ b/src/languages/messages.en.h @@ -118,6 +118,8 @@ #define MSG_MISSING_END_SELECT "SELECT/CASE without 'END SELECT'" #define MSG_MISSING_SELECT "END SELECT without SELECT" #define MSG_MISSING_CASE "SELECT without CASE" +#define MSG_MISSING_CATCH "TRY without CATCH" +#define MSG_MISSING_ENDTRY "TRY without END TRY" // executor #define WORD_ERROR_AT "ERROR AT" diff --git a/src/platform/android/jni/Android.mk b/src/platform/android/jni/Android.mk index 5b10f78e..237a447d 100644 --- a/src/platform/android/jni/Android.mk +++ b/src/platform/android/jni/Android.mk @@ -24,15 +24,15 @@ LOCAL_CFLAGS := -DHAVE_CONFIG_H=1 LOCAL_C_INCLUDES := $(SB_HOME) $(SB_HOME)/src \ $(FREETYPE_HOME)/freetype/include \ $(FREETYPE_HOME)/freetype/include/freetype2 -LOCAL_SRC_FILES := main.cpp \ - display.cpp \ - runtime.cpp \ - ../../common/screen.cpp \ - ../../common/ansiwidget.cpp \ - ../../common/form_ui.cpp \ - ../../common/StringLib.cpp \ - ../../common/graphics.cpp \ - ../../common/system.cpp +LOCAL_SRC_FILES := main.cpp \ + display.cpp \ + runtime.cpp \ + ../../../ui/screen.cpp \ + ../../../ui/ansiwidget.cpp \ + ../../../ui/form_ui.cpp \ + ../../../ui/StringLib.cpp \ + ../../../ui/graphics.cpp \ + ../../../ui/system.cpp LOCAL_LDLIBS := -llog -landroid -ljnigraphics LOCAL_STATIC_LIBRARIES := sb_common png freetype android_native_app_glue include $(BUILD_SHARED_LIBRARY) diff --git a/src/platform/android/jni/common/Android.mk b/src/platform/android/jni/common/Android.mk index 88b7b0ad..7b5bfefe 100644 --- a/src/platform/android/jni/common/Android.mk +++ b/src/platform/android/jni/common/Android.mk @@ -52,7 +52,6 @@ LOCAL_SRC_FILES := \ $(COMMON)/str.c \ $(COMMON)/tasks.c \ $(COMMON)/search.c \ - $(COMMON)/var_uds.c \ $(COMMON)/var_hash.c \ $(COMMON)/keymap.c \ $(COMMON)/units.c \ diff --git a/src/platform/android/jni/display.cpp b/src/platform/android/jni/display.cpp index c728ae2e..23be502e 100644 --- a/src/platform/android/jni/display.cpp +++ b/src/platform/android/jni/display.cpp @@ -9,8 +9,8 @@ #include "config.h" #include #include "platform/android/jni/display.h" -#include "platform/common/form_ui.h" -#include "platform/common/utils.h" +#include "ui/form_ui.h" +#include "ui/utils.h" #include "common/device.h" #define FONT_FACE_REGULAR "Envy Code R.ttf" diff --git a/src/platform/android/jni/display.h b/src/platform/android/jni/display.h index d4eacf1d..0a38a89a 100644 --- a/src/platform/android/jni/display.h +++ b/src/platform/android/jni/display.h @@ -12,9 +12,9 @@ #include #include -#include "platform/common/maapi.h" -#include "platform/common/StringLib.h" -#include "platform/common/graphics.h" +#include "ui/maapi.h" +#include "ui/StringLib.h" +#include "ui/graphics.h" using namespace strlib; diff --git a/src/platform/android/jni/runtime.cpp b/src/platform/android/jni/runtime.cpp index 2d88e8a1..0471f672 100644 --- a/src/platform/android/jni/runtime.cpp +++ b/src/platform/android/jni/runtime.cpp @@ -12,9 +12,9 @@ #include #include "platform/android/jni/runtime.h" -#include "platform/common/maapi.h" -#include "platform/common/utils.h" -#include "platform/common/form_ui.h" +#include "ui/maapi.h" +#include "ui/utils.h" +#include "ui/form_ui.h" #include "common/sbapp.h" #include "common/sys.h" #include "common/smbas.h" diff --git a/src/platform/android/jni/runtime.h b/src/platform/android/jni/runtime.h index b0da0dee..6b80a56d 100644 --- a/src/platform/android/jni/runtime.h +++ b/src/platform/android/jni/runtime.h @@ -10,10 +10,10 @@ #define RUNTIME_H #include "config.h" -#include "platform/common/maapi.h" -#include "platform/common/interface.h" -#include "platform/common/ansiwidget.h" -#include "platform/common/system.h" +#include "ui/maapi.h" +#include "ui/interface.h" +#include "ui/ansiwidget.h" +#include "ui/system.h" #include "platform/android/jni/display.h" #include diff --git a/src/platform/fltk/BasicEditor.h b/src/platform/fltk/BasicEditor.h index 1bd45a50..c8a6f8c9 100644 --- a/src/platform/fltk/BasicEditor.h +++ b/src/platform/fltk/BasicEditor.h @@ -14,7 +14,7 @@ #define BASIC_EDITOR_H #include -#include "platform/common/StringLib.h" +#include "ui/StringLib.h" using namespace fltk; diff --git a/src/platform/fltk/EditorWidget.h b/src/platform/fltk/EditorWidget.h index 343df45f..499d8fee 100644 --- a/src/platform/fltk/EditorWidget.h +++ b/src/platform/fltk/EditorWidget.h @@ -22,7 +22,7 @@ #include #include -#include "platform/common/StringLib.h" +#include "ui/StringLib.h" #include "TtyWidget.h" #include "BasicEditor.h" diff --git a/src/platform/fltk/FileWidget.cxx b/src/platform/fltk/FileWidget.cxx index fdac41fd..94d38694 100755 --- a/src/platform/fltk/FileWidget.cxx +++ b/src/platform/fltk/FileWidget.cxx @@ -20,7 +20,7 @@ #include "MainWindow.h" #include "HelpWidget.h" #include "FileWidget.h" -#include "platform/common/StringLib.h" +#include "ui/StringLib.h" #include "common/device.h" FileWidget *fileWidget; diff --git a/src/platform/fltk/HelpWidget.h b/src/platform/fltk/HelpWidget.h index 3c854c6e..3abea7fc 100644 --- a/src/platform/fltk/HelpWidget.h +++ b/src/platform/fltk/HelpWidget.h @@ -16,7 +16,7 @@ #include #include -#include "platform/common/StringLib.h" +#include "ui/StringLib.h" #define ID_BUTTON 1 #define ID_TEXTBOX 2 diff --git a/src/platform/fltk/MainWindow.cxx b/src/platform/fltk/MainWindow.cxx index 9fb1b956..ab02ffb8 100644 --- a/src/platform/fltk/MainWindow.cxx +++ b/src/platform/fltk/MainWindow.cxx @@ -25,7 +25,7 @@ #include "EditorWidget.h" #include "HelpWidget.h" #include "FileWidget.h" -#include "platform/common/StringLib.h" +#include "ui/StringLib.h" #include "common/sbapp.h" #include "common/sys.h" #include "common/fs_socket_client.h" diff --git a/src/platform/fltk/Makefile.am b/src/platform/fltk/Makefile.am index 9187bad1..1ed2f3a3 100644 --- a/src/platform/fltk/Makefile.am +++ b/src/platform/fltk/Makefile.am @@ -22,10 +22,10 @@ EXTRA_DIST = \ bin_PROGRAMS = sbasici sbasici_SOURCES = \ - ../common/ansiwidget.cpp \ - ../common/screen.cpp \ - ../common/form_ui.cpp \ - ../common/StringLib.cpp \ + ../../ui/ansiwidget.cpp \ + ../../ui/screen.cpp \ + ../../ui/form_ui.cpp \ + ../../ui/StringLib.cpp \ display.cxx display.h \ HelpWidget.cxx HelpWidget.h \ TtyWidget.cxx TtyWidget.h \ diff --git a/src/platform/fltk/Profile.h b/src/platform/fltk/Profile.h index d17e9e0c..2ec004aa 100644 --- a/src/platform/fltk/Profile.h +++ b/src/platform/fltk/Profile.h @@ -13,7 +13,7 @@ #include #include -#include "platform/common/StringLib.h" +#include "ui/StringLib.h" using namespace fltk; using namespace strlib; diff --git a/src/platform/fltk/TtyWidget.h b/src/platform/fltk/TtyWidget.h index 4ec9c37f..1b0d09a3 100644 --- a/src/platform/fltk/TtyWidget.h +++ b/src/platform/fltk/TtyWidget.h @@ -17,7 +17,7 @@ #include #include -#include "platform/common/StringLib.h" +#include "ui/StringLib.h" #define SCROLL_W 15 #define SCROLL_H 15 diff --git a/src/platform/fltk/blib_fltk_ui.cxx b/src/platform/fltk/blib_fltk_ui.cxx index a66d7c3f..a8134e7d 100644 --- a/src/platform/fltk/blib_fltk_ui.cxx +++ b/src/platform/fltk/blib_fltk_ui.cxx @@ -30,7 +30,7 @@ #include #include "platform/fltk/MainWindow.h" -#include "platform/common/StringLib.h" +#include "ui/StringLib.h" extern MainWindow *wnd; diff --git a/src/platform/fltk/dev_fltk.cxx b/src/platform/fltk/dev_fltk.cxx index 5b18f171..31bc95c2 100644 --- a/src/platform/fltk/dev_fltk.cxx +++ b/src/platform/fltk/dev_fltk.cxx @@ -25,8 +25,8 @@ #include "platform/fltk/TtyWidget.h" #include "platform/fltk/utils.h" #include "platform/fltk/system.h" -#include "platform/common/utils.h" -#include "platform/common/interface.h" +#include "ui/utils.h" +#include "ui/interface.h" #include "common/fs_socket_client.h" #ifdef WIN32 @@ -113,6 +113,7 @@ int osd_devinit() { ui_reset(); wnd->_out->reset(); open_audio(); + wnd->_out->setAutoflush(!opt_show_page); return 1; } @@ -131,6 +132,7 @@ void osd_refresh() { } int osd_devrestore() { + wnd->_out->setAutoflush(true); ui_reset(); close_audio(); return 1; @@ -319,7 +321,7 @@ void lwrite(const char *s) { } void dev_show_page() { - + wnd->_out->flushNow(); } //--ENV------------------------------------------------------------------------- diff --git a/src/platform/fltk/display.cxx b/src/platform/fltk/display.cxx index 4dda2beb..7eebec12 100755 --- a/src/platform/fltk/display.cxx +++ b/src/platform/fltk/display.cxx @@ -21,8 +21,8 @@ #include "platform/fltk/display.h" #include "platform/fltk/utils.h" #include "platform/fltk/system.h" -#include "platform/common/ansiwidget.h" -#include "platform/common/form_ui.h" +#include "ui/ansiwidget.h" +#include "ui/form_ui.h" using namespace fltk; @@ -430,6 +430,15 @@ int DisplayWidget::getBackgroundColor() { return _ansiWidget->getBackgroundColor(); } +void DisplayWidget::setAutoflush(bool autoflush) { + _ansiWidget->setAutoflush(autoflush); +} + +void DisplayWidget::flushNow() { + _ansiWidget->flushNow(); +} + + extern "C" long osd_getpixel(int x, int y) { return drawTarget->getPixel(x, y); } diff --git a/src/platform/fltk/display.h b/src/platform/fltk/display.h index 230cb1a7..10810478 100755 --- a/src/platform/fltk/display.h +++ b/src/platform/fltk/display.h @@ -13,8 +13,8 @@ #include #include -#include "platform/common/maapi.h" -#include "platform/common/interface.h" +#include "ui/maapi.h" +#include "ui/interface.h" struct AnsiWidget; @@ -68,6 +68,8 @@ class DisplayWidget : public fltk::Widget, IButtonListener { int getBackgroundColor(); void flush(bool force); void reset(); + void setAutoflush(bool autoflush); + void flushNow(); Canvas *getScreen() { return _screen; } int getDefaultSize() { return _defsize; } diff --git a/src/platform/mosync/common/Makefile.am b/src/platform/mosync/common/Makefile.am deleted file mode 100755 index 534d0fdf..00000000 --- a/src/platform/mosync/common/Makefile.am +++ /dev/null @@ -1,74 +0,0 @@ -# SmallBASIC -# Copyright(C) 2001-2012 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 -# - -COMMON=$(top_srcdir)/src/common - -CC=$(MOSYNC_HOME)/bin/xgcc${EXTN} - -AR=$(MOSYNC_HOME)/bin/pipe-tool${EXTN} - -ARFLAGS = -L -quiet - -RANLIB=echo - -AM_CPPFLAGS=-I$(top_srcdir)/src -I$(MOSYNC_HOME)/include/newlib @PACKAGE_CFLAGS@ - -noinst_LIBRARIES = libsb_common.a - -libsb_common_a_SOURCES = \ - $(COMMON)/bc.c $(COMMON)/bc.h \ - $(COMMON)/blib.c $(COMMON)/blib.h \ - $(COMMON)/blib_db.c \ - $(COMMON)/blib_func.c \ - $(COMMON)/blib_graph.c \ - $(COMMON)/blib_math.c \ - $(COMMON)/matrix.c \ - $(COMMON)/blib_math.h \ - $(COMMON)/blib_sound.c \ - $(COMMON)/brun.c \ - $(COMMON)/ceval.c \ - $(COMMON)/circle.c \ - $(COMMON)/decomp.c \ - $(COMMON)/device.c $(COMMON)/device.h \ - $(COMMON)/screen.c \ - $(COMMON)/system.c \ - $(COMMON)/drvmouse.h $(COMMON)/drvsound.h \ - $(COMMON)/eval.c \ - $(COMMON)/extlib.c $(COMMON)/extlib.h \ - $(COMMON)/file.c \ - $(COMMON)/ffill.c \ - $(COMMON)/fmt.c $(COMMON)/fmt.h \ - $(COMMON)/fs_serial.c $(COMMON)/fs_serial.h \ - $(COMMON)/fs_socket_client.c $(COMMON)/fs_socket_client.h \ - $(COMMON)/fs_stream.c $(COMMON)/fs_stream.h \ - $(COMMON)/g_line.c \ - $(COMMON)/geom.c $(COMMON)/geom.h $(COMMON)/g_bmp.h \ - $(COMMON)/inet.c $(COMMON)/inet.h \ - $(COMMON)/kw.c $(COMMON)/kw.h \ - $(COMMON)/match.c $(COMMON)/match.h \ - $(COMMON)/mem.c \ - $(COMMON)/panic.c $(COMMON)/panic.h \ - $(COMMON)/pfill.c \ - $(COMMON)/plot.c \ - $(COMMON)/proc.c $(COMMON)/pproc.h \ - $(COMMON)/sberr.c $(COMMON)/sberr.h \ - $(COMMON)/scan.c $(COMMON)/scan.h \ - $(COMMON)/str.c $(COMMON)/str.h \ - $(COMMON)/tasks.c $(COMMON)/tasks.h \ - $(COMMON)/var_uds.c $(COMMON)/var_uds.h \ - $(COMMON)/var_hash.c $(COMMON)/var_hash.h \ - $(COMMON)/keymap.c $(COMMON)/keymap.h \ - $(COMMON)/units.c $(COMMON)/units.h \ - $(COMMON)/var.c $(COMMON)/var.h \ - $(COMMON)/vmt.c $(COMMON)/vmt.h \ - $(COMMON)/messages.h \ - $(COMMON)/osd.h \ - $(COMMON)/pdb.h \ - $(COMMON)/pmem.h \ - $(COMMON)/sbapp.h \ - $(COMMON)/smbas.h \ - $(COMMON)/sys.h diff --git a/src/platform/mosync/common/portdefs.h b/src/platform/mosync/common/portdefs.h deleted file mode 100755 index d0c0eb22..00000000 --- a/src/platform/mosync/common/portdefs.h +++ /dev/null @@ -1,22 +0,0 @@ -// This file is part of SmallBASIC -// -// Copyright(C) 2001-2012 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 -// - -#if defined(__cplusplus) -extern "C" { -#endif - -int dev_clock(); - -#define CMD_PAUSE_DELAY -1 - -#undef clock -#define clock dev_clock - -#if defined(__cplusplus) -} -#endif diff --git a/src/platform/mosync/controller.cpp b/src/platform/mosync/controller.cpp deleted file mode 100755 index 7e7b8260..00000000 --- a/src/platform/mosync/controller.cpp +++ /dev/null @@ -1,679 +0,0 @@ -// This file is part of SmallBASIC -// -// Copyright(C) 2001-2013 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 -#include -#include - -#include -#include -#include - -#include "MAHeaders.h" -#include - -#include "platform/mosync/controller.h" -#include "platform/common/utils.h" - -#define SYSTEM_MENU "\033[ OConsole|Show Keypad|View Source" -#define MENU_CONSOLE 0 -#define MENU_KEYPAD 1 -#define MENU_SOURCE 2 -#define MENU_ZOOM_UP 3 -#define MENU_ZOOM_DN 4 -#define ERROR_BAS "print \"Failed to open program file\"" -#define FONT_SCALE_INTERVAL 10 -#define FONT_MIN 20 -#define FONT_MAX 200 -#define STORE_VERSION 1 - -Controller::Controller() : - Environment(), - _output(NULL), - _runMode(init_state), - _lastEventTime(0), - _eventTicks(0), - _touchX(-1), - _touchY(-1), - _touchCurX(-1), - _touchCurY(-1), - _initialFontSize(0), - _fontScale(100), - _mainBas(false), - _systemMenu(false), - _systemScreen(false), - _drainError(false), - _programSrc(NULL) { - logEntered(); -} - -bool Controller::construct() { - MAExtent screenSize = maGetScrSize(); - _output = new AnsiWidget(this, EXTENT_X(screenSize), EXTENT_Y(screenSize)); - _output->construct(); - _initialFontSize = _output->getFontSize(); - - _runMode = init_state; - opt_ide = IDE_NONE; - opt_graphics = true; - opt_pref_bpp = 0; - opt_nosave = true; - opt_interactive = true; - opt_verbose = false; - opt_quiet = true; - opt_command[0] = 0; - opt_usevmt = 0; - opt_file_permitted = 1; - os_graphics = 1; - - // restore the selected font scale and path - MAHandle data = maCreatePlaceholder(); - MAHandle store = maOpenStore(PACKAGE, 0); - - if (store != STERR_NONEXISTENT) { - if (maReadStore(store, data) == RES_OK) { - int offset = 0; - int storeVersion; - int pathLength; - char path[FILENAME_MAX + 1]; - - maReadData(data, &storeVersion, offset, sizeof(int)); - offset += sizeof(int); - - if (storeVersion == STORE_VERSION) { - maReadData(data, &_fontScale, offset, sizeof(int)); - offset += sizeof(int); - - if (_fontScale != 100) { - int fontSize = (_initialFontSize * _fontScale / 100); - _output->setFontSize(fontSize); - } - - maReadData(data, &pathLength, offset, sizeof(int)); - maReadData(data, &path, offset+ sizeof(int), pathLength); - if (pathLength > 1) { - chdir(path); - } - } - } - maCloseStore(store, 0); - } - maDestroyPlaceholder(data); - - return true; -} - -Controller::~Controller() { - // remember the selected font scale and path - char path[FILENAME_MAX + 1]; - getcwd(path, FILENAME_MAX); - int pathLength = strlen(path) + 1; - int dataLength = (sizeof(int) * 3) + pathLength; - MAHandle data = maCreatePlaceholder(); - - if (maCreateData(data, dataLength) == RES_OK) { - int storeVersion = STORE_VERSION; - int offset = 0; - - // write the version number - maWriteData(data, &storeVersion, offset, sizeof(int)); - offset += sizeof(int); - - // write the fontScale - maWriteData(data, &_fontScale, offset, sizeof(int)); - offset += sizeof(int); - - // write the current path - maWriteData(data, &pathLength, offset, sizeof(int)); - maWriteData(data, path, offset + sizeof(int), pathLength); - - MAHandle store = maOpenStore(PACKAGE, MAS_CREATE_IF_NECESSARY); - maWriteStore(store, data); - maCloseStore(store, 0); - } - maDestroyPlaceholder(data); - - delete _output; - delete [] _programSrc; -} - -const char *Controller::getLoadPath() { - return !_loadPath.length() ? NULL : _loadPath.c_str(); -} - -int Controller::getPen(int code) { - int result = 0; - if (!isExit()) { - switch (code) { - case 0: - // UNTIL PEN(0) - wait until click or move - processEvents(EVENT_WAIT_INFINITE, EVENT_TYPE_POINTER_PRESSED); - // fallthru - - case 3: // returns true if the pen is down (and save curpos) - if (_touchX != -1 && _touchY != -1) { - result = 1; - } else { - processEvents(EVENT_WAIT_NONE); - } - break; - - case 1: // last pen-down x - result = _touchX; - break; - - case 2: // last pen-down y - result = _touchY; - break; - - case 4: // cur pen-down x - case 10: - result = _touchCurX; - break; - - case 5: // cur pen-down y - case 11: - result = _touchCurY; - break; - } - } - return result; -} - -char *Controller::getText(char *dest, int maxSize) { - int x = _output->getX(); - int y = _output->getY(); - int w = EXTENT_X(maGetTextSize("YNM")); - int h = _output->textHeight(); - - dest[0] = '\0'; - _runMode = modal_state; - IFormWidget *formWidget = _output->createLineInput(dest, maxSize, x, y, w, h); - _output->redraw(); - maShowVirtualKeyboard(); - - while (isModal()) { - MAEvent event = processEvents(EVENT_WAIT_INFINITE, EVENT_TYPE_KEY_PRESSED); - if (event.type == EVENT_TYPE_KEY_PRESSED) { - dev_clrkb(); - if (isModal()) { - if (event.key == 10) { - _runMode = run_state; - } else { - _output->edit(formWidget, event.key); - } - } - } - } - - // paint the widget result onto the backing screen - if (dest[0]) { - _output->print(dest); - } - - delete formWidget; - return dest; -} - -// runtime system event processor -int Controller::handleEvents(int waitFlag) { - if (!waitFlag) { - // detect when we have been called too frequently - int now = maGetMilliSecondCount(); - _eventTicks++; - if (now - _lastEventTime >= EVENT_CHECK_EVERY) { - // next time inspection interval - if (_eventTicks >= EVENT_MAX_BURN_TIME) { - _output->print("\033[ LBattery drain"); - _drainError = true; - } else if (_drainError) { - _output->print("\033[ L"); - _drainError = false; - } - _lastEventTime = now; - _eventTicks = 0; - } - } - - switch (waitFlag) { - case 1: - // wait for an event - processEvents(EVENT_WAIT_INFINITE); - break; - case 2: - // pause - processEvents(EVENT_PAUSE_TIME); - break; - default: - // pump messages without pausing - processEvents(EVENT_WAIT_NONE); - break; - } - - _output->flush(false); - return isBreak() ? -2 : 0; -} - -// handle the system menu -void Controller::handleMenu(int menuId) { - int fontSize = _output->getFontSize(); - _systemMenu = false; - - switch (menuId) { - case MENU_SOURCE: - showSystemScreen(true); - break; - case MENU_CONSOLE: - showSystemScreen(false); - break; - case MENU_KEYPAD: - maShowVirtualKeyboard(); - break; - case MENU_ZOOM_UP: - if (_fontScale > FONT_MIN) { - _fontScale -= FONT_SCALE_INTERVAL; - fontSize = (_initialFontSize * _fontScale / 100); - } - break; - case MENU_ZOOM_DN: - if (_fontScale < FONT_MAX) { - _fontScale += FONT_SCALE_INTERVAL; - fontSize = (_initialFontSize * _fontScale / 100); - } - break; - } - - if (fontSize != _output->getFontSize()) { - _output->setFontSize(fontSize); - // restart the shell - buttonClicked("main.bas"); - brun_break(); - _runMode = break_state; - } - - if (!isRunning()) { - _output->flush(true); - } -} - -// process events on the system event queue -MAEvent Controller::processEvents(int ms, int untilType) { - MAEvent event; - MAExtent screenSize; - int loadPathSize = _loadPath.length(); - - if (ms < 0 && untilType != -1) { - // flush the display before pausing for target event - if (isRunning()) { - _output->flush(true); - } - maWait(ms); - ms = EVENT_WAIT_NONE; - } - - while (!isBreak() && maGetEvent(&event)) { - switch (event.type) { - case EVENT_TYPE_OPTIONS_BOX_BUTTON_CLICKED: - if (_systemMenu) { - handleMenu(event.optionsBoxButtonIndex); - ms = EVENT_WAIT_NONE; - } else if (isRunning()) { - if (!_output->optionSelected(event.optionsBoxButtonIndex)) { - dev_pushkey(event.optionsBoxButtonIndex); - } - } - break; - case EVENT_TYPE_SCREEN_CHANGED: - screenSize = maGetScrSize(); - _output->resize(EXTENT_X(screenSize), EXTENT_Y(screenSize)); - os_graf_mx = _output->getWidth(); - os_graf_my = _output->getHeight(); - handleKey(SB_PKEY_SIZE_CHG); - break; - case EVENT_TYPE_POINTER_PRESSED: - _touchX = _touchCurX = event.point.x; - _touchY = _touchCurY = event.point.y; - handleKey(SB_KEY_MK_PUSH); - _output->pointerTouchEvent(event); - break; - case EVENT_TYPE_POINTER_DRAGGED: - _touchCurX = event.point.x; - _touchCurY = event.point.y; - _output->pointerMoveEvent(event); - break; - case EVENT_TYPE_POINTER_RELEASED: - _touchX = _touchY = _touchCurX = _touchCurY = -1; - handleKey(SB_KEY_MK_RELEASE); - _output->pointerReleaseEvent(event); - break; - case EVENT_TYPE_CLOSE: - setExit(true); - break; - case EVENT_TYPE_KEY_PRESSED: - handleKey(event.key); - break; - } - if (untilType == EVENT_TYPE_EXIT_ANY || - untilType == event.type || - loadPathSize != _loadPath.length()) { - // skip next maWait() - found target event or loadPath changed - ms = EVENT_WAIT_NONE; - break; - } - } - - if (ms != EVENT_WAIT_NONE) { - maWait(ms); - } - return event; -} - -char *Controller::readSource(const char *fileName) { - char *buffer = NULL; - bool networkFile = strstr(fileName, "://"); - const char *delim = strchr(fileName, '?'); - int len = strlen(fileName); - int endIndex = delim ? (delim - fileName) : len; - if (delim && !networkFile) { - strcpy(opt_command, delim + 1); - } - - _mainBas = false; - trace("readSource %s %d %s", fileName, endIndex, opt_command); - - if (networkFile) { - buffer = readConnection(fileName); - } else if (strncasecmp("main.bas", fileName, endIndex) == 0) { - // load as resource - int len = maGetDataSize(MAIN_BAS); - buffer = (char *)tmp_alloc(len + 1); - maReadData(MAIN_BAS, buffer, 0, len); - buffer[len] = '\0'; - _mainBas = true; - } else { - // load from file system - MAHandle handle = maFileOpen(fileName, MA_ACCESS_READ); - if (maFileExists(handle)) { - int len = maFileSize(handle); - buffer = (char *)tmp_alloc(len + 1); - maFileRead(handle, buffer, len); - buffer[len] = '\0'; - } - maFileClose(handle); - } - - if (buffer == NULL) { - buffer = (char *)tmp_alloc(strlen(ERROR_BAS) + 1); - strcpy(buffer, ERROR_BAS); - } - - delete [] _programSrc; - len = strlen(buffer); - _programSrc = new char[len + 1]; - strncpy(_programSrc, buffer, len); - _programSrc[len] = 0; - - logPrint("Opened: %s %d bytes\n", fileName, len); - return buffer; -} - -// stop and running program -void Controller::setExit(bool quit) { - if (isRunning()) { - brun_break(); - } - _runMode = quit ? exit_state : back_state; -} - -// commence runtime state -void Controller::setRunning(bool running) { - if (running) { - dev_fgcolor = -DEFAULT_FOREGROUND; - dev_bgcolor = -DEFAULT_BACKGROUND; - os_graf_mx = _output->getWidth(); - os_graf_my = _output->getHeight(); - - os_ver = 1; - os_color = 1; - os_color_depth = 16; - setsysvar_str(SYSVAR_OSNAME, "MoSync"); - - dev_clrkb(); - ui_reset(); - - _runMode = run_state; - _loadPath.empty(); - _output->reset(); - - _lastEventTime = maGetMilliSecondCount(); - _eventTicks = 0; - _drainError = false; - } else { - _runMode = init_state; - } -} - -void Controller::showError() { - _runMode = init_state; - _loadPath.empty(); - showSystemScreen(false); -} - -void Controller::showCompletion(bool success) { - if (success) { - _output->print("\033[ LDone - press back [<-]"); - } else { - _output->print("\033[ LError - see console"); - } - _output->flush(true); -} - -void Controller::showMenu() { - _systemMenu = true; - if (_mainBas) { - char buffer[128]; - sprintf(buffer, "%s|Zoom %d%%|Zoom %d%%", SYSTEM_MENU, - _fontScale - FONT_SCALE_INTERVAL, - _fontScale + FONT_SCALE_INTERVAL); - _output->print(buffer); - } else { - _output->print(SYSTEM_MENU); - } -} - -void Controller::logPrint(const char *format, ...) { - char buf[4096], *p = buf; - va_list args; - - va_start(args, format); - p += vsnprintf(p, sizeof(buf) - 1, format, args); - va_end(args); - *p = '\0'; - - lprintfln(buf); - - if (_systemScreen) { - _output->print(buf); - } else { - _output->print("\033[ SW7"); - _output->print(buf); - _output->print("\033[ Sw"); - } -} - -// handler for hyperlink click actions -void Controller::buttonClicked(const char *url) { - _loadPath.empty(); - _loadPath.append(url, strlen(url)); -} - -// pass the key into the smallbasic keyboard handler -void Controller::handleKey(int key) { - switch (key) { - case MAK_FIRE: - case MAK_5: - return; - case MAK_SOFTRIGHT: - case MAK_BACK: - if (_systemScreen) { - // restore user screens - _output->print("\033[ SR"); - _systemScreen = false; - } else { - // quit app when shell is active - setExit(_mainBas); - } - return; - case MAK_MENU: - showMenu(); - return; - } - - if (isRunning()) { - switch (key) { - case MAK_TAB: - dev_pushkey(SB_KEY_TAB); - break; - case MAK_HOME: - dev_pushkey(SB_KEY_KP_HOME); - break; - case MAK_END: - dev_pushkey(SB_KEY_END); - break; - case MAK_INSERT: - dev_pushkey(SB_KEY_INSERT); - break; - case MAK_KP_MULTIPLY: - dev_pushkey(SB_KEY_KP_MUL); - break; - case MAK_KP_PLUS: - dev_pushkey(SB_KEY_KP_PLUS); - break; - case MAK_KP_MINUS: - dev_pushkey(SB_KEY_KP_MINUS); - break; - case MAK_SLASH: - dev_pushkey(SB_KEY_KP_DIV); - break; - case MAK_PAGEUP: - dev_pushkey(SB_KEY_PGUP); - break; - case MAK_PAGEDOWN: - dev_pushkey(SB_KEY_PGDN); - break; - case MAK_UP: - dev_pushkey(SB_KEY_UP); - break; - case MAK_DOWN: - dev_pushkey(SB_KEY_DN); - break; - case MAK_LEFT: - dev_pushkey(SB_KEY_LEFT); - break; - case MAK_RIGHT: - dev_pushkey(SB_KEY_RIGHT); - break; - case MAK_CLEAR: - case MAK_BACKSPACE: - case MAK_DELETE: - dev_pushkey(SB_KEY_BACKSPACE); - break; - default: - dev_pushkey(key); - break; - } - } -} - -// returns the contents of the given url -char *Controller::readConnection(const char *url) { - char *result = NULL; - logEntered(); - _output->print("\033[ LLoading..."); - - MAHandle conn = maConnect(url); - if (conn < 1) { - logPrint("Failed connecting to %s\n", url); - } else { - _runMode = conn_state; - logPrint("Connecting to %s\n", url); - - bool connected = false; - byte buffer[1024]; - int length = 0; - int size = 0; - int now = maGetMilliSecondCount(); - MAEvent event; - - // pause until connected - while (_runMode == conn_state) { - event = processEvents(EVENT_WAIT_INFINITE, EVENT_TYPE_CONN); - if (event.type == EVENT_TYPE_CONN) { - switch (event.conn.opType) { - case CONNOP_CONNECT: - // connection established - if (!connected) { - connected = (event.conn.result > 0); - if (connected) { - memset(buffer, 0, sizeof(buffer)); - maConnRead(conn, buffer, sizeof(buffer)); - } else { - logPrint("Connection error\n"); - _runMode = init_state; - } - } - break; - case CONNOP_READ: - // connRead completed - if (event.conn.result > 0) { - size = event.conn.result; - if (result == NULL) { - result = (char *)tmp_alloc(size + 1); - memcpy(result, buffer, size); - length = size; - } else { - result = (char *)tmp_realloc(result, length + size + 1); - memcpy(result + length, buffer, size); - length += size; - } - result[length] = 0; - memset(buffer, 0, sizeof(buffer)); - maConnRead(conn, buffer, sizeof(buffer)); - } else { - // no more data - _runMode = init_state; - } - break; - default: - logPrint("Connection error\n"); - _runMode = init_state; - } - } - } - logPrint("Loaded in %d msecs\n", maGetMilliSecondCount() - now); - } - - maConnClose(conn); - return result; -} - -void Controller::showSystemScreen(bool showSrc) { - if (showSrc) { - // screen command write screen 2 (\014=CLS) - _output->print("\033[ SW6\014"); - if (_programSrc) { - _output->print(_programSrc); - } - // restore write screen, display screen 6 (source) - _output->print("\033[ Sw; SD6"); - } else { - // screen command display screen 7 (console) - _output->print("\033[ SD7"); - } - _systemScreen = true; -} diff --git a/src/platform/mosync/controller.h b/src/platform/mosync/controller.h deleted file mode 100755 index c53cd013..00000000 --- a/src/platform/mosync/controller.h +++ /dev/null @@ -1,85 +0,0 @@ -// This file is part of SmallBASIC -// -// Copyright(C) 2001-2013 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 - -#include "config.h" -#include "common/sbapp.h" -#include "common/sys.h" -#include "common/smbas.h" -#include "common/osd.h" -#include "common/device.h" -#include "common/blib_ui.h" - -#include "platform/mosync/ansiwidget.h" - -#define EVENT_CHECK_EVERY 2000 -#define EVENT_MAX_BURN_TIME 30 -#define EVENT_PAUSE_TIME 400 -#define EVENT_TYPE_EXIT_ANY 0 -#define EVENT_WAIT_INFINITE -1 -#define EVENT_WAIT_NONE 0 - -struct Controller : public MAUtil::Environment, IButtonListener { - Controller(); - virtual ~Controller(); - - bool construct(); - const char *getLoadPath(); - int getPen(int code); - char *getText(char *dest, int maxSize); - int handleEvents(int waitFlag); - void handleMenu(int menuId); - MAEvent processEvents(int ms, int untilType = -1); - char *readSource(const char *fileName); - bool isExit() { return _runMode == exit_state; } - bool isBack() { return _runMode == back_state; } - bool isModal() { return _runMode == modal_state; } - bool isBreak() { return _runMode == exit_state || _runMode == back_state; } - bool isRunning() { return _runMode == run_state || _runMode == modal_state; } - void setExit(bool quit); - void setRunning(bool running = true); - void showError(); - void showCompletion(bool success); - void showMenu(); - void logPrint(const char *format, ...); - void buttonClicked(const char *url); - AnsiWidget *_output; - -private: - void handleKey(int key); - char *readConnection(const char *url); - void showSystemScreen(bool showSrc); - - enum ExecState { - init_state, - run_state, - restart_state, - modal_state, - break_state, - conn_state, - back_state, - exit_state - }; - - ExecState _runMode; - int _lastEventTime; - int _eventTicks; - int _touchX; - int _touchY; - int _touchCurX; - int _touchCurY; - int _initialFontSize; - int _fontScale; - bool _mainBas; - bool _systemMenu; - bool _systemScreen; - bool _drainError; - String _loadPath; - char *_programSrc; -}; diff --git a/src/platform/mosync/dev_mosync.cpp b/src/platform/mosync/dev_mosync.cpp deleted file mode 100755 index 0d94bb7a..00000000 --- a/src/platform/mosync/dev_mosync.cpp +++ /dev/null @@ -1,249 +0,0 @@ -// This file is part of SmallBASIC -// -// Copyright(C) 2012 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 "MAHeaders.h" - -#include "platform/common/utils.h" -#include "platform/mosync/controller.h" -#include "platform/mosync/form_ui.h" - -extern Controller *controller; - -#define ACCESS_EXIST 0 -#define ACCESS_WRITE 2 -#define ACCESS_READ 4 - -bool form_ui::isRunning() { - return controller->isRunning(); -} - -bool form_ui::isBreak() { - return controller->isBreak(); -} - -void form_ui::processEvents() { - controller->processEvents(EVENT_WAIT_INFINITE, EVENT_TYPE_EXIT_ANY); -} - -void form_ui::buttonClicked(const char *url) { - controller->buttonClicked(url); -} - -AnsiWidget *form_ui::getOutput() { - return controller->_output; -} - -// workaround for android/mosync bug where outer spaces are not counted -int get_text_width(char *s) { - int result = 0; - if (s && s[0]) { - int e = strlen(s) - 1; - char c1 = s[0]; - char c2 = s[e]; - if (c1 == ' ') { - s[0] = '_'; - } - if (c2 == ' ') { - s[e] = '_'; - } - result = EXTENT_X(maGetTextSize(s)); - s[0] = c1; - s[e] = c2; - } - return result; -} - -// set the current working directory to the given path -void set_path(const char *filename) { - const char *slash = strrchr(filename, '/'); - if (!slash) { - slash = strrchr(filename, '\\'); - } - if (slash) { - int len = slash - filename; - if (len > 0) { - char path[1024]; - strncpy(path, filename, len); - path[len] = 0; - chdir(path); - } - } -} - -// change the current working directory to the parent level folder -bool set_parent_path() { - bool result = true; - char path[FILENAME_MAX + 1]; - getcwd(path, FILENAME_MAX); - if (!path[0] || strcmp(path, "/") == 0) { - result = false; - } else { - int len = strlen(path); - if (path[len - 1] == '/') { - // eg /sdcard/bas/ - path[len - 1] = '\0'; - } - const char *slash = strrchr(path, '/'); - len = slash - path; - if (!len) { - strcpy(path, "/"); - } else { - path[len] = 0; - } - chdir(path); - } - return result; -} - -void osd_sound(int frq, int dur, int vol, int bgplay) { - -} - -void osd_clear_sound_queue() { - -} - -void osd_beep(void) { - controller->_output->beep(); -} - -void osd_cls(void) { - logEntered(); - ui_reset(); - controller->_output->clearScreen(); -} - -int osd_devinit(void) { - logEntered(); - controller->setRunning(true); - return 1; -} - -int osd_devrestore(void) { - ui_reset(); - return 0; -} - -int osd_events(int wait_flag) { - return controller->handleEvents(wait_flag); -} - -int osd_getpen(int mode) { - return controller->getPen(mode); -} - -long osd_getpixel(int x, int y) { - return controller->_output->getPixel(x, y); -} - -int osd_getx(void) { - return controller->_output->getX(); -} - -int osd_gety(void) { - return controller->_output->getY(); -} - -void osd_line(int x1, int y1, int x2, int y2) { - controller->_output->drawLine(x1, y1, x2, y2); -} - -void osd_rect(int x1, int y1, int x2, int y2, int fill) { - if (fill) { - controller->_output->drawRectFilled(x1, y1, x2, y2); - } else { - controller->_output->drawRect(x1, y1, x2, y2); - } -} - -void osd_refresh(void) { - controller->_output->flush(true); -} - -void osd_setcolor(long color) { - controller->_output->setColor(color); -} - -void osd_setpenmode(int enable) { - // touch mode is always active -} - -void osd_setpixel(int x, int y) { - controller->_output->setPixel(x, y, dev_fgcolor); -} - -void osd_settextcolor(long fg, long bg) { - controller->_output->setTextColor(fg, bg); -} - -void osd_setxy(int x, int y) { - controller->_output->setXY(x, y); -} - -int osd_textheight(const char *str) { - return controller->_output->textHeight(); -} - -int osd_textwidth(const char *str) { - return get_text_width((char*) str); -} - -void osd_write(const char *str) { - logEntered(); - controller->_output->print(str); -} - -char *dev_read(const char *fileName) { - return controller->readSource(fileName); -} - -void lwrite(const char *str) { - controller->logPrint("%s", str); -} - -void dev_image(int handle, int index, - int x, int y, int sx, int sy, int w, int h) { -} - -int dev_image_width(int handle, int index) { - return 0; -} - -int dev_image_height(int handle, int index) { - return 0; -} - -void dev_delay(dword ms) { - controller->processEvents(ms, EVENT_TYPE_EXIT_ANY); -} - -char *dev_gets(char *dest, int maxSize) { - return controller->getText(dest, maxSize); -} - -extern "C" int access(const char *path, int amode) { - int result = -1; - int mode = (amode && ACCESS_WRITE) ? MA_ACCESS_READ_WRITE : MA_ACCESS_READ; - MAHandle handle = maFileOpen(path, mode); - if (handle != MA_FERR_WRONG_TYPE) { - if (maFileExists(handle)) { - result = 0; - } - maFileClose(handle); - } - trace("access() %s %d = %d", path, amode, result); - return result; -} - -extern "C" void chmod(const char *path, int mode) { - trace("chmod() %s %d", path, mode); -} - -extern "C" int dev_clock() { - return maGetMilliSecondCount(); -} diff --git a/src/platform/mosync/main.cpp b/src/platform/mosync/main.cpp deleted file mode 100755 index f87c5eda..00000000 --- a/src/platform/mosync/main.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// This file is part of SmallBASIC -// -// Copyright(C) 2001-2012 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 - -#include "platform/mosync/controller.h" -#include "platform/common/utils.h" - -Controller *controller; - -extern "C" int MAMain() { - maScreenSetOrientation(SCREEN_ORIENTATION_DYNAMIC); - controller = new Controller(); - controller->construct(); - - bool mainBas = true; - sbasic_main("main.bas?welcome"); - - while (!controller->isExit()) { - if (controller->isBack()) { - if (mainBas) { - controller->setExit(!set_parent_path()); - } - if (!controller->isExit()) { - mainBas = true; - opt_command[0] = '\0'; - sbasic_main("main.bas"); - } - } else if (controller->getLoadPath() != NULL) { - mainBas = (strncmp(controller->getLoadPath(), "main.bas", 8) == 0); - if (!mainBas) { - set_path(controller->getLoadPath()); - } - bool success = sbasic_main(controller->getLoadPath()); - if (!controller->isBack()) { - if (!mainBas) { - // display an indication the program has completed - controller->showCompletion(success); - } - if (!success) { - // highlight the error - controller->showError(); - } - } - } else { - controller->setRunning(false); - controller->processEvents(-1, -1); - } - } - - delete controller; - return 0; -} diff --git a/src/platform/mosync/resources.lst b/src/platform/mosync/resources.lst deleted file mode 100755 index c4a364b2..00000000 --- a/src/platform/mosync/resources.lst +++ /dev/null @@ -1,7 +0,0 @@ -.res MAIN_BAS -.bin -.include "resources/main.bas" - - - - diff --git a/src/platform/mosync/resources/main.bas b/src/platform/mosync/resources/main.bas deleted file mode 100755 index 385ee783..00000000 --- a/src/platform/mosync/resources/main.bas +++ /dev/null @@ -1,164 +0,0 @@ -const app = "main.bas?" -const exitLinkType = "exit_link" -const exitButtonType = "exit_button" -const linkType = "link" - -sub space_print(s) - local ch, len_s - len_s = len(s) - for ch = 1 to len_s - print mid(s, ch, 1) + " "; - next ch -end - -sub intro() - local i - for i = 1 to 4 - color i, 0: print "Welcome to SmallBASIC" - next i - color 7, 0 - space_print "Welcome to SmallBASIC" - print "" -end - -sub about() - local bn_ok - cls - print " __ _ _____ _" - print "(_ ._ _ _.|| |_) /\ (_ | / " - print "__)| | |(_||| |_)/--\__)_|_\_" - print - print "Version 0.11.4" - print - print "Copyright (c) 2002-2013 Chris Warren-Smith" - print "Copyright (c) 2000-2006 Nicholas Christopoulos." + chr(10) - print "http://smallbasic.sourceforge.net" + chr(10) - print "SmallBASIC comes with ABSOLUTELY NO WARRANTY." - print "This program is free software; you can use it" - print "redistribute it and/or modify it under the terms of the" - print "GNU General Public License version 2 as published by" - print "the Free Software Foundation." - print - color 10, 8 - button xmax / 2, ypos * txth("A"), 0, 0, bn_ok, "OK" - doform - color 7, 0 - cls -end - -sub listFiles(path, byref basList, byref dirList) - local fileList, ent, esc, name, lastItem - - erase basList - erase dirList - - if (right(path, 1) != "/") then - path += "/" - endif - - color 7, 0 - print "Files in " + path - - esc = chr(27) + "[ H" - fileList = files(path) - - for ent in fileList - name = ent - if (isdir(path + name)) then - dirList << name - else if (right(ent, 4) == ".bas") then - basList << name - endif - next ent - - sort dirList - sort basList - - color 3, 0 - lastItem = len(dirList) - 1 - for i = 0 to lastItem - button 0, -1, 0, 0, dirList(i), "[" + dirList(i) + "]", linkType - dirList(i) = path + dirList(i) - print - next ent - - color 2, 0 - lastItem = len(basList) - 1 - for i = 0 to lastItem - button 0, -1, 0, 0, basList(i), basList(i), exitLinkType - basList(i) = path + basList(i) - print - next ent -end - -sub main - local basList, dirList, path - local form_var, bn_back, bn_about, bn_online - local y_height, do_intro - - dim basList - dim dirList - - form_var = "" - bn_back = "_back" - bn_about= "_about" - bn_online = "http://smallbasic.sourceforge.net/?q=export/code/1102" - y_height = txth(about_button) + 5 - - sub make_ui(path, welcome) - color 10, 8 - button 0, 0, 0, 0, bn_back, "Back" - button -4, 0, 0, 0, bn_online, "Online", exitButtonType - button -4, 0, 0, 0, bn_about, "About" - at 0, y_height - if (welcome) then - intro - fi - listFiles path, basList, dirList - end - - sub go_back - local backPath, index - backPath = "" - index = iff(isstring(path), rinstr(path, "/"), 0) - if (index > 0 && index == len(path)) then - index = rinstr(left(path, index - 1), "/") - fi - if (index == 1) then - index++ - fi - if (index > 0) - backPath = left(path, index - 1) - else - backPath = "/" - endif - path = backPath - end - - do_intro = false - if (command == "welcome") then - do_intro = true - fi - path = cwd - - make_ui path, do_intro - - while 1 - doform form_var - cls - - if (isdir(form_var)) then - path = form_var - chdir path - make_ui path, false - elif form_var == "About" then - about - make_ui path, false - elif form_var == "Back" then - go_back - make_ui path, false - fi - wend -end - -main diff --git a/src/platform/mosync/smallbasic.icon b/src/platform/mosync/smallbasic.icon deleted file mode 100755 index 57ba89df..00000000 --- a/src/platform/mosync/smallbasic.icon +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/src/platform/sdl/Makefile.am b/src/platform/sdl/Makefile.am index 8d95bfe4..184fc9fa 100644 --- a/src/platform/sdl/Makefile.am +++ b/src/platform/sdl/Makefile.am @@ -7,23 +7,23 @@ AM_CPPFLAGS = -I$(top_srcdir)/src -I. @PACKAGE_CFLAGS@ -EXTRA_DIST = \ - fixedfont.xpm \ - sbasic.nsi \ +EXTRA_DIST = \ + fixedfont.xpm \ + sbasic.nsi \ welcome.bas bin_PROGRAMS = sbasicg -sbasicg_SOURCES = \ - ../common/graphics.cpp \ - ../common/ansiwidget.cpp \ - ../common/screen.cpp \ - ../common/system.cpp \ - ../common/form_ui.cpp \ - ../common/StringLib.cpp \ - main.cpp \ - display.cpp \ - runtime.cpp \ +sbasicg_SOURCES = \ + ../../ui/graphics.cpp \ + ../../ui/ansiwidget.cpp \ + ../../ui/screen.cpp \ + ../../ui/system.cpp \ + ../../ui/form_ui.cpp \ + ../../ui/StringLib.cpp \ + main.cpp \ + display.cpp \ + runtime.cpp \ settings.cpp sbasicg_LDADD = -L$(top_srcdir)/src/common -lsb_common @PACKAGE_LIBS@ diff --git a/src/platform/sdl/display.cpp b/src/platform/sdl/display.cpp index 3eea0d7e..124dd350 100644 --- a/src/platform/sdl/display.cpp +++ b/src/platform/sdl/display.cpp @@ -8,8 +8,8 @@ #include "config.h" #include -#include "platform/common/form_ui.h" -#include "platform/common/utils.h" +#include "ui/form_ui.h" +#include "ui/utils.h" #include "platform/sdl/display.h" #include "common/device.h" diff --git a/src/platform/sdl/display.h b/src/platform/sdl/display.h index bf1f963a..0cc9e2a9 100644 --- a/src/platform/sdl/display.h +++ b/src/platform/sdl/display.h @@ -11,9 +11,9 @@ #include -#include "platform/common/maapi.h" -#include "platform/common/StringLib.h" -#include "platform/common/graphics.h" +#include "ui/maapi.h" +#include "ui/StringLib.h" +#include "ui/graphics.h" struct Graphics : common::Graphics { Graphics(SDL_Window *window); diff --git a/src/platform/sdl/main.cpp b/src/platform/sdl/main.cpp index 4fe26592..cdc84130 100644 --- a/src/platform/sdl/main.cpp +++ b/src/platform/sdl/main.cpp @@ -11,8 +11,8 @@ #include #include -#include "platform/common/utils.h" -#include "platform/common/StringLib.h" +#include "ui/utils.h" +#include "ui/StringLib.h" #include "platform/sdl/runtime.h" #include "platform/sdl/settings.h" #include "common/smbas.h" diff --git a/src/platform/sdl/runtime.cpp b/src/platform/sdl/runtime.cpp index 4fdc8b59..946174ec 100644 --- a/src/platform/sdl/runtime.cpp +++ b/src/platform/sdl/runtime.cpp @@ -14,9 +14,9 @@ #include "common/device.h" #include "common/blib_ui.h" #include "common/fs_socket_client.h" -#include "platform/common/maapi.h" -#include "platform/common/utils.h" -#include "platform/common/form_ui.h" +#include "ui/maapi.h" +#include "ui/utils.h" +#include "ui/form_ui.h" #include "platform/sdl/runtime.h" #include "platform/sdl/keymap.h" #include "platform/sdl/main_bas.h" diff --git a/src/platform/sdl/runtime.h b/src/platform/sdl/runtime.h index 34dd635f..fcb2ec1d 100644 --- a/src/platform/sdl/runtime.h +++ b/src/platform/sdl/runtime.h @@ -12,10 +12,10 @@ #include "config.h" #include -#include "platform/common/maapi.h" -#include "platform/common/interface.h" -#include "platform/common/ansiwidget.h" -#include "platform/common/system.h" +#include "ui/maapi.h" +#include "ui/interface.h" +#include "ui/ansiwidget.h" +#include "ui/system.h" #include "platform/sdl/display.h" struct Runtime : public System { diff --git a/src/platform/tizen/application.cpp b/src/platform/tizen/application.cpp index 776fbac9..e18fd261 100644 --- a/src/platform/tizen/application.cpp +++ b/src/platform/tizen/application.cpp @@ -9,7 +9,7 @@ #include "config.h" #include "platform/tizen/form.h" #include "platform/tizen/application.h" -#include "platform/common/utils.h" +#include "ui/utils.h" Application *TizenApp::createInstance() { logEntered(); diff --git a/src/platform/tizen/display.cpp b/src/platform/tizen/display.cpp index 529fc380..e3786963 100644 --- a/src/platform/tizen/display.cpp +++ b/src/platform/tizen/display.cpp @@ -9,8 +9,8 @@ #include "config.h" #include #include "platform/tizen/display.h" -#include "platform/common/form_ui.h" -#include "platform/common/utils.h" +#include "ui/form_ui.h" +#include "ui/utils.h" #define SIZE_LIMIT 4 #define FONT_FACE_NAME "Envy Code R.ttf" diff --git a/src/platform/tizen/display.h b/src/platform/tizen/display.h index b308c2e8..a87b9282 100644 --- a/src/platform/tizen/display.h +++ b/src/platform/tizen/display.h @@ -15,8 +15,8 @@ #include #include -#include "platform/common/maapi.h" -#include "platform/common/StringLib.h" +#include "ui/maapi.h" +#include "ui/StringLib.h" #define MSG_ID_REDRAW 5001 #define MSG_ID_SHOW_KEYPAD 5002 diff --git a/src/platform/tizen/form.cpp b/src/platform/tizen/form.cpp index 5bf3d397..c65a0520 100644 --- a/src/platform/tizen/form.cpp +++ b/src/platform/tizen/form.cpp @@ -8,7 +8,7 @@ #include "config.h" #include "platform/tizen/form.h" -#include "platform/common/utils.h" +#include "ui/utils.h" using namespace Tizen::App; using namespace Tizen::Base::Collection; diff --git a/src/platform/tizen/runtime.cpp b/src/platform/tizen/runtime.cpp index 5f84531b..9c8a4b3b 100644 --- a/src/platform/tizen/runtime.cpp +++ b/src/platform/tizen/runtime.cpp @@ -10,9 +10,9 @@ #include #include #include "platform/tizen/runtime.h" -#include "platform/common/maapi.h" -#include "platform/common/utils.h" -#include "platform/common/form_ui.h" +#include "ui/maapi.h" +#include "ui/utils.h" +#include "ui/form_ui.h" #include "common/sbapp.h" #include "common/sys.h" #include "common/smbas.h" diff --git a/src/platform/tizen/runtime.h b/src/platform/tizen/runtime.h index cad79a75..8e814f9e 100644 --- a/src/platform/tizen/runtime.h +++ b/src/platform/tizen/runtime.h @@ -11,10 +11,10 @@ #include -#include "platform/common/maapi.h" -#include "platform/common/interface.h" -#include "platform/common/ansiwidget.h" -#include "platform/common/system.h" +#include "ui/maapi.h" +#include "ui/interface.h" +#include "ui/ansiwidget.h" +#include "ui/system.h" using namespace Tizen::App; using namespace Tizen::Base::Collection; diff --git a/src/platform/unix/Makefile.am b/src/platform/unix/Makefile.am index 6fc6fa3b..649bb6c1 100644 --- a/src/platform/unix/Makefile.am +++ b/src/platform/unix/Makefile.am @@ -45,7 +45,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 ref + replace-test read-data proc optchk letbug ref ptr trycatch test: ${bin_PROGRAMS} @for utest in $(UNIT_TESTS); do \ diff --git a/src/platform/common/StringLib.cpp b/src/ui/StringLib.cpp similarity index 100% rename from src/platform/common/StringLib.cpp rename to src/ui/StringLib.cpp diff --git a/src/platform/common/StringLib.h b/src/ui/StringLib.h similarity index 100% rename from src/platform/common/StringLib.h rename to src/ui/StringLib.h diff --git a/src/platform/common/ansiwidget.cpp b/src/ui/ansiwidget.cpp similarity index 99% rename from src/platform/common/ansiwidget.cpp rename to src/ui/ansiwidget.cpp index 6a1b784b..edf540ed 100755 --- a/src/platform/common/ansiwidget.cpp +++ b/src/ui/ansiwidget.cpp @@ -14,8 +14,8 @@ #include #include -#include "platform/common/ansiwidget.h" -#include "platform/common/utils.h" +#include "ui/ansiwidget.h" +#include "ui/utils.h" /* class AnsiWidget @@ -303,7 +303,7 @@ void FormListBox::clicked(IButtonListener *listener, int x, int y) { } } -void FormListBox::draw(int dx, int dy) { +void FormListBox::draw(int dx, int dy, int sw, int chw) { if (_model) { maSetColor(getBackground(GRAY_BG_COL)); maFillRect(dx, dy, _width, _height); @@ -373,7 +373,7 @@ void FormDropList::clicked(IButtonListener *listener, int x, int y) { _listActive = !_listActive; } -void FormDropList::draw(int dx, int dy) { +void FormDropList::draw(int dx, int dy, int sw, int chw) { if (_model) { bool pressed = _listActive ? false : _pressed; drawButton(getText(), dx, dy, _width - CHOICE_BN_W, _height, pressed); diff --git a/src/platform/common/ansiwidget.h b/src/ui/ansiwidget.h similarity index 97% rename from src/platform/common/ansiwidget.h rename to src/ui/ansiwidget.h index d43a18a3..e139fb43 100755 --- a/src/platform/common/ansiwidget.h +++ b/src/ui/ansiwidget.h @@ -16,12 +16,12 @@ #if defined(_MOSYNC) #include #else - #include "platform/common/maapi.h" + #include "ui/maapi.h" #endif -#include "platform/common/StringLib.h" -#include "platform/common/screen.h" -#include "platform/common/interface.h" +#include "ui/StringLib.h" +#include "ui/screen.h" +#include "ui/interface.h" #define MAX_PENDING 250 #define MAX_PENDING_GRAPHICS 25 @@ -180,7 +180,7 @@ struct FormDropList : public FormList { FormDropList(Screen *screen, IFormWidgetListModel *model, int x, int y, int w, int h); void clicked(IButtonListener *listener, int x, int y); - void draw(int dx, int dy); + void draw(int dx, int dy, int sw, int chw); bool overlaps(MAPoint2d pt, int scrollX, int scrollY, bool &redraw); virtual ~FormDropList() {} @@ -196,7 +196,7 @@ struct FormListBox : public FormList { FormListBox(Screen *screen, IFormWidgetListModel *model, int x, int y, int w, int h); void clicked(IButtonListener *listener, int x, int y); - void draw(int dx, int dy); + void draw(int dx, int dy, int sw, int chw); bool overlaps(MAPoint2d pt, int scrollX, int scrollY, bool &redraw); virtual ~FormListBox() {} }; diff --git a/src/platform/common/canvas.h b/src/ui/canvas.h similarity index 100% rename from src/platform/common/canvas.h rename to src/ui/canvas.h diff --git a/src/platform/common/form_ui.cpp b/src/ui/form_ui.cpp similarity index 98% rename from src/platform/common/form_ui.cpp rename to src/ui/form_ui.cpp index 7f61434e..9a357896 100644 --- a/src/platform/common/form_ui.cpp +++ b/src/ui/form_ui.cpp @@ -8,12 +8,7 @@ #include "config.h" -#if defined(_MOSYNC) - #include -#else - #include "platform/common/maapi.h" -#endif - +#include "ui/maapi.h" #include "common/sbapp.h" #include "common/sys.h" #include "common/smbas.h" @@ -21,13 +16,13 @@ #include "common/device.h" #include "common/blib_ui.h" -#include "platform/common/utils.h" -#include "platform/common/form_ui.h" +#include "ui/utils.h" +#include "ui/form_ui.h" #if defined(_FLTK) #include "platform/fltk/system.h" #else - #include "platform/common/system.h" + #include "ui/system.h" #endif Form *form; diff --git a/src/platform/common/form_ui.h b/src/ui/form_ui.h similarity index 95% rename from src/platform/common/form_ui.h rename to src/ui/form_ui.h index 9bfa181b..02c41f7e 100644 --- a/src/platform/common/form_ui.h +++ b/src/ui/form_ui.h @@ -13,9 +13,9 @@ #include "common/sys.h" #include "common/var.h" -#include "platform/common/StringLib.h" -#include "platform/common/ansiwidget.h" -#include "platform/common/interface.h" +#include "ui/StringLib.h" +#include "ui/ansiwidget.h" +#include "ui/interface.h" namespace form_ui { AnsiWidget *getOutput(); diff --git a/src/platform/common/graphics.cpp b/src/ui/graphics.cpp similarity index 99% rename from src/platform/common/graphics.cpp rename to src/ui/graphics.cpp index 08d155f4..5a115de6 100644 --- a/src/platform/common/graphics.cpp +++ b/src/ui/graphics.cpp @@ -8,8 +8,8 @@ #include "config.h" -#include "platform/common/graphics.h" -#include "platform/common/utils.h" +#include "ui/graphics.h" +#include "ui/utils.h" #include "common/device.h" using namespace common; diff --git a/src/platform/common/graphics.h b/src/ui/graphics.h similarity index 93% rename from src/platform/common/graphics.h rename to src/ui/graphics.h index 85775a57..ea092dcb 100644 --- a/src/platform/common/graphics.h +++ b/src/ui/graphics.h @@ -9,9 +9,9 @@ #ifndef COMMON_GRAPHICS #define COMMON_GRAPHICS -#include "platform/common/maapi.h" -#include "platform/common/StringLib.h" -#include "platform/common/canvas.h" +#include "ui/maapi.h" +#include "ui/StringLib.h" +#include "ui/canvas.h" #include #include FT_FREETYPE_H diff --git a/src/platform/common/interface.h b/src/ui/interface.h similarity index 96% rename from src/platform/common/interface.h rename to src/ui/interface.h index c2964228..d9f8fefa 100755 --- a/src/platform/common/interface.h +++ b/src/ui/interface.h @@ -9,7 +9,7 @@ #ifndef INTERFACE_H #define INTERFACE_H -#include "platform/common/StringLib.h" +#include "ui/StringLib.h" struct IButtonListener { virtual ~IButtonListener() {} diff --git a/src/platform/common/maapi.h b/src/ui/maapi.h similarity index 100% rename from src/platform/common/maapi.h rename to src/ui/maapi.h diff --git a/src/platform/common/screen.cpp b/src/ui/screen.cpp similarity index 99% rename from src/platform/common/screen.cpp rename to src/ui/screen.cpp index 1f94d46e..cf06bfab 100644 --- a/src/platform/common/screen.cpp +++ b/src/ui/screen.cpp @@ -8,7 +8,7 @@ #include -#include "platform/common/screen.h" +#include "ui/screen.h" #define WHITE 15 #define SCROLL_IND 4 diff --git a/src/platform/common/screen.h b/src/ui/screen.h similarity index 98% rename from src/platform/common/screen.h rename to src/ui/screen.h index e21cd80e..0138cb80 100755 --- a/src/platform/common/screen.h +++ b/src/ui/screen.h @@ -17,12 +17,12 @@ #include #define LINE_SPACING 6 #else - #include "platform/common/maapi.h" + #include "ui/maapi.h" #define LINE_SPACING 0 #endif -#include "platform/common/StringLib.h" -#include "platform/common/utils.h" +#include "ui/StringLib.h" +#include "ui/utils.h" using namespace strlib; diff --git a/src/platform/common/system.cpp b/src/ui/system.cpp similarity index 99% rename from src/platform/common/system.cpp rename to src/ui/system.cpp index 3ae5750d..065d401d 100644 --- a/src/platform/common/system.cpp +++ b/src/ui/system.cpp @@ -10,7 +10,7 @@ #include #include -#include "platform/common/system.h" +#include "ui/system.h" #include "common/sbapp.h" #include "common/sys.h" #include "common/smbas.h" diff --git a/src/platform/common/system.h b/src/ui/system.h similarity index 96% rename from src/platform/common/system.h rename to src/ui/system.h index 6e697163..d8e54449 100755 --- a/src/platform/common/system.h +++ b/src/ui/system.h @@ -9,8 +9,8 @@ #ifndef SYSTEM_H #define SYSTEM_H -#include "platform/common/StringLib.h" -#include "platform/common/ansiwidget.h" +#include "ui/StringLib.h" +#include "ui/ansiwidget.h" struct System : public IButtonListener { System(); diff --git a/src/platform/common/utils.h b/src/ui/utils.h similarity index 100% rename from src/platform/common/utils.h rename to src/ui/utils.h