From 9dc72369e161ed7606c67392b7ffb403b47a3dc2 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Thu, 14 Aug 2014 06:58:48 +1000 Subject: [PATCH 01/21] COMMON: Added SHOWPAGE. code cleanup --- ChangeLog | 3 + samples/distro-examples/tests/pass1.bas | 2 +- src/common/brun.c | 3 + src/common/clibmgr.c | 258 ----------- src/common/device.h | 45 +- src/common/eval.c | 31 +- src/common/g_bmp.c | 242 ----------- src/common/g_bmp.h | 37 -- src/common/kw.h | 1 + src/common/osd.h | 42 -- src/common/scan.c | 4 +- src/common/screen.c | 1 - src/common/smbas.h | 2 +- src/common/var.h | 35 +- src/languages/chars.el.h | 12 - src/languages/keywords.el.c | 546 ------------------------ src/languages/keywords.en.c | 3 +- src/languages/messages.el.h | 224 ---------- src/platform/android/jni/runtime.cpp | 3 +- src/platform/common/ansiwidget.cpp | 5 +- src/platform/common/ansiwidget.h | 3 + src/platform/common/system.cpp | 9 +- src/platform/fltk/dev_fltk.cxx | 7 +- src/platform/sdl/runtime.cpp | 1 + src/platform/unix/dev_ndcfb.c | 6 +- src/platform/unix/dev_term.c | 1 - 26 files changed, 91 insertions(+), 1435 deletions(-) delete mode 100644 src/common/clibmgr.c delete mode 100644 src/common/g_bmp.c delete mode 100644 src/common/g_bmp.h delete mode 100644 src/languages/chars.el.h delete mode 100644 src/languages/keywords.el.c delete mode 100644 src/languages/messages.el.h diff --git a/ChangeLog b/ChangeLog index 44d06298..7e6b3e7f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2014-08-14 + Added SHOWPAGE. code cleanup + 2014-08-11 Cleanup system var handling, removed os_ver diff --git a/samples/distro-examples/tests/pass1.bas b/samples/distro-examples/tests/pass1.bas index f2d16fa3..85810f99 100644 --- a/samples/distro-examples/tests/pass1.bas +++ b/samples/distro-examples/tests/pass1.bas @@ -3,7 +3,7 @@ OPTION PREDEF TEXTMODE OPTION PREDEF COMMAND FOO if (command <> "FOO") then - print "ERROR" + print "ERROR"; " "; command else print "OK" end if diff --git a/src/common/brun.c b/src/common/brun.c index 9831e6c1..f4d1eac5 100755 --- a/src/common/brun.c +++ b/src/common/brun.c @@ -1267,6 +1267,9 @@ void bc_loop(int isf) { case kwDEFINEKEY: cmd_definekey(); break; + case kwSHOWPAGE: + dev_show_page(); + break; default: err_pcode_err(pcode); } diff --git a/src/common/clibmgr.c b/src/common/clibmgr.c deleted file mode 100644 index 2a1c259a..00000000 --- a/src/common/clibmgr.c +++ /dev/null @@ -1,258 +0,0 @@ -// This file is part of SmallBASIC -// -// external C-Lib support -// -// This program is distributed under the terms of the GPL v2.0 or later -// Download the GNU Public License (GPL) from www.gnu.org -// -// Copyright(C) 2000 Nicholas Christopoulos - -#include "common/sys.h" - -/** - * @defgroup clib C-Libraries manager - */ - -#if USE_CLIB -#define MAX_CLIBS 256 - -typedef struct { - void *handle; -} clib_cnode; - -static clib_node table[MAX_CLIBS]; // table of library nodes, the first -// element allocated for system purposes -static int clib_count;// number of loaded libs - -#endif - -/** - * @ingroup clib - * - * initializes the C-library manager - * - * @return 0 for success; -1 for error (actually: 'not supported' error) - */ -int clib_init() { -#if USE_CLIB - clib_count = 1; // handle 0 is reserved - table[0].handle = NULL; - return 0; -#else - return -1; -#endif -} - -/** - * @ingroup clib - * - * de-initializes the C-library manager (closes all open handles) - * - * @return 0 for success; -1 for error (actually: 'not supported' error) - */ -int clib_restore() { -#if USE_CLIB - int i; - - for (i = 1; i < clib_count; i++) - clib_unloadlib(i); - return 0; -#else - return -1; -#endif -} - -/** - * @ingroup clib - * - * loads a C-library - * - * @param libname the filename - * @return > 0 the library handle; -1 for error; 0 means static-linked (example: OS API) - */ -int clib_loadlib(const char *libname) { -#if USE_CLIB -#if defined(_UnixOS) - table[clib_count].handle = dlopen(libname, RTLD_LAZY); - if (table[clib_count].handle == NULL) { - rt_raise("CALL: CANNOT LOAD LIBRARY '%s'\nSystem reports: %s", libname, - dlerror()); - return -1; - } - - clib_count++; - return clib_count - 1; - -#elif defined(_Win32) - table[clib_count].handle = (void *)LoadLibrary(libname); - if (table[clib_count].handle == NULL) { - rt_raise("CALL: CANNOT LOAD LIBRARY '%s'", libname); - return -1; - } - - clib_count++; - return clib_count - 1; - -#endif - -#else - rt_raise("SUBSYSTEM NOT SUPPORTED"); - return -1; // not supported -#endif -} - -/** - * @ingroup clib - * - * unloads a C-library - * - * @param handle the lib-handle - */ -void clib_unloadlib(int handle) { -#if USE_CLIB - if (handle > 0 && handle < clib_count) { - if (table[handle].handle) { -#if defined(_UnixOS) - dlclose(table[handle].handle); -#elif defined(_Win32) - FreeLibrary((HMODULE) table[handle].handle); -#endif - table[handle].handle = NULL; - } - } - -#else - rt_raise("SUBSYSTEM NOT SUPPORTED"); -#endif -} - -/** - * @ingroup clib - * - * call a C-function - * - * @param handle the lib-handle - * @param name the function name - * @return depented on function - */ -void *clib_call_func(int handle, const char *name, ...) { - // NDC information - // - // It is valid for C to call a function with parameters - // even if it is declared without parameters. - // - // the ... operator works like all others, but there is - // a problem because compiler requires one parameters to be - // declared - // - // The compiler pushes the arguments on the stack with reverse order - // and after the call it is removes the allocated size from the stack - // - // Example: - // - // f(a,b,c) produces - // - // push c - // push b - // push a - // call f - // add sp, size(a)+size(b)+size(c) - // ; that means substract from stack pointer the correct size - // - // now, the push statement (at least on compilers output that I have - // study) uses default CPU's words (1 CPU word = 1 int). - // Real numbers or any bigest value uses 2 or more words. Smallest - // values (like 1 byte) are also uses 1 word. That is depented on - // CPU architecture, and it is correct. Unfortunately I don't know - // if there is a different way. - // - // The problem is the returned value. The default is to returned on - // accumulator, but that is not the rule (in any case there are no - // rules). For example the linux's gcc returns a 'int' the value on - // the stack. Turbo C uses AX (DX:AX for long ints). - // - // I had to found a cross-compiled code to call a C function, so, - // that is the idea. - // - // a) we will convert the parameters to CPU words (ptable, pcount) - // b) we will use the C function-pointer (f) without declaring the parameters - // c) we will call that function based on number of the parameters that we - // have - // d) we got the return value as int. - // - // Problems: - // We can't get a 'double' return value - -#if USE_CLIB - void *(f) (); - void *proc_ptr; - - int ptable[256]; - int pcount; - - if (handle > 0 && handle < clib_count) { - if (table[handle].handle) { -#if defined(_UnixOS) - proc_ptr = dlsym(table[handle].handle, name); -#elif defined(_Win32) - proc_ptr = GetProcAddress((HMODULE) table[handle].handle, name); -#endif - if (proc_ptr == NULL) - rt_raise("CALL: FUNCTION '%s' DOES NOT EXISTS", name); - else { - f = proc_ptr; - - } - } -} - -#else - rt_raise("SUBSYSTEM NOT SUPPORTED"); - return NULL; -#endif - } - -void clib_call_proc(int handle, const char *name, ...) { -} - -/* --- Glue with SB ------------------------------------------------------------------------------------------------------- */ - -/** - * @ingroup clib - * - * loads a C-library (SB-RTL glue) - * - * SB Syntax: handle = LOADLIB(filename) - */ -void blib_loadlib() { -} - -/** - * @ingroup clib - * - * unloads a C-library (SB-RTL glue) - * - * SB Syntax: UNLOADLIB handle - */ -void blib_unloadlib() { -} - -/** - * @ingroup clib - * - * Calls a C function (SB-RTL glue) - * - * SB Syntax: r = CALL(handle, func_name, ...) - */ -void blib_call_cfunc() { -} - -/** - * @ingroup clib - * - * Calls a C procedure (SB-RTL glue) - * - * SB Syntax: CALL handle, proc_name, ... - */ -void blib_call_cproc() { -} diff --git a/src/common/device.h b/src/common/device.h index 5dfb7294..b07ef6ab 100644 --- a/src/common/device.h +++ b/src/common/device.h @@ -69,7 +69,6 @@ typedef struct { * @param dotproc setpixel() function */ void g_line(int x1, int y1, int x2, int y2, void (*dotproc) (int, int)); -#include "common/g_bmp.h" /* * @@ -89,7 +88,6 @@ void g_line(int x1, int y1, int x2, int y2, void (*dotproc) (int, int)); #define CLR_MAGENTA 5 #define CLR_BROWN 6 #define CLR_GRAY 7 - #define CLR_WHITE 15 /** @@ -102,8 +100,6 @@ void g_line(int x1, int y1, int x2, int y2, void (*dotproc) (int, int)); * @code * byte os_charset; // System's charset (see os_charset_codes) * - * byte os_color; // True if the output has real colors (256+ colors) - * * dword os_color_depth; // The number of bits of the supported colors * // (i.e.: 8 for 256 colors, 15 or 16 for 64K, 24 or 32 for 1.6M) * @@ -313,8 +309,7 @@ void dev_delay(dword ms); * @param code is the information code * @return a value based on 'code' */ -int dev_getpen(int code); // returns the pen/mouse status -// (PEN(code)) +int dev_getpen(int code); /** * @ingroup dev_i @@ -327,8 +322,7 @@ int dev_getpen(int code); // returns the pen/mouse status * * @param enable non-zero to enable pen/mouse driver. */ -void dev_setpenmode(int enable); // enables or disables pen/mouse -// driver (PEN ON|OFF) +void dev_setpenmode(int enable); /* * @@ -343,7 +337,7 @@ void dev_setpenmode(int enable); // enables or disables pen/mouse * * @param str the string */ -void dev_print(const char *str); // write a string to the console +void dev_print(const char *str); /** * @ingroup dev_g @@ -370,15 +364,14 @@ void log_printf(const char *fmt, ...); * * clear screen */ -void dev_cls(void); // clear the screen +void dev_cls(void); /** * @ingroup dev_g * * clear from cursor to end-of-line */ -void dev_clreol(void); // clear the console line from the current -// pos. until the end of the line +void dev_clreol(void); /** * @ingroup dev_g @@ -390,7 +383,7 @@ void dev_clreol(void); // clear the console line from the current * @param x the x in pixels * @param y the y in pixels */ -void dev_setxy(int x, int y, int transform); // set cursor position. parameters in pixels. +void dev_setxy(int x, int y, int transform); /** * @ingroup dev_g @@ -399,7 +392,7 @@ void dev_setxy(int x, int y, int transform); // set cursor position. parameters * * @return the current x position */ -int dev_getx(void); // returns the current cursor x position (in pixels) +int dev_getx(void); /** * @ingroup dev_g @@ -408,7 +401,7 @@ int dev_getx(void); // returns the current cursor x position (in pixels) * * @return the current y position */ -int dev_gety(void); // returns the current cursor y position (in pixels) +int dev_gety(void); /** * @ingroup dev_g @@ -418,16 +411,16 @@ int dev_gety(void); // returns the current cursor y position (in pixels) * @param fg the standard VGA foreground color * @param bg the standard VGA foreground color */ -void dev_settextcolor(long fg, long bg); // set the text colors. (fg = foreground, bg = background) +void dev_settextcolor(long fg, long bg); /** * @ingroup dev_i * - * waits for a key + * waits until a key is pressed and returns its code * * @return the key-code */ -long int dev_getch(void); // waits until a key is pressed and returns its code +long int dev_getch(void); /** * @ingroup dev_i @@ -440,7 +433,7 @@ long int dev_getch(void); // waits until a key is pressed and returns its code * @param size the size of the buffer * @return the buf or NULL on ESCAPE */ -char *dev_gets(char *buf, int size); // the real INPUT command. Gets a string from the console +char *dev_gets(char *buf, int size); /* * @@ -634,6 +627,14 @@ void dev_ffill(word x0, word y0, long fill_color, long border_color); */ void dev_pfill(ipt_t *pts, int ptNum); +/** + * @ingroup dev_g + * + * Refreshes the graphic output. When used, the drawing to the graphic + * output window or screen is not visible until SHOWPAGE is performed + */ +void dev_show_page(); + /* * * Sound @@ -1052,8 +1053,7 @@ void dev_destroy_file_list(char_p_t *list, int count); * @param h * */ -void dev_html(const char *html, const char *title, int x, int y, int w, - int h); +void dev_html(const char *html, const char *title, int x, int y, int w, int h); /** * @image @@ -1066,8 +1066,7 @@ void dev_html(const char *html, const char *title, int x, int y, int w, * @param y * */ -void dev_image(int handle, int index, int x, int y, int sx, int sy, int w, - int h); +void dev_image(int handle, int index, int x, int y, int sx, int sy, int w, int h); /** * @imagew diff --git a/src/common/eval.c b/src/common/eval.c index fd73d931..4a2239a5 100644 --- a/src/common/eval.c +++ b/src/common/eval.c @@ -19,7 +19,8 @@ #define IP prog_ip #define CODE(x) prog_source[(x)] #define CODE_PEEK() CODE(IP) -#define V_FREE(v) if ( (v) ) { if ( (v)->type == V_STR || (v)->type == V_ARRAY ) v_free((v)); } +#define V_FREE(v) if ((v)) { if ((v)->type == V_STR || (v)->type == V_ARRAY) v_free((v)); } +#define V_IS_TYPE(v,t) (v != NULL && v->type == t) void eval(var_t *result); void mat_op1(var_t *l, int op, var_num_t n); @@ -209,9 +210,9 @@ void mat_mul(var_t *l, var_t *r) { if (m1) { m2 = mat_toc(r, &rr, &rc); if (m2) { - if (lc != rr) + if (lc != rr) { err_matdim(); - else { + } else { mr = lr; mc = rc; m = (var_num_t*) tmp_alloc(sizeof(var_num_t) * mr * mc); @@ -353,7 +354,7 @@ void eval(var_t *r) { V_FREE(r); IP--; - var_p = code_getvarptr(); + var_p = code_getvarptr_parens(0); if (prog_error) { return; @@ -426,38 +427,38 @@ void eval(var_t *r) { op = CODE(IP); IP++; - if (r->type == V_INT && v_is_type(left, V_INT)) { + if (r->type == V_INT && V_IS_TYPE(left, V_INT)) { if (op == '+') { r->v.i += left->v.i; } else { r->v.i = left->v.i - r->v.i; } - } else if (r->type == V_NUM && v_is_type(left, V_NUM)) { + } else if (r->type == V_NUM && V_IS_TYPE(left, V_NUM)) { r->type = V_NUM; if (op == '+') { r->v.n += left->v.n; } else { r->v.n = left->v.n - r->v.n; } - } else if (r->type == V_INT && v_is_type(left, V_NUM)) { + } else if (r->type == V_INT && V_IS_TYPE(left, V_NUM)) { r->type = V_NUM; if (op == '+') { r->v.n = r->v.i + left->v.n; } else { r->v.n = left->v.n - r->v.i; } - } else if (r->type == V_NUM && v_is_type(left, V_INT)) { + } else if (r->type == V_NUM && V_IS_TYPE(left, V_INT)) { if (op == '+') { r->v.n += left->v.i; } else { r->v.n = left->v.i - r->v.n; } } else { - if (r->type == V_ARRAY || v_is_type(left, V_ARRAY)) { + if (r->type == V_ARRAY || V_IS_TYPE(left, V_ARRAY)) { // // ARRAYS // - if (r->type == V_ARRAY && v_is_type(left, V_ARRAY)) { + if (r->type == V_ARRAY && V_IS_TYPE(left, V_ARRAY)) { if (op == '+') { mat_add(r, left); } else { @@ -499,11 +500,11 @@ void eval(var_t *r) { op = CODE(IP); IP++; - if (r->type == V_ARRAY || v_is_type(left, V_ARRAY)) { + if (r->type == V_ARRAY || V_IS_TYPE(left, V_ARRAY)) { // // ARRAYS // - if (r->type == V_ARRAY && v_is_type(left, V_ARRAY)) { + if (r->type == V_ARRAY && V_IS_TYPE(left, V_ARRAY)) { if (op == '*') { mat_mul(left, r); } else { @@ -769,13 +770,13 @@ void eval(var_t *r) { } } } else if (r->type == V_STR) { - if (v_is_type(left, V_STR)) { + if (V_IS_TYPE(left, V_STR)) { if (left->v.p.ptr[0] != '\0') { ri = (strstr(r->v.p.ptr, left->v.p.ptr) != NULL); } else { ri = 0; } - } else if (v_is_type(left, V_NUM) || v_is_type(left, V_INT)) { + } else if (V_IS_TYPE(left, V_NUM) || V_IS_TYPE(left, V_INT)) { var_t *v; v = v_clone(left); @@ -866,7 +867,7 @@ void eval(var_t *r) { var_t *vp; IP++; - vp = code_getvarptr(); + vp = code_getvarptr_parens(0); if (!prog_error) { r->type = V_INT; r->v.i = (intptr_t) vp->v.p.ptr; diff --git a/src/common/g_bmp.c b/src/common/g_bmp.c deleted file mode 100644 index 876bd366..00000000 --- a/src/common/g_bmp.c +++ /dev/null @@ -1,242 +0,0 @@ -// This file is part of SmallBASIC -// -// Bitmap manipulation routines -// -// This program is distributed under the terms of the GPL v2.0 or later -// Download the GNU Public License (GPL) from www.gnu.org -// -// Copyright(C) 2002 Nicholas Christopoulos - -#include "common/g_bmp.h" - -// combine dest with source using AND and store result to dest -void bmp_combine_AND(unsigned char *dest, unsigned char *source, int bpl) { - unsigned char *p = source; - unsigned char *d = dest; - - while (bpl) { - *d++ &= *p++; - bpl--; - } -} - -// combine dest with source using OR and store result to dest -void bmp_combine_OR(unsigned char *dest, unsigned char *source, int bpl) { - unsigned char *p = source; - unsigned char *d = dest; - - while (bpl) { - *d++ |= *p++; - bpl--; - } -} - -// combine dest with source using XOR and store result to dest -void bmp_combine_XOR(unsigned char *dest, unsigned char *source, int bpl) { - unsigned char *p = source; - unsigned char *d = dest; - - while (bpl) { - *d++ ^= *p++; - bpl--; - } -} - -// combine dest with source using NOT and store result to dest -void bmp_combine_NOT(unsigned char *dest, unsigned char *source, int bpl) { - unsigned char *p = source; - unsigned char *d = dest; - - while (bpl) { - *d++ = ~(*p); - p++; - bpl--; - } -} - -// combine dest with source using NAND and store result to dest -void bmp_combine_NAND(unsigned char *dest, unsigned char *source, int bpl) { - unsigned char *p = source; - unsigned char *d = dest; - - while (bpl) { - *d++ = ~(*d & *p); - p++; - bpl--; - } -} - -// combine dest with source using NOR and store result to dest -void bmp_combine_NOR(unsigned char *dest, unsigned char *source, int bpl) { - unsigned char *p = source; - unsigned char *d = dest; - - while (bpl) { - *d++ = ~(*d | *p); - p++; - bpl--; - } -} - -// combine dest with source using XNOR and store result to dest -void bmp_combine_XNOR(unsigned char *dest, unsigned char *source, int bpl) { - unsigned char *p = source; - unsigned char *d = dest; - - while (bpl) { - *d++ = ~(*d ^ *p); - p++; - bpl--; - } -} - -/* - * returns the required size for the bitmap - */ -long bmp_size(int x1, int y1, int x2, int y2, int bpp) { - long isize; - - isize = ((y2 - y1) + 1) * ((x2 - x1) + 1); - - if (bpp >= 8) - return isize * (bpp / 8) + sizeof(bmp_header_t); - - return isize * (bpp / 8 + 1) + sizeof(bmp_header_t); -} - -/* - * combine two bitmaps - */ -void bmp_combine(unsigned char *dest, unsigned char *source, int bpl, int lines, int mode) { - int ofs, y; - - for (y = 0; y < lines; y++) { - ofs = y + bpl; - - switch (mode) { - case BMP_AND: - bmp_combine_AND(dest + ofs, source + ofs, bpl); - break; - case BMP_OR: - bmp_combine_OR(dest + ofs, source + ofs, bpl); - break; - case BMP_XOR: - bmp_combine_XOR(dest + ofs, source + ofs, bpl); - break; - case BMP_NOT: - bmp_combine_NOT(dest + ofs, source + ofs, bpl); - break; - case BMP_NAND: - bmp_combine_NAND(dest + ofs, source + ofs, bpl); - break; - case BMP_NOR: - bmp_combine_NOR(dest + ofs, source + ofs, bpl); - break; - case BMP_XNOR: - bmp_combine_XNOR(dest + ofs, source + ofs, bpl); - break; - } - } -} - -/* - * generic bmp copy (using getpixel style routine) - */ -void bmp_get(bmp_t * bmp, int x1, int y1, int x2, int y2, int bpp, long(*pget)(int x, int y)) { - int x, y, dx, dx24; - long c; - char *dest; - bmp_header_t *hdr; - - hdr = (bmp_header_t *) bmp; - dest = (char *) (bmp + sizeof(bmp_header_t)); - - strcpy(hdr->sign, "$img1"); - hdr->dx = dx = (x2 - x1) + 1; - hdr->dy = (y2 - y1) + 1; - hdr->bpp = bpp; - if (bpp > 8) - hdr->bytespp = bpp / 8; - else - hdr->bytespp = 1; - - dx24 = dx * 3; - - for (y = y1; y <= y2; y++) { - for (x = x1; x <= x2; x++) { - switch (bpp) { - case 8: - ((unsigned char *) dest)[y * dx + x] = pget(x, y); - break; - case 16: - ((unsigned short int *) dest)[y * dx + x] = pget(x, y); - break; - case 24: - c = pget(x, y); -#if defined(CPU_BIGENDIAN) - ((unsigned char *) dest)[y * dx + x] = (c & 0xFF0000) >> 16; - ((unsigned char *) dest)[y * dx + x + 1] = (c & 0xFF00) >> 8; - ((unsigned char *) dest)[y * dx + x + 2] = (c & 0xFF); -#else - ((unsigned char *)dest)[y * dx + x] = (c & 0xFF); - ((unsigned char *)dest)[y * dx + x + 1] = (c & 0xFF00) >> 8; - ((unsigned char *)dest)[y * dx + x + 2] = (c & 0xFF0000) >> 16; -#endif - break; - case 32: - ((unsigned int *) dest)[y * dx + x] = pget(x, y); - break; - } - } - } -} - -/* - * generic bmp copy (using setpixel style routine) - */ -void bmp_put(bmp_t * bmp, int x1, int y1, void(*pset)(int x, int y, long c)) { - int x, y, dx, dx24; - int x2, y2, bpp; - dword c; - char *src; - - dx = bmp->dx; - x2 = x1 + bmp->dx; - y2 = y1 + bmp->dy; - bpp = bmp->bpp; - dx24 = dx * 3; - src = (char *) (bmp + sizeof(bmp_header_t)); - for (y = y1; y <= y2; y++) { - for (x = x1; x <= x2; x++) { - switch (bpp) { - case 8: - pset(x, y, ((unsigned char *) src)[y * dx + x]); - break; - case 16: - pset(x, y, ((unsigned short int *) src)[y * dx + x]); - break; - case 24: -#if defined(CPU_BIGENDIAN) - c = ((unsigned char *) src)[y * dx + x] << 16; - c |= ((unsigned char *) src)[y * dx + x + 1] << 8; - c |= ((unsigned char *) src)[y * dx + x + 2]; -#else - c = ((unsigned char *)src)[y * dx + x]; - c |= ((unsigned char *)src)[y * dx + x + 1] << 8; - c |= ((unsigned char *)src)[y * dx + x + 2] << 16; -#endif - pset(x, y, c); - break; - case 32: - pset(x, y, ((unsigned int *) src)[y * dx + x]); - break; - } - } - } -} - -/* - */ -int bmp_isvalid(bmp_t * bmp) { - return (memcmp(bmp, "$img1", 5) == 0); -} diff --git a/src/common/g_bmp.h b/src/common/g_bmp.h deleted file mode 100644 index d89d33e1..00000000 --- a/src/common/g_bmp.h +++ /dev/null @@ -1,37 +0,0 @@ -// This file is part of SmallBASIC -// -// Bitmap manipulation routines -// -// This program is distributed under the terms of the GPL v2.0 or later -// Download the GNU Public License (GPL) from www.gnu.org -// -// Copyright(C) 2000 Nicholas Christopoulos - -#if !defined(_bmp_generic_h) -#define _bmp_generic_h - -#include "common/sys.h" - -#define BMP_AND 2 -#define BMP_OR 4 -#define BMP_XOR 8 -#define BMP_NOT 0x10 -#define BMP_NAND 0x12 -#define BMP_NOR 0x14 -#define BMP_XNOR 0x18 - -typedef struct { - char sign[6]; - int dx, dy, bpp; - int bytespp; -} bmp_header_t; - -typedef bmp_header_t bmp_t; - -void bmp_combine(unsigned char *dest, unsigned char *source, int bpl, int lines, int mode); -void bmp_get(bmp_t *dest, int x1, int y1, int x2, int y2, int bpp, long(*pget)(int x, int y)); -void bmp_put(bmp_t *src, int x1, int y1, void(*pset)(int x, int y, long c)); -long bmp_size(int x1, int y1, int x2, int y2, int bpp); -int bmp_isvalid(bmp_t *bmp); - -#endif diff --git a/src/common/kw.h b/src/common/kw.h index 01d1ad13..be24fa5e 100644 --- a/src/common/kw.h +++ b/src/common/kw.h @@ -253,6 +253,7 @@ enum proc_keywords { kwHTML, kwIMAGE, kwDEFINEKEY, + kwSHOWPAGE, kwNULLPROC }; diff --git a/src/common/osd.h b/src/common/osd.h index 57a181f6..2a1a2f02 100644 --- a/src/common/osd.h +++ b/src/common/osd.h @@ -305,48 +305,6 @@ void osd_beep(void); */ void osd_refresh(void); -/** - * @ingroup lgraf - * - * return the required size in bytes of the screen image - * - * @param x1 upper-left corner - * @param y1 upper-left corner - * @param x2 lower-right corner - * @param y2 lower-right corner - * @return the image's size in bytes - */ -long osd_bmpsize(int x1, int y1, int x2, int y2); - -/** - * @ingroup lgraf - * - * copy an image from screen to buf - * - * @param x1 upper-left corner - * @param y1 upper-left corner - * @param x2 lower-right corner - * @param y2 lower-right corner - * @param buf the memory block to store the image - */ -void osd_bmpget(int x1, int y1, int x2, int y2, char *buf); - -/** - * @ingroup lgraf - * - * copy an image from memory to screen - * - * there is a c-module to do all the basics, - * like combine images using the specified write_mode. - * see g_bmp.h - * - * @param x upper-left corner - * @param y upper-left corner - * @param write_mode the write-mode - * @param buf the image - */ -void osd_bmpput(int x, int y, int write_mode, char *buf); - #if defined(__cplusplus) } #endif diff --git a/src/common/scan.c b/src/common/scan.c index 10b61a62..704eccd7 100644 --- a/src/common/scan.c +++ b/src/common/scan.c @@ -42,6 +42,7 @@ extern void sc_raise2(const char *fmt, int line, const char *buff); // sberr #define LEN_TEXTMODE STRLEN(LCN_TEXTMODE) #define LEN_CSTR STRLEN(LCN_CSTR) #define LEN_COMMAND STRLEN(LCN_COMMAND) +#define LEN_SHOWPAGE STRLEN(LCN_SHOWPAGE) #define SKIP_SPACES(p) \ while (*p == ' ' || *p == '\t') { \ @@ -3291,7 +3292,6 @@ void comp_init() { dbt_prealloc(comp_stack, os_ccpass2, sizeof(comp_pass_node_t)); // create system variables - comp_var_getID(LCN_SV_OSVER); comp_vartable[comp_var_getID(LCN_SV_OSNAME)].dolar_sup = 1; comp_var_getID(LCN_SV_SBVER); comp_var_getID(LCN_SV_PI); @@ -3978,6 +3978,8 @@ void comp_preproc_pass1(char *p) { strncmp(LCN_END_WNL, p, LEN_END_WRS) == 0)) { // end sub/func comp_preproc_func_end(p); + } else if (strncmp(LCN_SHOWPAGE, p, LEN_SHOWPAGE) == 0) { + opt_show_page = 1; } // skip text line diff --git a/src/common/screen.c b/src/common/screen.c index 6eac46d9..e25ad588 100644 --- a/src/common/screen.c +++ b/src/common/screen.c @@ -25,7 +25,6 @@ #define CLIPIN(c) ((c & 0xF) == 0) dword os_ver = 0x40000; -byte os_color = 1; dword os_color_depth = 16; byte os_graphics = 0; // CONSOLE int os_graf_mx = 80; diff --git a/src/common/smbas.h b/src/common/smbas.h index 56cd830c..f052e581 100644 --- a/src/common/smbas.h +++ b/src/common/smbas.h @@ -104,7 +104,6 @@ EXTERN byte opt_decomp; /**< decompile EXTERN byte opt_syntaxcheck; /**< syntax check only @ingroup sys */ EXTERN char opt_command[OPT_CMD_SZ]; /**< command-line parameters (COMMAND$) @ingroup sys */ -EXTERN byte opt_safedraw; /**< using safest drawing routines (PalmOS: Use API for draw) @ingroup sys */ EXTERN byte opt_usevmt; /**< using VMT on compilation by default @ingroup sys */ EXTERN int opt_base; /**< OPTION BASE x @ingroup sys */ EXTERN byte opt_uipos; /**< OPTION UICS {CHARS|PIXELS} @ingroup sys */ @@ -121,6 +120,7 @@ EXTERN byte opt_nosave; /**< do not create .sbx files EXTERN byte opt_interactive; /**< interactive mode @ingroup sys */ EXTERN byte opt_usepcre; /**< OPTION PREDEF PCRE @ingroup sys */ EXTERN byte opt_file_permitted; /**< file system permission */ +EXTERN byte opt_show_page; /**< SHOWPAGE graphics flush mode */ #define IDE_NONE 0 #define IDE_LINKED 1 diff --git a/src/common/var.h b/src/common/var.h index c155d2cd..5dce1243 100644 --- a/src/common/var.h +++ b/src/common/var.h @@ -44,24 +44,23 @@ /* * predefined system variables - index */ -#define SYSVAR_OSVER 0 /**< system variable, OSVER @ingroup var */ -#define SYSVAR_OSNAME 1 /**< system variable, OSNAME$ @ingroup var */ -#define SYSVAR_SBVER 2 /**< system variable, SBVER @ingroup var */ -#define SYSVAR_PI 3 /**< system variable, PI @ingroup var */ -#define SYSVAR_XMAX 4 /**< system variable, XMAX @ingroup var */ -#define SYSVAR_YMAX 5 /**< system variable, YMAX @ingroup var */ -#define SYSVAR_BPP 6 /**< system variable, BPP @ingroup var */ -#define SYSVAR_TRUE 7 /**< system variable, TRUE @ingroup var */ -#define SYSVAR_FALSE 8 /**< system variable, FALSE @ingroup var */ -#define SYSVAR_LINECHART 9 /**< system variable, LINECHART @ingroup var */ -#define SYSVAR_BARCHART 10 /**< system variable, BARCHART @ingroup var */ -#define SYSVAR_PWD 11 /**< system variable, PWD$ @ingroup var */ -#define SYSVAR_HOME 12 /**< system variable, HOME$ @ingroup var */ -#define SYSVAR_COMMAND 13 /**< system variable, COMMAND$ @ingroup var */ -#define SYSVAR_X 14 /**< system variable, X @ingroup var */ -#define SYSVAR_Y 15 /**< system variable, Y @ingroup var */ -#define SYSVAR_Z 16 /**< system variable, Z @ingroup var */ -#define SYSVAR_VIDADR 17 /**< system variable, VIDADR @ingroup var */ +#define SYSVAR_OSNAME 0 /**< system variable, OSNAME$ @ingroup var */ +#define SYSVAR_SBVER 1 /**< system variable, SBVER @ingroup var */ +#define SYSVAR_PI 2 /**< system variable, PI @ingroup var */ +#define SYSVAR_XMAX 3 /**< system variable, XMAX @ingroup var */ +#define SYSVAR_YMAX 4 /**< system variable, YMAX @ingroup var */ +#define SYSVAR_BPP 5 /**< system variable, BPP @ingroup var */ +#define SYSVAR_TRUE 6 /**< system variable, TRUE @ingroup var */ +#define SYSVAR_FALSE 7 /**< system variable, FALSE @ingroup var */ +#define SYSVAR_LINECHART 8 /**< system variable, LINECHART @ingroup var */ +#define SYSVAR_BARCHART 9 /**< system variable, BARCHART @ingroup var */ +#define SYSVAR_PWD 10 /**< system variable, PWD$ @ingroup var */ +#define SYSVAR_HOME 11 /**< system variable, HOME$ @ingroup var */ +#define SYSVAR_COMMAND 12 /**< system variable, COMMAND$ @ingroup var */ +#define SYSVAR_X 13 /**< system variable, X @ingroup var */ +#define SYSVAR_Y 14 /**< system variable, Y @ingroup var */ +#define SYSVAR_Z 15 /**< system variable, Z @ingroup var */ +#define SYSVAR_VIDADR 16 /**< system variable, VIDADR @ingroup var */ /** * @ingroup var diff --git a/src/languages/chars.el.h b/src/languages/chars.el.h deleted file mode 100644 index b06e9f29..00000000 --- a/src/languages/chars.el.h +++ /dev/null @@ -1,12 +0,0 @@ -#define CHS_UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZΑΆΒΓΔΕΈΖΗΉΘΙΊΪΚΛΜΝΞΟΌΠΡΣΣΤΥΎΫΦΧΨΩΏ" -#define CHS_LOWER "abcdefghijklmnopqrstuvwxyzαάβγδεέζηήθιίϊκλμνξοόπρσςτυύϋφχψωώ" - -#define is_digit(c) ((c) >= 48 && (c) <= 57) /**< true if the character is a digit @ingroup str */ -#define is_upper(c) (strchr(CHS_UPPER, (c)) != NULL) -#define is_lower(c) (strchr(CHS_LOWER, (c)) != NULL) -#define to_upper(c) (char_table_replace(CHS_LOWER, (c), CHS_UPPER)) -#define to_lower(c) (char_table_replace(CHS_UPPER, (c), CHS_LOWER)) -#define is_hexdigit(c) (is_digit((c)) || (to_upper((c)) >= 65 && to_upper((c)) <= 70)) /**< true if the character is a hexadecimal digit @ingroup str */ -#define is_octdigit(c) ((c) >= '0' && (c) <= '7') /**< true if the character is an octadecimal digit @ingroup str */ -#define to_hexdigit(c) ( ( ((c) & 0xF) > 9)? ((c)-10)+'A' : (c)+'0' ) /**< returns the hex-digit of the 4-bit number c @ingroup str */ - diff --git a/src/languages/keywords.el.c b/src/languages/keywords.el.c deleted file mode 100644 index ec6f0a1a..00000000 --- a/src/languages/keywords.el.c +++ /dev/null @@ -1,546 +0,0 @@ -/* -* SB Keywords in Greek - ISO-8859-7 -* -* Rules: -* * Names can be 15 chars long. (defined on scan.h) -* * Names must defined always with capitals. lower-case means invisible keywords. -* * Spaces are not allowed. Only letters, digits and the character '_'. -* * Alias supported just repeat the keyword. -* Example: -* { "GOTO", kwGOTO }, -* { "GOTHERE", kwGOTO }, -* This means the command GOTO it is known to the compiler with the names "GOTO" and "GOTHERE". -*/ - -/* -* GENERIC KEYWORDS (basic bc-types & oldest code) -* -* This table is limited to 256 elements -*/ -struct keyword_s keyword_table[] = { -//{ Command-Name, Command-Code }, -///1234567890123456 -{ "ΤΟΠΙΚΉ", kwLOCAL }, -{ "ΔΙΑΔΙΚΑΣΊΑ", kwPROC }, -{ "ΣΥΝΆΡΤΗΣΗ", kwFUNC }, -{ "DEF", kwFUNC }, -{ "BYREF", kwBYREF }, -{ "DECLARE", kwDECLARE }, -{ "IMPORT", kwIMPORT }, -{ "EXPORT", kwEXPORT }, -{ "UNIT", kwUNIT }, - -{ "LET", kwLET }, -{ "CONST", kwCONST }, -{ "ΠΊΝΑΚΑΣ", kwDIM }, -{ "REDIM", kwREDIM }, -{ "ΣΤΑΜΆΤΑ", kwSTOP }, -{ "ΤΈΛΟΣ", kwEND }, -{ "ΤΎΠΩΣΕ", kwPRINT }, -{ "SPRINT", kwSPRINT }, -{ "ΖΉΤΗΣΕ", kwINPUT }, -{ "SINPUT", kwSINPUT }, -{ "ΣΗΜ", kwREM }, -{ "CHAIN", kwCHAIN }, -{ "ON", kwON }, - -{ "LABEL", kwLABEL }, -{ "ΠΉΓΑΙΝΕ", kwGOTO }, -{ "ΑΝ", kwIF }, -{ "ΤΌΤΕ", kwTHEN }, -{ "ΑΛΛΙΏΣ", kwELSE }, -{ "ELIF", kwELIF }, -{ "ELSEIF", kwELIF }, -{ "ΤΈΛΟΣΤΟΥΑΝ", kwENDIF }, -{ "ΤΈΛΟΣΑΝ", kwENDIF }, -{ "ΤΑΝ", kwENDIF }, -{ "ΓΙΑ", kwFOR }, -{ "ΈΩΣ", kwTO }, -{ "STEP", kwSTEP }, -{ "ΕΠΌΜΕΝΟ", kwNEXT }, -{ "ΕΦΌΣΟΝ", kwWHILE }, -{ "ΤΕΦ", kwWEND }, -{ "ΕΠΑΝΈΛΑΒΕ", kwREPEAT }, -{ "ΜΈΧΡΙ", kwUNTIL }, -{ "SELECT", kwSELECT }, -{ "CASE", kwCASE }, -{ "GOSUB", kwGOSUB }, -{ "RETURN", kwRETURN }, -{ "READ", kwREAD }, -{ "DATA", kwDATA }, -{ "RESTORE", kwRESTORE }, -{ "ΒΓΕΣ", kwEXIT }, - -{ "ERASE", kwERASE }, -{ "USE", kwUSE }, -{ "USING", kwUSING }, -{ "USG", kwUSING }, - -{ "LINE", kwLINE }, -{ "COLOR", kwCOLOR }, - -{ "RUN", kwRUN }, -{ "EXEC", kwEXEC }, - -{ "OPEN", kwOPEN }, -{ "APPEND", kwAPPEND }, -{ "AS", kwAS }, // OPEN's args -{ "CLOSE", kwCLOSE }, -{ "LINEINPUT", kwLINEINPUT }, // The QB's keyword is "LINE INPUT" -{ "LINPUT", kwLINEINPUT }, // The QB's keyword is "LINE INPUT" -{ "SEEK", kwSEEK }, -{ "WRITE", kwFILEWRITE }, -//{ "READ", kwFILEREAD }, -//{ "INPUT", kwFINPUT }, // not needed - -{ "INSERT", kwINSERT }, -{ "DELETE", kwDELETE }, - -/* DEBUG */ -{ "TRON", kwTRON }, -{ "TROFF", kwTROFF }, -{ "OPTION", kwOPTION }, - -{ "BG", kwBACKG }, - -/* for debug */ -/* by using small letters, */ -/* the keywords are invisible by compiler */ -{ "$i32", kwTYPE_INT }, -{ "$r64", kwTYPE_NUM }, -{ "$str", kwTYPE_STR }, -{ "$log", kwTYPE_LOGOPR }, -{ "$cmp", kwTYPE_CMPOPR }, -{ "$add", kwTYPE_ADDOPR }, -{ "$mul", kwTYPE_MULOPR }, -{ "$pow", kwTYPE_POWOPR }, -{ "$unr", kwTYPE_UNROPR }, -{ "$var", kwTYPE_VAR }, -{ "$tln", kwTYPE_LINE }, -{ "$lpr", kwTYPE_LEVEL_BEGIN }, -{ "$rpr", kwTYPE_LEVEL_END }, -{ "$crv", kwTYPE_CRVAR }, -{ "$sep", kwTYPE_SEP }, -{ "$biF", kwTYPE_CALLF }, -{ "$biP", kwTYPE_CALLP }, -{ "$exF", kwTYPE_CALLEXTF }, -{ "$exP", kwTYPE_CALLEXTP }, -{ "$ret", kwTYPE_RET }, -{ "$udp", kwTYPE_CALL_UDP }, -{ "$udf", kwTYPE_CALL_UDF }, - -{ "", 0 } -}; - -/* ----------------------------------------------------------------------------------------------------------------------- */ - -/* -* OPERATORS (not the symbols) -*/ -struct opr_keyword_s opr_table[] = { -{ "ΚΑΙ", kwTYPE_LOGOPR, '&' }, -{ "Ή", kwTYPE_LOGOPR, '|' }, -{ "BAND", kwTYPE_LOGOPR, OPLOG_BAND }, -{ "BOR", kwTYPE_LOGOPR, OPLOG_BOR }, -{ "XOR", kwTYPE_LOGOPR, '~' }, -{ "NOT", kwTYPE_UNROPR, '!' }, -{ "ΥΠΌΛΟΙΠΟ", kwTYPE_MULOPR, OPLOG_MOD }, -{ "MDL", kwTYPE_MULOPR, OPLOG_MDL }, -{ "EQV", kwTYPE_LOGOPR, OPLOG_EQV }, -{ "IMP", kwTYPE_LOGOPR, OPLOG_IMP }, -{ "NAND", kwTYPE_LOGOPR, OPLOG_NAND }, -{ "NOR", kwTYPE_LOGOPR, OPLOG_NOR }, -{ "XNOR", kwTYPE_LOGOPR, OPLOG_NOR }, -{ "ΑΝΉΚΕΙ", kwTYPE_CMPOPR, OPLOG_IN }, -{ "LIKE", kwTYPE_CMPOPR, OPLOG_LIKE }, - -{ "", 0, 0 } -}; - -/* ----------------------------------------------------------------------------------------------------------------------- */ - -/* -* SPECIAL SEPERATORS -* -* This keywords are used on commands but are not commands nor operators -* -* example: -* print USING ... -* for f IN x -* open x FOR INPUT ... -*/ -struct spopr_keyword_s spopr_table[] = { -{ "ΜΕΧΡΏΜΑ", kwCOLOR }, -{ "ΓΕΜΆΤΟ", kwFILLED }, -{ "FOR", kwFORSEP }, -{ "INPUT", kwINPUTSEP }, -{ "OUTPUT", kwOUTPUTSEP }, -{ "APPEND", kwAPPENDSEP }, -{ "ACCESS", kwACCESS }, -{ "USING", kwUSING }, -{ "USG", kwUSING }, -{ "SHARED", kwSHARED }, -{ "AS", kwAS }, -{ "ΈΩΣ", kwTO }, -{ "DO", kwDO }, -{ "STEP", kwSTEP }, -{ "ΤΌΤΕ", kwTHEN }, -{ "SUB", kwPROCSEP }, -{ "FUNC", kwFUNCSEP }, -{ "DEF", kwFUNCSEP }, -{ "LOOP", kwLOOPSEP }, -{ "ON", kwON }, -{ "OFF", kwOFF }, -{ "USE", kwUSE }, -{ "BG", kwBACKG }, - -{ "", 0 } -}; - -/* ----------------------------------------------------------------------------------------------------------------------- */ - -/* -* BUILDIN-FUNCTIONS -*/ -struct func_keyword_s func_table[] = { -///1234567890123456 -{ "ASC", kwASC }, -{ "ΑΡΙΘΜ", kwVAL }, -{ "CHR", kwCHR }, -{ "ΚΕΊΜ", kwSTR }, -{ "OCT", kwOCT }, -{ "HEX", kwHEX }, -{ "LCASE", kwLCASE }, -{ "LOWER", kwLCASE }, -{ "UCASE", kwUCASE }, -{ "UPPER", kwUCASE }, -{ "LTRIM", kwLTRIM }, -{ "RTRIM", kwRTRIM }, -{ "SPACE", kwSPACE }, -{ "SPC", kwSPACE }, -{ "TAB", kwTAB }, -{ "CAT", kwCAT }, -{ "ENVIRON", kwENVIRONF }, -{ "ENV", kwENVIRONF }, -{ "TRIM", kwTRIM }, -{ "STRING", kwSTRING }, -{ "SQUEEZE", kwSQUEEZE }, -{ "LEFT", kwLEFT }, -{ "RIGHT", kwRIGHT }, -{ "LEFTOF", kwLEFTOF }, -{ "RIGHTOF", kwRIGHTOF }, -{ "LEFTOFLAST", kwLEFTOFLAST }, -{ "RIGHTOFLAST", kwRIGHTOFLAST }, -{ "MID", kwMID }, -{ "REPLACE", kwREPLACE }, -{ "RUN", kwRUNF }, -{ "INKEY", kwINKEY }, -{ "TIME", kwTIME }, -{ "DATE", kwDATE }, -{ "INSTR", kwINSTR }, -{ "RINSTR", kwRINSTR }, -{ "LBOUND", kwLBOUND }, -{ "UBOUND", kwUBOUND }, -{ "LEN", kwLEN }, -{ "EMPTY", kwEMPTY }, -{ "ISARRAY", kwISARRAY }, -{ "ISNUMBER", kwISNUMBER }, -{ "ISSTRING", kwISSTRING }, -{ "ATAN2", kwATAN2 }, -{ "POW", kwPOW }, -{ "ROUND", kwROUND }, -{ "COS", kwCOS }, -{ "SIN", kwSIN }, -{ "TAN", kwTAN }, -{ "COSH", kwCOSH }, -{ "SINH", kwSINH }, -{ "TANH", kwTANH }, -{ "ACOS", kwACOS }, -{ "ASIN", kwASIN }, -{ "ATAN", kwATAN }, -{ "ATN", kwATAN }, -{ "ACOSH", kwACOSH }, -{ "ASINH", kwASINH }, -{ "ATANH", kwATANH }, - -{ "SEC", kwSEC }, -{ "ASEC", kwASEC }, -{ "SECH", kwSECH }, -{ "ASECH", kwASECH }, - -{ "CSC", kwCSC }, -{ "ACSC", kwACSC }, -{ "CSCH", kwCSCH }, -{ "ACSCH", kwACSCH }, - -{ "COT", kwCOT }, -{ "ACOT", kwACOT }, -{ "COTH", kwCOTH }, -{ "ACOTH", kwACOTH }, - -{ "SQR", kwSQR }, -{ "ABS", kwABS }, -{ "EXP", kwEXP }, -{ "LOG", kwLOG }, -{ "LOG10", kwLOG10 }, -{ "FIX", kwFIX }, -{ "ΑΚΈΡΑΙΟΣ", kwINT }, -{ "CDBL", kwCDBL }, -{ "CREAL", kwCDBL }, -{ "DEG", kwDEG }, -{ "RAD", kwRAD }, -{ "PEN", kwPENF }, -{ "FLOOR", kwFLOOR }, -{ "CEIL", kwCEIL }, -{ "FRAC", kwFRAC }, -{ "FRE", kwFRE }, -{ "SGN", kwSGN }, -{ "CINT", kwCINT }, -{ "EOF", kwEOF }, -{ "SEEK", kwSEEKF }, -{ "LOF", kwLOF }, -{ "ΤΥΧΑΊΟΣ", kwRND }, -{ "MAX", kwMAX }, -{ "MIN", kwMIN }, -{ "ABSMAX", kwABSMAX }, -{ "ABSMIN", kwABSMIN }, -{ "SUM", kwSUM }, -{ "SUMSQ", kwSUMSV }, -{ "STATMEAN", kwSTATMEAN }, -{ "STATMEANDEV", kwSTATMEANDEV }, -{ "STATSPREADS", kwSTATSPREADS }, -{ "STATSPREADP", kwSTATSPREADP }, -{ "SEGCOS", kwSEGCOS }, -{ "SEGSIN", kwSEGSIN }, -{ "SEGLEN", kwSEGLEN }, -{ "POLYAREA", kwPOLYAREA }, -{ "POLYCENT", kwPOLYCENT }, -{ "PTDISTSEG", kwPTDISTSEG }, -{ "PTSIGN", kwPTSIGN }, -{ "PTDISTLN", kwPTDISTLN }, -{ "POINT", kwPOINT }, -{ "XPOS", kwXPOS }, -{ "YPOS", kwYPOS }, -{ "INPUT", kwINPUTF }, -{ "ARRAY", kwCODEARRAY }, -{ "LINEQN", kwGAUSSJORDAN }, -{ "FILES", kwFILES }, -{ "INVERSE", kwINVERSE }, -{ "DETERM", kwDETERM }, -{ "JULIAN", kwJULIAN }, -{ "DATEFMT", kwDATEFMT }, -{ "WEEKDAY", kwWDAY }, -{ "IF", kwIFF }, -{ "IFF", kwIFF }, -{ "FORMAT", kwFORMAT }, -{ "FREEFILE", kwFREEFILE }, -{ "TICKS", kwTICKS }, -{ "TICKSPERSEC", kwTICKSPERSEC }, -{ "TIMER", kwTIMER }, -{ "PROGLINE", kwPROGLINE }, -{ "RUN", kwRUNF }, -{ "ΠΛΆΤΟΣΚ", kwTEXTWIDTH }, -{ "ΎΨΟΣΚ", kwTEXTHEIGHT }, -{ "EXIST", kwEXIST }, -{ "ISFILE", kwISFILE }, -{ "ISDIR", kwISDIR }, -{ "ISLINK", kwISLINK }, -{ "ACCESS", kwACCESSF }, -{ "RGB", kwRGB }, -{ "RGBF", kwRGBF }, -{ "BIN", kwBIN }, -{ "ENCLOSE", kwENCLOSE }, -{ "DISCLOSE", kwDISCLOSE }, -{ "TRANSLATE", kwTRANSLATEF }, -{ "CHOP", kwCHOP }, -{ "BGETC", kwBGETC }, -{ "BALLOC", kwBALLOC }, -{ "MALLOC", kwBALLOC }, -{ "PEEK32", kwPEEK32 }, -{ "PEEK16", kwPEEK16 }, -{ "PEEK", kwPEEK }, -{ "VADR", kwVADDR }, - -{ "SEQ", kwSEQ }, - -{ "CBS", kwCBS }, -{ "BCS", kwBCS }, - -{ "LOADLIB", kwLOADLIB }, -{ "CALL", kwCALLCF }, - -{ "IMAGEW", kwIMGW }, -{ "IMAGEH", kwIMGH }, - -{ "", 0 } -}; - -/* ----------------------------------------------------------------------------------------------------------------------- */ - -/* -* BUILD-IN PROCEDURES -*/ -struct proc_keyword_s proc_table[] = { -///1234567890123456 -{ "CLS", kwCLS }, -{ "RTE", kwRTE }, -//kwSHELL, -{ "ENVIRON", kwENVIRON }, -{ "ENV", kwENVIRON }, -{ "LOCATE", kwLOCATE }, -{ "AT", kwAT }, -{ "PEN", kwPEN }, -{ "DATEDMY", kwDATEDMY }, -{ "BEEP", kwBEEP }, -{ "SOUND", kwSOUND }, -{ "NOSOUND", kwNOSOUND }, -{ "PSET", kwPSET }, -{ "RECT", kwRECT }, -{ "CIRCLE", kwCIRCLE }, -{ "RANDOMIZE", kwRANDOMIZE }, -{ "SPLIT", kwSPLIT }, -{ "WSPLIT", kwWSPLIT }, -{ "JOIN", kwWJOIN }, -{ "PAUSE", kwPAUSE }, -{ "DELAY", kwDELAY }, -{ "ARC", kwARC }, -{ "DRAW", kwDRAW }, -{ "PAINT", kwPAINT }, -{ "PLAY", kwPLAY }, -{ "SORT", kwSORT }, -{ "SEARCH", kwSEARCH }, -{ "ROOT", kwROOT }, -{ "DIFFEQN", kwDIFFEQ }, -{ "CHART", kwCHART }, -{ "WINDOW", kwWINDOW }, -{ "VIEW", kwVIEW }, -{ "DRAWPOLY", kwDRAWPOLY }, -{ "M3IDENT", kwM3IDENT }, -{ "M3ROTATE", kwM3ROTATE }, -{ "M3SCALE", kwM3SCALE }, -{ "M3TRANS", kwM3TRANSLATE }, -{ "M3APPLY", kwM3APPLY }, -{ "INTERSECT", kwSEGINTERSECT }, -{ "POLYEXT", kwPOLYEXT }, -{ "DERIV", kwDERIV }, -{ "KILL", kwKILL }, -{ "RENAME", kwRENAME }, -{ "COPY", kwCOPY }, -{ "CHDIR", kwCHDIR }, -{ "MKDIR", kwMKDIR }, -{ "RMDIR", kwRMDIR }, -{ "TLOAD", kwLOADLN }, -{ "TSAVE", kwSAVELN }, -{ "LOCK", kwFLOCK }, -{ "CHMOD", kwCHMOD }, -{ "PLOT2", kwPLOT2 }, -{ "PLOT", kwPLOT }, -{ "LOGPRINT", kwLOGPRINT }, -{ "SWAP", kwSWAP }, -{ "BUTTON", kwBUTTON }, -{ "TEXT", kwTEXT }, -{ "DOFORM", kwDOFORM }, -{ "DIRWALK", kwDIRWALK }, -{ "BPUTC", kwBPUTC }, -{ "POKE32", kwPOKE32 }, -{ "POKE16", kwPOKE16 }, -{ "POKE", kwPOKE }, -{ "BCOPY", kwBCOPY }, -{ "BLOAD", kwBLOAD }, -{ "BSAVE", kwBSAVE }, -{ "IMGGET", kwIMGGET }, -{ "IMGPUT", kwIMGPUT }, -{ "TIMEHMS", kwTIMEHMS }, -{ "EXPRSEQ", kwEXPRSEQ }, -{ "UNLOADLIB", kwUNLOADLIB }, -{ "CALL", kwCALLCP }, -{ "HTML", kwHTML }, -{ "IMAGE", kwIMAGE }, - -#if !defined(OS_LIMITED) -{ "STKDUMP", kwSTKDUMP }, -#endif - -{ "", 0 } -}; - -/* -* in some cases (preprocessor) there is needed the texts -* (single-line IFs, option keyword, include, fast-cut of 'rem's. '@' -> byref, procedures declarations, etc) -* -* _WS = With spaces (one left and one right) -* _WRS = With one space at right -*/ -#define LCN_PRINT "ΤΎΠΩΣΕ" -#define LCN_REM "ΣΗΜ" -#define LCN_THEN_WS " ΤΌΤΕ " -#define LCN_GOTO_WRS "ΠΉΓΑΙΝΕ " -#define LCN_GOTO_WS " ΠΉΓΑΙΝΕ " -#define LCN_ELSE "ΑΛΛΙΏΣ" -#define LCN_UICS_WRS "UICS " -#define LCN_CHARS "CHARS" -#define LCN_PIXELS "PIXELS" -#define LCN_BASE_WRS "BASE " -#define LCN_PCRE_CASELESS "MATCH PCRE CASELESS" -#define LCN_PCRE "MATCH PCRE" -#define LCN_SIMPLE "MATCH SIMPLE" -#define LCN_PREDEF_WRS "PREDEF " -#define LCN_IMPORT_WRS "IMPORT " -#define LCN_UNIT_WRS "UNIT " -#define LCN_BYREF_WRS "BYREF " -#define LCN_END "ΤΈΛΟΣ" -#define LCN_ENDIF "ΤΈΛΟΣΑΝ" -#define LCN_GOSUB_WS " GOSUB " -#define LCN_DO_WS " DO " -#define LCN_NEXT "ΕΠΌΜΕΝΟ" -#define LCN_IN_WS " IN " -#define LCN_WEND "ΤΕΦ" -#define LCN_IF "ΑΝ" -#define LCN_SELECT "SELECT" -#define LCN_CASE "CASE" -#define LCN_INPUT_WRS "ΖΉΤΗΣΕ " -#define LCN_OPTION "OPTION" -#define LCN_PREDEF "PREDEF" -#define LCN_QUIET "QUIET" -#define LCN_GRMODE "GRMODE" -#define LCN_TEXTMODE "TEXTMODE" -#define LCN_CSTR "CSTR" -#define LCN_UNIT_PATH "#UNIT-PATH:" -#define LCN_COMMAND "COMMAND" -#define LCN_INC "#INC:" -#define LCN_SUB_WRS "ΔΙΑΔΙΚΑΣΊΑ " -#define LCN_FUNC_WRS "ΣΥΝΆΡΤΗΣΗ " -#define LCN_DEF_WRS "DEF " -#define LCN_END_WRS "ΤΈΛΟΣ " -#define LCN_END_WNL "ΤΈΛΟΣ\n" - -/* system variables */ -#define LCN_SV_OSVER "OSVER" -#define LCN_SV_OSNAME "OSNAME" -#define LCN_SV_SBVER "SBVER" -#define LCN_SV_PI "Π" -#define LCN_SV_XMAX "ΜΈΓΙΣΤΟΧ" -#define LCN_SV_YMAX "ΜΈΓΙΣΤΟΨ" -#define LCN_SV_BPP "BPP" // Bits Per Pixel -#define LCN_SV_TRUE "TRUE" -#define LCN_SV_FALSE "FALSE" -#define LCN_SV_LINECHART "LINECHART" -#define LCN_SV_BARCHART "BARCHART" -#define LCN_SV_CWD "CWD" // Current Working Directory -#define LCN_SV_HOME "HOME" // home directory (user's personal directory) -#define LCN_SV_COMMAND "COMMAND" - -// x,y,z (USE keyword parameters) -#define LCN_SV_X "X" -#define LCN_SV_Y "Y" -#define LCN_SV_Z "Z" - -#define LCN_SV_VADR "VIDADR" // video-ram address - -// fast cut of comments (pp) -#define LCN_REM_1 ":σημ " -#define LCN_REM_2 ":σημ\t" -#define LCN_REM_3 "σημ " -#define LCN_REM_4 "σημ\n" - -#define SYS_MAIN_SECTION_NAME "Κεντρική" diff --git a/src/languages/keywords.en.c b/src/languages/keywords.en.c index 75917b5b..c699a464 100644 --- a/src/languages/keywords.en.c +++ b/src/languages/keywords.en.c @@ -423,6 +423,7 @@ struct proc_keyword_s proc_table[] = { { "HTML", kwHTML }, { "IMAGE", kwIMAGE }, { "DEFINEKEY", kwDEFINEKEY }, +{ "SHOWPAGE", kwSHOWPAGE }, #if !defined(OS_LIMITED) { "STKDUMP", kwSTKDUMP }, @@ -482,9 +483,9 @@ struct proc_keyword_s proc_table[] = { #define LCN_DEF_WRS "DEF " #define LCN_END_WRS "END " #define LCN_END_WNL "END\n" +#define LCN_SHOWPAGE "SHOWPAGE" /* system variables */ -#define LCN_SV_OSVER "OSVER" #define LCN_SV_OSNAME "OSNAME" #define LCN_SV_SBVER "SBVER" #define LCN_SV_PI "PI" diff --git a/src/languages/messages.el.h b/src/languages/messages.el.h deleted file mode 100644 index a6021030..00000000 --- a/src/languages/messages.el.h +++ /dev/null @@ -1,224 +0,0 @@ -/* -* SB Messages in Greek - ISO-8859-7 -*/ - -#define LOWER_CHAR_FOR_YES 'ν' -#define WORD_FILE "Αρχείο" -#define WORD_SECTION "Ενότητα" - -#define TABLE_WEEKDAYS_3C { "Κυρ", "Δευ", "Τρι", "Τετ", "Πεμ", "Παρ", "Σαβ" } -#define TABLE_WEEKDAYS_FULL { "Κυριακή", "Δευτέρα", "Τρίτη", "Τετάρτη", "Πέμπτη", "Παρασκευή", "Σάβατο" } -#define TABLE_MONTH_3C { "Ιαν", "Φεβ", "Μαρ", "Απρ", "Μάι", "Ιον", "Ιολ", "Αυγ", "Σεπ", "Οκτ", "Νοε", "Δεκ" } -#define TABLE_MONTH_FULL { "Ιανουάριος", "Φεβρουάριος", "Μάρτιος", "Απρίλιος", "Μάιος", "Ιούνιος", "Ιούλιος", "Αύγουστος", "Σεπτέμβριος", "Οκτώβριος", "Νοέμβριος", "Δεκέμβριος" } - -#define DATEFMT_DAY_U 'Η' -#define DATEFMT_DAY_L 'η' -#define DATEFMT_MONTH_U 'Μ' -#define DATEFMT_MONTH_L 'μ' -#define DATEFMT_YEAR_U 'Ε' -#define DATEFMT_YEAR_L 'ε' - -#define RES_NUMBER_OF_VARS "Αριθμός μεταβλητών %d (%d)\n" -#define RES_NUMBER_OF_LABS "Αριθμός ετικετών %d\n" -#define RES_NUMBER_OF_UDPS "Αριθμός ρουτινών %d\n" -#define RES_CODE_SIZE "Μέγεθος κώδικα %d\n" -#define RES_IMPORTED_LIBS "Συνδεμένες βιβλιοθήκες %d\n" -#define RES_IMPORTED_SYMS "Εισαγώμενα σύμβολα %d\n" -#define RES_EXPORTED_SYMS "Εξαγόμενα σύμβολα %d\n" -#define RES_FINAL_SIZE "Τελικό μέγεθος %d\n" - -// compiler -#define MSG_WRONG_PROCNAME "Προβληματικό όνομα ρουτίνας ή συνάρτησης: %s" -#define MSG_EXP_MIS_DQ "(έκφραση): Απουσιάζει το δεύτερο (\") όπου κλείνει το κείμενο" -#define MSG_EXP_MIS_RP "(έκφραση): Δεν υπάρχει αντιστοιχία παρενθέσεων. Απουσιάζει ένα \')\' ή υπάρχει ένα '(' παραπάνω" -#define MSG_EXP_MIS_LP "(έκφραση): Δεν υπάρχει αντιστοιχία παρενθέσεων. Απουσιάζει ένα \'(\' ή υπάρχει ένα ')' παραπάνω" -#define MSG_LABEL_NOT_DEFINED "Δεν έχετε ορίσει ετικέτα με όνομα '%s'" -#define MSG_WRONG_UNIT "Άγνωστη βιβλιοθήκη (μονάδα) '%s'. Χρησιμοποιήστε την εντολή ΣΥΝΔΕΣΗ\n" -#define MSG_NEW_LABEL "%d: νέα ετικέτα [%s], δείκτης %d\n" -#define MSG_NEW_UDP "%d: νέα ρουτίνα ή συνάρτηση [%s], δείκτης %d\n" -#define MSG_NEW_VAR "%d: νέα μεταβλητή [%s], δείκτης %d\n" -#define MSG_WRONG_VARNAME "Προβληματικό όνομα μεταβλητής: %s" -#define MSG_EXP_GENERR "Σφάλμα στην αριθμητική έκφραση" -#define MSG_BF_ARGERR "buildin function %s: without parameters" -#define MSG_KEYWORD_DO_ERR "Δεν επιτρέπεται η χρήση του KANE σ' αυτό το σημείο" -#define MSG_STATEMENT_ON_RIGHT "Statement %s must be on the left side (the first keyword of the line)" -#define MSG_OPR_APPEND_ERR "Δεν επιτρέπεται η χρήση του << σ' αυτό το σημείο" -#define MSG_WRONG_OPR "Άγνωστο σύμβολο πράξης: '%c'" -#define MSG_PARNUM_LIMIT "Paremeters limit: %d" -#define MSG_NIL_PAR_ERR "'Empty' parameters are not allowed" -#define MSG_MISSING_CHAR "Missing '%c'" -#define MSG_ARRAY_SE "Array: syntax error" -#define MSG_ARRAY_MIS_RP "Array: Missing ')', (left side of expression)" -#define MSG_ARRAY_MIS_LP "Array: Missing '(', (left side of expression)" -#define MSG_OPT_UICS_ERR "Syntax error: OPTION UICS {CHARS|PIXELS}" -#define MSG_OPTION_ERR "OPTION: Unrecognized option '%s'" -#define MSG_IT_IS_KEYWORD "%s: is keyword (left side of expression)" -#define MSG_USE_DECL "Use DECLARE with SUB or FUNC keyword" -#define MSG_LET_MISSING_EQ "LET/CONST/APPEND: Missing '='" -#define MSG_EXIT_ERR "Use EXIT [FOR|LOOP|SUB|FUNC]" -#define MSG_UDP_ALREADY_EXISTS "The SUB/FUNC %s is already defined" -#define MSG_MISSING_UDP_BODY "FUNC/DEF it has an '=' on declaration, but I didn't found the body!" -#define MSG_UNIT_NAME_MISSING "EXPORT: Unit name is not defined" -#define MSG_ON_GOTO_ERR "ON x GOTO WHERE?" -#define MSG_ON_GOSUB_ERR "ON x GOSUB WHERE?" -#define MSG_ON_NOTHING "ON WHAT?" -#define MSG_FOR_NOTHING "FOR: Missing '=' OR 'IN'" -#define MSG_FOR_COUNT_ERR "FOR: %s is not a variable" -#define MSG_FOR_ARR_COUNT "FOR: %s is an array. Arrays are not allowed" -#define MSG_SPECIAL_KW_ERR "%s: Wrong position" -#define MSG_DETAILED_REPORT_Q "Detailed report (y/N) ?" -#define MSG_PASS2_COUNT "\rΦάση 2: Κόμβος %d/%d" -#define MSG_UDP_MISSING_END "SUB/FUNC: Missing END on the same level" -#define MSG_MISSING_NEXT "FOR: Missing NEXT on the same level" -#define MSG_MISSING_IN "FOR: Missing IN" -#define MSG_MISSING_TO "FOR: Missing TO" -#define MSG_MISSING_WEND "WHILE: Missing WEND on the same level" -#define MSG_MISSING_UNTIL "REPEAT: Missing UNTIL on the same level" -#define MSG_MISSING_ENDIF_OR_ELSE "IF: Missing ELIF/ELSE/ENDIF on the same level" -#define MSG_MISSING_ENDIF "(ELSE) IF: Missing ENDIF on the same level" -#define MSG_MISSING_WHILE "WEND: Missing WHILE on the same level" -#define MSG_MISSING_REPEAT "UNTIL: Missing REPEAT on the same level" -#define MSG_MISSING_FOR "NEXT: Missing FOR on the same level" -#define MSG_MISSING_IF "ENDIF: Missing IF on the same level" -#define MSG_MEMBER_DOES_NOT_EXISTS "Unit has no member named '%s'\n" -#define MSG_CANT_OPEN_FILE_AT "Can't open '%s' at '%s'\n" -#define MSG_CANT_OPEN_FILE "Can't open '%s'\n" -#define MSG_GRMODE_ERR "GRMODE, usage:x[x]\nExample: OPTION PREDEF GRMODE=640x480x4\n" -#define MSG_UNIT_NOT_FOUND "Unit %s.sbu not found" -#define MSG_IMPORT_FAILED "Unit %s.sbu, import failed" -#define MSG_INVALID_UNIT_NAME "Invalid unit name" -#define MSG_UNIT_ALREADY_DEFINED "Unit name alread defined" -#define MSG_OPT_PREDEF_ERR "OPTION PREDEF: Unrecognized option '%s'" -#define MSG_MANY_UNIT_DECL "Use 'Unit' keyword only once" -#define MSG_INC_MIS_DQ "#INC: Missing \"" -#define MSG_INC_FILE_DNE "File %s: File %s does not exist" -#define MSG_UDP_ALREADY_DECL "SUB/FUNC %s already defined" -#define MSG_UDP_MIS_END_2 "File %s: SUB/FUNC: Missing END (possibly in %s)" -#define MSG_PASS1 "Φάση 1...\n" -#define MSG_PASS1_COUNT "\rΦάση 1: Γραμμή %d" -#define MSG_UNDEFINED_UDP "Μη ορισμένη ρουτίνα ή συνάρτηση: %s" -#define MSG_PASS1_FIN "\rΦάση 1: Γραμμή %d... Τελείωσε.\n" -#define MSG_EXP_SYM_NOT_FOUND "Export symbol '%s' not found" -#define MSG_PASS2 "Φάση 2..." -#define MSG_MISSING_END_3 "SUB/FUNC: Missing END" -#define MSG_LOOPS_OPEN "%d loop(s) remains open" -#define MSG_CREATING_UNIT "\nΔημιουργία βιβλιοθήκης (μονάδα) %s...\n" -#define MSG_CREATING_BC "Δημιουργία κωδικοποιημένου αρχείου...\n" -#define MSG_UNIT_NAME_DIF_THAN_SRC "Warning: unit's file name is different than source\n" -#define MSG_BC_FILE_CREATED "Το τελικό αρχείο '%s' δημιουργήθηκε!\n" -#define MSG_BC_FILE_ERROR "Can't create binary file\n" -#define MSG_CASE_CASE_ELSE "CASE following CASE ELSE" -#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" - -// executor -#define WORD_ERROR_AT "ΣΦΑΛΜΑ ΣΤΗΝ ΓΡΑΜΜΗ" -#define WORD_DESCRIPTION "Περιγραφή" -#define WORD_COMP "ΜΕΤΑΦΡΑΣΗ" // Compiler (COMP) error or RunTime error (RTE) -#define WORD_RTE "ΕΚΤΕΛΕΣΗ" -#define WORD_DONE "ΤΕΛΟΣ" -#define WORD_BREAK_AT "ΔΙΑΚΟΠΗ ΣΤΗΝ ΓΡΑΜΜΗ" -#define WORD_INPUT_REDO "Επανάληψη από την αρχή" -#define WORD_GOTO "ΕΚΤΕΛΕΣΕ" -#define WORD_GOSUB "ΕΚΤΡΟΥ" -#define WORD_INF "ΑΠΡ" // infinity - -#define FSERR_OUT_OF_MEMORY "FS: Out of memory" -#define FSERR_INVALID_PARAMETER "FS: Invalid parameter" -#define FSERR_CORRUPTED "FS: File is corrupted or invalid" -#define FSERR_NOT_FOUND "FS: File not found" -#define FSERR_TYPE_MSM "FS: Type or creator not what was specified" -#define FSERR_OVERWRITE "FS: Coundn't replace existing file" -#define FSERR_CREATE "FS: Couldn't create new file" -#define FSERR_OPEN "FS: Generic open error" -#define FSERR_USED "FS: File is in use" // (exclusive) -#define FSERR_READ_ONLY "FS: File is read-only" -#define FSERR_HANDLE "FS: Invalid file handle" -#define FSERR_CLOSE "FS: Error closing file" -#define FSERR_EOF "FS: Past end of file" -#define FSERR_ACCESS "FS: Access denied" -#define FSERR_GENERIC "FS: Generic I/O error" -#define FSERR_PALM_EOF "FS: End-Of-File error!" -#define FSERR_ANOMALO "FS: File is not a stream" -#define FSERR_FMT "FS(%d): %s" -#define FSERR_TOO_MANY_FILES "FS: TOO MANY OPEN FILES" -#define FSERR_WRONG_DRIVER "UNKNOWN DEVICE OR FS" - -#define ERR_MISSING_RP "Missing ')' OR invalid number of parameters" -#define ERR_MATRIX_DIM "Matrix dimension error" -#define ERR_SYNTAX "Συντακτικό σφάλμα" -#define ERR_MISSING_SEP "Missing separator '%c'" -#define ERR_PARCOUNT "Error number of parameters" -#define ERR_STACK_OVERFLOW "Stack overflow" -#define ERR_STACK_UNDERFLOW "Stack underflow" -#define ERR_STACK "Stack mess!" -#define ERR_ARRAY_MISSING_LP "Array: Missing '('" -#define ERR_ARRAY_MISSING_RP "Array: Missing ')'" -#define ERR_ARRAY_RANGE "Array: Index '%d' out of range. (Max = %d)" -#define ERR_TYPE "Type mismatch" -#define ERR_PARAM "Invalid parameter" - -#define EVAL_VAR_IS_ARRAY "Eval: Variable is an array" -#define EVAL_VAR_IS_NOT_ARRAY "Eval: Variable is NOT an array (Use DIM)" -#define EVAL_NOT_A_NUM "Eval: Not a number" -#define EVAL_SYNTAX "Eval: Syntax error" -#define EVAL_TYPE "Eval: Type mismatch" -#define EVAL_PARAM "Eval: Invalid parameter" -#define ERR_UNSUPPORTED "Unsupported" -#define ERR_CONST "LET: Cannot change a constant" -#define ERR_NOT_A_VAR "Not a variable" -#define ERR_NOT_ARR_OR_FUNC "NOT an array OR function" -#define ERR_RANGE "Out of range" -#define ERR_MISSING_SEP_OR_PAR "Missing separator OR parenthesis" -#define ERR_DIVZERO "Division by zero" -#define ERR_OPERATOR "Operator NOT allowed" -#define ERR_MATSIG "Matrix singular" -#define ERR_MISSING_LP "Missing '('" -#define ERR_PARFMT "Parameters count/format error (%s)" -#define ERR_BYREF "Parameter %d cannot BYREF" -#define ERR_STR_RANGE "String: Index out of range (%d)" -#define ERR_BAD_FILE_HANDLE "VFS: Bad 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 buildin function call %ld, please report this bug" -#define ERR_GPF "\n\aOUT OF ADDRESS SPACE\n" -#define ERR_CRITICAL_MISSING_PROC "Unsupported buildin procedure call %ld, please report this bug" -#define ERR_CHAIN_FILE "CHAIN: FILE '%s' DOES NOT EXIST" -#define ERR_RUN_FILE "RUN/EXEC\"%s\" FAILED" -#define ERR_RUNFUNC_FILE "RUN(\"%s\"): FAILED" -#define ERR_PARCOUNT_SP "PARAM COUNT ERROR @%d=%X" -#define ERR_DATE "Invalid DATE: '%s'. Expected DD/MM/YYYY" -#define ERR_TIME "Invalid TIME: '%s'. Expected HH:MM:SS" -#define ERR_BOUND_DIM "U/LBOUND: Array of %d dimensions (%d)" -#define ERR_BOUND_VAR "U/LBOUND: Variable is not an array" -#define ERR_FORMAT_INVALID_FORMAT "WRONG FORMAT" -#define ERR_CENTROID "CENTROID IS UNDEFINED" -#define ERR_WRONG_POLY "POLYGON IS WRONG" -#define ERR_POINT "POINT() Invalid parameter" -#define ERR_LINEEQN_ADIM "MATRIX A WRONG DIM %dx%d" -#define ERR_LINEEQN_BDIM "MATRIX B WRONG DIM %dx%d" -#define ERR_WRONG_MAT "MATRIX: WRONG DIM %dx%d" -#define ERR_INPUT_NO_VARS "INPUT without variables" -#define ERR_ONGOTO_RANGE "ON x %s: OUT OF RANGE" -#define ERR_EXITFOR "EXIT FOR: NO 'FOR' INSIDE SUB/FUNC" -#define ERR_EXITLOOP "EXIT LOOP: NO 'LOOP' INSIDE SUB/FUNC" - -#define ERR_READ_DATA_START "READ: USE RESTORE [label]" -#define ERR_READ_DATA_INDEX "READ: OUT OF RANGE(DATA)" -#define ERR_READ_DATA_INDEX_FMT "READ: OUT OF RANGE(DATA) IDX=%d" - -#define ERR_PUTENV "ENV failed" -#define ERR_EXPRSEQ_WITHOUT_EXPR "EXPRSEQ: missing expression" -#define ERR_POLY_POINT "Parsing point: type mismatch!" - -#define ERR_VP_POS "Viewport out of screen" -#define ERR_VP_ZERO "Viewport of zero size" -#define ERR_WIN_ZERO "Window of zero size" - -#define ERR_DRAW_SEP "DRAW: MISSING ," -#define ERR_DRAW_CMD "DRAW: '%c' UNSUPPORTED" - -// memory manager -#define MEM_OUT_OF_MEM "Δεν υπάρχει αρκετή μνήμη" - diff --git a/src/platform/android/jni/runtime.cpp b/src/platform/android/jni/runtime.cpp index 9bd35a60..2d88e8a1 100644 --- a/src/platform/android/jni/runtime.cpp +++ b/src/platform/android/jni/runtime.cpp @@ -286,8 +286,9 @@ void Runtime::runShell() { opt_quiet = true; opt_command[0] = 0; opt_usevmt = 0; - os_graphics = 1; opt_file_permitted = 1; + os_graphics = 1; + os_color_depth = 16; _app->activity->callbacks->onContentRectChanged = onContentRectChanged; loadConfig(); diff --git a/src/platform/common/ansiwidget.cpp b/src/platform/common/ansiwidget.cpp index c64e3efd..6a1b784b 100755 --- a/src/platform/common/ansiwidget.cpp +++ b/src/platform/common/ansiwidget.cpp @@ -463,6 +463,7 @@ AnsiWidget::AnsiWidget(IButtonListener *listener, int width, int height) : _yMove(-1), _touchTime(0), _swipeExit(false), + _autoflush(true), _buttonListener(listener), _activeButton(NULL) { for (int i = 0; i < MAX_SCREENS; i++) { @@ -573,8 +574,8 @@ void AnsiWidget::edit(IFormWidget *formWidget, int c) { // display and pending images changed void AnsiWidget::flush(bool force, bool vscroll, int maxPending) { - bool update = false; - if (_front != NULL) { + if (_front != NULL && _autoflush) { + bool update = false; if (force) { update = _front->_dirty; } else if (_front->_dirty) { diff --git a/src/platform/common/ansiwidget.h b/src/platform/common/ansiwidget.h index 3982683c..d43a18a3 100755 --- a/src/platform/common/ansiwidget.h +++ b/src/platform/common/ansiwidget.h @@ -222,6 +222,7 @@ struct AnsiWidget { void drawRectFilled(int x1, int y1, int x2, int y2); void edit(IFormWidget *formWidget, int c); void flush(bool force, bool vscroll=false, int maxPending = MAX_PENDING); + void flushNow() { if (_front) _front->drawBase(false); } int getBackgroundColor() { return _back->_bg; } int getColor() { return _back->_fg; } int getFontSize() { return _fontSize; } @@ -239,6 +240,7 @@ struct AnsiWidget { void resize(int width, int height); void setColor(long color); void setDirty() { _back->setDirty(); } + void setAutoflush(bool autoflush) { _autoflush = autoflush; } void setFontSize(int fontSize); void setPixel(int x, int y, int c); void setTextColor(long fg, long bg); @@ -279,6 +281,7 @@ struct AnsiWidget { int _yMove; // touch move y value int _touchTime; // last move time bool _swipeExit; // last touch-down was swipe exit + bool _autoflush; // flush internally IButtonListener *_buttonListener; Widget *_activeButton; }; diff --git a/src/platform/common/system.cpp b/src/platform/common/system.cpp index a8b421fe..31104820 100644 --- a/src/platform/common/system.cpp +++ b/src/platform/common/system.cpp @@ -405,14 +405,11 @@ void System::setRunning(bool running) { os_graf_mx = _output->getWidth(); os_graf_my = _output->getHeight(); - os_ver = 1; - os_color = 1; - os_color_depth = 16; - dev_clrkb(); ui_reset(); _output->reset(); + _output->setAutoflush(!opt_show_page); _state = kRunState; _loadPath.empty(); _lastEventTime = maGetMilliSecondCount(); @@ -616,4 +613,6 @@ char *dev_read(const char *fileName) { return g_system->readSource(fileName); } - +void dev_show_page() { + g_system->_output->flushNow(); +} diff --git a/src/platform/fltk/dev_fltk.cxx b/src/platform/fltk/dev_fltk.cxx index 2a9cd0bf..b39c3f70 100644 --- a/src/platform/fltk/dev_fltk.cxx +++ b/src/platform/fltk/dev_fltk.cxx @@ -96,8 +96,7 @@ int osd_devinit() { os_graf_mx = wnd->_out->w(); os_graf_my = wnd->_out->h(); - os_color = 1; - os_color_depth = 16; + os_color_depth = 32; if (SharedImage::first_image) { SharedImage::first_image->clear_cache(); } @@ -315,6 +314,10 @@ void lwrite(const char *s) { } } +void dev_show_page() { + +} + //--ENV------------------------------------------------------------------------- int dev_putenv(const char *s) { diff --git a/src/platform/sdl/runtime.cpp b/src/platform/sdl/runtime.cpp index f17f7886..4fdc8b59 100644 --- a/src/platform/sdl/runtime.cpp +++ b/src/platform/sdl/runtime.cpp @@ -84,6 +84,7 @@ int Runtime::runShell(const char *startupBas, int fontScale) { logEntered(); os_graphics = 1; + os_color_depth = 16; opt_interactive = true; opt_usevmt = 0; opt_file_permitted = 1; diff --git a/src/platform/unix/dev_ndcfb.c b/src/platform/unix/dev_ndcfb.c index 19b2123a..bd36e27a 100644 --- a/src/platform/unix/dev_ndcfb.c +++ b/src/platform/unix/dev_ndcfb.c @@ -225,8 +225,6 @@ int osd_devinit() { os_graf_mx = dev_width; os_graf_my = dev_height; os_color_depth = dev_depth; - os_color = 1; - setsysvar_str(SYSVAR_OSNAME, "Unix/FB"); gfb_init(dev_width, dev_height, dev_depth); @@ -353,6 +351,10 @@ int osd_events(int wait_flag) { return 0; } +void dev_show_page() { + // empty +} + ////////// #if !defined(DRV_SOUND) diff --git a/src/platform/unix/dev_term.c b/src/platform/unix/dev_term.c index defadca8..dfd7be9a 100644 --- a/src/platform/unix/dev_term.c +++ b/src/platform/unix/dev_term.c @@ -468,7 +468,6 @@ int term_init() { */ os_graf_mx = scr_w; os_graf_my = scr_h; - os_color = 1; /* * build VRAM From 9ccace451dcd3a2a9843f2dd0acb72098c5d3e28 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Sat, 16 Aug 2014 08:14:28 +1000 Subject: [PATCH 02/21] COMMON: code clean, hotspot fixes --- ChangeLog | 3 + configure.ac | 200 +---- samples/distro-examples/tests/plasma.bas | 42 + src/common/brun.c | 58 -- src/common/eval.c | 30 +- src/common/smbas.h | 56 ++ src/common/var.c | 16 - src/common/var.h | 46 +- src/platform/common/system.cpp | 1 + src/platform/gtk/Makefile.am | 35 - src/platform/gtk/configure.in | 114 --- src/platform/gtk/data/Makefile.am | 12 - .../gtk/data/com.nokia.sbasic.service.in | 4 - src/platform/gtk/data/sbasic.desktop.in | 12 - src/platform/gtk/debian/changelog | 21 - src/platform/gtk/debian/control | 10 - src/platform/gtk/debian/copyright | 2 - src/platform/gtk/debian/rules | 83 -- src/platform/gtk/debian/sbasic.links | 3 - src/platform/gtk/icons/Makefile.am | 7 - src/platform/gtk/icons/sbasic_32.png | Bin 1013 -> 0 bytes src/platform/gtk/ide/config.h | 60 -- src/platform/gtk/ide/sbgtk.dev | 129 --- src/platform/gtk/ide/sbgtk.dsp | 136 --- src/platform/gtk/ide/sbgtk.dsw | 30 - src/platform/gtk/sbgtk.glade | 321 ------- src/platform/gtk/sbgtk.gladep | 9 - src/platform/gtk/src/Makefile.am | 38 - src/platform/gtk/src/callbacks.c | 80 -- src/platform/gtk/src/callbacks.h | 19 - src/platform/gtk/src/form_ui.c | 735 ---------------- src/platform/gtk/src/interface.c | 293 ------- src/platform/gtk/src/interface.h | 8 - src/platform/gtk/src/main.c | 85 -- src/platform/gtk/src/output.c | 680 --------------- src/platform/gtk/src/output.h | 16 - src/platform/gtk/src/output_model.c | 163 ---- src/platform/gtk/src/output_model.h | 84 -- src/platform/gtk/src/output_write.c | 333 ------- src/platform/gtk/src/support.c | 121 --- src/platform/gtk/src/support.h | 65 -- src/platform/qt/Makefile.am | 50 -- src/platform/qt/ansiwidget.cpp | 815 ------------------ src/platform/qt/ansiwidget.h | 120 --- src/platform/qt/bas/bookmarks.bas | 2 - src/platform/qt/bas/home.bas | 2 - src/platform/qt/bas/list.bas | 11 - src/platform/qt/bas/settings.bas | 3 - src/platform/qt/console_view.ui | 36 - src/platform/qt/dev_qt.cpp | 622 ------------- src/platform/qt/fixedlayout.cpp | 75 -- src/platform/qt/fixedlayout.h | 38 - src/platform/qt/form_ui.cpp | 776 ----------------- src/platform/qt/form_ui.h | 52 -- src/platform/qt/httpfile.cpp | 61 -- src/platform/qt/httpfile.h | 40 - src/platform/qt/images/home.png | Bin 1364 -> 0 bytes src/platform/qt/images/jump.png | Bin 1567 -> 0 bytes src/platform/qt/images/next.png | Bin 1503 -> 0 bytes src/platform/qt/images/previous.png | Bin 1515 -> 0 bytes src/platform/qt/images/refresh.png | Bin 1714 -> 0 bytes src/platform/qt/images/stop.png | Bin 1796 -> 0 bytes src/platform/qt/main.cpp | 25 - src/platform/qt/mainwindow.cpp | 698 --------------- src/platform/qt/mainwindow.h | 120 --- src/platform/qt/mainwindow.ui | 310 ------- src/platform/qt/res/bookmarks.bas | 2 - src/platform/qt/res/home.bas | 2 - src/platform/qt/res/home.png | Bin 1364 -> 0 bytes src/platform/qt/res/jump.png | Bin 1567 -> 0 bytes src/platform/qt/res/next.png | Bin 1503 -> 0 bytes src/platform/qt/res/previous.png | Bin 1515 -> 0 bytes src/platform/qt/res/refresh.png | Bin 1714 -> 0 bytes src/platform/qt/res/settings.bas | 3 - src/platform/qt/res/stop.png | Bin 1796 -> 0 bytes src/platform/qt/sbasic.pro | 40 - src/platform/qt/sbasic.qrc | 15 - src/platform/qt/source_view.ui | 40 - 78 files changed, 139 insertions(+), 7979 deletions(-) create mode 100644 samples/distro-examples/tests/plasma.bas delete mode 100644 src/platform/gtk/Makefile.am delete mode 100644 src/platform/gtk/configure.in delete mode 100644 src/platform/gtk/data/Makefile.am delete mode 100644 src/platform/gtk/data/com.nokia.sbasic.service.in delete mode 100644 src/platform/gtk/data/sbasic.desktop.in delete mode 100644 src/platform/gtk/debian/changelog delete mode 100644 src/platform/gtk/debian/control delete mode 100644 src/platform/gtk/debian/copyright delete mode 100644 src/platform/gtk/debian/rules delete mode 100644 src/platform/gtk/debian/sbasic.links delete mode 100644 src/platform/gtk/icons/Makefile.am delete mode 100644 src/platform/gtk/icons/sbasic_32.png delete mode 100644 src/platform/gtk/ide/config.h delete mode 100644 src/platform/gtk/ide/sbgtk.dev delete mode 100644 src/platform/gtk/ide/sbgtk.dsp delete mode 100644 src/platform/gtk/ide/sbgtk.dsw delete mode 100644 src/platform/gtk/sbgtk.glade delete mode 100644 src/platform/gtk/sbgtk.gladep delete mode 100644 src/platform/gtk/src/Makefile.am delete mode 100644 src/platform/gtk/src/callbacks.c delete mode 100644 src/platform/gtk/src/callbacks.h delete mode 100644 src/platform/gtk/src/form_ui.c delete mode 100644 src/platform/gtk/src/interface.c delete mode 100644 src/platform/gtk/src/interface.h delete mode 100644 src/platform/gtk/src/main.c delete mode 100644 src/platform/gtk/src/output.c delete mode 100644 src/platform/gtk/src/output.h delete mode 100644 src/platform/gtk/src/output_model.c delete mode 100644 src/platform/gtk/src/output_model.h delete mode 100644 src/platform/gtk/src/output_write.c delete mode 100644 src/platform/gtk/src/support.c delete mode 100644 src/platform/gtk/src/support.h delete mode 100644 src/platform/qt/Makefile.am delete mode 100644 src/platform/qt/ansiwidget.cpp delete mode 100644 src/platform/qt/ansiwidget.h delete mode 100644 src/platform/qt/bas/bookmarks.bas delete mode 100644 src/platform/qt/bas/home.bas delete mode 100644 src/platform/qt/bas/list.bas delete mode 100644 src/platform/qt/bas/settings.bas delete mode 100644 src/platform/qt/console_view.ui delete mode 100644 src/platform/qt/dev_qt.cpp delete mode 100644 src/platform/qt/fixedlayout.cpp delete mode 100644 src/platform/qt/fixedlayout.h delete mode 100644 src/platform/qt/form_ui.cpp delete mode 100644 src/platform/qt/form_ui.h delete mode 100644 src/platform/qt/httpfile.cpp delete mode 100644 src/platform/qt/httpfile.h delete mode 100644 src/platform/qt/images/home.png delete mode 100644 src/platform/qt/images/jump.png delete mode 100644 src/platform/qt/images/next.png delete mode 100644 src/platform/qt/images/previous.png delete mode 100644 src/platform/qt/images/refresh.png delete mode 100644 src/platform/qt/images/stop.png delete mode 100644 src/platform/qt/main.cpp delete mode 100644 src/platform/qt/mainwindow.cpp delete mode 100644 src/platform/qt/mainwindow.h delete mode 100644 src/platform/qt/mainwindow.ui delete mode 100644 src/platform/qt/res/bookmarks.bas delete mode 100644 src/platform/qt/res/home.bas delete mode 100644 src/platform/qt/res/home.png delete mode 100644 src/platform/qt/res/jump.png delete mode 100644 src/platform/qt/res/next.png delete mode 100644 src/platform/qt/res/previous.png delete mode 100644 src/platform/qt/res/refresh.png delete mode 100644 src/platform/qt/res/settings.bas delete mode 100644 src/platform/qt/res/stop.png delete mode 100644 src/platform/qt/sbasic.pro delete mode 100644 src/platform/qt/sbasic.qrc delete mode 100644 src/platform/qt/source_view.ui diff --git a/ChangeLog b/ChangeLog index 7e6b3e7f..7c2ffdaa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2014-08-15 + Performance tweaks + 2014-08-14 Added SHOWPAGE. code cleanup diff --git a/configure.ac b/configure.ac index 1e5b22b5..be114145 100644 --- a/configure.ac +++ b/configure.ac @@ -24,11 +24,6 @@ PKG_PROG_PKG_CONFIG TARGET="" dnl define build arguments -AC_ARG_ENABLE(gtk, - AS_HELP_STRING([--enable-gtk],[build gtk version(default=no)]), - [ac_build_gtk="yes"], - [ac_build_gtk="no"]) - AC_ARG_ENABLE(fltk, AS_HELP_STRING([--enable-fltk],[build fltk version(default=no)]), [ac_build_fltk="yes"], @@ -39,11 +34,6 @@ AC_ARG_ENABLE(sdl, [ac_build_sdl="yes"], [ac_build_sdl="no"]) -AC_ARG_ENABLE(qt, - AS_HELP_STRING([--enable-qt],[build QT version(default=no)]), - [ac_build_qt="yes"], - [ac_build_qt="no"]) - AC_ARG_ENABLE(mosync, AS_HELP_STRING([--enable-mosync],[build common library for Mosync(default=no)]), [ac_build_mosync="yes"], @@ -91,9 +81,6 @@ function checkDebugMode() { CFLAGS="${CFLAGS} -g -O0" CXXFLAGS="${CXXFLAGS} -g -O0" AC_DEFINE(_DEBUG, 1, [debugging build enabled]) - else - CFLAGS="${CFLAGS} -O3 -Os" - CXXFLAGS="${CXXFLAGS} -O3 -Os" fi AC_SUBST(CFLAGS) } @@ -124,135 +111,9 @@ function checkPCRE() { } function defaultConditionals() { - AM_CONDITIONAL(WITH_HILDON, false) AM_CONDITIONAL(WITH_CYGWIN_CONSOLE, false) } -function checkHILDON() { - # copied from - # https://stage.maemo.org/svn/maemo/projects/tools/branches/maemopad/chinook/configure.ac - - # Hildon library dependsncies - PKG_CHECK_MODULES(HILDON, hildon-1 hildon-fm-2 hildon-help conbtdialogs) - AC_SUBST(HILDON_LIBS) - AC_SUBST(HILDON_CFLAGS) - - # Only used for the .service file path - PKG_CHECK_MODULES(DBUS, dbus-glib-1 >= 0.60) - - # OSSO application framework dependencies - PKG_CHECK_MODULES(OSSO, osso-af-settings >= 0.8.5 libosso >= 0.9.17 - gnome-vfs-2.0 >= 2.8.4.11 gnome-vfs-module-2.0 >= 2.8.4.11) - AC_SUBST(OSSO_LIBS) - AC_SUBST(OSSO_CFLAGS) - - # To make application visible in maemo Task Navigator it needs a Desktop - # file for the application. - # D-BUS service file is needed to be able to launch the maemo application - # and connect it to D-BUS services. - # The following line defines install directories for these files. - desktopentrydir=`$PKG_CONFIG osso-af-settings --variable=desktopentrydir` - serviceentrydir=`$PKG_CONFIG osso-af-settings --variable=dbusservicedir` - - # Application locale install directory - localedir=`$PKG_CONFIG osso-af-settings --variable=localedir` - - # Application pixmaps install directory - pixmapdir=`$PKG_CONFIG osso-af-settings --variable=hildonpixmapdir` - - # Application icon install directories - icon_26x26dir=$datadir/icons/hicolor/26x26/hildon - icon_34x34dir=$datadir/icons/hicolor/34x34/hildon - icon_40x40dir=$datadir/icons/hicolor/40x40/hildon - icon_50x50dir=$datadir/icons/hicolor/50x50/hildon - icon_scalabledir=$datadir/icons/hicolor/scalable/hildon - - # Hildon control panel plugin install directories - pluginlibdir=`$PKG_CONFIG hildon-control-panel --variable=plugindir` - plugindesktopentrydir=`$PKG_CONFIG hildon-control-panel --variable=plugindesktopentrydir` - - # Define as variables in Makefiles - AC_SUBST(desktopentrydir) - AC_SUBST(serviceentrydir) - AC_SUBST(localedir) - AC_SUBST(pixmapdir) - AC_SUBST(icon_26x26dir) - AC_SUBST(icon_34x34dir) - AC_SUBST(icon_40x40dir) - AC_SUBST(icon_50x50dir) - AC_SUBST(icon_scalabledir) - AC_SUBST(pluginlibdir) - AC_SUBST(plugindesktopentrydir) - - AC_DEFINE_UNQUOTED([LOCALEDIR], "${localedir}", [Runtime locale catalog files path]) - AC_DEFINE_UNQUOTED([PIXMAPDIR], "${pixmapdir}", [Runtime pixmap files path]) - - PACKAGE_CFLAGS="${PACKAGE_CFLAGS} ${HILDON_CFLAGS} ${OSSO_CFLAGS}" - PACKAGE_LIBS="${PACKAGE_LIBS} ${HILDON_LIBS} ${OSSO_LIBS}" - ln -s src/gtk/debian -} - -function buildGTK() { - TARGET="Building GTK version." - - dnl disable build for hildon - AC_ARG_ENABLE(hildon, - AS_HELP_STRING([--enable-hildon],[disable hildon build (default=yes)]), - [ac_hildon_build="yes"], - [ac_hildon_build="no"]) - - AM_CONDITIONAL(WITH_HILDON, test "x$ac_hildon_build" = "xyes") - AM_CONDITIONAL(WITH_CYGWIN_CONSOLE, false) - - if test "x$ac_hildon_build" = "xyes"; then - AC_DEFINE(USE_HILDON, 1, [Define if building for hildon/maemo/n770.]) - checkHILDON - else - dnl check for gtk libraries - pkg_modules="gtk+-2.0 >= 2.0.0" - PKG_CHECK_MODULES(PACKAGE, [$pkg_modules]) - - dnl Checks for glade-2 - AC_CHECK_PROG(have_glade, glade-2, [yes], [no]) - - if test "${have_glade}" = "yes" ; then - dnl build the user interface - glade-2 -w src/platform/gtk/sbgtk.glade - AC_DEFINE(gtk_widget_unref, g_object_unref, [hack for glade-2.]) - else - AC_MSG_ERROR([ - glade-2 not found: configure failed. - ]) - fi - - dnl check for dbus - PKG_CHECK_MODULES(DBUS, [dbus-1 >= 0.35 dbus-glib-1 >= 0.35], [ - PACKAGE_CFLAGS="${PACKAGE_CFLAGS} ${DBUS_CFLAGS}" - PACKAGE_LIBS="${PACKAGE_LIBS} ${DBUS_LIBS}" - AC_DEFINE(USE_DBUS, 1, [use dbus-glib]) - ]) - fi - - dnl preconfigured values for GTK build - AC_DEFINE(_UnixOS, 1, [Building under Unix like systems.]) - AC_DEFINE(USE_TERM_IO, 0, [Does not use terminal-io functions.]) - AC_DEFINE(DEV_EVENTS_OSD, 1, [dev_events() implemented using osd_events().]) - AC_DEFINE(KBHIT_PWR_CONSERVE, 1, [Conserve power in dev_kbhit()]) - AC_DEFINE(DRV_SOUND, 1, [Driver implements functions in drvsound.h]) - AC_DEFINE(IMPL_IMAGE, 1, [Driver implements image commands]) - AC_DEFINE(IMPL_DEV_GETS, 1, [Driver implements dev_gets()]) - AC_DEFINE(IMPL_DEV_DELAY, 1, [Driver implements dev_delay()]) - AC_DEFINE(GTK_DISABLE_DEPRECATED, 1, [avoid building obsolete code)]) - AC_DEFINE(HILDON_DISABLE_DEPRECATED, 1, [avoid building obsolete code)]) - AC_DEFINE(IMPL_HTML, 1, [Driver implements the html command]) - AC_DEFINE(OS_PREC64, 1, [64 bit variables]) - AC_DEFINE(NO_SCAN_ERROR_PROMPT, 1, [No prompt for detailed scan report]) - AC_DEFINE(DRV_BEEP, 1, [Use the driver based beep function]) - - BUILD_SUBDIRS="src/common src/platform/gtk/src src/platform/gtk/data src/platform/gtk/icons" - AC_SUBST(BUILD_SUBDIRS) -} - function buildFLTK() { TARGET="Building FLTK version." @@ -384,50 +245,6 @@ function buildSDL() { (cd ide/android/assets && xxd -i main.bas > ../../../src/platform/sdl/main_bas.h) } -function buildQT() { - TARGET="Building QT version." - - dnl Checks for qmake - AC_CHECK_PROG(have_qt, qmake, [yes], [no]) - if test "${have_qt}" = "no" ; then - AC_MSG_ERROR([You need QT version 4.* configure failed.]) - fi - - dnl avoid using MSCRT versions of printf for long double - case "${host_os}" in - cygwin*) - PACKAGE_CFLAGS="${PACKAGE_CFLAGS} -D__USE_MINGW_ANSI_STDIO" - esac - - defaultConditionals - - dnl preconfigured values for QT build - AC_DEFINE(_UnixOS, 1, [Building under Unix like systems.]) - AC_DEFINE(_QT, 1, [Defined for QT build.]) - AC_DEFINE(USE_TERM_IO, 0, [Does not use terminal-io functions.]) - AC_DEFINE(DEV_EVENTS_OSD, 1, [dev_events() implemented using osd_events().]) - AC_DEFINE(IMPL_IMAGE, 1, [Driver implements image commands]) - 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]) - AC_DEFINE(IMPL_LOG_WRITE, 1, [Driver implements lwrite()]) - AC_DEFINE(OS_PREC64, 1, [64 bit variables]) - AC_DEFINE(NO_SCAN_ERROR_PROMPT, 1, [No prompt for detailed scan report]) - AC_DEFINE(DRV_BEEP, 1, [Use the driver based beep function]) - AC_DEFINE(IMPL_OSD_SOUND, 1, [Driver implements osd_sound()]) - AC_DEFINE(IMPL_DEV_RUN, 1, [Driver implements dev_run()]) - AC_DEFINE(IMPL_DEV_CIRCLE, 1, [Driver implements circle/elipse funcs]) - - BUILD_SUBDIRS="src/common src/platform/qt" - AC_SUBST(BUILD_SUBDIRS) - - desktopentrydir='$(datarootdir)'/applications - AC_SUBST(desktopentrydir) - - dnl generate qt project files - (cd src/platform/qt && qmake -o Makefile.qt) -} - function buildMosync() { TARGET="Building common library for Mosync." @@ -534,7 +351,6 @@ function buildConsole() { win32="yes" esac - AM_CONDITIONAL(WITH_HILDON, false) AM_CONDITIONAL(WITH_CYGWIN_CONSOLE, test $win32 = yes) if test $win32 = yes; then @@ -601,7 +417,6 @@ function buildDist() { BUILD_SUBDIRS="${BUILD_SUBDIRS} src/platform/cygwin" BUILD_SUBDIRS="${BUILD_SUBDIRS} src/platform/unix" BUILD_SUBDIRS="${BUILD_SUBDIRS} src/platform/mingw" - BUILD_SUBDIRS="${BUILD_SUBDIRS} src/platform/qt" AC_SUBST(BUILD_SUBDIRS) } @@ -612,14 +427,10 @@ AC_DEFINE(HAVE_C_MALLOC, 1, [allocate memory with regular malloc calls]) if test x$ac_build_dist = xyes; then buildDist -elif test x$ac_build_gtk = xyes; then - buildGTK elif test x$ac_build_fltk = xyes; then buildFLTK elif test x$ac_build_sdl = xyes; then buildSDL -elif test x$ac_build_qt = xyes; then - buildQT elif test x$ac_build_mosync = xyes; then buildMosync elif test x$ac_build_tizen = xyes; then @@ -634,17 +445,14 @@ checkPCRE checkDebugMode checkForWindows +AC_SUBST(PACKAGE_CFLAGS) +AC_SUBST(PACKAGE_LIBS) + AC_CONFIG_FILES([ Makefile src/common/Makefile -src/platform/gtk/src/Makefile -src/platform/gtk/data/sbasic.desktop -src/platform/gtk/data/com.nokia.sbasic.service -src/platform/gtk/data/Makefile -src/platform/gtk/icons/Makefile src/platform/fltk/Makefile src/platform/sdl/Makefile -src/platform/qt/Makefile src/platform/cygwin/Makefile src/platform/mingw/Makefile src/platform/unix/Makefile @@ -656,6 +464,8 @@ AC_OUTPUT echo echo ${TARGET} +echo "CFLAGS=${CFLAGS}" +echo "CXXFLAGS=${CXXFLAGS}" echo if test x$ac_build_dist = xyes; then diff --git a/samples/distro-examples/tests/plasma.bas b/samples/distro-examples/tests/plasma.bas new file mode 100644 index 00000000..864cea4d --- /dev/null +++ b/samples/distro-examples/tests/plasma.bas @@ -0,0 +1,42 @@ +' http://forum.basicprogramming.org/index.php/topic,3408.0.html +' sdl plasma example on: https://gist.github.com/stevenlr/824019 +' ported to CMLua by Cybermonkey 08/2014 +' ported to OxygenBasic by Peter Wirbelauer o7.o8.2o14 +' ported to X11Basic by vsync o8.o8.2o14 + +' +' valgrind --tool=callgrind ./src/platform/sdl/sbasicg samples/distro-examples/tests/plasma.bas +' kcachegrind +' + +bw=320 +bh=200 +DIM c(256) +FOR x=0 TO 255 + r=255-((SIN(PI*2*x/255)+1)*127) + c(x)= RGB(r/256, (SIN(PI*2*x/127)+1)/4, 1-r/256) +NEXT x +t1=timer +for iter = 1 to 10 + t=TICKS + FOR y=0 TO bh + FOR x=0 TO bw + a=COS(1.2*f)*100-y+100 + b=SIN(0.8*f)*160-x+160 + COLOR ((SIN(x/50+f+y/200)+SIN(SQR(b*b+a*a)/50))/2+1)*127 + pset x,y + NEXT x + NEXT y + fps=TICKSPERSEC/(TICKS-t) + at bw+10,0 + print format("Fps: ###.##", fps) + at bw+10,20 + print format("Cnt: ###", iter) + at bw+10,40 + print format("Elap: ###", timer-t1) + + f=f+0.2 + SHOWPAGE +next iter + + diff --git a/src/common/brun.c b/src/common/brun.c index f4d1eac5..d671bd2e 100755 --- a/src/common/brun.c +++ b/src/common/brun.c @@ -52,56 +52,6 @@ static char fileName[OS_FILENAME_SIZE + 1]; static int main_tid; static int exec_tid; -/** - * returns the next 32bit and moves the instruction pointer to the next instruction - */ -dword code_getnext32() { - dword v; - - memcpy(&v, prog_source + prog_ip, 4); - prog_ip += 4; - return v; -} - -#if defined(OS_PREC64) - -/** - * returns the next 64bit and moves the instruction pointer to the next instruction - */ -var_int_t code_getnext64i() { - var_int_t v; - - memcpy(&v, prog_source + prog_ip, sizeof(var_int_t)); - prog_ip += sizeof(var_int_t); - return v; -} -#endif - -/** - * returns the next 64bit and moves the instruction pointer to the next instruction - */ -double code_getnext64f() { - double v; - - memcpy(&v, prog_source + prog_ip, sizeof(double)); - prog_ip += sizeof(double); - return v; -} - -#if defined(OS_PREC64) - -/** - * returns the next 128bit and moves the instruction pointer to the next instruction - */ -var_num_t code_getnext128f() { - var_num_t v; - - memcpy(&v, prog_source + prog_ip, sizeof(var_num_t)); - prog_ip += sizeof(var_num_t); - return v; -} -#endif - /** * jump to label */ @@ -381,14 +331,6 @@ var_t* code_resolve_varptr(var_t* var_p, int until_parens) { return var_p; } -/** - * returns the varptr of the next variable. if the variable is an array - * returns the element ptr - */ -var_t *code_getvarptr() { - return code_getvarptr_parens(0); -} - /** * helper for code_getvarptr */ diff --git a/src/common/eval.c b/src/common/eval.c index 4a2239a5..b08ea8e7 100644 --- a/src/common/eval.c +++ b/src/common/eval.c @@ -19,8 +19,10 @@ #define IP prog_ip #define CODE(x) prog_source[(x)] #define CODE_PEEK() CODE(IP) -#define V_FREE(v) if ((v)) { if ((v)->type == V_STR || (v)->type == V_ARRAY) v_free((v)); } -#define V_IS_TYPE(v,t) (v != NULL && v->type == t) +#define V_FREE(v) \ + if ((v) && ((v)->type == V_STR || (v)->type == V_ARRAY)) { \ + v_free((v)); \ + } void eval(var_t *result); void mat_op1(var_t *l, int op, var_num_t n); @@ -354,7 +356,7 @@ void eval(var_t *r) { V_FREE(r); IP--; - var_p = code_getvarptr_parens(0); + var_p = code_getvarptr(); if (prog_error) { return; @@ -427,38 +429,38 @@ void eval(var_t *r) { op = CODE(IP); IP++; - if (r->type == V_INT && V_IS_TYPE(left, V_INT)) { + if (r->type == V_INT && v_is_type(left, V_INT)) { if (op == '+') { r->v.i += left->v.i; } else { r->v.i = left->v.i - r->v.i; } - } else if (r->type == V_NUM && V_IS_TYPE(left, V_NUM)) { + } else if (r->type == V_NUM && v_is_type(left, V_NUM)) { r->type = V_NUM; if (op == '+') { r->v.n += left->v.n; } else { r->v.n = left->v.n - r->v.n; } - } else if (r->type == V_INT && V_IS_TYPE(left, V_NUM)) { + } else if (r->type == V_INT && v_is_type(left, V_NUM)) { r->type = V_NUM; if (op == '+') { r->v.n = r->v.i + left->v.n; } else { r->v.n = left->v.n - r->v.i; } - } else if (r->type == V_NUM && V_IS_TYPE(left, V_INT)) { + } else if (r->type == V_NUM && v_is_type(left, V_INT)) { if (op == '+') { r->v.n += left->v.i; } else { r->v.n = left->v.i - r->v.n; } } else { - if (r->type == V_ARRAY || V_IS_TYPE(left, V_ARRAY)) { + if (r->type == V_ARRAY || v_is_type(left, V_ARRAY)) { // // ARRAYS // - if (r->type == V_ARRAY && V_IS_TYPE(left, V_ARRAY)) { + if (r->type == V_ARRAY && v_is_type(left, V_ARRAY)) { if (op == '+') { mat_add(r, left); } else { @@ -500,11 +502,11 @@ void eval(var_t *r) { op = CODE(IP); IP++; - if (r->type == V_ARRAY || V_IS_TYPE(left, V_ARRAY)) { + if (r->type == V_ARRAY || v_is_type(left, V_ARRAY)) { // // ARRAYS // - if (r->type == V_ARRAY && V_IS_TYPE(left, V_ARRAY)) { + if (r->type == V_ARRAY && v_is_type(left, V_ARRAY)) { if (op == '*') { mat_mul(left, r); } else { @@ -770,13 +772,13 @@ void eval(var_t *r) { } } } else if (r->type == V_STR) { - if (V_IS_TYPE(left, V_STR)) { + if (v_is_type(left, V_STR)) { if (left->v.p.ptr[0] != '\0') { ri = (strstr(r->v.p.ptr, left->v.p.ptr) != NULL); } else { ri = 0; } - } else if (V_IS_TYPE(left, V_NUM) || V_IS_TYPE(left, V_INT)) { + } else if (v_is_type(left, V_NUM) || v_is_type(left, V_INT)) { var_t *v; v = v_clone(left); @@ -867,7 +869,7 @@ void eval(var_t *r) { var_t *vp; IP++; - vp = code_getvarptr_parens(0); + vp = code_getvarptr(); if (!prog_error) { r->type = V_INT; r->v.i = (intptr_t) vp->v.p.ptr; diff --git a/src/common/smbas.h b/src/common/smbas.h index f052e581..2dfb069e 100644 --- a/src/common/smbas.h +++ b/src/common/smbas.h @@ -223,6 +223,62 @@ EXTERN char gsb_last_errmsg[SB_ERRMSG_SIZE + 1]; /**< last error message #undef EXTERN +/** + * @ingroup var + * + * returns the next integer and moves the IP 4 bytes forward. + * + * R(long int) <- Code[IP]; IP+=4 + */ +static inline dword code_getnext32(void) { + dword v; + memcpy(&v, prog_source + prog_ip, 4); + prog_ip += 4; + return v; +} + +/** + * @ingroup var + * + * returns the next 64bit and moves the instruction pointer to the next instruction + * + * R(double) <- Code[IP]; IP+=8 + */ +static inline double code_getnext64f() { + double v; + memcpy(&v, prog_source + prog_ip, sizeof(double)); + prog_ip += sizeof(double); + return v; +} + +#if defined(OS_PREC64) + +/** + * @ingroup var + * + * returns the next 64bit and moves the instruction pointer to the next instruction + */ +static inline var_int_t code_getnext64i() { + var_int_t v; + memcpy(&v, prog_source + prog_ip, sizeof(var_int_t)); + prog_ip += sizeof(var_int_t); + return v; +} + +/** + * @ingroup var + * + * returns the next 128bit and moves the instruction pointer to the next instruction + */ +static inline var_num_t code_getnext128f() { + var_num_t v; + memcpy(&v, prog_source + prog_ip, sizeof(var_num_t)); + prog_ip += sizeof(var_num_t); + return v; +} + +#endif + /** * @ingroup exec * diff --git a/src/common/var.c b/src/common/var.c index e8d6dcd1..b7d4b321 100644 --- a/src/common/var.c +++ b/src/common/var.c @@ -17,15 +17,6 @@ #define ARR_ALLOC 256 -/* - * initialize a variable - */ -void v_init(var_t *v) { - v->type = V_INT; - v->const_flag = 0; - v->v.i = 0; -} - /* * creates and returns a new variable */ @@ -921,10 +912,3 @@ void v_input2var(const char *str, var_t *var) { tmp_free(sb); } } - -/* - * null safe variable type check - */ -int v_is_type(var_t *v, int type) { - return (v != NULL && v->type == type); -} diff --git a/src/common/var.h b/src/common/var.h index 5dce1243..2bdb3b6b 100644 --- a/src/common/var.h +++ b/src/common/var.h @@ -262,7 +262,8 @@ int v_is_nonzero(var_t *v); * @return the numeric value of a variable */ var_num_t v_getval(var_t *v); -#define v_getnum(a) v_getval((a)) /* @ingroup var */ + +#define v_getnum(a) v_getval((a)) /** * @ingroup var @@ -315,7 +316,11 @@ void v_add(var_t *result, var_t *a, var_t *b); * * @param v the variable */ -void v_init(var_t *v); +static inline void v_init(var_t *v) { + v->type = V_INT; + v->const_flag = 0; + v->v.i = 0; +} /** * @ingroup var @@ -710,7 +715,7 @@ char *v_getstr(var_t *v); * @param v is the variable * @return whether the variable is of the given type */ -int v_is_type(var_t *v, int type); +#define v_is_type(v, t) (v != NULL && v->type == t) /* * low-level byte-code parsing @@ -719,33 +724,6 @@ int v_is_type(var_t *v, int type); * try the parameters API. */ -/** - * @ingroup exec - * - * returns the next integer and moves the IP 4 bytes forward. - * - * R(long int) <- Code[IP]; IP+=4 - * - * @return the integer - */ -dword code_getnext32(void); - -/** - * @ingroup exec - * - * returns the next double and moves the IP 8 bytes forward. - * - * R(double) <- Code[IP]; IP+=8 - * - * @return the double-number - */ -double code_getnext64f(void); - -#if defined(OS_PREC64) - var_int_t code_getnext64i(void); // R(long long) <- Code[IP]; IP+=8 - var_num_t code_getnext128f(void);// R(long double) <- Code[IP]; IP+=16 -#endif - int code_checkop(byte op); int code_checkop_s(byte *str); void code_jump_label(word label_id); // IP <- LABEL_IP_TABLE[label_id] @@ -859,6 +837,14 @@ stknode_t *code_stackpeek(); #define code_getreal() code_getnext64f() /**< get real (kwTYPE_NUM) @ingroup exec */ #endif +/** + * @ingroup var + * + * Returns the varptr of the next variable. if the variable is an array + * returns the element ptr + */ +#define code_getvarptr() code_getvarptr_parens(0) + /** * @ingroup var * @page sysvar System variables diff --git a/src/platform/common/system.cpp b/src/platform/common/system.cpp index 31104820..4ae0d879 100644 --- a/src/platform/common/system.cpp +++ b/src/platform/common/system.cpp @@ -417,6 +417,7 @@ void System::setRunning(bool running) { _overruns = 0; } else if (!isClosing() && !isRestart() && !isBack()) { _state = kActiveState; + _output->setAutoflush(true); } } diff --git a/src/platform/gtk/Makefile.am b/src/platform/gtk/Makefile.am deleted file mode 100644 index d339964b..00000000 --- a/src/platform/gtk/Makefile.am +++ /dev/null @@ -1,35 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = src - -EXTRA_DIST = \ - autogen.sh \ - sbgtk.glade \ - sbgtk.gladep \ - debian/changelog \ - debian/control \ - debian/copyright \ - debian/rules \ - debian/sbasic.links - -install-data-local: - @$(NORMAL_INSTALL) - if test -d $(srcdir)/pixmaps; then \ - $(mkinstalldirs) $(DESTDIR)$(pkgdatadir)/pixmaps; \ - for pixmap in $(srcdir)/pixmaps/*; do \ - if test -f $$pixmap; then \ - $(INSTALL_DATA) $$pixmap $(DESTDIR)$(pkgdatadir)/pixmaps; \ - fi \ - done \ - fi - -dist-hook: - if test -d pixmaps; then \ - mkdir $(distdir)/pixmaps; \ - for pixmap in pixmaps/*; do \ - if test -f $$pixmap; then \ - cp -p $$pixmap $(distdir)/pixmaps; \ - fi \ - done \ - fi - diff --git a/src/platform/gtk/configure.in b/src/platform/gtk/configure.in deleted file mode 100644 index 3d040651..00000000 --- a/src/platform/gtk/configure.in +++ /dev/null @@ -1,114 +0,0 @@ -# -# "$Id: configure.in,v 1.1 2006-02-07 02:02:02 zeeb90au Exp $" -# -# Configure script for sbgtk. SmallBASIC (GTK) -# -# Copyright(C) 2001-2006 Chris Warren-Smith. Gawler, South Australia -# -# This program is distributed under the terms of the GPL v2.0 -# Download the GNU Public License (GPL) from www.gnu.org -# -# - -AC_INIT(configure.in) -AC_CANONICAL_SYSTEM -AM_INIT_AUTOMAKE(sbgtk, 0.9.7) -AM_CONFIG_HEADER(config.h) -AM_MAINTAINER_MODE - -# Checks for programs. -AC_ISC_POSIX -AC_PROG_CC -AM_PROG_CC_STDC -AC_HEADER_STDC -AC_PROG_RANLIB - -# Checks for header files. -AC_FUNC_ALLOCA -AC_HEADER_DIRENT -AC_HEADER_STDC -AC_HEADER_SYS_WAIT -AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h locale.h malloc.h memory.h netdb.h netinet/in.h sgtty.h stddef.h stdint.h stdlib.h string.h strings.h sys/file.h sys/ioctl.h sys/param.h sys/socket.h sys/time.h termio.h termios.h unistd.h utime.h wchar.h wctype.h]) - -# Checks for typedefs, structures, and compiler characteristics. -#AC_HEADER_STAT -#AC_HEADER_STDBOOL -#AC_C_CONST -#AC_TYPE_UID_T -#AC_C_INLINE -#AC_TYPE_OFF_T -#AC_TYPE_PID_T -#AC_TYPE_SIZE_T -#AC_CHECK_MEMBERS([struct stat.st_blksize]) -#AC_STRUCT_ST_BLOCKS -#AC_CHECK_MEMBERS([struct stat.st_rdev]) -#AC_HEADER_TIME -#AC_STRUCT_TM -#AC_C_VOLATILE - -# Checks for library functions. -#AC_FUNC_CHOWN -#AC_FUNC_CLOSEDIR_VOID -#AC_FUNC_ERROR_AT_LINE -#AC_FUNC_FORK -#AC_PROG_GCC_TRADITIONAL -#AC_FUNC_LSTAT -#AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK -#AC_FUNC_MALLOC -#AC_FUNC_MBRTOWC -#AC_FUNC_MEMCMP -#AC_HEADER_MAJOR -#AC_FUNC_MKTIME -#AC_FUNC_MMAP -#AC_FUNC_REALLOC -#AC_FUNC_SELECT_ARGTYPES -#AC_FUNC_SETVBUF_REVERSED -#AC_TYPE_SIGNAL -#AC_FUNC_STAT -#AC_FUNC_STRCOLL -#AC_FUNC_STRFTIME -#AC_FUNC_STRTOD -#AC_FUNC_VPRINTF -#AC_CHECK_FUNCS([alarm atexit bzero dup2 endpwent floor ftruncate getcwd gethostbyname isascii mbrlen memmove memset mkdir modf munmap pow putenv rint rmdir select setenv setlocale socket sqrt strcasecmp strchr strdup strerror strncasecmp strndup strrchr strspn strstr strtol wcwidth]) - -pkg_modules="gtk+-2.0 >= 2.0.0" -PKG_CHECK_MODULES(PACKAGE, [$pkg_modules]) - -win32=no -case "${host_os}" in - *mingw* | pw32* | cygwin*) - win32="yes" - AC_CHECK_TOOL(WINDRES, windres, :) - PACKAGE_CFLAGS="$PACKAGE_CFLAGS -mms-bitfields -mno-cygwin" -esac -AM_CONDITIONAL(WITH_WIN32, test x"$win32" = "xyes") -AC_SUBST(PACKAGE_CFLAGS) -AC_SUBST(PACKAGE_LIBS) - -GETTEXT_PACKAGE=sbgtk -AC_SUBST(GETTEXT_PACKAGE) -AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package.]) - -# disable build for hildon -AC_ARG_ENABLE(hildon, - AC_HELP_STRING([--disable-hildon], [disable hildon build (default=no)]), - [ac_hildon_build="no"], - [ac_hildon_build="yes"]) - -if test "x$ac_hildon_build" = "xyes"; then - AC_DEFINE(USE_HILDON, 1, [Define if building for hildon/maemo/n770.]) -fi - -dnl Add the languages which your application supports here. -ALL_LINGUAS="" -AM_GLIB_GNU_GETTEXT - -AC_OUTPUT([ -Makefile -common/Makefile -src/Makefile -]) - -make clean > /dev/null 2>&1 - - diff --git a/src/platform/gtk/data/Makefile.am b/src/platform/gtk/data/Makefile.am deleted file mode 100644 index 3ae68e7f..00000000 --- a/src/platform/gtk/data/Makefile.am +++ /dev/null @@ -1,12 +0,0 @@ -# -# This file is part of SmallBASIC -# - -serviceentry_DATA = com.nokia.sbasic.service -desktopentry_DATA = sbasic.desktop - -EXTRA_DIST = $(serviceentry_DATA) $(desktopentry_DATA) - -### - - diff --git a/src/platform/gtk/data/com.nokia.sbasic.service.in b/src/platform/gtk/data/com.nokia.sbasic.service.in deleted file mode 100644 index 35c27891..00000000 --- a/src/platform/gtk/data/com.nokia.sbasic.service.in +++ /dev/null @@ -1,4 +0,0 @@ -[D-BUS Service] -Name=com.nokia.sbasic -Exec=/usr/bin/sbasic - diff --git a/src/platform/gtk/data/sbasic.desktop.in b/src/platform/gtk/data/sbasic.desktop.in deleted file mode 100644 index 4b1b5b4e..00000000 --- a/src/platform/gtk/data/sbasic.desktop.in +++ /dev/null @@ -1,12 +0,0 @@ -[Desktop Entry] -Encoding=UTF-8 -Version=0.1 -Type=Application -Name=SmallBASIC -Exec=/usr/bin/sbasic -Icon=sbasic_32 -X-Window-Icon=sbasic_32 -X-Window-Icon-Dimmed=sbasic_32 -X-HildonDesk-ShowInToolbar=true -StartupWMClass=sbasic - diff --git a/src/platform/gtk/debian/changelog b/src/platform/gtk/debian/changelog deleted file mode 100644 index 249644a7..00000000 --- a/src/platform/gtk/debian/changelog +++ /dev/null @@ -1,21 +0,0 @@ -sbasic (0.9.7.3) unstable; urgency=low - - * Added GRID button support - - -- Chris Warren-Smith Tue, 26 Jul 2006 18:34:00 +0930 - -sbasic (0.9.7.2) unstable; urgency=low - - * Updated for Maemo 2. - - -- Chris Warren-Smith Tue, 27 Jun 2006 18:34:00 +0930 - -sbasic (0.9.7.1) unstable; urgency=low - - * Initial Release. - - -- Chris Warren-Smith Sat, 04 Mar 2006 18:34:00 +0930 - - - - diff --git a/src/platform/gtk/debian/control b/src/platform/gtk/debian/control deleted file mode 100644 index 96dabdb4..00000000 --- a/src/platform/gtk/debian/control +++ /dev/null @@ -1,10 +0,0 @@ -Source: sbasic -Section: user/office -Priority: optional -Maintainer: Chris Warren-Smith -Build-Depends: debhelper (>= 4.0.0) -Standards-Version: 3.6.0 - -Package: sbasic -Architecture: any -Description: SmallBASIC is designed to be a simple, lightweight programming environment for experimentation, featuring strong mathematical and high level graphics commands. diff --git a/src/platform/gtk/debian/copyright b/src/platform/gtk/debian/copyright deleted file mode 100644 index 1ea6d7fd..00000000 --- a/src/platform/gtk/debian/copyright +++ /dev/null @@ -1,2 +0,0 @@ -GTK portions Copyright: (c) 2006 Chris Warren-Smith -Copyright (c) 2000-2006 Nicholas Christopoulos. diff --git a/src/platform/gtk/debian/rules b/src/platform/gtk/debian/rules deleted file mode 100644 index fff9dba1..00000000 --- a/src/platform/gtk/debian/rules +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/make -f -# -*- makefile -*- -# Sample debian/rules that uses debhelper. -# GNU copyright 1997 to 1999 by Joey Hess. - -# Uncomment this to turn on verbose mode. -#export DH_VERBOSE=1 - - -# These are used for cross-compiling and for saving the configure script -# from having to guess our platform (since we know it already) -DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) -DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) - - -CFLAGS = -Wall -g -PACKAGENAME = sbasic - -ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) - CFLAGS += -O0 -else - CFLAGS += -O2 -endif -ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS))) - INSTALL_PROGRAM += -s -endif - -config.status: configure - dh_testdir - # Add here commands to configure the package. - CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info --enable-gtk - - -build: build-stamp - -build-stamp: config.status - dh_testdir - - # Add here commands to compile the package. - $(MAKE) - touch build-stamp - -clean: - dh_testdir - dh_testroot - rm -f build-stamp - - # Add here commands to clean up after the build process. - -$(MAKE) distclean - - dh_clean - -install: build - dh_testdir - dh_testroot - dh_clean -k - dh_installdirs - - # Add here commands to install the package into debian/tmp - #$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp/var/lib/install - $(MAKE) install DESTDIR=$(CURDIR)/debian/tmp - - -# Build architecture-independent files here. -binary-indep: build install -# We have nothing to do by default. - -# Build architecture-dependent files here. -binary-arch: build install - dh_testdir - dh_testroot - dh_link - dh_strip - dh_compress - dh_fixperms - dh_installdeb - dh_shlibdeps - dh_gencontrol - dh_md5sums - dh_builddeb - -binary: binary-indep binary-arch -.PHONY: build clean binary-indep binary-arch binary install diff --git a/src/platform/gtk/debian/sbasic.links b/src/platform/gtk/debian/sbasic.links deleted file mode 100644 index d944d9df..00000000 --- a/src/platform/gtk/debian/sbasic.links +++ /dev/null @@ -1,3 +0,0 @@ -/usr/share/applications/hildon/sbasic.desktop /etc/others-menu/extra_applications/sbasic.desktop - - diff --git a/src/platform/gtk/icons/Makefile.am b/src/platform/gtk/icons/Makefile.am deleted file mode 100644 index bf21562b..00000000 --- a/src/platform/gtk/icons/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -MAINTAINERCLEANFILES = Makefile.in - -iconsdir = $(datadir)/icons/hicolor/26x26/apps -icons_DATA = sbasic_32.png - -EXTRA_DIST = sbasic_32.png - diff --git a/src/platform/gtk/icons/sbasic_32.png b/src/platform/gtk/icons/sbasic_32.png deleted file mode 100644 index cd46a64271649524febe3199cffa691dc253e208..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1013 zcmV+f@|DKlhh3UDKr|Ynn1zw%T<{*@N0&)iTJVb3POYKIp@`IniI4Fbflu z4W^S8se*s-Z4p#Z^u>P<5%)0sLlHa4MG`xcjRvzdF|M86Lgw10>F@f`{Q3Qsn2G~I z@WA2syZ4@RzvrCqx%a}qB%;B*18|ncYd{fD{}jkkZ!!?*U}F5ZdDs{(c6F{4&&AW` zO2NFPjLH!+FmMkC4~&q_{zf7Z=b^oOac|0DE=v;eE%f$m=9kn}!e_4D8qods-OHXm z58!Y(iN$`z>%EP_a*obGJ5P?>L2FBq^U)kr-$8C^-KV>|o0gUq*4EZ27K>!FSyoq9 z8v~`&bL<~^ydeiihL^=wKlBB3C8Z>tPS>^5bsZ_CuwWF0Ww8ci^4KlF(Ia>rwNC{N=j)3^8k76W(O%HQc3`>&o6O({zhdU;P+g8+hj6HEEcPm zV3VzM^`v9_Fw6N2&+Utf_m!V;Y14W#Gc!XXk-+VCZ_pJELFt?{(n^_2rB=XS{g=gS z%V=oO$Km|};cXUl?Ro`|FMuXY7UwegU%0jZ8&lAsx$u~mfV9|BGY-`$pmWsEl z*WW9TUIO5Y&p#4dupiW&JNs;$mF3aL9>!xX^3Lga-HK_A%2`fY6Jtk4(KOL8xZS&ln7we0 zUsF+1KYzvPx1Yu3tSOQm2qU66r4*->x-=U_j~FVr5LCg1pz`^AL<~bI*jROAU8`BO z)jktOM4{^d%sqHP?7Q-sa&KQJ_wJLs#KBcl>7fwldR3*Y{f0t_>fRn8Z^QZQ;}30_ zUCtzJnfd+xYG%4#n@wr$)su&;+cwv9ou)aN9a|BUTDLRYt3L4@5;rdP1JEDuSA(ID zkcI&_-x7uap%Afe-xBRUkF8N_fIObfxLnO-j=3seJ>Lwe@u;r?7F-Bc!F0n0lK9~R z0kEmLsqs_(^_ef}>Gq;b#kE|Xfp^<0oVlOYME}{RDx6JqOo@nLC|v?F#Q2FZv2Z!V z#Y=N6T)D>gk@Hpz`)&W?^P?OceT2cg?xe4G8{W27Fd|A5)p+!XQE}R_qnC(bsMc0D jE>{yyr-T3Hzbk(Nr@OfC_^uy~00000NkvXXu0mjfnhNR+ diff --git a/src/platform/gtk/ide/config.h b/src/platform/gtk/ide/config.h deleted file mode 100644 index 765ec14e..00000000 --- a/src/platform/gtk/ide/config.h +++ /dev/null @@ -1,60 +0,0 @@ -/* always defined to indicate that i18n is enabled */ -#define ENABLE_NLS 1 - -/* Gettext package. */ -#define GETTEXT_PACKAGE "sbgtk" - -/* Define to 1 if you have the `bind_textdomain_codeset' function. */ -#define HAVE_BIND_TEXTDOMAIN_CODESET 1 - -/* Define to 1 if you have the `dcgettext' function. */ -#define HAVE_DCGETTEXT 1 - -/* Define if the GNU gettext() function is already present or preinstalled. */ -#define HAVE_GETTEXT 1 - -/* Define if your file defines LC_MESSAGES. */ -/* #undef HAVE_LC_MESSAGES */ - -/* Define to 1 if you have the header file. */ -#define HAVE_LOCALE_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Name of package */ -#define PACKAGE "sbgtk" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "" - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Version number of package */ -#define VERSION "0.1" - diff --git a/src/platform/gtk/ide/sbgtk.dev b/src/platform/gtk/ide/sbgtk.dev deleted file mode 100644 index f914fa7d..00000000 --- a/src/platform/gtk/ide/sbgtk.dev +++ /dev/null @@ -1,129 +0,0 @@ -[Project] -FileName=sbgtk.dev -Name=sbgtk -UnitCount=8 -Type=0 -Ver=1 -ObjFiles= -Includes=. -Libs= -PrivateResource= -ResourceIncludes= -MakeIncludes= -Compiler=-mms-bitfields -mwindows -DHAVE_CONFIG_H -I"$(GTK_BASEPATH)/include/gtk-2.0" -I"$(GTK_BASEPATH)/lib/gtk-2.0/include" -I"$(GTK_BASEPATH)/include/atk-1.0" -I"$(GTK_BASEPATH)/include/pango-1.0" -I"$(GTK_BASEPATH)/include/glib-2.0" -I"$(GTK_BASEPATH)/lib/glib-2.0/include" -I"$(GTK_BASEPATH)/include/cairo" -I"$(GTK_BASEPATH)/include" -DPACKAGE_PREFIX=\"\" -DPACKAGE_DATA_DIR=\"\" -DPACKAGE_LOCALE_DIR=\"\"_@@_ -CppCompiler=-mms-bitfields -mwindows -DHAVE_CONFIG_H -I"$(GTK_BASEPATH)/include/gtk-2.0" -I"$(GTK_BASEPATH)/lib/gtk-2.0/include" -I"$(GTK_BASEPATH)/include/atk-1.0" -I"$(GTK_BASEPATH)/include/pango-1.0" -I"$(GTK_BASEPATH)/include/glib-2.0" -I"$(GTK_BASEPATH)/lib/glib-2.0/include" -I"$(GTK_BASEPATH)/include/cairo" -I"$(GTK_BASEPATH)/include" -DPACKAGE_PREFIX=\"\" -DPACKAGE_DATA_DIR=\"\" -DPACKAGE_LOCALE_DIR=\"\"_@@_ -Linker=-L"$(GTK_BASEPATH)/lib" -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lpangowin32-1.0 -lgdi32 -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl -liconv_@@_ -IsCpp=0 -Icon= -ExeOutput= -ObjectOutput= -OverrideOutput=0 -OverrideOutputName=sbgtk.exe -HostApplication= -Folders= -CommandLine= -UseCustomMakefile=0 -CustomMakefile= -IncludeVersionInfo=0 -SupportXPThemes=0 -CompilerSet=0 -CompilerSettings=0000000000000000000000 - -[VersionInfo] -Major=0 -Minor=1 -Release=1 -Build=1 -LanguageID=1033 -CharsetID=1252 -CompanyName= -FileVersion= -FileDescription=Developed using the Dev-C++ IDE -InternalName= -LegalCopyright= -LegalTrademarks= -OriginalFilename= -ProductName= -ProductVersion= -AutoIncBuildNr=0 - -[Unit1] -FileName=..\src\main.c -CompileCpp=0 -Folder=sbgtk -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit2] -FileName=config.h -CompileCpp=0 -Folder=sbgtk -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit3] -FileName=..\src\callbacks.c -CompileCpp=0 -Folder=sbgtk -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit4] -FileName=..\src\callbacks.h -CompileCpp=0 -Folder=sbgtk -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit5] -FileName=..\src\interface.c -CompileCpp=0 -Folder=sbgtk -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit6] -FileName=..\src\interface.h -CompileCpp=0 -Folder=sbgtk -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit7] -FileName=..\src\support.c -CompileCpp=0 -Folder=sbgtk -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit8] -FileName=..\src\support.h -CompileCpp=0 -Folder=sbgtk -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - diff --git a/src/platform/gtk/ide/sbgtk.dsp b/src/platform/gtk/ide/sbgtk.dsp deleted file mode 100644 index 4a7c85ad..00000000 --- a/src/platform/gtk/ide/sbgtk.dsp +++ /dev/null @@ -1,136 +0,0 @@ -# Microsoft Developer Studio Project File - Name="sbgtk" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Application" 0x0101 - -CFG=sbgtk - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "sbgtk.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "sbgtk.mak" CFG="sbgtk - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "sbgtk - Win32 Release" (based on "Win32 (x86) Application") -!MESSAGE "sbgtk - Win32 Debug" (based on "Win32 (x86) Application") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "sbgtk - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "./" -I "$(GTK_BASEPATH)/include/gtk-2.0" -I "$(GTK_BASEPATH)/lib/gtk-2.0/include" -I "$(GTK_BASEPATH)/include/atk-1.0" -I "$(GTK_BASEPATH)/include/pango-1.0" -I "$(GTK_BASEPATH)/include/glib-2.0" -I "$(GTK_BASEPATH)/lib/glib-2.0/include" -I "$(GTK_BASEPATH)/include/cairo" -I "$(GTK_BASEPATH)/include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "HAVE_CONFIG_H" /D PACKAGE_PREFIX=\"\" /D PACKAGE_DATA_DIR=\"\" /D PACKAGE_LOCALE_DIR=\"\" /YX /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 -# ADD LINK32 gtk-win32-2.0.lib gdk-win32-2.0.lib atk-1.0.lib gdk_pixbuf-2.0.lib pangowin32-1.0.lib gdi32.lib pango-1.0.lib gobject-2.0.lib gmodule-2.0.lib glib-2.0.lib intl.lib iconv.lib /nologo /subsystem:windows /machine:I386 /libpath:"$(GTK_BASEPATH)/lib" - -!ELSEIF "$(CFG)" == "sbgtk - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "./" -I "$(GTK_BASEPATH)/include/gtk-2.0" -I "$(GTK_BASEPATH)/lib/gtk-2.0/include" -I "$(GTK_BASEPATH)/include/atk-1.0" -I "$(GTK_BASEPATH)/include/pango-1.0" -I "$(GTK_BASEPATH)/include/glib-2.0" -I "$(GTK_BASEPATH)/lib/glib-2.0/include" -I "$(GTK_BASEPATH)/include/cairo" -I "$(GTK_BASEPATH)/include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "HAVE_CONFIG_H" /D PACKAGE_PREFIX=\"\" /D PACKAGE_DATA_DIR=\"\" /D PACKAGE_LOCALE_DIR=\"\" /YX /FD /GZ /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept -# ADD LINK32 gtk-win32-2.0.lib gdk-win32-2.0.lib atk-1.0.lib gdk_pixbuf-2.0.lib pangowin32-1.0.lib gdi32.lib pango-1.0.lib gobject-2.0.lib gmodule-2.0.lib glib-2.0.lib intl.lib iconv.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept /libpath:"$(GTK_BASEPATH)/lib" - -!ENDIF - -# Begin Target - -# Name "sbgtk - Win32 Release" -# Name "sbgtk - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=..\src\callbacks.c -# End Source File -# Begin Source File - -SOURCE=..\src\interface.c -# End Source File -# Begin Source File - -SOURCE=..\src\main.c -# End Source File -# Begin Source File - -SOURCE=..\src\support.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=..\src\callbacks.h -# End Source File -# Begin Source File - -SOURCE=.\config.h -# End Source File -# Begin Source File - -SOURCE=..\src\interface.h -# End Source File -# Begin Source File - -SOURCE=..\src\support.h -# End Source File -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project - diff --git a/src/platform/gtk/ide/sbgtk.dsw b/src/platform/gtk/ide/sbgtk.dsw deleted file mode 100644 index 39031228..00000000 --- a/src/platform/gtk/ide/sbgtk.dsw +++ /dev/null @@ -1,30 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "sbgtk"=.\sbgtk.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - - diff --git a/src/platform/gtk/sbgtk.glade b/src/platform/gtk/sbgtk.glade deleted file mode 100644 index 7b8a98dc..00000000 --- a/src/platform/gtk/sbgtk.glade +++ /dev/null @@ -1,321 +0,0 @@ - - - - - - - True - SmallBASIC - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - True - True - True - False - False - GDK_WINDOW_TYPE_HINT_NORMAL - GDK_GRAVITY_NORTH_WEST - True - False - - - - True - False - 0 - - - - True - GTK_PACK_DIRECTION_LTR - GTK_PACK_DIRECTION_LTR - - - - True - _File - True - - - - - - - True - _Break - True - - - - - - - True - - - - - - True - _Reset keys - True - - - - - - - True - _Save Screen - True - - - - - - - True - - - - - - True - gtk-about - True - - - - - - - True - - - - - - True - gtk-quit - True - - - - - - - - - - 0 - False - False - - - - - - True - True - - - 0 - False - False - GTK_PACK_END - - - - - - True - True - GTK_POLICY_NEVER - GTK_POLICY_NEVER - GTK_SHADOW_ETCHED_IN - GTK_CORNER_TOP_LEFT - - - - 668 - 392 - 1 - 1 - 0 0 668 10 601.2 668 - 0 0 392 10 352.8 392 - - - - - 0 - True - True - - - - - - - - True - False - SmallBASIC - Copyright (c) 2006 Chris Warren-Smith - - SmallBASIC comes with ABSOLUTELY NO WARRANTY. -This program is free software; you can use it redistribute -it and/or modify it under the terms of the -GNU General Public License version 2 as published by -the Free Software Foundation. - - True - smallbasic.sf.net - SmallBASIC - Nicholas Christopoulos -Chris Warren-Smith - - translator-credits - - - - True - GTK_FILE_CHOOSER_ACTION_OPEN - True - False - False - False - Open BAS File - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - True - True - False - True - False - False - GDK_WINDOW_TYPE_HINT_DIALOG - GDK_GRAVITY_NORTH_WEST - True - False - - - - True - False - 24 - - - - True - GTK_BUTTONBOX_END - - - - True - True - True - gtk-cancel - True - GTK_RELIEF_NORMAL - True - -6 - - - - - - True - True - True - True - gtk-open - True - GTK_RELIEF_NORMAL - True - -5 - - - - - 0 - False - True - GTK_PACK_END - - - - - - - - True - GTK_FILE_CHOOSER_ACTION_SAVE - True - False - False - False - Save Screen - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - True - False - True - False - False - GDK_WINDOW_TYPE_HINT_DIALOG - GDK_GRAVITY_NORTH_WEST - True - False - - - - True - False - 24 - - - - True - GTK_BUTTONBOX_END - - - - True - True - True - gtk-cancel - True - GTK_RELIEF_NORMAL - True - -6 - - - - - - True - True - True - True - gtk-open - True - GTK_RELIEF_NORMAL - True - -5 - - - - - 0 - False - True - GTK_PACK_END - - - - - - - diff --git a/src/platform/gtk/sbgtk.gladep b/src/platform/gtk/sbgtk.gladep deleted file mode 100644 index ac128c59..00000000 --- a/src/platform/gtk/sbgtk.gladep +++ /dev/null @@ -1,9 +0,0 @@ - - - - - sbgtk - sbgtk - FALSE - TRUE - diff --git a/src/platform/gtk/src/Makefile.am b/src/platform/gtk/src/Makefile.am deleted file mode 100644 index 1a0b5ff2..00000000 --- a/src/platform/gtk/src/Makefile.am +++ /dev/null @@ -1,38 +0,0 @@ -# SmallBASIC for GTK -# 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 -# - -AM_CPPFLAGS = \ - -I../../../common -I. \ - -DPACKAGE_PREFIX=\""$(prefix)"\" \ - -DPACKAGE_DATA_DIR=\""$(datadir)"\" \ - -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ - @PACKAGE_CFLAGS@ - -bin_PROGRAMS = sbasic - -bin_PROGRAMS : ../../../common/libsb_common.a - -sbasic_SOURCES = \ - main.c \ - output.c output.h \ - output_model.c output_model.h \ - output_write.c \ - form_ui.c \ - callbacks.c callbacks.h \ - interface.c interface.h - -sbasic_LDADD = @PACKAGE_LIBS@ -L$(top_srcdir)/src/common -lsb_common - -sbasic_DEPENDENCIES = ../../../common/libsb_common.a - -# -#servicefiledir=`$(PKG_CONFIG) --variable=libdir dbus-glib-1`/dbus-1.0/services - - - - - diff --git a/src/platform/gtk/src/callbacks.c b/src/platform/gtk/src/callbacks.c deleted file mode 100644 index 943d1939..00000000 --- a/src/platform/gtk/src/callbacks.c +++ /dev/null @@ -1,80 +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 -// - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#ifdef USE_HILDON -#include -#endif - -#include "callbacks.h" -#include "interface.h" -#include "output_model.h" - -extern OutputModel output; -extern int keymap[]; - -void on_break(GtkMenuItem *menuitem, gpointer user_data) { - output.break_exec = 1; -} - -void on_about_activate(GtkMenuItem *menuitem, gpointer user_data) { - GtkWidget *about = create_aboutdialog(); - gtk_dialog_run(GTK_DIALOG(about)); - gtk_widget_destroy(about); -} - -void on_reset_keys(GtkMenuItem *menuitem, gpointer user_data) { - int i; - for (i = KEYMAP_FIRST; i <= KEYMAP_LAST; i++) { - keymap[i] = 0; - } -} - -void on_quit_activate(GtkMenuItem *menuitem, gpointer user_data) { - exit(1); -} - -void on_save_screen(GtkMenuItem *menuitem, gpointer user_data) { - GtkWidget *dialog = create_savedialog(); - - if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { - char *chooser_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - char *filename = chooser_name; - GString *filename_extn = 0; - int len = strlen(filename); - if (g_ascii_strcasecmp(filename + len - 4, ".jpg") != 0 && - g_ascii_strcasecmp(filename + len - 5, ".jpeg") != 0) { - filename_extn = g_string_new(filename); - g_string_append(filename_extn, ".jpeg"); - filename = filename_extn->str; - } - - GdkPixbuf *pixbuf = gdk_pixbuf_get_from_drawable(NULL, output.pixmap, NULL, - 0, 0, 0, 0, - output.width, - output.height); - if (pixbuf) { - GError *error = 0; - gdk_pixbuf_save(pixbuf, filename, "jpeg", &error, "quality", "100", NULL); - g_object_unref(pixbuf); - g_clear_error(&error); - } - g_free(chooser_name); - if (filename_extn) { - g_string_free(filename_extn, TRUE); - } - } - gtk_widget_destroy(dialog); -} - diff --git a/src/platform/gtk/src/callbacks.h b/src/platform/gtk/src/callbacks.h deleted file mode 100644 index 2d3a2306..00000000 --- a/src/platform/gtk/src/callbacks.h +++ /dev/null @@ -1,19 +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 -// - -/* - * DO NOT EDIT THIS FILE - generated by Glade2Hildon version 1.0 - */ -#include - -void on_break(GtkMenuItem *menuitem, gpointer user_data); -void on_reset_keys(GtkMenuItem *menuitem, gpointer user_data); -void on_save_screen(GtkMenuItem *menuitem, gpointer user_data); -void on_about_activate(GtkMenuItem *menuitem, gpointer user_data); -void on_quit_activate(GtkMenuItem *menuitem, gpointer user_data); - diff --git a/src/platform/gtk/src/form_ui.c b/src/platform/gtk/src/form_ui.c deleted file mode 100644 index 2d31a995..00000000 --- a/src/platform/gtk/src/form_ui.c +++ /dev/null @@ -1,735 +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 -// - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "sys.h" -#include "var.h" -#include "kw.h" -#include "pproc.h" -#include "device.h" -#include "smbas.h" -#include "blib_ui.h" - -#include - -#ifdef USE_HILDON -#include -#endif - -#include "output_model.h" - -GtkWidget *form = 0; -GtkWidget *notebook = 0; -enum { m_unset, m_init, m_modeless, m_modal, m_clicked } mode = m_unset; -int modeless_x; -int modeless_y; -int modeless_w; -int modeless_h; -char buff[40]; -extern OutputModel output; - -void ui_transfer_data(GtkWidget *container); - -#define TABLE_GAP 2 - -typedef enum ControlType { - ctrl_button, - ctrl_radio, - ctrl_check, - ctrl_text, - ctrl_text_multi, - ctrl_label, - ctrl_list, - ctrl_grid, - ctrl_tab, - ctrl_calendar, - ctrl_file_button, - ctrl_font_button, - ctrl_color_button -} ControlType; - -typedef struct WidgetInfo { - ControlType type; - var_t *var; -} WidgetInfo; - -WidgetInfo *get_widget_info(GtkWidget *w) { - return (WidgetInfo *) g_object_get_data(G_OBJECT(w), "widget_info"); -} - -void set_widget_info(GtkWidget *w, WidgetInfo *inf) { - g_object_set_data(G_OBJECT(w), "widget_info", inf); -} - -// create the form -void ui_begin() { - if (form == 0) { - form = gtk_table_new(1, 1, FALSE); - gtk_table_set_col_spacings(GTK_TABLE(form), TABLE_GAP); - gtk_table_set_row_spacings(GTK_TABLE(form), TABLE_GAP); - gtk_container_add(GTK_CONTAINER(output.widget), form); - gtk_widget_show(form); - } -} - -// clean up child widgets of the given container -void remove_children(GtkWidget *container) { - GList *list = gtk_container_get_children(GTK_CONTAINER(container)); - int n = g_list_length(list); - int i; - for (i = 0; i < n; i++) { - GtkWidget *w = (GtkWidget *) g_list_nth_data(list, i); - WidgetInfo *inf = get_widget_info(w); - if (inf->type == ctrl_tab) { - int n_pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(w)); - int j; - for (j = 0; j < n_pages; j++) { - GtkWidget *table = gtk_notebook_get_nth_page(GTK_NOTEBOOK(w), j); - remove_children(table); - } - } - g_free(inf); - } - g_list_free(list); -} - -// destroy the form -void ui_reset() { - if (form != 0) { - remove_children(form); - gtk_widget_destroy(form); - form = 0; - } - mode = m_unset; - notebook = 0; -} - -gchar *get_multi_edit_text(GtkWidget *scolled_window) { - GtkTextIter start, end; - GtkTextBuffer *buffer; - - GtkWidget *widget = gtk_bin_get_child(GTK_BIN(scolled_window)); - buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget)); - - gtk_text_buffer_get_start_iter(buffer, &start); - gtk_text_buffer_get_end_iter(buffer, &end); - - return gtk_text_buffer_get_text(buffer, &start, &end, FALSE); -} - -// copy widget data into its matching basic variable -void update_vars(GtkWidget *widget) { - WidgetInfo *inf = get_widget_info(widget); - gchar *text = 0; - guint year, month, day; - GdkColor color; - int n_pages, j; - - switch (inf->type) { - case ctrl_label: - if (inf->var->type == V_STR && inf->var->v.p.ptr && - g_ascii_strcasecmp(inf->var->v.p.ptr, gtk_label_get_text(GTK_LABEL(widget))) != 0) { - gtk_label_set_text(GTK_LABEL(widget), inf->var->v.p.ptr); - } - break; - case ctrl_check: - case ctrl_radio: - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { - v_setstr(inf->var, gtk_button_get_label(GTK_BUTTON(widget))); - } - break; - case ctrl_text: - text = (gchar *) gtk_entry_get_text(GTK_ENTRY(widget)); - if (text && text[0]) { - v_setstr(inf->var, text); - } - // internal text not freed - break; - case ctrl_text_multi: - text = get_multi_edit_text(widget); - if (text && text[0]) { - v_setstr(inf->var, text); - } - g_free(text); - break; - case ctrl_list: - text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(widget)); - if (text && text[0]) { - v_setstr(inf->var, text); - } - g_free(text); - break; - case ctrl_calendar: - gtk_calendar_get_date(GTK_CALENDAR(widget), &year, &month, &day); - sprintf(buff, "%02d/%02d/%d", day, month + 1, year); - v_setstr(inf->var, buff); - break; - case ctrl_file_button: - text = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); - if (text && text[0]) { - v_setstr(inf->var, text); - } - g_free(text); - break; - case ctrl_font_button: - text = (char *)gtk_font_button_get_font_name(GTK_FONT_BUTTON(widget)); - if (text && text[0]) { - v_setstr(inf->var, text); - } - break; - case ctrl_color_button: - gtk_color_button_get_color(GTK_COLOR_BUTTON(widget), &color); - text = gtk_color_selection_palette_to_string(&color, 1); - if (text && text[0]) { - v_setstr(inf->var, text); - } - g_free(text); - break; - case ctrl_tab: - n_pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(widget)); - for (j = 0; j < n_pages; j++) { - GtkWidget *table = gtk_notebook_get_nth_page(GTK_NOTEBOOK(widget), j); - ui_transfer_data(table); - } - break; - default: - break; - } -} - -// copy form data into basic variables -void ui_transfer_data(GtkWidget *container) { - if (container) { - GList *list = gtk_container_get_children(GTK_CONTAINER(container)); - int n = g_list_length(list); - int i; - for (i = 0; i < n; i++) { - update_vars((GtkWidget *) g_list_nth_data(list, i)); - } - g_list_free(list); - } -} - -// button callback -void button_clicked(GtkWidget *button, gpointer user_data) { - WidgetInfo *inf = get_widget_info(button); - v_setstr(inf->var, gtk_button_get_label(GTK_BUTTON(button))); - - if (user_data) { - // submit button - close modeless form - if (mode == m_modeless) { - ui_reset(); - } - } - if (mode != m_unset) { - mode = m_clicked; - } -} - -// set the radio into a group that shares a common basic variable -void set_radio_group(var_t *v, GtkWidget *radio_widget) { - GSList *radio_group = NULL; - if (v == 0 || v->type != V_STR) { - return; - } - - GList *list = gtk_container_get_children(GTK_CONTAINER(form)); - int n = g_list_length(list); - int i; - for (i = 0; i < n; i++) { - GtkWidget *widget = (GtkWidget *) g_list_nth_data(list, i); - WidgetInfo *inf = get_widget_info(widget); - if (inf->type == ctrl_radio && - inf->var->type == V_STR && (inf->var == v || inf->var->v.p.ptr == v->v.p.ptr)) { - radio_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(widget)); - gtk_radio_button_set_group(GTK_RADIO_BUTTON(radio_widget), radio_group); - break; - } - } - g_list_free(list); -} - -// refer to rev 1.10 or less for the obsolete layout version -void add_form_child(GtkWidget *widget, int expand, int x1, int x2, int y1, int y2) { - int resized = FALSE; - int rows, cols; - GtkWidget *table; - - if (notebook != 0) { - int last_index = gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook)) - 1; - table = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), last_index); - } else { - table = form; - } - - g_object_get(G_OBJECT(table), "n-rows", &rows, "n-columns", &cols, 0); - - if (x2 > cols) { - cols = x2; - resized = TRUE; - } - if (y2 > rows) { - rows = y2; - resized = TRUE; - } - if (resized) { - gtk_table_resize(GTK_TABLE(table), rows, cols); - } - - if (expand) { - gtk_table_attach(GTK_TABLE(table), widget, x1, x2, y1, y2, - (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), - (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0); - } else { - gtk_table_attach(GTK_TABLE(table), widget, x1, x2, y1, y2, - (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); - } - if (mode != m_unset) { - gtk_widget_show(widget); - } -} - -// create a row in the grid from the given basic variable -void create_grid_row(var_t *row_p, GtkTreeStore *model, GtkTreeIter *parent_row, int n_columns) { - GtkTreeIter row_iter; - int col = 0; - int i; - - if (row_p->type != V_ARRAY && row_p->type != V_STR && row_p->type != V_INT) { - return; - } - - gtk_tree_store_append(model, &row_iter, parent_row); - if (row_p->type == V_STR) { - // basic variable is a 1D array, eg: f = files("*.bas") - gtk_tree_store_set(model, &row_iter, 0, row_p->v.p.ptr, -1); - return; - } - if (row_p->type == V_INT) { - sprintf(buff, "%d", row_p->v.i); - gtk_tree_store_set(model, &row_iter, 0, buff, -1); - return; - } - - for (col = 0, i = 0; i < row_p->v.a.size; i++) { - var_t *col_p = (var_t *) (row_p->v.a.ptr + sizeof(var_t) * col); - if (col_p->type == V_STR) { - gtk_tree_store_set(model, &row_iter, col++, col_p->v.p.ptr, -1); - } else if (col_p->type == V_INT) { - sprintf(buff, "%d", col_p->v.i); - gtk_tree_store_set(model, &row_iter, col++, buff, -1); - } else if (col_p->type == V_ARRAY) { - create_grid_row(col_p, model, &row_iter, n_columns); - } - if (col >= n_columns) { - break; - } - } -} - -// called when a row is selected -void on_grid_selection(GtkTreeSelection *selection, var_t *v) { - GtkTreeModel *model; - GtkTreeIter iter; - if (gtk_tree_selection_get_selected(selection, &model, &iter)) { - GValue value = { 0 }; - gtk_tree_model_get_value(model, &iter, 0, &value); - const char *val = g_value_get_string(&value); - if (val) { - v_setstr(v, val); - } - g_value_unset(&value); - } -} - -// called when a row is double clicked -void on_treeview_row_activated(GtkTreeView *treeview, - GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data) { - if (mode != m_unset) { - mode = m_clicked; - ui_reset(); - } -} - -// create a grid control type -GtkWidget *create_grid(const char *caption, var_t *v) { - GtkWidget *view = gtk_tree_view_new(); - GtkCellRenderer *renderer = 0; - int i; - int len = caption ? strlen(caption) : 0; - int n_columns = 0; - - // create the title area from the caption - for (i = 0; i < len; i++) { - const char *c = strchr(caption + i, '|'); - int end_index = c ? c - caption : len; - GString *s = g_string_new_len(caption + i, end_index - i); - - GtkTreeViewColumn *col = gtk_tree_view_column_new(); - gtk_tree_view_column_set_title(col, s->str); - gtk_tree_view_column_set_sort_column_id(col, n_columns); - gtk_tree_view_column_set_sort_indicator(col, TRUE); - - // pack tree view column into tree view - gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); - - // pack cell renderer into tree view column - if (renderer == 0) { - renderer = gtk_cell_renderer_text_new(); - } - gtk_tree_view_column_pack_start(col, renderer, TRUE); - - // set the 'text' property of the cell renderer to be - // populated from the nth column of the tree-view-column - gtk_tree_view_column_add_attribute(col, renderer, "text", n_columns++); - - i = end_index; - g_string_free(s, TRUE); - } - - gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(view), TRUE); - gtk_tree_view_set_enable_search(GTK_TREE_VIEW(view), TRUE); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), TRUE); - - GType *types = (GType *) g_malloc(sizeof(GType) * n_columns); - for (i = 0; i < n_columns; i++) { - types[i] = G_TYPE_STRING; - } - - GtkTreeStore *model = gtk_tree_store_newv(n_columns, types); - g_free(types); - gtk_tree_view_set_model(GTK_TREE_VIEW(view), gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(model))); - g_object_unref(model); // destroy model automatically with view - - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); - gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE); - - g_signal_connect((gpointer) view, "row_activated", G_CALLBACK(on_treeview_row_activated), NULL); - - // if the first row contains a string then - // use it as the row selection container - var_t *sel_row = (var_t *) v->v.a.ptr; - if (sel_row->type == V_STR) { - g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(on_grid_selection), sel_row); - i = 1; // populate from second element onwards - } else { - i = 0; - } - - // populate the grid - for (; i < v->v.a.size; i++) { - var_t *row_p = (var_t *) (v->v.a.ptr + sizeof(var_t) * i); - create_grid_row(row_p, model, NULL, n_columns); - } - - GtkWidget *scrolledwindow = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow), GTK_SHADOW_IN); - gtk_container_add(GTK_CONTAINER(scrolledwindow), view); - - return scrolledwindow; -} - -// BUTTON x1, x2, y1, y2, variable, caption [,type] -// -void cmd_button() { - int x1, x2, y1, y2; - var_t *v = 0; - char *caption = 0; - char *type = 0; - - if (-1 != par_massget("IIIIPSs", &x1, &x2, &y1, &y2, &v, &caption, &type)) { - GtkWidget *widget = 0; - WidgetInfo *inf = (WidgetInfo *) g_malloc(sizeof(WidgetInfo)); - inf->var = v; - - ui_begin(); - if (type) { - if (g_ascii_strcasecmp("radio", type) == 0) { - inf->type = ctrl_radio; - widget = gtk_radio_button_new_with_label(NULL, caption); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), FALSE); - set_radio_group(v, widget); - g_signal_connect((gpointer) widget, "clicked", G_CALLBACK(button_clicked), NULL); - } else if (g_ascii_strcasecmp("checkbox", type) == 0) { - inf->type = ctrl_check; - widget = gtk_check_button_new_with_label(caption); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), FALSE); - g_signal_connect((gpointer) widget, "clicked", G_CALLBACK(button_clicked), NULL); - } else if (g_ascii_strcasecmp("submit", type) == 0) { - inf->type = ctrl_button; - widget = gtk_button_new_with_mnemonic(caption); - g_signal_connect((gpointer) widget, "clicked", G_CALLBACK(button_clicked), (gpointer) TRUE); - } else if (g_ascii_strcasecmp("label", type) == 0) { - inf->type = ctrl_label; - widget = gtk_label_new(caption); - gtk_misc_set_alignment(GTK_MISC(widget), 0, 0); - } else if (g_ascii_strcasecmp("calendar", type) == 0) { - inf->type = ctrl_calendar; - widget = gtk_calendar_new(); - gtk_calendar_display_options(GTK_CALENDAR(widget), - GTK_CALENDAR_SHOW_HEADING | GTK_CALENDAR_SHOW_DAY_NAMES); - } else if (g_ascii_strcasecmp("file", type) == 0) { - inf->type = ctrl_file_button; - widget = gtk_file_chooser_button_new(caption, GTK_FILE_CHOOSER_ACTION_OPEN); - if (v->type == V_STR && v->v.p.ptr) { - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(widget), v->v.p.ptr); - } - } else if (g_ascii_strcasecmp("font", type) == 0) { - inf->type = ctrl_font_button; - widget = gtk_font_button_new(); - gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), caption); - if (v->type == V_STR && v->v.p.ptr) { - gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), v->v.p.ptr); - } - } else if (g_ascii_strcasecmp("color", type) == 0) { - inf->type = ctrl_color_button; - widget = gtk_color_button_new(); - if (v->type == V_STR && v->v.p.ptr) { - gint n_colors = 1; - GdkColor *colors = 0; - gtk_color_selection_palette_from_string(v->v.p.ptr, &colors, &n_colors); - if (n_colors) { - gtk_color_button_set_color(GTK_COLOR_BUTTON(widget), colors); - } - g_free(colors); - } - } else if (g_ascii_strcasecmp("choice", type) == 0) { - inf->type = ctrl_list; - widget = gtk_combo_box_new_text(); - // "Easy|Medium|Hard" - int item_index = 0; - int len = caption ? strlen(caption) : 0; - int i; - for (i = 0; i < len; i++) { - const char *c = strchr(caption + i, '|'); - int end_index = c ? c - caption : len; - GString *s = g_string_new_len(caption + i, end_index - i); - gtk_combo_box_append_text(GTK_COMBO_BOX(widget), s->str); - i = end_index; - if (v->type == V_STR && v->v.p.ptr && strcmp((const char *)v->v.p.ptr, s->str) == 0) { - // item text same as variable - set selected - gtk_combo_box_set_active(GTK_COMBO_BOX(widget), item_index); - } - item_index++; - g_string_free(s, TRUE); - } - } else if (g_ascii_strcasecmp("grid", type) == 0) { - if (v->type != V_ARRAY || caption == 0 || caption[0] == 0) { - rt_raise("INVALID GRID BUTTON ARRAY"); - } else { - inf->type = ctrl_grid; - widget = create_grid(caption, v); - } - } else if (g_ascii_strcasecmp("tab", type) == 0) { - if (notebook == 0) { - notebook = gtk_notebook_new(); - inf->type = ctrl_tab; - gtk_container_add(GTK_CONTAINER(form), notebook); - set_widget_info(notebook, inf); - } - GtkWidget *label = gtk_label_new(caption); - GtkWidget *table = gtk_table_new(1, 1, FALSE); - gtk_table_set_col_spacings(GTK_TABLE(table), TABLE_GAP); - gtk_table_set_row_spacings(GTK_TABLE(table), TABLE_GAP); - gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table, label); - pfree2(caption, type); - return; - } else { - rt_raise("UNKNOWN BUTTON TYPE: %s", type); - } - - if (prog_error) { - ui_reset(); - pfree2(caption, type); - g_free(inf); - return; - } - } - - if (widget == 0) { - // becomes a submit button when not modeless - inf->type = ctrl_button; - widget = gtk_button_new_with_mnemonic(caption); - g_signal_connect((gpointer) widget, "clicked", - G_CALLBACK(button_clicked), (gpointer) (mode == m_unset ? TRUE : FALSE)); - } - - set_widget_info(widget, inf); - add_form_child(widget, (inf->type == ctrl_grid), x1, x2, y1, y2); - - // prime input field from variable - if (v->type == V_STR && v->v.p.ptr && strcmp((const char *)v->v.p.ptr, caption) == 0) { - if (inf->type == ctrl_check || inf->type == ctrl_radio) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE); - } - } - } - pfree2(caption, type); -} - -// TEXT x1, x2, y1, y2, variable [|"multiline"] -// When DOFORM returns the variable contains the user entered value -// -void cmd_text() { - int x1, x2, y1, y2; - var_t arg; - var_t *v = 0; - char *type = 0; - - v_init(&arg); - eval(&arg); - - if (arg.type == V_STR) { - GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(output.main_view->parent), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, - GTK_BUTTONS_OK, - "%s", arg.v.p.ptr); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - v_free(&arg); - return; - } else { - x1 = v_igetval(&arg); - v_free(&arg); - } - - if (-1 != par_massget("IIIPs", &x2, &y1, &y2, &v, &type)) { - ui_begin(); - - WidgetInfo *inf = (WidgetInfo *) g_malloc(sizeof(WidgetInfo)); - inf->var = v; - - if (type && g_ascii_strcasecmp("multiline", type) == 0) { - GtkWidget *widget = gtk_text_view_new(); - inf->type = ctrl_text_multi; - - // prime field from var_t - if (v->type == V_STR && v->v.p.ptr) { - GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget)); - gtk_text_buffer_set_text(buffer, (const char *)v->v.p.ptr, -1); - } - - GtkWidget *scrolledwindow = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow), GTK_SHADOW_ETCHED_IN); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_container_add(GTK_CONTAINER(scrolledwindow), widget); - - set_widget_info(scrolledwindow, inf); - add_form_child(scrolledwindow, TRUE, x1, x2, y1, y2); - } else { - GtkWidget *widget = gtk_entry_new(); - inf->type = ctrl_text; - - // prime field from var_t - if (v->type == V_STR && v->v.p.ptr) { - gtk_entry_set_text(GTK_ENTRY(widget), (const char *)v->v.p.ptr); - } - - gtk_entry_set_has_frame(GTK_ENTRY(widget), TRUE); - gtk_entry_set_max_length(GTK_ENTRY(widget), 100); - - set_widget_info(widget, inf); - add_form_child(widget, FALSE, x1, x2, y1, y2); - } - pfree(type); - } -} - -// DOFORM [x,y,w,h] -// -// Modal syntax: -// BUTTON ... -// DOFORM ... -// -// Modeless syntax: -// DOFORM 'begin modeless form -// BUTTON .... -// DOFORM 'continue modeless form -// -void cmd_doform() { - int x, y, w, h; - int num_args; - - x = y = w = h = 0; - num_args = par_massget("iiii", &x, &y, &w, &h); - - if (form == 0) { - // begin modeless state - m_unset, m_init, m_modeless - mode = m_init; - modeless_x = x; - modeless_y = y; - modeless_w = w; - modeless_h = h; - return; - } - - if (mode != m_unset) { - // continue modeless state - if (form == 0) { - rt_raise("UI: FORM HAS CLOSED"); - return; - } - // set form position in initial iteration - if (mode == m_init) { - mode = m_modeless; - if (num_args == 0) { - // apply coordinates from inital doform call - x = modeless_x; - y = modeless_y; - w = modeless_w; - h = modeless_h; - } - } else { - // pump system messages until button is clicked - while (mode == m_modeless && output.break_exec == 0) { - gtk_main_iteration_do(TRUE); - } - mode = m_modeless; - ui_transfer_data(form); - return; - } - } - - switch (num_args) { - case 0: - case 2: - case 4: - break; - default: - ui_reset(); - rt_raise("UI: INVALID FORM ARGUMENTS: %d", num_args); - return; - } - - if (w < 1 || x + w > output.width) { - w = output.width - x; - } - if (h < 1 || y + h > output.height) { - h = output.height - y; - } - - gtk_layout_move(GTK_LAYOUT(output.widget), form, x, y); - gtk_widget_set_size_request(GTK_WIDGET(form), w, h); - gtk_widget_grab_focus(form); - gtk_widget_show_all(form); - - if (mode == m_unset) { - mode = m_modal; - while (mode == m_modal && output.break_exec == 0) { - gtk_main_iteration_do(TRUE); - } - ui_transfer_data(form); - ui_reset(); - } -} - diff --git a/src/platform/gtk/src/interface.c b/src/platform/gtk/src/interface.c deleted file mode 100644 index 7da7212f..00000000 --- a/src/platform/gtk/src/interface.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * DO NOT EDIT THIS FILE - it is generated by Glade. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include - -#include -#include - -#include "callbacks.h" -#include "interface.h" -#include "support.h" - -#define GLADE_HOOKUP_OBJECT(component,widget,name) \ - g_object_set_data_full (G_OBJECT (component), name, \ - gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref) - -#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \ - g_object_set_data (G_OBJECT (component), name, widget) - -GtkWidget *create_main_window(void) { - GtkWidget *main_window; - GtkWidget *main_container; - GtkWidget *menubar; - GtkWidget *menuitem; - GtkWidget *menuitem_menu; - GtkWidget *break_bn; - GtkWidget *separator2; - GtkWidget *reset_keys; - GtkWidget *save_screen; - GtkWidget *separator1; - GtkWidget *about; - GtkWidget *separatormenuitem1; - GtkWidget *quit; - GtkWidget *statusbar2; - GtkWidget *scrolledwindow2; - GtkWidget *drawing_area; - GtkAccelGroup *accel_group; - - accel_group = gtk_accel_group_new(); - - main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_widget_set_name(main_window, "main_window"); - gtk_window_set_title(GTK_WINDOW(main_window), _("SmallBASIC")); - gtk_window_set_destroy_with_parent(GTK_WINDOW(main_window), TRUE); - - main_container = gtk_vbox_new(FALSE, 0); - gtk_widget_set_name(main_container, "main_container"); - gtk_widget_show(main_container); - gtk_container_add(GTK_CONTAINER(main_window), main_container); - - menubar = gtk_menu_bar_new(); - gtk_widget_set_name(menubar, "menubar"); - gtk_widget_show(menubar); - gtk_box_pack_start(GTK_BOX(main_container), menubar, FALSE, FALSE, 0); - - menuitem = gtk_menu_item_new_with_mnemonic(_("_File")); - gtk_widget_set_name(menuitem, "menuitem"); - gtk_widget_show(menuitem); - gtk_container_add(GTK_CONTAINER(menubar), menuitem); - - menuitem_menu = gtk_menu_new(); - gtk_widget_set_name(menuitem_menu, "menuitem_menu"); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menuitem_menu); - - break_bn = gtk_menu_item_new_with_mnemonic(_("_Break")); - gtk_widget_set_name(break_bn, "break_bn"); - gtk_widget_show(break_bn); - gtk_container_add(GTK_CONTAINER(menuitem_menu), break_bn); - - separator2 = gtk_separator_menu_item_new(); - gtk_widget_set_name(separator2, "separator2"); - gtk_widget_show(separator2); - gtk_container_add(GTK_CONTAINER(menuitem_menu), separator2); - gtk_widget_set_sensitive(separator2, FALSE); - - reset_keys = gtk_menu_item_new_with_mnemonic(_("_Reset keys")); - gtk_widget_set_name(reset_keys, "reset_keys"); - gtk_widget_show(reset_keys); - gtk_container_add(GTK_CONTAINER(menuitem_menu), reset_keys); - - save_screen = gtk_menu_item_new_with_mnemonic(_("_Save Screen")); - gtk_widget_set_name(save_screen, "save_screen"); - gtk_widget_show(save_screen); - gtk_container_add(GTK_CONTAINER(menuitem_menu), save_screen); - - separator1 = gtk_separator_menu_item_new(); - gtk_widget_set_name(separator1, "separator1"); - gtk_widget_show(separator1); - gtk_container_add(GTK_CONTAINER(menuitem_menu), separator1); - gtk_widget_set_sensitive(separator1, FALSE); - - about = gtk_image_menu_item_new_from_stock("gtk-about", accel_group); - gtk_widget_set_name(about, "about"); - gtk_widget_show(about); - gtk_container_add(GTK_CONTAINER(menuitem_menu), about); - - separatormenuitem1 = gtk_separator_menu_item_new(); - gtk_widget_set_name(separatormenuitem1, "separatormenuitem1"); - gtk_widget_show(separatormenuitem1); - gtk_container_add(GTK_CONTAINER(menuitem_menu), separatormenuitem1); - gtk_widget_set_sensitive(separatormenuitem1, FALSE); - - quit = gtk_image_menu_item_new_from_stock("gtk-quit", accel_group); - gtk_widget_set_name(quit, "quit"); - gtk_widget_show(quit); - gtk_container_add(GTK_CONTAINER(menuitem_menu), quit); - - statusbar2 = gtk_statusbar_new(); - gtk_widget_set_name(statusbar2, "statusbar2"); - gtk_widget_show(statusbar2); - gtk_box_pack_end(GTK_BOX(main_container), statusbar2, FALSE, FALSE, 0); - - scrolledwindow2 = gtk_scrolled_window_new(NULL, NULL); - gtk_widget_set_name(scrolledwindow2, "scrolledwindow2"); - gtk_widget_show(scrolledwindow2); - gtk_box_pack_start(GTK_BOX(main_container), scrolledwindow2, TRUE, TRUE, 0); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow2), GTK_POLICY_NEVER, GTK_POLICY_NEVER); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow2), GTK_SHADOW_ETCHED_IN); - - drawing_area = gtk_layout_new(NULL, NULL); - gtk_widget_set_name(drawing_area, "drawing_area"); - gtk_container_add(GTK_CONTAINER(scrolledwindow2), drawing_area); - gtk_widget_set_size_request(drawing_area, 668, 392); - gtk_layout_set_size(GTK_LAYOUT(drawing_area), 1, 1); - GTK_ADJUSTMENT(GTK_LAYOUT(drawing_area)->hadjustment)->step_increment = 10; - GTK_ADJUSTMENT(GTK_LAYOUT(drawing_area)->vadjustment)->step_increment = 10; - - g_signal_connect((gpointer) break_bn, "activate", G_CALLBACK(on_break), NULL); - g_signal_connect((gpointer) reset_keys, "activate", G_CALLBACK(on_reset_keys), NULL); - g_signal_connect((gpointer) save_screen, "activate", G_CALLBACK(on_save_screen), NULL); - g_signal_connect((gpointer) about, "activate", G_CALLBACK(on_about_activate), NULL); - g_signal_connect((gpointer) quit, "activate", G_CALLBACK(on_quit_activate), NULL); - - /* - * Store pointers to all widgets, for use by lookup_widget(). - */ - GLADE_HOOKUP_OBJECT_NO_REF(main_window, main_window, "main_window"); - GLADE_HOOKUP_OBJECT(main_window, main_container, "main_container"); - GLADE_HOOKUP_OBJECT(main_window, menubar, "menubar"); - GLADE_HOOKUP_OBJECT(main_window, menuitem, "menuitem"); - GLADE_HOOKUP_OBJECT(main_window, menuitem_menu, "menuitem_menu"); - GLADE_HOOKUP_OBJECT(main_window, break_bn, "break_bn"); - GLADE_HOOKUP_OBJECT(main_window, separator2, "separator2"); - GLADE_HOOKUP_OBJECT(main_window, reset_keys, "reset_keys"); - GLADE_HOOKUP_OBJECT(main_window, save_screen, "save_screen"); - GLADE_HOOKUP_OBJECT(main_window, separator1, "separator1"); - GLADE_HOOKUP_OBJECT(main_window, about, "about"); - GLADE_HOOKUP_OBJECT(main_window, separatormenuitem1, "separatormenuitem1"); - GLADE_HOOKUP_OBJECT(main_window, quit, "quit"); - GLADE_HOOKUP_OBJECT(main_window, statusbar2, "statusbar2"); - GLADE_HOOKUP_OBJECT(main_window, scrolledwindow2, "scrolledwindow2"); - GLADE_HOOKUP_OBJECT(main_window, drawing_area, "drawing_area"); - - gtk_window_add_accel_group(GTK_WINDOW(main_window), accel_group); - - return main_window; -} - -GtkWidget *create_aboutdialog(void) { - GtkWidget *aboutdialog; - const gchar *authors[] = { - "Nicholas Christopoulos", - "Chris Warren-Smith", - NULL - }; - /* - * TRANSLATORS: Replace this string with your names, one name per line. - */ - gchar *translators = _("translator-credits"); - - aboutdialog = gtk_about_dialog_new(); - gtk_widget_set_name(aboutdialog, "aboutdialog"); - gtk_container_set_border_width(GTK_CONTAINER(aboutdialog), 5); - gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(aboutdialog), VERSION); - gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(aboutdialog), _("SmallBASIC")); - gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(aboutdialog), _("Copyright (c) 2006 Chris Warren-Smith")); - gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(aboutdialog), - "SmallBASIC comes with ABSOLUTELY NO WARRANTY.\nThis program is free software; you can use it redistribute\nit and/or modify it under the terms of the \nGNU General Public License version 2 as published by\nthe Free Software Foundation.\n"); - gtk_about_dialog_set_wrap_license(GTK_ABOUT_DIALOG(aboutdialog), TRUE); - gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(aboutdialog), "smallbasic.sf.net"); - gtk_about_dialog_set_website_label(GTK_ABOUT_DIALOG(aboutdialog), _("SmallBASIC")); - gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(aboutdialog), authors); - gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(aboutdialog), translators); - - /* - * Store pointers to all widgets, for use by lookup_widget(). - */ - GLADE_HOOKUP_OBJECT_NO_REF(aboutdialog, aboutdialog, "aboutdialog"); - - return aboutdialog; -} - -GtkWidget *create_opendialog(void) { - GtkWidget *opendialog; - GtkWidget *dialog_vbox1; - GtkWidget *dialog_action_area1; - GtkWidget *button1; - GtkWidget *button2; - - opendialog = gtk_file_chooser_dialog_new(_("Open BAS File"), NULL, GTK_FILE_CHOOSER_ACTION_OPEN, NULL); - gtk_widget_set_name(opendialog, "opendialog"); - gtk_container_set_border_width(GTK_CONTAINER(opendialog), 5); - gtk_window_set_modal(GTK_WINDOW(opendialog), TRUE); - gtk_window_set_type_hint(GTK_WINDOW(opendialog), GDK_WINDOW_TYPE_HINT_DIALOG); - - dialog_vbox1 = GTK_DIALOG(opendialog)->vbox; - gtk_widget_set_name(dialog_vbox1, "dialog_vbox1"); - gtk_widget_show(dialog_vbox1); - - dialog_action_area1 = GTK_DIALOG(opendialog)->action_area; - gtk_widget_set_name(dialog_action_area1, "dialog_action_area1"); - gtk_widget_show(dialog_action_area1); - gtk_button_box_set_layout(GTK_BUTTON_BOX(dialog_action_area1), GTK_BUTTONBOX_END); - - button1 = gtk_button_new_from_stock("gtk-cancel"); - gtk_widget_set_name(button1, "button1"); - gtk_widget_show(button1); - gtk_dialog_add_action_widget(GTK_DIALOG(opendialog), button1, GTK_RESPONSE_CANCEL); - GTK_WIDGET_SET_FLAGS(button1, GTK_CAN_DEFAULT); - - button2 = gtk_button_new_from_stock("gtk-open"); - gtk_widget_set_name(button2, "button2"); - gtk_widget_show(button2); - gtk_dialog_add_action_widget(GTK_DIALOG(opendialog), button2, GTK_RESPONSE_OK); - GTK_WIDGET_SET_FLAGS(button2, GTK_CAN_DEFAULT); - - /* - * Store pointers to all widgets, for use by lookup_widget(). - */ - GLADE_HOOKUP_OBJECT_NO_REF(opendialog, opendialog, "opendialog"); - GLADE_HOOKUP_OBJECT_NO_REF(opendialog, dialog_vbox1, "dialog_vbox1"); - GLADE_HOOKUP_OBJECT_NO_REF(opendialog, dialog_action_area1, "dialog_action_area1"); - GLADE_HOOKUP_OBJECT(opendialog, button1, "button1"); - GLADE_HOOKUP_OBJECT(opendialog, button2, "button2"); - - gtk_widget_grab_default(button2); - return opendialog; -} - -GtkWidget *create_savedialog(void) { - GtkWidget *savedialog; - GtkWidget *dialog_vbox2; - GtkWidget *dialog_action_area2; - GtkWidget *button3; - GtkWidget *button4; - - savedialog = gtk_file_chooser_dialog_new(_("Save Screen"), NULL, GTK_FILE_CHOOSER_ACTION_SAVE, NULL); - gtk_widget_set_name(savedialog, "savedialog"); - gtk_container_set_border_width(GTK_CONTAINER(savedialog), 5); - gtk_window_set_type_hint(GTK_WINDOW(savedialog), GDK_WINDOW_TYPE_HINT_DIALOG); - - dialog_vbox2 = GTK_DIALOG(savedialog)->vbox; - gtk_widget_set_name(dialog_vbox2, "dialog_vbox2"); - gtk_widget_show(dialog_vbox2); - - dialog_action_area2 = GTK_DIALOG(savedialog)->action_area; - gtk_widget_set_name(dialog_action_area2, "dialog_action_area2"); - gtk_widget_show(dialog_action_area2); - gtk_button_box_set_layout(GTK_BUTTON_BOX(dialog_action_area2), GTK_BUTTONBOX_END); - - button3 = gtk_button_new_from_stock("gtk-cancel"); - gtk_widget_set_name(button3, "button3"); - gtk_widget_show(button3); - gtk_dialog_add_action_widget(GTK_DIALOG(savedialog), button3, GTK_RESPONSE_CANCEL); - GTK_WIDGET_SET_FLAGS(button3, GTK_CAN_DEFAULT); - - button4 = gtk_button_new_from_stock("gtk-open"); - gtk_widget_set_name(button4, "button4"); - gtk_widget_show(button4); - gtk_dialog_add_action_widget(GTK_DIALOG(savedialog), button4, GTK_RESPONSE_OK); - GTK_WIDGET_SET_FLAGS(button4, GTK_CAN_DEFAULT); - - /* - * Store pointers to all widgets, for use by lookup_widget(). - */ - GLADE_HOOKUP_OBJECT_NO_REF(savedialog, savedialog, "savedialog"); - GLADE_HOOKUP_OBJECT_NO_REF(savedialog, dialog_vbox2, "dialog_vbox2"); - GLADE_HOOKUP_OBJECT_NO_REF(savedialog, dialog_action_area2, "dialog_action_area2"); - GLADE_HOOKUP_OBJECT(savedialog, button3, "button3"); - GLADE_HOOKUP_OBJECT(savedialog, button4, "button4"); - - gtk_widget_grab_default(button4); - return savedialog; -} diff --git a/src/platform/gtk/src/interface.h b/src/platform/gtk/src/interface.h deleted file mode 100644 index 2a11e48d..00000000 --- a/src/platform/gtk/src/interface.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * DO NOT EDIT THIS FILE - it is generated by Glade. - */ - -GtkWidget *create_main_window(void); -GtkWidget *create_aboutdialog(void); -GtkWidget *create_opendialog(void); -GtkWidget *create_savedialog(void); diff --git a/src/platform/gtk/src/main.c b/src/platform/gtk/src/main.c deleted file mode 100644 index 607382fe..00000000 --- a/src/platform/gtk/src/main.c +++ /dev/null @@ -1,85 +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 -// - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#ifdef USE_HILDON -#include -#include -#endif - -#include "interface.h" -#include "output.h" -#include "output_model.h" - -extern OutputModel output; - -void destroy_event(GtkObject *object, gpointer user_data) { - exit(1); -} - -int main(int argc, char *argv[]) { - GtkWidget *main_window; - - gtk_set_locale(); - gtk_init(&argc, &argv); - - main_window = create_main_window(); - -#ifdef USE_HILDON - HildonProgram *app = HILDON_PROGRAM(hildon_program_get_instance()); - g_set_application_name("SmallBASIC"); - output.osso = osso_initialize(PACKAGE, VERSION, TRUE, NULL); - hildon_program_add_window(app, HILDON_WINDOW(main_window)); -#endif - - drawing_area_init(main_window); - gtk_widget_show_all(GTK_WIDGET(main_window)); - g_signal_connect(G_OBJECT(main_window), "destroy", G_CALLBACK(destroy_event), NULL); - - // prepare runtime flags - opt_graphics = 1; - opt_quiet = 1; - opt_interactive = 0; - opt_nosave = 1; - opt_ide = IDE_NONE; // for sberr.c - opt_command[0] = 0; - opt_pref_width = 0; - opt_pref_height = 0; - opt_pref_bpp = 0; - opt_file_permitted = 1; - - if (argc == 2 && access(argv[1], R_OK) == 0) { - sbasic_main(argv[1]); - } - - GtkWidget *dialog = create_opendialog(); - while (1) { - gtk_widget_show(dialog); - gtk_window_set_title(GTK_WINDOW(dialog), "Open BAS File"); - if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { - char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - const char *p = strrchr(filename, '/'); - gtk_window_set_title(GTK_WINDOW(main_window), p ? p + 1 : filename); - gtk_widget_hide(dialog); - sbasic_main(filename); - g_free(filename); - } else { - break; - } - } - gtk_widget_destroy(dialog); - om_cleanup(); - return 0; -} - diff --git a/src/platform/gtk/src/output.c b/src/platform/gtk/src/output.c deleted file mode 100644 index 00875fc1..00000000 --- a/src/platform/gtk/src/output.c +++ /dev/null @@ -1,680 +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 -// - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "device.h" -#include "osd.h" - -#include -#include - -#ifdef USE_HILDON -#include -#include -#endif - -#include "interface.h" -#include "output.h" -#include "output_model.h" - -extern OutputModel output; - -#define PEN_ON 2 -#define PEN_OFF 0 - -GtkWidget *entry = 0; -GtkWidget *html_widget = 0; -int keymap[KEYMAP_LAST + 1]; -typedef struct { - GtkWidget *dialog; - GtkWidget *label; - GtkIMContext *imctx; - int index; -} keymap_data; - -gboolean key_press_event(GtkWidget *widget, GdkEventKey *event, keymap_data *data); - -int osd_devinit() { - dev_fgcolor = 0; - dev_bgcolor = 15; - os_graphics = 1; - os_ver = 1; - os_color = 1; - os_color_depth = 16; - os_graf_mx = output.width; - os_graf_my = output.height; - setsysvar_str(SYSVAR_OSNAME, "GTK"); - dev_clrkb(); - osd_cls(); - output.break_exec = 0; -} - -void osd_setcolor(long color) { - om_set_fg_color(color); -} - -void osd_settextcolor(long fg, long bg) { - om_set_fg_color(fg); - om_set_bg_color(bg); -} - -void osd_refresh() { - GdkRectangle rc = { 0, 0, os_graf_mx, os_graf_my }; - gdk_window_invalidate_rect(output.widget->window, &rc, TRUE); -} - -void close_html() { - if (html_widget) { - gtk_container_remove(GTK_CONTAINER(output.widget), html_widget); - html_widget = 0; - } -} - -int osd_devrestore() { - ui_reset(); - close_html(); - return 1; -} - -/** - * system event-loop - * return value: - * 0 continue - * -1 close sbpad application - * -2 stop running basic application - */ -int osd_events(int wait_flag) { - if (wait_flag || (output.pen_down == 0 && output.pen_mode == PEN_ON && - gtk_events_pending() == FALSE)) { - // in a "while 1" loop checking for a pen/mouse - // event with pen(0) or executing input statement. - gtk_main_iteration_do(TRUE); - } - - if (gtk_events_pending()) { - gtk_main_iteration_do(FALSE); - } - - if (output.break_exec == 1) { - brun_break(); - return -2; - } - return 0; -} - -void osd_setpenmode(int enable) { - output.pen_mode = enable; -} - -int osd_getpen(int code) { - if (output.pen_mode == PEN_OFF) { - gtk_main_iteration_do(TRUE); - } - - if (output.break_exec == 1) { - brun_break(); - return 1; // break from WHILE PEN(0)=0 - } - - GdkModifierType mask; - int x, y; - - switch (code) { - case 0: // return true if there is a waiting pen event(up/down) - if (output.pen_down != 0) { - gtk_main_iteration_do(FALSE); - gdk_window_get_pointer(output.widget->window, &output.pen_down_x, &output.pen_down_y, &mask); - return 1; - } - gtk_main_iteration_do(TRUE); // UNTIL PEN(0) - return 0; - - case 3: // returns true if the pen is down(and save curpos) - if (output.pen_down != 0) { - gdk_window_get_pointer(output.widget->window, &output.pen_down_x, &output.pen_down_y, &mask); - return 1; - } - return 0; - - case 1: // last pen-down x - return output.pen_down_x; - - case 2: // last pen-down y - return output.pen_down_y; - - case 4: // cur pen-down x - case 10: - gdk_window_get_pointer(output.widget->window, &x, &y, &mask); - return x; - - case 5: // cur pen-down y - case 11: - gdk_window_get_pointer(output.widget->window, &x, &y, &mask); - return y; - - case 12: // true if left button pressed - return (output.pen_down == 1); - - case 13: // true if right button pressed - return (output.pen_down == 3); - - case 14: // true if middle button pressed - return (output.pen_down == 2); - break; - } - return 0; - -} - -int osd_getx() { - return output.cur_x; -} - -int osd_gety() { - return output.cur_y; -} - -void osd_setxy(int x, int y) { - output.cur_x = x; - output.cur_y = y; -} - -void osd_cls() { - gint width, height; - gdk_drawable_get_size(output.pixmap, &width, &height); - gdk_gc_set_rgb_fg_color(output.gc, &output.bg); - gdk_draw_rectangle(output.pixmap, output.gc, TRUE, 0, 0, width, height); - om_reset(TRUE); - osd_refresh(); -} - -int osd_textwidth(const char *text) { - return (text && text[0] ? strlen(text) * output.font_width : 0); -} - -int osd_textheight(const char *text) { - return output.ascent + output.descent; -} - -void osd_setpixel(int x, int y) { - GdkImage *image = gdk_drawable_get_image(output.pixmap, x, y, 1, 1); - gdk_image_put_pixel(image, 0, 0, dev_fgcolor); - gdk_draw_image(output.pixmap, output.gc, image, 0, 0, x, y, 1, 1); - g_object_unref(image); - invalidate_rect(x, y, x + 1, y + 1); -} - -long osd_getpixel(int x, int y) { - GdkImage *image = gdk_drawable_get_image(output.pixmap, x, y, 1, 1); - guint32 px = gdk_image_get_pixel(image, 0, 0); - g_object_unref(image); - return px; -} - -void osd_line(int x1, int y1, int x2, int y2) { - gdk_gc_set_rgb_fg_color(output.gc, &output.fg); - gdk_draw_line(output.pixmap, output.gc, x1, y1, x2, y2); - invalidate_rect(x1, y1, x2, y2); -} - -void osd_rect(int x1, int y1, int x2, int y2, int bFill) { - gdk_gc_set_rgb_fg_color(output.gc, &output.fg); - gdk_draw_rectangle(output.pixmap, output.gc, bFill, x1, y1, x2 - x1, y2 - y1); - invalidate_rect(x1, y1, x2, y2); -} - -int drvsound_init(void) { -} - -/* - * restores device state - */ -void drvsound_close(void) { -} - -/* - * plays a tone - * frq = frequency - * ms = duration in milliseconds - * vol = volume(0..100) - * bgplay = true for play in background - */ -void drvsound_sound(int frq, int ms, int vol, int bgplay) { - - // If you want nonblocking audio that's not a system sound, combination of: - // int esd = esd_open_sound(NULL); - // int sample = esd_file_cache(esd, "myprogname", "soundfile.wav"); - // esd_sample_play(esd, sample); - // esd_sample_free(esd, sample); - // esd_close(esd); -} - -/* - * clear background queue - */ -void drvsound_clear_queue(void) { -} - -/* - * For OSes that does not supports threads, this enables background plays - * (Its called every ~50ms) - */ -void drvsound_event(void) { -} - -/* - * beep! - */ -void drvsound_beep(void) { - gdk_beep(); -} - -gint timeout_callback(gpointer data) { - output.modal_flag = FALSE; -} - -void dev_delay(dword ms) { - gint timer_id = g_timeout_add(ms, timeout_callback, 0); - output.modal_flag = TRUE; - while (output.modal_flag && output.break_exec == 0) { - gtk_main_iteration_do(TRUE); - } - g_source_remove(timer_id); -} - - -void dev_html(const char *html, const char *t, int x, int y, int w, int h) { - close_html(); - if (html == 0 || html[0] == 0) { - return; - } - // fit within the output box - if (w < 1 || x + w > output.width) { - w = output.width - x; - } - if (h < 1 || y + h > output.height) { - h = output.height - y; - } - - html_widget = gtk_scrolled_window_new(NULL, NULL); - gtk_widget_show(html_widget); - gtk_layout_put(GTK_LAYOUT(output.widget), html_widget, x, y); - gtk_widget_set_size_request(html_widget, w, h); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(html_widget), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - - GtkWidget *viewport = gtk_viewport_new(NULL, NULL); - gtk_widget_show(viewport); - gtk_container_add(GTK_CONTAINER(html_widget), viewport); - - GtkWidget *label = gtk_label_new(NULL); - gtk_container_add(GTK_CONTAINER(viewport), label); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); - gtk_label_set_use_markup(GTK_LABEL(label), TRUE); - gtk_label_set_markup(GTK_LABEL(label), html); - gtk_widget_show(label); -} - -/* - * Image commmands ... - */ -GdkPixbuf *get_image(dev_file_t *filep, int index) { - GtkWidget *image = gtk_image_new_from_file(filep->name); - if (gtk_image_get_storage_type(GTK_IMAGE(image)) != GTK_IMAGE_PIXBUF) { - return 0; - } - GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image)); - return pixbuf; -} - -void dev_image(int handle, int index, int x, int y, int sx, int sy, int w, int h) { - int imgw = -1; - int imgh = -1; - dev_file_t *filep = dev_getfileptr(handle); - if (filep == 0) { - return; - } - - if (filep->open_flags == DEV_FILE_INPUT) { - GdkPixbuf *pixbuf = get_image(filep, index); - if (pixbuf) { - gdk_draw_pixbuf(output.pixmap, output.gc, pixbuf, sx, sy, x, y, w, h, GDK_RGB_DITHER_NORMAL, 0, 0); - GdkRectangle rc = { x - 1, y - 1, w + 2, h + 2 }; - gdk_window_invalidate_rect(output.widget->window, &rc, TRUE); - } - } else { - // output screen area image to jpeg - GdkPixbuf *pixbuf = gdk_pixbuf_get_from_drawable(NULL, output.pixmap, NULL, - x, y, 0, 0, sx, sy); - if (pixbuf) { - GError *error = 0; - gdk_pixbuf_save(pixbuf, filep->name, "jpeg", &error, "quality", "100", NULL); - g_object_unref(pixbuf); - g_clear_error(&error); - } - } -} - -int dev_image_width(int handle, int index) { - dev_file_t *filep = dev_getfileptr(handle); - if (filep == 0 || filep->open_flags != DEV_FILE_INPUT) { - return 0; - } - GdkPixbuf *pixbuf = get_image(filep, index); - return pixbuf != 0 ? gdk_pixbuf_get_width(pixbuf) : -1; -} - -int dev_image_height(int handle, int index) { - int imgw = -1; - int imgh = -1; - dev_file_t *filep = dev_getfileptr(handle); - if (filep == 0 || filep->open_flags != DEV_FILE_INPUT) { - return 0; - } - GdkPixbuf *pixbuf = get_image(filep, index); - return pixbuf != 0 ? gdk_pixbuf_get_height(pixbuf) : -1; -} - -gboolean focus_event(GtkWidget *widget, GdkEventFocus *event, GtkIMContext *imctx) { -#ifdef USE_HILDON - if (event->in) { - gtk_im_context_focus_in(imctx); - gtk_im_context_show(imctx); - } else { - gtk_im_context_focus_out(imctx); - } -#endif - return FALSE; -} - -void press_key(int key) { - if (entry) { - // input s$ - char t[] = { key, 0 }; - int pos = gtk_editable_get_position(GTK_EDITABLE(entry)); - gtk_editable_insert_text(GTK_EDITABLE(entry), t, 1, &pos); - gtk_editable_set_position(GTK_EDITABLE(entry), pos); - } else { - // k = inkey - dev_pushkey(key); - } -} - -gboolean im_context_commit(GtkIMContext *ctx, const gchar *str, keymap_data *data) { - if (str && str[0]) { - keymap[data->index] = str[0]; - press_key(keymap[data->index]); - gtk_dialog_response(GTK_DIALOG(data->dialog), GTK_RESPONSE_ACCEPT); - } - return TRUE; -} - -#ifdef USE_HILDON -void handle_key(int index, int def_key, int keyval, keymap_data *data) { - if (keymap[index]) { - // press the key - press_key(keymap[index]); - } else if (data) { - // assign default - keymap[index] = def_key; - press_key(keymap[index]); - if (data->dialog) { - gtk_dialog_response(GTK_DIALOG(data->dialog), GTK_RESPONSE_ACCEPT); - } - } else { - // ask for key assignment - keymap_data *data = g_new0(keymap_data, 1); - data->index = index; - data->dialog = - gtk_dialog_new_with_buttons("Map Key", - GTK_WINDOW(output.main_view->parent), - GTK_DIALOG_MODAL | - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); - data->label = gtk_label_new("Press a key (or cancel)"); - gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(data->dialog)->vbox), data->label); - g_signal_connect(G_OBJECT(data->dialog), "key_press_event", G_CALLBACK(key_press_event), data); - - gtk_widget_show_all(data->dialog); - - data->imctx = gtk_im_multicontext_new(); - g_signal_connect(G_OBJECT(data->imctx), "commit", G_CALLBACK(im_context_commit), data); - gtk_im_context_set_client_window(data->imctx, GTK_WIDGET(data->dialog)->window); - g_signal_connect(G_OBJECT(data->dialog), "focus_in_event", G_CALLBACK(focus_event), data->imctx); - g_signal_connect(G_OBJECT(data->dialog), "focus_out_event", G_CALLBACK(focus_event), data->imctx); - - gtk_dialog_run(GTK_DIALOG(data->dialog)); - - // cleanup - gtk_widget_hide(data->dialog); - gtk_widget_destroy(data->dialog); - gtk_im_context_focus_out(data->imctx); - g_object_unref(G_OBJECT(data->imctx)); - g_free(data); - } -} -#else -void handle_key(int index, int def_key, int keyval, keymap_data *data) { - press_key(def_key); -} -#endif - -/* handler for maemo hardware keys */ -gboolean key_press_event(GtkWidget *widget, GdkEventKey *event, keymap_data *data) { - switch (event->keyval) { - case GDK_Up: // Navigation Key Up - handle_key(KEYMAP_UP, SB_KEY_UP, GDK_Up, data); - break; - - case GDK_Down: // Navigation Key Down - handle_key(KEYMAP_DOWN, SB_KEY_DN, GDK_Down, data); - break; - - case GDK_Left: // Navigation Key Left - handle_key(KEYMAP_LEFT, SB_KEY_LEFT, GDK_Left, data); - break; - - case GDK_Right: // Navigation Key Right - handle_key(KEYMAP_RIGHT, SB_KEY_RIGHT, GDK_Right, data); - break; - - case GDK_F7: // Increase(zoom in) - handle_key(KEYMAP_F7, SB_KEY_PGUP, GDK_F7, data); - break; - - case GDK_F8: // Decrease(zoom out) - handle_key(KEYMAP_F8, SB_KEY_PGDN, GDK_F8, data); - break; - - case GDK_F6: // Full screen - handle_key(KEYMAP_F6, SB_KEY_HOME, GDK_F6, data); - break; - - case GDK_Return: // Navigation Key select - case GDK_KP_Enter: - output.modal_flag = FALSE; - break; - - case GDK_Escape: // Cancel/Close - output.break_exec = 1; - return TRUE; - - case GDK_C: - case GDK_c: - if (event->state & GDK_CONTROL_MASK) { - output.break_exec = TRUE; - return TRUE; - } - } - return FALSE; // continue event processing -} - -void input_changed(GtkEditable *editable, GtkWidget *entry) { - // adjust the size of the input to fix the text - const gchar *value = gtk_entry_get_text(GTK_ENTRY(entry)); - gtk_entry_set_width_chars(GTK_ENTRY(entry), 1 + strlen(value)); -} - -/* - * Keyboard input command - */ -char *dev_gets(char *dest, int size) { - entry = gtk_entry_new(); - - gtk_layout_put(GTK_LAYOUT(output.widget), entry, output.cur_x - 1, output.cur_y - 1); - gtk_entry_set_has_frame(GTK_ENTRY(entry), FALSE); - gtk_entry_set_max_length(GTK_ENTRY(entry), size); - gtk_entry_set_width_chars(GTK_ENTRY(entry), 1); - gtk_entry_set_alignment(GTK_ENTRY(entry), 0); - gtk_widget_modify_font(entry, output.font_desc); - g_signal_connect(G_OBJECT(entry), "key_press_event", G_CALLBACK(key_press_event), NULL); - g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(input_changed), entry); - - gtk_widget_show(entry); - gtk_widget_grab_focus(entry); -#ifdef USE_HILDON - gtk_im_context_show(GTK_ENTRY(entry)->im_context); -#endif - - output.modal_flag = TRUE; - while (output.modal_flag && output.break_exec == 0) { - gtk_main_iteration_do(TRUE); - } - - const gchar *value = gtk_entry_get_text(GTK_ENTRY(entry)); - strcpy(dest, value); - osd_write(dest); - - // remove and destroy the entry widget - gtk_container_remove(GTK_CONTAINER(output.widget), entry); - entry = 0; - return dest; -} - -void invalidate_rect(int x1, int y1, int x2, int y2) { - int x, y, w, h; - if (x1 < x2) { - x = x1; - w = x2 - x1; - } else if (x1 > x2) { - x = x2; - w = x1 - x2; - } else { - x = x1; - w = 1; - } - if (y1 < y2) { - y = y1; - h = y2 - y1; - } else if (y1 > y2) { - y = y2; - h = y1 - y2; - } else { - y = y1; - h = 1; - } - GdkRectangle rc = { x - 1, y - 1, w + 2, h + 2 }; - gdk_window_invalidate_rect(output.widget->window, &rc, TRUE); -} - -/* Create a new backing pixmap of the appropriate size */ -void on_realize(GtkWidget *widget, gpointer user_data) { - if (output.gc == 0) { - // deferred init to here since we don't run gtk_main() - output.gc = gdk_gc_new(widget->window); - om_reset(TRUE); - } - - if (output.layout == 0) { - output.layout = gtk_widget_create_pango_layout(output.widget, 0); - pango_layout_set_width(output.layout, -1); - pango_layout_set_font_description(output.layout, output.font_desc); - } - - if (output.pixmap) { - // copy old image onto new/resized image - int old_w, old_h; - gdk_drawable_get_size(output.pixmap, &old_w, &old_h); - int w = MAX(output.width, old_w); - int h = MAX(output.height, old_h); - - GdkPixmap *pixmap = gdk_pixmap_new(widget->window, w, h, -1); - gdk_gc_set_rgb_fg_color(output.gc, &output.bg); - gdk_draw_rectangle(pixmap, output.gc, TRUE, 0, 0, w, h); - gdk_draw_drawable(pixmap, output.gc, output.pixmap, 0, 0, 0, 0, // src/dest x/y - old_w, old_h); - g_object_unref(output.pixmap); - output.pixmap = pixmap; - } else { - // create a new pixmap - output.pixmap = gdk_pixmap_new(widget->window, output.width, output.height, -1); - osd_cls(); - } -} - -/* called when ever the client area size changes */ -void on_size_allocate(GtkWidget *widget, GdkRectangle *allocation, gpointer user_data) { - if (output.width != allocation->width || output.height != allocation->height) { - output.width = allocation->width; - output.height = allocation->height; - if (widget->window) { - on_realize(widget, user_data); - } - } -} - -/* Redraw the screen from the backing pixmap */ -gboolean expose_event(GtkWidget *widget, GdkEventExpose *event) { - if (output.pixmap) { - gdk_draw_drawable(GTK_LAYOUT(widget)->bin_window, output.gc, output.pixmap, event->area.x, event->area.y, // src - // - event->area.x, event->area.y, // dest - event->area.width, event->area.height); - } - return FALSE; -} - -gboolean button_press_event(GtkWidget *widget, GdkEventButton *event) { - GdkModifierType mask; - - output.pen_down = event->button; - if (output.pen_down) { - gdk_window_get_pointer(output.widget->window, &output.pen_down_x, &output.pen_down_y, &mask); - } - return TRUE; -} - -gboolean button_release_event(GtkWidget *w, GdkEventButton *e, gpointer data) { - output.pen_down = 0; - return TRUE; -} - -gboolean drawing_area_init(GtkWidget *main_window) { - GtkWidget *drawing_area = g_object_get_data(G_OBJECT(main_window), "drawing_area"); - - output.main_view = main_window; - - // connect signals - g_signal_connect(G_OBJECT(drawing_area), "size_allocate", G_CALLBACK(on_size_allocate), NULL); - g_signal_connect(G_OBJECT(drawing_area), "realize", G_CALLBACK(on_realize), NULL); - g_signal_connect(G_OBJECT(drawing_area), "expose_event", G_CALLBACK(expose_event), NULL); - g_signal_connect(G_OBJECT(drawing_area), "button_press_event", G_CALLBACK(button_press_event), NULL); - g_signal_connect(G_OBJECT(drawing_area), "button_release_event", G_CALLBACK(button_release_event), NULL); - g_signal_connect(G_OBJECT(main_window), "key_press_event", G_CALLBACK(key_press_event), NULL); - - gtk_widget_set_events(drawing_area, - GDK_KEY_PRESS_MASK | - GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); - - om_init(drawing_area); -} - diff --git a/src/platform/gtk/src/output.h b/src/platform/gtk/src/output.h deleted file mode 100644 index 28cd8d65..00000000 --- a/src/platform/gtk/src/output.h +++ /dev/null @@ -1,16 +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 -// - -#ifndef DEV_GTK_OUTPUT_H -#define DEV_GTK_OUTPUT_H - -gboolean drawing_area_init(GtkWidget *window); -void invalidate_rect(int x1, int y1, int x2, int y2); - -#endif - diff --git a/src/platform/gtk/src/output_model.c b/src/platform/gtk/src/output_model.c deleted file mode 100644 index 880d1f27..00000000 --- a/src/platform/gtk/src/output_model.c +++ /dev/null @@ -1,163 +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 -// - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#ifdef USE_HILDON -#include -#endif - -#include "output_model.h" - -struct OutputModel output; - -#define FONT_SIZE 10 -#define COLOR(r,g,b) {0, (r*65535/255), (g*65535/255), (b*65535/255)} -#define WHITE COLOR(255,255,255) - -/* basic colors - see: - * http://www.uv.tietgen.dk/staff/mlha/PC/Soft/Prog/BAS/VB/Function.html - */ -static GdkColor colors[] = { - COLOR(0, 0, 0), // 0 black - COLOR(0, 0, 128), // 1 blue - COLOR(0, 128, 0), // 2 green - COLOR(0, 128, 128), // 3 cyan - COLOR(128, 0, 0), // 4 red - COLOR(128, 0, 128), // 5 magenta - COLOR(128, 128, 0), // 6 yellow - COLOR(192, 192, 192), // 7 white - COLOR(128, 128, 128), // 8 gray - COLOR(0, 0, 255), // 9 light blue - COLOR(0, 255, 0), // 10 light green - COLOR(0, 255, 255), // 11 light cyan - COLOR(255, 0, 0), // 12 light red - COLOR(255, 0, 255), // 13 light magenta - COLOR(255, 255, 0), // 14 light yellow - WHITE // 15 bright white -}; - -int get_font_size() { - int size = FONT_SIZE * PANGO_SCALE; - GError *error = 0; - GKeyFile *key_file = g_key_file_new(); - const gchar *home = g_get_home_dir(); - gchar *filename = g_build_filename(home, "text.ini", NULL); - - g_key_file_load_from_file(key_file, filename, G_KEY_FILE_NONE, &error); - if (error == NULL) { - int n = g_key_file_get_integer(key_file, - g_key_file_get_start_group(key_file), - "size", &error); - if (error == NULL) { - size = n * PANGO_SCALE; - } - } - - g_clear_error(&error); - g_key_file_free(key_file); - g_free(filename); - return size; -} - -/* this is called once during application startup */ -void om_init(GtkWidget *widget) { - output.widget = widget; - output.pixmap = 0; - output.layout = 0; - output.gc = 0; - output.break_exec = 0; - - /* - * pango_font_description_from_string - */ - output.font_desc = pango_font_description_new(); - pango_font_description_set_size(output.font_desc, get_font_size()); - pango_font_description_set_family(output.font_desc, "monospace"); -} - -/* this is called once during application shutdown */ -void om_cleanup() { - if (output.layout) { - g_object_unref(output.layout); - } - if (output.gc) { - g_object_unref(output.gc); - } - if (output.pixmap) { - g_object_unref(output.pixmap); - } - pango_font_description_free(output.font_desc); -} - -/* this is called during program execution */ -void om_reset(int reset_cursor) { - if (reset_cursor) { - output.cur_x = INITXY; - output.cur_y = INITXY; - } - - output.underline = 0; - output.invert = 0; - output.resized = 0; - output.cur_y_saved = 0; - output.cur_x_saved = 0; - output.tab_size = 40; /* tab size in pixels (160/32 = 5) */ - output.pen_mode = 0; - output.pen_down = 0; - output.pen_down_x = 0; - output.pen_down_y = 0; - - om_set_fg_color(C_BLUE); /* blue foreground */ - om_set_bg_color(C_BRIGHT_WH); /* white background */ - - pango_font_description_set_weight(output.font_desc, PANGO_WEIGHT_NORMAL); - pango_font_description_set_style(output.font_desc, PANGO_STYLE_NORMAL); - om_calc_font_metrics(); -} - -void om_calc_font_metrics() { - PangoContext *context = gtk_widget_create_pango_context(output.widget); - PangoFontMetrics *metrics = pango_context_get_metrics(context, output.font_desc, - pango_context_get_language(context)); - output.ascent = PANGO_PIXELS(pango_font_metrics_get_ascent(metrics)); - output.descent = PANGO_PIXELS(pango_font_metrics_get_descent(metrics)); - output.font_width = PANGO_PIXELS(pango_font_metrics_get_approximate_digit_width(metrics)); - pango_font_metrics_unref(metrics); - g_object_unref(context); -} - -GdkColor om_get_sb_color(long c) { - if (c < 0) { - // assume color is windows style RGB packing - // RGB(r,g,b) ((COLORREF)((BYTE)(r)|((BYTE)(g) << 8)|((BYTE)(b) << 16))) - c = -c; - int b = (c >> 16) & 0xFF; - int g = (c >> 8) & 0xFF; - int r = (c) & 0xFF; - GdkColor color = COLOR(r, g, b); - return color; - } - if (c > 16) { - GdkColor color = WHITE; - return color; - } - return colors[c]; -} - -void om_set_fg_color(int color) { - output.fg = om_get_sb_color(color); -} - -void om_set_bg_color(int color) { - output.bg = om_get_sb_color(color); -} diff --git a/src/platform/gtk/src/output_model.h b/src/platform/gtk/src/output_model.h deleted file mode 100644 index 651827bf..00000000 --- a/src/platform/gtk/src/output_model.h +++ /dev/null @@ -1,84 +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 -// - -#ifndef DEV_GTK_OUTPUT_MODEL_H -#define DEV_GTK_OUTPUT_MODEL_H - -#define C_BLACK 0 -#define C_BLUE 1 -#define C_GREEN 2 -#define C_CYAN 3 -#define C_RED 4 -#define C_MAGENTA 5 -#define C_YELLOW 6 -#define C_WHITE 7 -#define C_GRAY 8 -#define C_LT_BLUE 9 -#define C_LT_GREEN 10 -#define C_LT_CYAN 11 -#define C_LT_RED 12 -#define C_LT_MAG 13 -#define C_LT_YELLOW 14 -#define C_BRIGHT_WH 15 - -typedef struct OutputModel { - GdkPixmap *pixmap; /* Backing pixmap for drawing area */ - GtkWidget *widget; /* the drawing_area widget */ - GtkWidget *main_view; - GdkGC *gc; /* current drawing colors */ - PangoFontDescription *font_desc; /* bold, italic */ - GdkColor fg, bg; /* couldn't find a gdk_gc_get_rgb_fg_color */ - PangoLayout *layout; -#ifdef USE_HILDON - osso_context_t *osso; -#endif - int ascent; - int descent; - int font_width; - int underline; - int invert; - int resized; - int cur_x; - int cur_y; - int cur_y_saved; - int cur_x_saved; - int tab_size; - int pen_mode; - int pen_down; /* index to current mouse button */ - int pen_down_x; - int pen_down_y; - int break_exec; - int modal_flag; - int width; - int height; -} OutputModel; - -void om_reset(int reset_cursor); -void om_init(GtkWidget *widget); -void om_cleanup(); -GdkColor om_get_sb_color(long c); -void om_set_fg_color(int color); -void om_set_bg_color(int color); -void om_calc_font_metrics(); - -#define INITXY 4 - -// mapping for hardware keys -#define KEYMAP_UP 0 -#define KEYMAP_DOWN 1 -#define KEYMAP_LEFT 2 -#define KEYMAP_RIGHT 3 -#define KEYMAP_F7 4 -#define KEYMAP_F8 5 -#define KEYMAP_F6 6 -#define KEYMAP_ENTER 7 -#define KEYMAP_FIRST 0 -#define KEYMAP_LAST 7 - -#endif - diff --git a/src/platform/gtk/src/output_write.c b/src/platform/gtk/src/output_write.c deleted file mode 100644 index db979dee..00000000 --- a/src/platform/gtk/src/output_write.c +++ /dev/null @@ -1,333 +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 -// - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#ifdef USE_HILDON -#include -#endif - -#include "output.h" -#include "output_model.h" - -extern OutputModel output; - -// ? chr(2)+"Hello world"+chr(0)# -void speak_string(const char *s, int len) { -#ifdef USE_HILDON - osso_rpc_t retval; - int speed = 2; - int pitch = 4; - GString *text = g_string_new_len(s, len); - osso_rpc_run(output.osso, "com.nokia.flite", "/com/nokia/flite", - "com.nokia.flite", "flite_tts", - &retval, DBUS_TYPE_UINT32, // id for the order - getpid(), DBUS_TYPE_STRING, // string to be read - text->str, DBUS_TYPE_UINT32, // priority. From 0 to 20. - 20, DBUS_TYPE_DOUBLE, // speed of speeching. From 0.1 to 3 - speed, DBUS_TYPE_DOUBLE, // adjust pitch of voice. From -2 to 8 - pitch, DBUS_TYPE_STRING, // name of the voice (not implemented) - "cmu_us_kal", DBUS_TYPE_INVALID); - g_string_free(text, TRUE); -#endif -} - -void new_line() { - gint font_height = output.ascent + output.descent; - gint h = output.height; - output.cur_x = INITXY; - - if (output.cur_y + font_height + font_height >= h) { - // shift image up font_height pixels - gint w = output.width; - gdk_draw_drawable(output.pixmap, output.gc, output.pixmap, 0, font_height, // src x,y - 0, 0, // dest x,y - w, h - font_height); - // erase bottom line - gdk_gc_set_rgb_fg_color(output.gc, &output.bg); - gdk_draw_rectangle(output.pixmap, output.gc, TRUE, 0, h - font_height, w, font_height); - osd_refresh(); - } else { - output.cur_y += font_height; - } -} - -int calc_tab(int x) { - int c = 1; - while (x > output.tab_size) { - x -= output.tab_size; - c++; - } - return c * output.tab_size; -} - -int set_graphics_rendition(char c, int escValue) { - gint font_height = output.ascent + output.descent; - switch (c) { - case 'K': // \e[K - clear to eol - gdk_gc_set_rgb_fg_color(output.gc, &output.bg); - gdk_draw_rectangle(output.pixmap, output.gc, TRUE, output.cur_x, output.cur_y, - output.width - output.cur_x, font_height); - break; - case 'G': // move to column - output.cur_x = escValue; - break; - case 'T': // non-standard: move to n/80th of screen width - output.cur_x = escValue * output.width / 80; - break; - case 's': // save cursor position - output.cur_y_saved = output.cur_x; - output.cur_x_saved = output.cur_y; - break; - case 'u': // restore cursor position - output.cur_x = output.cur_y_saved; - output.cur_y = output.cur_x_saved; - break; - case ';': // fallthru - case 'm': // \e[...m - ANSI terminal - switch (escValue) { - case 0: // reset - om_reset(FALSE); - break; - case 1: // set bold on - pango_font_description_set_weight(output.font_desc, PANGO_WEIGHT_BOLD); - return 1; - case 2: // set faint on - pango_font_description_set_weight(output.font_desc, PANGO_WEIGHT_ULTRALIGHT); - break; - case 3: // set italic on - pango_font_description_set_style(output.font_desc, PANGO_STYLE_ITALIC); - return 1; - case 4: // set underline on - output.underline = 1; - break; - case 5: // set blink on - break; - case 6: // rapid blink on - break; - case 7: // reverse video on - output.invert = 1; - break; - case 8: // conceal on - break; - case 21: // set bold off - pango_font_description_set_weight(output.font_desc, PANGO_WEIGHT_NORMAL); - return 1; - case 23: // italic off - pango_font_description_set_style(output.font_desc, PANGO_STYLE_NORMAL); - return 1; - case 24: // set underline off - output.underline = 0; - break; - case 27: // reverse video off - output.invert = 0; - break; - // colors - 30..37 foreground, 40..47 background - case 30: // set black fg - om_set_fg_color(C_BLACK); - break; - case 31: // set red fg - om_set_fg_color(C_RED); - break; - case 32: // set green fg - om_set_fg_color(C_GREEN); - break; - case 33: // set yellow fg - om_set_fg_color(C_YELLOW); - break; - case 34: // set blue fg - om_set_fg_color(C_BLUE); - break; - case 35: // set magenta fg - om_set_fg_color(C_MAGENTA); - break; - case 36: // set cyan fg - om_set_fg_color(C_CYAN); - break; - case 37: // set white fg - om_set_fg_color(C_WHITE); - break; - case 40: // set black bg - om_set_bg_color(C_BLACK); - break; - case 41: // set red bg - om_set_bg_color(C_RED); - break; - case 42: // set green bg - om_set_bg_color(C_GREEN); - break; - case 43: // set yellow bg - om_set_bg_color(C_YELLOW); - break; - case 44: // set blue bg - om_set_bg_color(C_BLUE); - break; - case 45: // set magenta bg - om_set_bg_color(C_MAGENTA); - break; - case 46: // set cyan bg - om_set_bg_color(C_CYAN); - break; - case 47: // set white bg - om_set_bg_color(C_WHITE); - break; - case 48: // subscript on - break; - case 49: // superscript - break; - }; - } - return 0; -} - -int do_escape(unsigned char **p) { - int escValue = 0; - while (isdigit(**p)) { - escValue = (escValue * 10) + (**p - '0'); - (*p)++; - } - - if (set_graphics_rendition(**p, escValue)) { - om_calc_font_metrics(); - } - if (**p == ';') { - (*p)++; // next rendition - return 1; - } - return 0; -} - -/** - * Supported control codes: - * \t tab (20 px) - * \a beep - * \r return - * \n next line - * \xC clear screen - * \e[K clear to end of line - * \e[0m reset all attributes to their defaults - * \e[1m set bold on - * \e[4m set underline on - * \e[7m reverse video - * \e[21m set bold off - * \e[24m set underline off - * \e[27m set reverse off - */ -void osd_write(const char *str) { - int len = strlen(str); - if (len <= 0) { - return; - } - - unsigned char *p = (unsigned char *)str; - int num_chars, cx, width; - - while (*p) { - switch (*p) { - case '\a': // beep - drvsound_beep(); - break; - case '\t': - output.cur_x = calc_tab(output.cur_x + 1); - break; - case '\xC': - om_reset(TRUE); - osd_cls(); - break; - case '\033': // ESC ctrl chars - if (*(p + 1) == '[') { - p += 2; - while (1) { - if (!do_escape(&p)) { - break; - } - } - } - break; - case '\n': // new line - new_line(); - break; - case '\r': // return - output.cur_x = INITXY; - gdk_gc_set_rgb_fg_color(output.gc, &output.bg); - gdk_draw_rectangle(output.pixmap, output.gc, TRUE, 0, output.cur_y, - output.width, output.ascent + output.descent); - break; - case 2: // STX: start of flite text - num_chars = 0; - p++; - while (p[num_chars] > 31) { - num_chars++; - } - if (num_chars) { - speak_string((const char *)p, num_chars); - p += num_chars; - } - break; - - default: - num_chars = 1; // print minimum of one character - cx = output.font_width; - width = output.width - 1; - - if (output.cur_x + cx >= width) { - new_line(); - } - // print further non-control, non-null characters - // up to the width of the line - while (p[num_chars] > 31) { - cx += output.font_width; - if (output.cur_x + cx < width) { - num_chars++; - } else { - break; - } - } - - if (output.invert) { - GdkColor c; - c.red = (output.fg.red ^ 0xffff); - c.blue = (output.fg.blue ^ 0xffff); - c.green = (output.fg.green ^ 0xffff); - gdk_gc_set_rgb_fg_color(output.gc, &c); - } else { - gdk_gc_set_rgb_fg_color(output.gc, &output.bg); - } - - gdk_draw_rectangle(output.pixmap, output.gc, TRUE, - output.cur_x, output.cur_y, cx, output.ascent + output.descent); - - pango_layout_set_text(output.layout, (const char *)p, num_chars); - gdk_gc_set_rgb_fg_color(output.gc, &output.fg); - gdk_draw_layout(output.pixmap, output.gc, output.cur_x, output.cur_y, output.layout); - - if (output.underline) { - gdk_draw_line(output.pixmap, output.gc, - output.cur_x, - output.cur_y + output.ascent + 1, output.cur_x + cx, output.cur_y + output.ascent + 1); - } - output.cur_x += cx; - - // advance text pointer - p += num_chars - 1; // allow for p++ - }; - - if (*p == '\0') { - break; - } - p++; - } - - osd_refresh(); -} - diff --git a/src/platform/gtk/src/support.c b/src/platform/gtk/src/support.c deleted file mode 100644 index 91ddeb49..00000000 --- a/src/platform/gtk/src/support.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - *DO NOT EDIT THIS FILE - it is generated by Glade. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include - -#include - -#include "support.h" - -GtkWidget *lookup_widget(GtkWidget *widget, const gchar *widget_name) { - GtkWidget *parent, *found_widget; - - for (;;) { - if (GTK_IS_MENU(widget)) - parent = gtk_menu_get_attach_widget(GTK_MENU(widget)); - else - parent = widget->parent; - if (!parent) - parent = (GtkWidget *) g_object_get_data(G_OBJECT(widget), "GladeParentKey"); - if (parent == NULL) - break; - widget = parent; - } - - found_widget = (GtkWidget *) g_object_get_data(G_OBJECT(widget), widget_name); - if (!found_widget) - g_warning("Widget not found: %s", widget_name); - return found_widget; -} - -static GList *pixmaps_directories = NULL; - -/* Use this function to set the directory containing installed pixmaps. */ -void add_pixmap_directory(const gchar *directory) { - pixmaps_directories = g_list_prepend(pixmaps_directories, g_strdup(directory)); -} - -/* This is an internally used function to find pixmap files. */ -static gchar *find_pixmap_file(const gchar *filename) { - GList *elem; - - /* - * We step through each of the pixmaps directory to find it. - */ - elem = pixmaps_directories; - while (elem) { - gchar *pathname = g_strdup_printf("%s%s%s", (gchar *) elem->data, - G_DIR_SEPARATOR_S, filename); - if (g_file_test(pathname, G_FILE_TEST_EXISTS)) - return pathname; - g_free(pathname); - elem = elem->next; - } - return NULL; -} - -/* This is an internally used function to create pixmaps. */ -GtkWidget *create_pixmap(GtkWidget *widget, const gchar *filename) { - gchar *pathname = NULL; - GtkWidget *pixmap; - - if (!filename || !filename[0]) - return gtk_image_new(); - - pathname = find_pixmap_file(filename); - - if (!pathname) { - g_warning(_("Couldn't find pixmap file: %s"), filename); - return gtk_image_new(); - } - - pixmap = gtk_image_new_from_file(pathname); - g_free(pathname); - return pixmap; -} - -/* This is an internally used function to create pixmaps. */ -GdkPixbuf *create_pixbuf(const gchar *filename) { - gchar *pathname = NULL; - GdkPixbuf *pixbuf; - GError *error = NULL; - - if (!filename || !filename[0]) - return NULL; - - pathname = find_pixmap_file(filename); - - if (!pathname) { - g_warning(_("Couldn't find pixmap file: %s"), filename); - return NULL; - } - - pixbuf = gdk_pixbuf_new_from_file(pathname, &error); - if (!pixbuf) { - fprintf(stderr, "Failed to load pixbuf file: %s: %s\n", pathname, error->message); - g_error_free(error); - } - g_free(pathname); - return pixbuf; -} - -/* This is used to set ATK action descriptions. */ -void glade_set_atk_action_description(AtkAction *action, const gchar *action_name, - const gchar *description) { - gint n_actions, i; - - n_actions = atk_action_get_n_actions(action); - for (i = 0; i < n_actions; i++) { - if (!strcmp(atk_action_get_name(action, i), action_name)) - atk_action_set_description(action, i, description); - } -} diff --git a/src/platform/gtk/src/support.h b/src/platform/gtk/src/support.h deleted file mode 100644 index d483368f..00000000 --- a/src/platform/gtk/src/support.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * DO NOT EDIT THIS FILE - it is generated by Glade. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -/* - * Standard gettext macros. - */ -#ifdef ENABLE_NLS -#include -#undef _ -#define _(String) dgettext (PACKAGE, String) -#define Q_(String) g_strip_context ((String), gettext (String)) -#ifdef gettext_noop -#define N_(String) gettext_noop (String) -#else -#define N_(String) (String) -#endif -#else -#define textdomain(String) (String) -#define gettext(String) (String) -#define dgettext(Domain,Message) (Message) -#define dcgettext(Domain,Message,Type) (Message) -#define bindtextdomain(Domain,Directory) (Domain) -#define _(String) (String) -#define Q_(String) g_strip_context ((String), (String)) -#define N_(String) (String) -#endif - - -/* - * Public Functions. - */ - -/* - * This function returns a widget in a component created by Glade. - * Call it with the toplevel widget in the component (i.e. a window/dialog), - * or alternatively any widget in the component, and the name of the widget - * you want returned. - */ -GtkWidget *lookup_widget(GtkWidget *widget, const gchar *widget_name); - - -/* Use this function to set the directory containing installed pixmaps. */ -void add_pixmap_directory(const gchar *directory); - - -/* - * Private Functions. - */ - -/* This is used to create the pixmaps used in the interface. */ -GtkWidget *create_pixmap(GtkWidget *widget, const gchar *filename); - -/* This is used to create the pixbufs used in the interface. */ -GdkPixbuf *create_pixbuf(const gchar *filename); - -/* This is used to set ATK action descriptions. */ -void glade_set_atk_action_description(AtkAction *action, - const gchar *action_name, const gchar *description); diff --git a/src/platform/qt/Makefile.am b/src/platform/qt/Makefile.am deleted file mode 100644 index 3cf9ad7b..00000000 --- a/src/platform/qt/Makefile.am +++ /dev/null @@ -1,50 +0,0 @@ -# SmallBASIC using QT -# Copyright(C) 2001-2011 Chris Warren-Smith. [http://tinyurl.com/ja2ss] -# -# This program is distributed under the terms of the GPL v2.0 or later -# Download the GNU Public License (GPL) from www.gnu.org -# - -EXTRA_DIST = \ - sbasic.pro \ - sbasic.qrc \ - mainwindow.ui \ - source_view.ui \ - console_view.ui \ - images/next.png \ - images/previous.png \ - images/jump.png \ - images/home.png \ - images/refresh.png \ - images/stop.png \ - bas/settings.bas \ - bas/list.bas \ - bas/bookmarks.bas \ - bas/home.bas - -sbasicb_SOURCES = \ - fixedlayout.cpp \ - fixedlayout.h \ - httpfile.cpp \ - httpfile.h \ - ansiwidget.cpp \ - ansiwidget.h \ - main.cpp \ - mainwindow.cpp \ - mainwindow.h \ - dev_qt.cpp \ - form_ui.cpp \ - form_ui.h - -bin_PROGRAMS = sbasicb - -sbasicb_LDADD = -L$(top_srcdir)/src/common -lsb_common @PACKAGE_LIBS@ - -sbasicb_DEPENDENCIES = ../common/libsb_common.a - -sbasicb$(EXEEXT): ${sbasicb_SOURCES} - $(MAKE) -f Makefile.qt - -clean-local: - $(MAKE) -f Makefile.qt clean - diff --git a/src/platform/qt/ansiwidget.cpp b/src/platform/qt/ansiwidget.cpp deleted file mode 100644 index 193eb168..00000000 --- a/src/platform/qt/ansiwidget.cpp +++ /dev/null @@ -1,815 +0,0 @@ -// This file is part of SmallBASIC -// -// Copyright(C) 2001-2011 Chris Warren-Smith. [http://tinyurl.com/ja2ss] -// -// 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 "ansiwidget.h" - -/*! \class AnsiWidget - - Displays ANSI escape codes. - - Escape sequences start with the characters ESC (ASCII 27d / 1Bh / 033o ) - and [ (left bracket). This sequence is called CSI for - "Control Sequence Introducer". - - For more information about ANSI code see: - http://en.wikipedia.org/wiki/ANSI_escape_code - http://www.uv.tietgen.dk/staff/mlha/PC/Soft/Prog/BAS/VB/Function.html - http://bjh21.me.uk/all-escapes/all-escapes.txt - - Supported control codes: - \t tab (20 px) - \a beep - \r return - \n next line - \xC clear screen - \e[K clear to end of line - \e[0m reset all attributes to their defaults - \e[1m set bold on - \e[4m set underline on - \e[7m reverse video - \e[21m set bold off - \e[24m set underline off - \e[27m set reverse off -*/ - -#define INITXY 2 - -static QColor colors[] = { - Qt::black, // 0 black - Qt::darkBlue, // 1 blue - Qt::darkGreen, // 2 green - Qt::darkCyan, // 3 cyan - Qt::darkRed, // 4 red - Qt::darkMagenta, // 5 magenta - Qt::darkYellow, // 6 yellow - Qt::lightGray, // 7 white - Qt::gray, // 8 gray - Qt::blue, // 9 light blue - Qt::green, // 10 light green - Qt::cyan, // 11 light cyan - Qt::red, // 12 light red - Qt::magenta, // 13 light magenta - Qt::yellow, // 14 light yellow - Qt::white // 15 bright white -}; - -struct HyperlinkButton : public QAbstractButton { - HyperlinkButton(QString url, QString text, QWidget *parent) : - QAbstractButton(parent) { - this->url = url; - setText(text); - }; - - void paintEvent(QPaintEvent *event) { - AnsiWidget *out = (AnsiWidget *) parent(); - QPainter painter(this); - QFontMetrics fm = fontMetrics(); - int width = fm.width(text()); - int y = fm.ascent(); - - painter.setRenderHint(QPainter::TextAntialiasing); - painter.setFont(out->font()); - painter.setPen(isDown() ? Qt::blue : underMouse() ? Qt::red : Qt::darkGreen); - - painter.drawText(0, y, text()); - if (underMouse()) { - painter.drawLine(0, y + 2, width, y + 2); - } - } - - QString url; -}; - -AnsiWidget::AnsiWidget(QWidget *parent) : - QWidget(parent), img(0) { - reset(true); - - // setup scrolling - scrollSize = 250; - scrollbar = new QScrollBar(Qt::Vertical, this); - connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); -} - -/*! widget clean up - */ -AnsiWidget::~AnsiWidget() { - destroyImage(); -} - -/*! create audible beep sound - */ -void AnsiWidget::beep() const { - QApplication::beep(); -} - -/*! clear the offscreen buffer - */ -void AnsiWidget::clearScreen() { - reset(true); - QPainter painter(this->img); - painter.fillRect(this->geometry(), this->bg); - scrollbar->setMaximum(0); - scrollbar->setValue(0); -} - -/*! draws an arc onto the offscreen buffer - */ -void AnsiWidget::drawArc(int xc, int yc, double r, - double start, double end, double aspect) { - QPainter painter(this->img); - update(); -} - -/*! draws an ellipse onto the offscreen buffer - */ -void AnsiWidget::drawEllipse(int xc, int yc, int xr, int yr, double aspect, int fill) { - QPainter painter(this->img); - painter.setRenderHint(QPainter::HighQualityAntialiasing); - const QPoint center(xc, yc); - if (fill) { - QPainterPath path; - QBrush brush(this->fg); - path.addEllipse(center, xr, yr * aspect); - painter.fillPath(path, brush); - } else { - painter.setPen(this->fg); - painter.drawEllipse(center, xr, static_cast(yr * aspect)); - } - update(); -} - -/*! draws the given image onto the offscreen buffer - */ -void AnsiWidget::drawImage(QImage *image, int x, int y, int sx, int sy, int w, int h) { - QPainter painter(this->img); - painter.drawImage(x, y, *image, sx, sy, w, h); -} - -/*! draw a line onto the offscreen buffer - */ -void AnsiWidget::drawLine(int x1, int y1, int x2, int y2) { - QPainter painter(this->img); - painter.setPen(this->fg); - painter.drawLine(x1, y1, x2, y2); -} - -/*! draw a rectangle onto the offscreen buffer - */ -void AnsiWidget::drawRect(int x1, int y1, int x2, int y2) { - QPainter painter(this->img); - painter.setPen(this->fg); - painter.drawRect(x1, y1, x2-x1, y2-y1); -} - -/*! draw a filled rectangle onto the offscreen buffer - */ -void AnsiWidget::drawRectFilled(int x1, int y1, int x2, int y2) { - QPainter painter(this->img); - painter.fillRect(x1, y1, x2 - x1, y2 - y1, this->fg); -} - -/*! returns the color of the pixel at the given xy location - */ -QRgb AnsiWidget::getPixel(int x, int y) { - return img->copy(x, y, 1, 1).toImage().pixel(0, 0); -} - -/*! Returns the height in pixels using the current font setting - */ -int AnsiWidget::textHeight(void) { - QFontMetrics fm = fontMetrics(); - return fm.ascent() + fm.descent(); -} - -/*! Returns the width in pixels using the current font setting - */ -int AnsiWidget::textWidth(const char *s) { - QFontMetrics fm = fontMetrics(); - return fm.width(s); -} - -/*! Prints the contents of the given string onto the backbuffer - */ -void AnsiWidget::print(const char *str) { - int len = strlen(str); - if (len <= 0) { - return; - } - - QFontMetrics fm = fontMetrics(); - int ascent = fm.ascent(); - int fontHeight = fm.ascent() + fm.descent(); - unsigned char *p = (unsigned char *)str; - - while (*p) { - switch (*p) { - case '\a': // beep - beep(); - break; - case '\t': - curX = calcTab(curX + 1); - break; - case '\xC': - clearScreen(); - break; - case '\033': // ESC ctrl chars - if (*(p + 1) == '[') { - p += 2; - while (doEscape(p)) { - // continue - } - } - break; - case '\n': // new line - newLine(); - break; - case '\r': // return - { - curX = INITXY; - QPainter painter(this->img); - painter.fillRect(0, curY, width(), fontHeight, this->bg); - } - break; - default: - int numChars = 1; // print minimum of one character - int cx = fontMetrics().width((const char *)p, 1); - int w = width() - 1; - - if (curX + cx >= w) { - newLine(); - } - // print further non-control, non-null characters - // up to the width of the line - while (p[numChars] > 31) { - cx += fontMetrics().width((const char *)p + numChars, 1); - if (curX + cx < w) { - numChars++; - } else { - break; - } - } - - QPainter painter(this->img); - painter.setRenderHint(QPainter::TextAntialiasing); - painter.setFont(font()); - painter.setBackground(invert ? this->fg : this->bg); - painter.setPen(invert ? this->bg : this->fg); - painter.fillRect(curX, curY, cx, fontHeight, invert ? this->fg : this->bg); - painter.drawText(curX, curY + ascent, QString::fromUtf8((const char *)p, numChars)); - - if (underline) { - painter.drawLine(curX, curY + ascent + 1, curX + cx, curY + ascent + 1); - } - // advance - p += numChars - 1; // allow for p++ - curX += cx; - }; - - if (*p == '\0') { - break; - } - p++; - } - - update(); -} - -/*! save the offscreen buffer to the given filename - */ -void AnsiWidget::saveImage(const char *filename, int x, int y, int w, int h) { - if (w == 0) { - w = width(); - } - if (h == 0) { - h = height(); - } - - img->copy(x, y, w, h).save(filename); -} - -/*! sets the current drawing color - */ -void AnsiWidget::setColor(long fg) { - this->fg = ansiToQt(fg); -} - -/*! sets the pixel to the given color at the given xy location - */ -void AnsiWidget::setPixel(int x, int y, int c) { - QPainter painter(this->img); - painter.setPen(c); - painter.drawPoint(x, y); - update(x, y, 1, 1); -} - -/*! sets the current text drawing color - */ -void AnsiWidget::setTextColor(long fg, long bg) { - this->bg = ansiToQt(bg); - this->fg = ansiToQt(fg); -} - -/*! sets the number of scrollback lines - */ -void AnsiWidget::setScrollSize(int scrollSize) { - this->scrollSize = scrollSize; -} - -/*! sets mouse mode on or off - */ -void AnsiWidget::setMouseMode(bool flag) { - mouseMode = flag; - setMouseTracking(flag); -} - -/*! resets mouse mode to false - */ -void AnsiWidget::resetMouse() { - pointX = pointY = markX = markY = 0; - mouseMode = false; - setMouseTracking(false); -} - -/*! public slot - copy selected text to the clipboard - */ -void AnsiWidget::copySelection() { -} - -/*! public slot - a hyperlink has been clicked - */ -void AnsiWidget::linkClicked() { - HyperlinkButton *button = (HyperlinkButton *) sender(); - if (listener) { - listener->loadPath(button->url, true, true); - } -} - -/*! public slot - find the next text item - */ -void AnsiWidget::findNextText() { -} - -/*! public slot - find text - */ -void AnsiWidget::findText() { -} - -/*! public slot - select all text - */ -void AnsiWidget::selectAll() { -} - -/*! private slot - scrollbar position has changed - */ -void AnsiWidget::scrollChanged(int value) { - int n = hyperlinks.size(); - - for (int i = 0; i < n; i++) { - QAbstractButton *nextObject = hyperlinks.at(i); - QPoint pt = nextObject->pos(); - nextObject->move(pt.x(), pt.y() - value); - } - update(); -} - -/*! Converts ANSI colors to FLTK colors - */ -QColor AnsiWidget::ansiToQt(long c) { - if (c < 0) { - // assume color is windows style RGB packing - // RGB(r,g,b) ((COLORREF)((BYTE)(r)|((BYTE)(g) << 8)|((BYTE)(b) << 16))) - c = -c; - int r = (c >> 16) & 0xFF; - int g = (c >> 8) & 0xFF; - int b = (c) & 0xFF; - return QColor(r, g, b); - } - - return (c > 16) ? Qt::white : colors[c]; -} - -/*! Calculate the pixel movement for the given cursor position - */ -int AnsiWidget::calcTab(int x) const { - int c = 1; - while (x > tabSize) { - x -= tabSize; - c++; - } - return c * tabSize; -} - -/*! Creates a hyperlink, eg // ^[ hwww.foo.com:title:hover;More text - */ -void AnsiWidget::createLink(unsigned char *&p, bool execLink) { - QString url; - QString text; - QString tooltip; - - unsigned char *next = p + 1; - bool eot = false; - int segment = 0; - - while (*p && !eot) { - p++; - - switch (*p) { - case '\033': - case '\n': - case ':': - eot = true; - // fallthru - - case ';': - switch (segment++) { - case 0: - url = QString::fromUtf8((const char *)next, (p - next)); - text = tooltip = url; - break; - case 1: - text = QString::fromUtf8((const char *)next, (p - next)); - tooltip = text; - break; - case 2: - tooltip = QString::fromUtf8((const char *)next, (p - next)); - eot = true; - break; - default: - break; - } - next = p + 1; - break; - - default: - break; - } - } - - if (execLink && listener) { - listener->loadPath(url, true, true); - } else { - HyperlinkButton *button = new HyperlinkButton(url, text, this); - QFontMetrics fm = fontMetrics(); - int width = fm.width(text) + 2; - int height = fm.ascent() + fm.descent() + 4; - - button->setGeometry(curX, curY, width, height); - button->setToolTip(tooltip); - button->connect(button, SIGNAL(clicked(bool)), this, SLOT(linkClicked())); - button->setCursor(Qt::PointingHandCursor); - button->show(); - - hyperlinks.append(button); - curX += width; - } -} - -/*! clean up the offscreen buffer - */ -void AnsiWidget::destroyImage() { - if (img) { - delete img; - img = 0; - } -} - -/*! Handles the characters following the \e[ sequence. Returns whether a further call - * is required to complete the process. - */ -bool AnsiWidget::doEscape(unsigned char *&p) { - int escValue = 0; - - while (isdigit(*p)) { - escValue = (escValue *10) + (*p - '0'); - p++; - } - - if (*p == ' ') { - p++; - switch (*p) { - case 'C': - // GSS Graphic Size Selection - textSize = escValue; - updateFont(); - break; - case 'h': - createLink(p, false); - break; - case 'H': - createLink(p, true); - break; - } - } else if (setGraphicsRendition(*p, escValue)) { - updateFont(); - } - - if (*p == ';') { - p++; // next rendition - return true; - } - return false; -} - -/*! Handles the \n character - */ -void AnsiWidget::newLine() { - int imgH = img->height(); - int fontHeight = textHeight(); - - curX = INITXY; - if (curY + (fontHeight * 2) >= imgH) { - QRegion exposed; - img->scroll(0, -fontHeight, 0, 0, width(), imgH, &exposed); - - QPainter painter(this->img); - painter.fillRect(exposed.boundingRect(), this->bg); - update(); - - // scroll any hyperlinks - int n = hyperlinks.size(); - for (int i = 0; i < n; i++) { - QAbstractButton *nextObject = hyperlinks.at(i); - QPoint pt = nextObject->pos(); - if (pt.y() < -fontHeight) { - delete nextObject; - hyperlinks.removeAt(i); - n--; - } else { - nextObject->move(pt.x(), pt.y() - fontHeight); - } - } - } else if (curY + (fontHeight * 2) >= height()) { - // setup scrollbar scrolling - scrollbar->setMaximum(scrollbar->maximum() + fontHeight); - scrollbar->setValue(scrollbar->value() + fontHeight); - curY += fontHeight; - } else { - curY += fontHeight; - } -} - -/*! reset the current drawing variables - */ -void AnsiWidget::reset(bool init) { - if (init) { - curY = INITXY; // allow for input control border - curX = INITXY; - tabSize = 40; // tab size in pixels (160/32 = 5) - markX = markY = pointX = pointY = 0; - copyMode = false; - } - // cleanup any hyperlinks - int n = hyperlinks.size(); - for (int i = 0; i < n; i++) { - QAbstractButton *nextObject = hyperlinks.at(i); - delete nextObject; - } - hyperlinks.clear(); - - curYSaved = 0; - curXSaved = 0; - invert = false; - underline = false; - bold = false; - italic = false; - fg = Qt::black; - bg = Qt::white; - textSize = 8; - updateFont(); -} - -/*! Handles the given escape character. Returns whether the font has changed - */ -bool AnsiWidget::setGraphicsRendition(char c, int escValue) { - switch (c) { - case 'K': - { // \e[K - clear to eol - QPainter painter(this->img); - painter.fillRect(curX, curY, width() - curX, textHeight(), this->bg); - } - break; - case 'G': // move to column - curX = escValue; - break; - case 'T': // non-standard: move to n/80th of screen width - curX = escValue * width() / 80; - break; - case 's': // save cursor position - curYSaved = curX; - curXSaved = curY; - break; - case 'u': // restore cursor position - curX = curYSaved; - curY = curXSaved; - break; - case ';': // fallthru - case 'm': // \e[...m - ANSI terminal - switch (escValue) { - case 0: // reset - reset(false); - break; - case 1: // set bold on - bold = true; - return true; - case 2: // set faint on - break; - case 3: // set italic on - italic = true; - return true; - case 4: // set underline on - underline = true; - break; - case 5: // set blink on - break; - case 6: // rapid blink on - break; - case 7: // reverse video on - invert = true; - break; - case 8: // conceal on - break; - case 21: // set bold off - bold = false; - return true; - case 23: - italic = false; - return true; - case 24: // set underline off - underline = false; - break; - case 27: // reverse video off - invert = false; - break; - // colors - 30..37 foreground, 40..47 background - case 30: // set black fg - this->fg = ansiToQt(0); - break; - case 31: // set red fg - this->fg = ansiToQt(4); - break; - case 32: // set green fg - this->fg = ansiToQt(2); - break; - case 33: // set yellow fg - this->fg = ansiToQt(6); - break; - case 34: // set blue fg - this->fg = ansiToQt(1); - break; - case 35: // set magenta fg - this->fg = ansiToQt(5); - break; - case 36: // set cyan fg - this->fg = ansiToQt(3); - break; - case 37: // set white fg - this->fg = ansiToQt(7); - break; - case 40: // set black bg - this->bg = ansiToQt(0); - break; - case 41: // set red bg - this->bg = ansiToQt(4); - break; - case 42: // set green bg - this->bg = ansiToQt(2); - break; - case 43: // set yellow bg - this->bg = ansiToQt(6); - break; - case 44: // set blue bg - this->bg = ansiToQt(1); - break; - case 45: // set magenta bg - this->bg = ansiToQt(5); - break; - case 46: // set cyan bg - this->bg = ansiToQt(3); - break; - case 47: // set white bg - this->bg = ansiToQt(15); - break; - case 48: // subscript on - break; - case 49: // superscript - break; - }; - } - return false; -} - -/*! Updated the current font according to accumulated flags - */ -void AnsiWidget::updateFont() { - QFont font = QFont("TypeWriter"); - font.setFixedPitch(true); - font.setPointSize(textSize); - font.setBold(bold); - font.setItalic(italic); - this->setFont(font); -} - -void AnsiWidget::mouseMoveEvent(QMouseEvent *event) { - pointX = event->x(); - pointY = event->y(); - if (copyMode) { - update(); - } - if (mouseMode && listener) { - listener->mouseMoveEvent(event->button()); - } -} - -void AnsiWidget::mousePressEvent(QMouseEvent *event) { - bool selected = (markX != pointX || markY != pointY); - markX = pointX = event->x(); - markY = pointY = event->y(); - if (mouseMode && selected) { - update(); - } - if (copyMode && listener) { - listener->mousePressEvent(); - } -} - -void AnsiWidget::mouseReleaseEvent(QMouseEvent *) { - bool selected = (markX != pointX || markY != pointY); - if (copyMode && selected) { - update(); - } - if (mouseMode && listener) { - listener->mousePressEvent(); - } -} - -void AnsiWidget::paintEvent(QPaintEvent *event) { - QPainter painter(this); - QRect rc = event->rect(); - - painter.drawPixmap(rc.x(), rc.y(), rc.width(), rc.height(), *img, - 0, scrollbar->value(), width(), height()); - - // draw the mouse selection - if (copyMode && (markX != pointX || markY != pointY)) { - painter.setPen(Qt::DashDotDotLine); - painter.setBackgroundMode(Qt::TransparentMode); - painter.drawRect(markX, markY, pointX - markX, pointY - markY); - } - - QWidget::paintEvent(event); -} - -void AnsiWidget::resizeEvent(QResizeEvent *event) { - scrollbar->resize(18, event->size().height()); - scrollbar->move(event->size().width() - scrollbar->width(), 0); - - if (img) { - int scrollH = textSize * scrollSize; - int imgW = img->width(); - int imgH = img->height() - scrollH; - - if (width() > imgW) { - imgW = width(); - } - - if (height() > imgH) { - imgH = height(); - } - - imgH += scrollH; - scrollbar->setPageStep(event->size().height()); - - QPixmap *old = img; - img = new QPixmap(imgW, imgH); - QPainter painter(img); - painter.fillRect(0, 0, imgW, imgH, this->bg); - painter.drawPixmap(0, 0, old->width(), old->height(), *old); - delete old; - } - - QWidget::resizeEvent(event); -} - -void AnsiWidget::showEvent(QShowEvent *event) { - if (img == NULL) { - int imgH = parentWidget()->height() + (textSize * scrollSize); - img = new QPixmap(parentWidget()->width(), imgH); - img->fill(this->bg); - - scrollbar->setPageStep(parentWidget()->height()); - scrollbar->setSingleStep(textSize); - scrollbar->setValue(0); - scrollbar->setRange(0, 0); - } -} diff --git a/src/platform/qt/ansiwidget.h b/src/platform/qt/ansiwidget.h deleted file mode 100644 index 5517156b..00000000 --- a/src/platform/qt/ansiwidget.h +++ /dev/null @@ -1,120 +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 -// - -#ifndef ANSIWIDGET_H -#define ANSIWIDGET_H - -#include -#include -#include -#include - -struct AnsiWidgetListener { - virtual void mouseMoveEvent(bool down) = 0; - virtual void mousePressEvent() = 0; - virtual void mouseReleaseEvent() = 0; - virtual void loadPath(QString path, bool showPath, bool setHistory) = 0; -}; - -class AnsiWidget : public QWidget { - Q_OBJECT - -public: - explicit AnsiWidget(QWidget *parent = 0); - ~AnsiWidget(); - - // public api - void beep() const; - void clearScreen(); - void drawArc(int xc, int yc, double r, double start, double end, double aspect); - void drawEllipse(int xc, int yc, int xr, int yr, double aspect, int fill); - void drawImage(QImage *img, int x, int y, int sx, int sy, int w, int h); - void drawLine(int x1, int y1, int x2, int y2); - void drawRect(int x1, int y1, int x2, int y2); - void drawRectFilled(int x1, int y1, int x2, int y2); - QColor getBackgroundColor() { return bg; } - QColor getColor() { return fg; } - QRgb getPixel(int x, int y); - int getHeight() { return height(); } - int getWidth() { return width(); } - int getX() { return curX; } - int getY() { return curY; } - int textHeight(void); - int textWidth(const char *s); - void print(const char *str); - void saveImage(const char *fn, int x, int y, int w, int h); - void setColor(long color); - void setPixel(int x, int y, int c); - void setTextColor(long fg, long bg); - void setXY(int x, int y) { curX=x; curY=y; } - void setScrollSize(int scrollSize); - - // mouse support - int getMouseX(bool down) { return down ? markX : pointX; } - int getMouseY(bool down) { return down ? markY : pointY; } - bool getMouseMode() { return mouseMode; } - void resetMouse(); - void setMouseMode(bool mode); - void setMouseListener(AnsiWidgetListener *ml) { listener = ml; } - -public slots: - void copySelection(); - void linkClicked(); - void findNextText(); - void findText(); - void selectAll(); - -private slots: - void scrollChanged(int value); - -private: - QColor ansiToQt(long color); - int calcTab(int x) const; - void createLink(unsigned char *&p, bool execLink); - void destroyImage(); - bool doEscape(unsigned char *&p); - void newLine(); - void reset(bool init); - bool setGraphicsRendition(char c, int escValue); - void updateFont(); - - void mouseMoveEvent(QMouseEvent *event); - void mousePressEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - void paintEvent(QPaintEvent *event); - void resizeEvent(QResizeEvent *event); - void showEvent(QShowEvent *event); - - QPixmap *img; - QColor bg; - QColor fg; - QScrollBar *scrollbar; - - bool underline; - bool invert; - bool bold; - bool italic; - int curY; - int curX; - int curYSaved; - int curXSaved; - int tabSize; - int textSize; - int scrollSize; - - // clipboard handling - int markX, markY, pointX, pointY; - bool copyMode; - - // mouse handling - bool mouseMode; // PEN ON/OFF - AnsiWidgetListener *listener; - QList < QAbstractButton *>hyperlinks; -}; - -#endif // ANSIWIDGET_H diff --git a/src/platform/qt/bas/bookmarks.bas b/src/platform/qt/bas/bookmarks.bas deleted file mode 100644 index 85905b55..00000000 --- a/src/platform/qt/bas/bookmarks.bas +++ /dev/null @@ -1,2 +0,0 @@ -# process bookmarks -print "Bookmarks" diff --git a/src/platform/qt/bas/home.bas b/src/platform/qt/bas/home.bas deleted file mode 100644 index 3112d7c9..00000000 --- a/src/platform/qt/bas/home.bas +++ /dev/null @@ -1,2 +0,0 @@ -# home page -print "Welcome to SmallBASIC" diff --git a/src/platform/qt/bas/list.bas b/src/platform/qt/bas/list.bas deleted file mode 100644 index bf6fee8d..00000000 --- a/src/platform/qt/bas/list.bas +++ /dev/null @@ -1,11 +0,0 @@ -? cat(3) + command + cat(0) -f = files(command + "/*") -sort f - -? chr(27) + "[ h" + command + "/..;..:" - -for a in f - if (isdir(command + "/" + a) or right(a, 4) == ".bas") then - ? chr(27) + "[ h" + command + "/" + a + ";" + a + ":" - endif -next a diff --git a/src/platform/qt/bas/settings.bas b/src/platform/qt/bas/settings.bas deleted file mode 100644 index ea6b0859..00000000 --- a/src/platform/qt/bas/settings.bas +++ /dev/null @@ -1,3 +0,0 @@ -# settings dialog -print "Settings" - diff --git a/src/platform/qt/console_view.ui b/src/platform/qt/console_view.ui deleted file mode 100644 index 872d7e5e..00000000 --- a/src/platform/qt/console_view.ui +++ /dev/null @@ -1,36 +0,0 @@ - - - ErrorConsole - - - - 0 - 0 - 609 - 492 - - - - SmallBASIC - Error Console - - - - :/images/smallbasic.png:/images/smallbasic.png - - - - 0 - - - 0 - - - - - - - - - - - diff --git a/src/platform/qt/dev_qt.cpp b/src/platform/qt/dev_qt.cpp deleted file mode 100644 index 00b11e09..00000000 --- a/src/platform/qt/dev_qt.cpp +++ /dev/null @@ -1,622 +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 "config.h" -#include "sys.h" -#include "device.h" -#include "smbas.h" -#include "osd.h" -#include "blib_ui.h" -#include "mainwindow.h" -#include "form_ui.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern "C" { -#include "fs_socket_client.h" -} -#ifdef WIN32 -#include -#ifdef __MINGW32__ -#include -#endif -#else -#include -#endif -#if defined(__MINGW32__) -#define makedir(f) mkdir(f) -#else -#define makedir(f) mkdir(f, 0700) -#endif -#define PEN_OFF 0 // pen mode disabled -#define PEN_ON 2 // pen mode active -clock_t lastEventTime; -dword eventsPerTick; -QString envBuffer; - -#define EVT_MAX_BURN_TIME (CLOCKS_PER_SEC / 4) -#define EVT_PAUSE_TIME 500 // MS -#define EVT_CHECK_EVERY ((50 * CLOCKS_PER_SEC) / 1000) - -void getHomeDir(char *fileName, bool appendSlash = true); -bool cacheLink(dev_file_t *df, char *localFile); - -//--ANSI Output----------------------------------------------------------------- - -C_LINKAGE_BEGIN - -int osd_devinit() { - wnd->out->resetMouse(); - - // allow the application to set the preferred width and height - if ((opt_pref_width || opt_pref_height)) { - int delta_x = wnd->width() - wnd->out->width(); - int delta_y = wnd->height() - wnd->out->height(); - if (opt_pref_width < 10) { - opt_pref_width = 10; - } - if (opt_pref_height < 10) { - opt_pref_height = 10; - } - wnd->resize(opt_pref_width + delta_x, opt_pref_height + delta_y); - } - - os_graf_mx = wnd->out->width(); - os_graf_my = wnd->out->height(); - - os_ver = QT_VERSION; - os_color = 1; - os_color_depth = 16; - setsysvar_str(SYSVAR_OSNAME, "QT"); - - osd_cls(); - dev_clrkb(); - ui_reset(); - return 1; -} - -void osd_setcolor(long color) { - wnd->out->setColor(color); -} - -void osd_settextcolor(long fg, long bg) { - wnd->out->setTextColor(fg, bg); -} - -void osd_refresh() { - wnd->out->update(); -} - -int osd_devrestore() { - ui_reset(); - return 1; -} - -/** - * system event-loop - * return value: - * 0 continue - * -1 close sbpad application - * -2 stop running basic application - */ -int osd_events(int wait_flag) { - if (!wait_flag) { - // pause when we have been called too frequently - clock_t now = clock(); - if (now - lastEventTime <= EVT_CHECK_EVERY) { - eventsPerTick += (now - lastEventTime); - if (eventsPerTick >= EVT_MAX_BURN_TIME) { - eventsPerTick = 0; - wait_flag = 2; - } - } - lastEventTime = now; - } - - switch (wait_flag) { - case 1: - // wait for an event - QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); - break; - case 2: - // pause - dev_delay(EVT_PAUSE_TIME); - break; - default: - // pump messages without pausing - QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); - } - - if (wnd->isBreakExec()) { - ui_reset(); - return -2; - } - return 0; -} - -void osd_setpenmode(int enable) { - wnd->out->setMouseMode(enable ? PEN_ON : PEN_OFF); -} - -int osd_getpen(int code) { - if (wnd->isBreakExec()) { - ui_reset(); - brun_break(); - return 0; - } - - if (wnd->out->getMouseMode() == PEN_OFF) { - QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); - } - - switch (code) { - case 0: - // UNTIL PEN(0) - wait until click or move - if (form_event()) { - // clicked a form widget - return 1; - } - // flush any waiting update/paint events to allow mouse events to fire - QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); - - // receive any mouse events in wnd->out - if (!wnd->isBreakExec()) { - QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); - } - // second wait required following out.newLine() to avoid race condition - if (!wnd->isBreakExec()) { - QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); - } - // fallthru to re-test - - case 3: // returns true if the pen is down (and save curpos) - return (Qt::LeftButton == QApplication::mouseButtons()); - - case 1: // last down x - return wnd->out->getMouseX(true); - - case 2: // last down y - return wnd->out->getMouseY(true); - - case 4: // cur x - case 10: - return wnd->out->getMouseX(false); - - case 5: // cur y - case 11: - return wnd->out->getMouseY(false); - - case 12: // true if left button pressed - return (Qt::LeftButton == QApplication::mouseButtons()); - - case 13: // true if right button pressed - return (Qt::RightButton == QApplication::mouseButtons()); - - case 14: // true if middle button pressed - return (Qt::MiddleButton == QApplication::mouseButtons()); - } - return 0; -} - -int osd_getx() { - return wnd->out->getX(); -} - -int osd_gety() { - return wnd->out->getY(); -} - -void osd_setxy(int x, int y) { - wnd->out->setXY(x, y); -} - -void osd_cls() { - // send reset and clear screen codes - if (opt_interactive) { - wnd->out->print("\033[0m\xC"); - } -} - -int osd_textwidth(const char *str) { - return (int)wnd->out->textWidth(str); -} - -int osd_textheight(const char *str) { - return wnd->out->textHeight(); -} - -void osd_setpixel(int x, int y) { - wnd->out->setPixel(x, y, dev_fgcolor); -} - -long osd_getpixel(int x, int y) { - return wnd->out->getPixel(x, y); -} - -void osd_line(int x1, int y1, int x2, int y2) { - wnd->out->drawLine(x1, y1, x2, y2); -} - -void osd_rect(int x1, int y1, int x2, int y2, int bFill) { - if (bFill) { - wnd->out->drawRectFilled(x1, y1, x2, y2); - } else { - wnd->out->drawRect(x1, y1, x2, y2); - } -} - -void dev_arc(int xc, int yc, double r, double start, double end, double aspect) { - wnd->out->drawArc(xc, yc, r, start, end, aspect); -} - -void dev_ellipse(int xc, int yc, int xr, int yr, double aspect, int fill) { - wnd->out->drawEllipse(xc, yc, xr, yr, aspect, fill); -} - -void osd_beep() { - wnd->out->beep(); -} - -void osd_sound(int frq, int ms, int vol, int bgplay) { -} - -void osd_clear_sound_queue() { -} - -void osd_write(const char *s) { - wnd->out->print(s); -} - -void lwrite(const char *s) { - wnd->logWrite(s); -} - -/** - * run a program (if retflg wait and return; otherwise just exec()) - */ -int dev_run(const char *src, int retflg) { - int result = 0; - if (retflg) { - result = QProcess::execute(src); - } else { - QProcess::startDetached(src); - } - return result; -} - -//--ENV------------------------------------------------------------------------- - -int dev_putenv(const char *s) { - QStringList elems = QString::fromAscii(s).split("="); - QString s1 = elems.at(0); - QString s2 = elems.at(1); - - QSettings settings; - settings.beginGroup(wnd->isResourceApp() ? "settings" : "env"); - settings.setValue(s1, s2); - settings.endGroup(); - - return 1; -} - -char *dev_getenv(const char *s) { - QSettings settings; - settings.beginGroup("env"); - settings.beginGroup(wnd->isResourceApp() ? "settings" : "env"); - envBuffer.resize(0); - envBuffer.append(settings.value(QString(s)).toString()); - settings.endGroup(); - return envBuffer.length() ? envBuffer.toUtf8().data() : 0; -} - -char *dev_getenv_n(int n) { - QSettings settings; - settings.beginGroup(wnd->isResourceApp() ? "settings" : "env"); - QStringList keys = settings.childKeys(); - int count = keys.size(); - if (n < count) { - // first n number of elements exist in the qmap - QString key = keys.at(n); - QString value = settings.value(key).toString(); - - envBuffer.resize(0); - envBuffer.append(key); - envBuffer.append("="); - envBuffer.append(value); - return envBuffer.toUtf8().data(); - } - - return 0; -} - -int dev_env_count() { - QSettings settings; - int count; - - settings.beginGroup(wnd->isResourceApp() ? "settings" : "env"); - count = settings.childKeys().size(); - settings.endGroup(); - - return count; -} - -//--IMAGE----------------------------------------------------------------------- - -QImage *getImage(dev_file_t *filep, int index) { - // check for cached imaged - QImage *image = new QImage(filep->name); - char localFile[PATH_MAX]; - - // read image from web server - switch (filep->type) { - case ft_http_client: - // open "http://localhost/image1.gif" as #1 - if (cacheLink(filep, localFile) == false) { - return 0; - } - strcpy(filep->name, localFile); - image = new QImage(filep->name); - break; - case ft_stream: - // loaded in SharedImage - break; - default: - return 0; - } - - return image; -} - -void dev_image(int handle, int index, int x, int y, int sx, int sy, int w, int h) { - int imgw = -1; - int imgh = -1; - dev_file_t *filep = dev_getfileptr(handle); - if (filep == 0) { - return; - } - - if (filep->open_flags == DEV_FILE_INPUT) { - QImage *img = getImage(filep, index); - if (img != 0) { - // input/read image and display - imgw = img->width(); - imgh = img->height(); - wnd->out->drawImage(img, x, y, sx, sy, (w == 0 ? imgw : w), (h == 0 ? imgh : h)); - } - } else { - // output screen area image to jpeg - wnd->out->saveImage(filep->name, x, y, sx, sy); - } -} - -int dev_image_width(int handle, int index) { - int imgw = -1; - dev_file_t *filep = dev_getfileptr(handle); - if (filep == 0 || filep->open_flags != DEV_FILE_INPUT) { - return 0; - } - - QImage *img = getImage(filep, index); - if (img) { - imgw = img->width(); - } - return imgw; -} - -int dev_image_height(int handle, int index) { - int imgh = -1; - dev_file_t *filep = dev_getfileptr(handle); - if (filep == 0 || filep->open_flags != DEV_FILE_INPUT) { - return 0; - } - - QImage *img = getImage(filep, index); - if (img) { - imgh = img->height(); - } - return imgh; -} - -//--DELAY----------------------------------------------------------------------- - -void dev_delay(dword ms) { - if (!wnd->isBreakExec()) { - wnd->setRunModal(true); - QTimer::singleShot(ms, wnd, SLOT(endModal())); - - while (wnd->isRunModal()) { - QApplication::processEvents(QEventLoop::WaitForMoreEvents); - } - } -} - -//--INPUT----------------------------------------------------------------------- - -char *dev_gets(char *dest, int size) { - LineInput *in = new LineInput(wnd->out->font(), - wnd->out->getX() + 2, - wnd->out->getY() - 4); - wnd->addWidget(in); - wnd->setRunModal(true); - - in->setMaxLength(size); - in->connect(in, SIGNAL(returnPressed()), wnd, SLOT(endModal())); - in->setFocus(); - - while (wnd->isRunModal()) { - QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); - } - - if (wnd->isBreakExec()) { - ui_reset(); - brun_break(); - } - - wnd->removeWidget(in); - QString text = in->text(); - int len = text.length() < size ? text.length() : size; - strncpy(dest, text.toUtf8().data(), len); - dest[len] = 0; - delete in; - - // reposition x to adjust for input box - wnd->out->setXY(wnd->out->getX() + 4, wnd->out->getY()); - wnd->out->print(dest); - - return dest; -} - -C_LINKAGE_END - -//--HTML Utils------------------------------------------------------------------ -void getHomeDir(char *fileName, bool appendSlash) { - const char *vars[] = { - "APPDATA", "HOME", "TMP", "TEMP", "TMPDIR" - }; - - int vars_len = sizeof(vars) / sizeof(vars[0]); - - fileName[0] = 0; - - for (int i = 0; i < vars_len; i++) { - const char *home = getenv(vars[i]); - if (home && access(home, R_OK) == 0) { - strcpy(fileName, home); - if (i == 1) { - // unix path - strcat(fileName, "/.config"); - makedir(fileName); - } - strcat(fileName, "/SmallBASIC"); - if (appendSlash) { - strcat(fileName, "/"); - } - makedir(fileName); - break; - } - } -} - -// copy the url into the local cache -bool cacheLink(dev_file_t *df, char *localFile) { - char rxbuff[1024]; - FILE *fp; - const char *url = df->name; - const char *pathBegin = strchr(url + 7, '/'); - const char *pathEnd = strrchr(url + 7, '/'); - const char *pathNext; - bool inHeader = true; - bool httpOK = false; - - getHomeDir(localFile); - strcat(localFile, "/cache/"); - makedir(localFile); - - // create host name component - strncat(localFile, url + 7, pathBegin - url - 7); - strcat(localFile, "/"); - makedir(localFile); - - if (pathBegin != 0 && pathBegin < pathEnd) { - // re-create the server path in cache - int level = 0; - pathBegin++; - do { - pathNext = strchr(pathBegin, '/'); - strncat(localFile, pathBegin, pathNext - pathBegin + 1); - makedir(localFile); - pathBegin = pathNext + 1; - } - while (pathBegin < pathEnd && ++level < 20); - } - if (pathEnd == 0 || pathEnd[1] == 0 || pathEnd[1] == '?') { - strcat(localFile, "index.html"); - } else { - strcat(localFile, pathEnd + 1); - } - - fp = fopen(localFile, "wb"); - if (fp == 0) { - if (df->handle != -1) { - shutdown(df->handle, df->handle); - } - return false; - } - - if (df->handle == -1) { - // pass the cache file modified time to the HTTP server - struct stat st; - if (stat(localFile, &st) == 0) { - df->drv_dw[2] = st.st_mtime; - } - if (http_open(df) == 0) { - return false; - } - } - - while (true) { - int bytes = recv(df->handle, (char *)rxbuff, sizeof(rxbuff), 0); - if (bytes == 0) { - break; // no more data - } - // assumes http header < 1024 bytes - if (inHeader) { - int i = 0; - while (true) { - int iattr = i; - while (rxbuff[i] != 0 && rxbuff[i] != '\n') { - i++; - } - if (rxbuff[i] == 0) { - inHeader = false; - break; // no end delimiter - } - if (rxbuff[i + 2] == '\n') { - if (!fwrite(rxbuff + i + 3, bytes - i - 3, 1, fp)) { - break; - } - inHeader = false; - break; // found start of content - } - // null terminate attribute (in \r) - rxbuff[i - 1] = 0; - i++; - if (strstr(rxbuff + iattr, "200 OK") != 0) { - httpOK = true; - } - if (strncmp(rxbuff + iattr, "Location: ", 10) == 0) { - // handle redirection - shutdown(df->handle, df->handle); - strcpy(df->name, rxbuff + iattr + 10); - if (http_open(df) == 0) { - fclose(fp); - return false; - } - break; // scan next header - } - } - } else { - if (!fwrite(rxbuff, bytes, 1, fp)) { - break; - } - } - } - - // cleanup - fclose(fp); - shutdown(df->handle, df->handle); - return httpOK; -} diff --git a/src/platform/qt/fixedlayout.cpp b/src/platform/qt/fixedlayout.cpp deleted file mode 100644 index 74a08729..00000000 --- a/src/platform/qt/fixedlayout.cpp +++ /dev/null @@ -1,75 +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 "mainwindow.h" -#include "fixedlayout.h" - -// creates a new line input -LineInput::LineInput(const QFont &font, int x, int y) : QLineEdit() { - setFont(font); - QFontMetrics fm = fontMetrics(); - setGeometry(x, y, fm.width("ZZZ"), 8 + fm.ascent() + fm.descent()); -} - -// change the layout of the lineinput upon text change -void LineInput::keyPressEvent(QKeyEvent *event) { - QLineEdit::keyPressEvent(event); - - if (event->key() == Qt::Key_B &&event->modifiers() &Qt::ControlModifier) { - wnd->runBreak(); - } else if (event->key() == Qt::Key_Escape) { - wnd->endModal(); - } else { - QFontMetrics fm = fontMetrics(); - int width = fm.width(text() + "ZZ"); - if (width + pos().x() < parentWidget()->width()) { - resize(width, size().height()); - } - } -} - -// creates the fixed layout -FixedLayout::FixedLayout(QWidget *parent) : - QLayout(parent) { - // empty -} - -// destroys the fixed layout -FixedLayout::~FixedLayout() { - QLayoutItem *item; - while ((item = takeAt(0))) { - delete item; - } -} - -// returns the number of QLayoutItems in the list -int FixedLayout::count() const { - return list.size(); -} - -// QList::value() performs index checking, and returns 0 if we are // outside the valid range -QLayoutItem *FixedLayout::itemAt(int idx) const { - return list.value(idx); -} - -// QList::take does not do index checking -QLayoutItem *FixedLayout::takeAt(int idx) { - return idx >= 0 &&idx < list.size() ? list.takeAt(idx) : 0; -} - -void FixedLayout::addItem(QLayoutItem *item) { - list.append(item); -} - -void FixedLayout::setGeometry(const QRect &r) { - QLayout::setGeometry(r); -} - -QSize FixedLayout::sizeHint() const { - return parentWidget()->size(); -} diff --git a/src/platform/qt/fixedlayout.h b/src/platform/qt/fixedlayout.h deleted file mode 100644 index 6c885942..00000000 --- a/src/platform/qt/fixedlayout.h +++ /dev/null @@ -1,38 +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 -// - -#ifndef FIXEDLAYOUT_H -#define FIXEDLAYOUT_H - -#include -#include -#include - -struct LineInput : public QLineEdit { - LineInput(const QFont &font, int x, int y); - ~LineInput() { - }; - void keyPressEvent(QKeyEvent *event); -}; - -struct FixedLayout:public QLayout { - FixedLayout(QWidget *parent); - ~FixedLayout(); - - void addItem(QLayoutItem *item); - QSize sizeHint() const; - int count() const; - QLayoutItem *itemAt(int) const; - QLayoutItem *takeAt(int); - void setGeometry(const QRect &rect); - -private: - QList list; -}; - -#endif diff --git a/src/platform/qt/form_ui.cpp b/src/platform/qt/form_ui.cpp deleted file mode 100644 index c4edd0d5..00000000 --- a/src/platform/qt/form_ui.cpp +++ /dev/null @@ -1,776 +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 "config.h" -#include "sys.h" -#include "var.h" -#include "kw.h" -#include "pproc.h" -#include "device.h" -#include "smbas.h" -#include "keymap.h" -#include "mainwindow.h" -#include "form_ui.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern "C" { -#include "blib_ui.h" -} - -struct Form : public QWidget { - Form(int x1, int x2, int y1, int y2) : QWidget() { - setGeometry(x1, x2, y1, y2); - this->_cmd = 0; - this->var = 0; - this->kb_handle = false; - } - ~Form() {} - var_t *var; // form variable contains the value of the event widget - int _cmd; // doform argument by value - bool kb_handle; // whether doform returns on a keyboard event - int prev_x; - int prev_y; -}; - -Form *form = 0; - -enum Mode { m_reset, m_init, m_active, m_selected } mode = m_reset; - -// whether a widget event has fired -bool form_event() { - return mode == m_selected; -} - -// width and height fudge factors for when button w+h specified as -1 -#define BN_W 16 -#define BN_H 8 -#define RAD_W 22 -#define RAD_H 0 - -// forward declared for invoked() -void transfer_data(QWidget *w, WidgetInfo *inf); - -// default constructor for Q_DECLARE_METATYPE -WidgetInfo::WidgetInfo() : QObject() {} - -// copy constructor for Q_DECLARE_METATYPE -WidgetInfo::WidgetInfo(const WidgetInfo &winf) : QObject() { - widget = winf.widget; - type = winf.type; - var = winf.var; - is_group_radio = winf.is_group_radio; - orig = winf.orig; -} - -// public destructor for Q_DECLARE_METATYPE -WidgetInfo::~WidgetInfo() {} - -// update the smallbasic variable -void WidgetInfo::update_var_flag() { - switch (var->type) { - case V_STR: - orig.ptr = var->v.p.ptr; - break; - case V_ARRAY: - orig.ptr = var->v.a.ptr; - break; - case V_INT: - orig.i = var->v.i; - break; - default: - orig.i = 0; - } -} - -// slot/callback for the widget info called when the widget has been invoked -void WidgetInfo::invoked() { - if (wnd->isRunning()) { - transfer_data(widget, this); - - mode = m_selected; - - if (form->var) { - // array type cannot be used in program select statement - if (this->var->type == V_ARRAY) { - v_zerostr(form->var); - } else { - // set the form variable from the widget var - v_set(form->var, this->var); - } - } - } -} - -// implements abstract StringList as a list of strings -struct DropListModel : QAbstractItemModel { - QVariantList list; - int focus_index; - - DropListModel(const char *items, var_t *v) : - QAbstractItemModel() { - focus_index = -1; - - if (v && v->type == V_ARRAY) { - fromArray(items, v); - return; - } - - // construct from a string like "Easy|Medium|Hard" - int item_index = 0; - int len = items ? strlen(items) : 0; - for (int i = 0; i < len; i++) { - const char *c = strchr(items + i, '|'); - int end_index = c ? c - items : len; - if (end_index > 0) { - QString s = QString::fromUtf8(items + i, end_index - i); - list.append(s); - i = end_index; - if (v != 0 && v->type == V_STR && v->v.p.ptr && - strcasecmp((const char *)v->v.p.ptr, s.toUtf8().data()) == 0) { - focus_index = item_index; - } - item_index++; - } - } - } - - virtual ~DropListModel() {} - - // construct from an array of values - void fromArray(const char *caption, var_t *v) { - for (int i = 0; i < v->v.a.size; i++) { - var_t *el_p = (var_t *)(v->v.a.ptr + sizeof(var_t) * i); - if (el_p->type == V_STR) { - list << (const char *)el_p->v.p.ptr; - if (caption && strcasecmp((const char *)el_p->v.p.ptr, caption) == 0) { - focus_index = i; - } - } else if (el_p->type == V_INT) { - char buff[40]; - sprintf(buff, VAR_INT_FMT, el_p->v.i); - list << buff; - } else if (el_p->type == V_ARRAY) { - fromArray(caption, el_p); - } - } - } - - // returns the index corresponding to the given string - int getPosition(const char *t) { - int size = list.count(); - for (int i = 0; i < size; i++) { - if (!strcasecmp(list.at(i).toString().toUtf8().data(), t)) { - return i; - } - } - return -1; - } - - // return the text at the given index - const char *getTextAt(int index) { - const char *s = 0; - if (index < list.count()) { - s = list.at(index).toString().toUtf8().data(); - } - return s; - } - - // returns the model index corresponding to the given string - QModelIndex getIndex(const char *t) { - return createIndex(getPosition(t), 0); - } - - // index of the item in the model - QModelIndex index(int row, int column, const QModelIndex &/* index */ )const { - return createIndex(row, column); - } - - // parent of the model item with the given index - QModelIndex parent(const QModelIndex& /*index*/) const { - return createIndex(-1, -1); - } - - // return the number of rows under the given parent - int rowCount(const QModelIndex& parent) const { - return parent.isValid() ? 0 : list.count(); - } - - // return the number of columns - int columnCount(const QModelIndex& /*parent*/) const { - return 1; - } - - // return the data at the given index - QVariant data(const QModelIndex& index, int role) const { - return list.at(index.row()); - } -}; - -// convert a basic array into a QString -void array_to_string(QString &s, var_t *v) { - for (int i = 0; i < v->v.a.size; i++) { - var_t *el_p = (var_t *)(v->v.a.ptr + sizeof(var_t) * i); - if (el_p->type == V_STR) { - s.append((const char *)el_p->v.p.ptr); - s.append("\n"); - } else if (el_p->type == V_INT) { - char buff[40]; - sprintf(buff, VAR_INT_FMT "\n", el_p->v.i); - s.append(buff); - } else if (el_p->type == V_ARRAY) { - array_to_string(s, el_p); - } - } -} - -// returns the button text -const char *getText(QAbstractButton *w) { - return w->text().toUtf8().data(); -} - -// set basic string variable to widget state when the variable has changed -bool update_gui(QWidget *w, WidgetInfoPtr inf) { - QComboBox *dropdown; - QListView *listbox; - DropListModel *model; - - if (inf->var->type == V_INT && inf->var->v.i != inf->orig.i) { - // update list control with new int variable - switch (inf->type) { - case ctrl_dropdown: - ((QComboBox *)w)->setCurrentIndex(inf->var->v.i); - return true; - - case ctrl_listbox: - { - QAbstractItemModel *model = ((QListView *)w)->model(); - ((QListView *)w)->setCurrentIndex(model->index(inf->var->v.i, 0)); - } - return true; - - default: - return false; - } - } - - if (inf->var->type == V_ARRAY && inf->var->v.p.ptr != inf->orig.ptr) { - // update list control with new array variable - QString s; - - switch (inf->type) { - case ctrl_dropdown: - delete((QComboBox *)w)->model(); - ((QComboBox *)w)->setModel(new DropListModel(0, inf->var)); - return true; - - case ctrl_listbox: - delete((QListView *)w)->model(); - ((QListView *)w)->setModel(new DropListModel(0, inf->var)); - ((QListView *)w)->selectionModel()->clear(); - return true; - - case ctrl_label: - array_to_string(s, inf->var); - ((QLabel *)w)->setText(s); - break; - - case ctrl_text: - array_to_string(s, inf->var); - ((QPlainTextEdit *)w)->setPlainText(s); - break; - - default: - return false; - } - } - - if (inf->var->type == V_STR && inf->orig.ptr != inf->var->v.p.ptr) { - // update list control with new string variable - switch (inf->type) { - case ctrl_dropdown: - dropdown = (QComboBox *)w; - model = (DropListModel *)dropdown->model(); - if (strchr((const char *)inf->var->v.p.ptr, '|')) { - // create a new list of items - delete model; - model = new DropListModel((const char *)inf->var->v.p.ptr, 0); - dropdown->setModel(model); - } else { - // select one of the existing list items - int selection = model->getPosition((const char *)inf->var->v.p.ptr); - if (selection != -1) { - dropdown->setCurrentIndex(selection); - } - } - break; - - case ctrl_listbox: - listbox = (QListView *)w; - model = (DropListModel *)listbox->model(); - if (strchr((const char *)inf->var->v.p.ptr, '|')) { - // create a new list of items - delete model; - model = new DropListModel((const char *)inf->var->v.p.ptr, 0); - listbox->setModel(model); - } else { - QModelIndex selection = model->getIndex((const char *)inf->var->v.p.ptr); - if (selection.isValid()) { - listbox->setCurrentIndex(selection); - } - } - break; - - case ctrl_check: - case ctrl_radio: - ((QCheckBox *)w)->setCheckState(!strcasecmp((const char *)inf->var->v.p.ptr, - getText((QCheckBox *)w)) - ? Qt::Checked : Qt::Unchecked); - break; - - case ctrl_label: - ((QLabel *)w)->setText((const char *)inf->var->v.p.ptr); - break; - - case ctrl_text: - ((QPlainTextEdit *)w)->setPlainText((const char *)inf->var->v.p.ptr); - break; - - case ctrl_button: - ((QPushButton *)w)->setText((const char *)inf->var->v.p.ptr); - break; - - default: - break; - } - return true; - } - return false; -} - -// synchronise basic variable and widget state -void transfer_data(QWidget *w, WidgetInfoPtr inf) { - QString s; - QComboBox *dropdown; - QListView *listbox; - DropListModel *model; - - if (update_gui(w, inf)) { - inf->update_var_flag(); - return; - } - // set widget state to basic variable - switch (inf->type) { - case ctrl_check: - if (((QCheckBox *)w)->checkState()) { - v_setstr(inf->var, getText((QCheckBox *)w)); - } else { - v_zerostr(inf->var); - } - break; - - case ctrl_radio: - if (((QRadioButton *)w)->isChecked()) { - const char *label = getText((QRadioButton *)w); - if (label) { - v_setstr(inf->var, label); - } - } else if (!inf->is_group_radio) { - // reset radio variable for radio that is not part of a group - v_zerostr(inf->var); - } - break; - - case ctrl_text: - s = ((QPlainTextEdit *)w)->toPlainText(); - if (s.length()) { - v_setstr(inf->var, s.toUtf8().data()); - } else { - v_zerostr(inf->var); - } - break; - - case ctrl_dropdown: - dropdown = (QComboBox *)w; - model = (DropListModel *)dropdown->model(); - if (dropdown->currentIndex() != -1) { - const char *s = model->getTextAt(dropdown->currentIndex()); - if (s) { - v_setstr(inf->var, s); - } - } - break; - - case ctrl_listbox: - listbox = (QListView *)w; - model = (DropListModel *)listbox->model(); - if (listbox->selectionModel()->currentIndex().isValid()) { - const char *s = model->getTextAt(listbox->selectionModel()->currentIndex().row()); - if (s) { - v_setstr(inf->var, s); - } - } - break; - - case ctrl_button: - // update the basic variable with the button label - v_setstr(inf->var, getText((QPushButton *)w)); - break; - - default: - break; - } - - // only update the gui when the variable is changed in basic code - inf->update_var_flag(); -} - -// find the radio group of the given variable from within the parent -QButtonGroup *findButtonGroup(QWidget *parent, var_t *v) { - QButtonGroup *radioGroup = 0; - QObjectList children = parent->children(); - int n = children.size(); - - for (int i = 0; i < n && !radioGroup; i++) { - QObject *nextObject = children.at(i); - if (nextObject->inherits("QButtonGroup")) { - QList < QAbstractButton *>buttons = ((QButtonGroup *)nextObject)->buttons(); - int nButtons = buttons.size(); - for (int j = 0; j < nButtons && !radioGroup; j++) { - QAbstractButton *nextButton = buttons.at(j); - WidgetInfoPtr inf = nextButton->property("widgetInfo").value (); - if (inf != NULL) { - if (inf->type == ctrl_radio && - inf->var->type == V_STR && (inf->var == v || inf->var->v.p.ptr == v->v.p.ptr)) { - // another ctrl_radio is linked to the same variable - inf->is_group_radio = true; - radioGroup = (QButtonGroup *)nextObject; - } - } - } - } - } - return radioGroup; -} - -// radio control's belong to the same group when they share -// a common basic variable -void update_radio_group(WidgetInfoPtr radioInf, QRadioButton *radio) { - var_t *v = radioInf->var; - - if (v == 0 || v->type != V_STR) { - return; - } - - QButtonGroup *radioGroup = findButtonGroup(form, v); - if (!radioGroup) { - radioGroup = new QButtonGroup(form); - } else { - radioInf->is_group_radio = true; - } - - radioGroup->addButton(radio); -} - -void update_widget(QWidget *widget, WidgetInfoPtr inf, QRect &rect) { - if (rect.width() != -1) { - widget->setFixedWidth(rect.width()); - } - - if (rect.height() != -1) { - widget->setFixedHeight(rect.height()); - } - - if (rect.x() < 0) { - rect.setX(form->prev_x - rect.x()); - } - - if (rect.y() < 0) { - rect.setY(form->prev_y - rect.y()); - } - - form->prev_x = rect.x() + rect.width(); - form->prev_y = rect.y() + rect.height(); - - widget->setGeometry(rect); - widget->setProperty("widgetInfo", QVariant::fromValue(inf)); - // qVariantFromValue(inf)); - widget->setParent(form); - inf->widget = widget; - - // allow form init to update widget from basic variable - inf->orig.ptr = 0; - inf->orig.i = 0; - - // copy output widget colors - // widget->color(wnd->out->getColor()); - // widget->labelcolor(wnd->out->getBackgroundColor()); -} - -void update_button(QAbstractButton *widget, WidgetInfoPtr inf, - const char *caption, QRect &rect, int def_w, int def_h) { - if (rect.width() < 0 && caption != 0) { - rect.setWidth((int)wnd->out->textWidth(caption) + def_w + (-rect.width() - 1)); - } - - if (rect.height() < 0) { - rect.setHeight((int)(wnd->out->textHeight() + def_h + (-rect.height() - 1))); - } - - update_widget(widget, inf, rect); - widget->setText(caption); - widget->connect(widget, SIGNAL(clicked(bool)), inf, SLOT(invoked())); -} - -// create a new form -void form_create() { - if (form == 0) { - form = new Form(wnd->out->x() + 2, - wnd->out->y() + 2, wnd->out->width() - 2, wnd->out->height() - 2); - } - // form->begin(); - mode = m_init; -} - -// prepare the form for display -void form_init() { - if (form) { - form->setGeometry(0, 0, form->width(), form->height()); - } -} - -// copy all widget fields into variables -void form_update(QWidget *group) { - if (group && wnd->isRunning()) { - QObjectList children = group->children(); - int n = children.size(); - - for (int i = 0; i < n; i++) { - QObject *w = children.at(i); - if (w->isWidgetType()) { - WidgetInfoPtr widgetInfo = w->property("widgetInfo").value(); - if (widgetInfo == NULL) { - form_update((QWidget *)w); - } else { - transfer_data((QWidget *)w, widgetInfo); - } - } - } - } -} - -// close the form -void form_end() { - if (form != 0) { - // form->end(); - } -} - -// destroy the form -C_LINKAGE_BEGIN void ui_reset() { - if (form != 0) { - QObjectList children = form->children(); - int n = children.size(); - - for (int i = 0; i < n; i++) { - QObject *w = children.at(i); - if (w->isWidgetType()) { - WidgetInfoPtr widgetInfo = w->property("widgetInfo").value(); - if (widgetInfo != NULL) { - delete widgetInfo; - } - } - } - - delete form; - form = 0; - } - mode = m_reset; -} - -// BUTTON x, y, w, h, variable, caption [,type] -// -void cmd_button() { - var_int_t x, y, w, h; - var_t *v = 0; - char *caption = 0; - char *type = 0; - - form_create(); - if (-1 != par_massget("IIIIPSs", &x, &y, &w, &h, &v, &caption, &type)) { - WidgetInfoPtr inf = new WidgetInfo(); - inf->var = v; - QRect rect(x, y, w, h); - - if (prog_error) { - return; - } - if (type) { - if (strcasecmp("radio", type) == 0) { - inf->type = ctrl_radio; - inf->is_group_radio = false; - form_end(); // add widget to RadioGroup - QRadioButton *widget = new QRadioButton(); - widget->setGeometry(x, y, w, h); - update_radio_group(inf, widget); - update_button(widget, inf, caption, rect, RAD_W, RAD_H); - } else if (strcasecmp("checkbox", type) == 0 || strcasecmp("check", type) == 0) { - inf->type = ctrl_check; - QCheckBox *widget = new QCheckBox(); - widget->setGeometry(x, y, w, h); - update_button(widget, inf, caption, rect, RAD_W, RAD_H); - } else if (strcasecmp("button", type) == 0) { - inf->type = ctrl_button; - QPushButton *widget = new QPushButton(); - widget->setGeometry(x, y, w, h); - update_button(widget, inf, caption, rect, BN_W, BN_H); - } else if (strcasecmp("label", type) == 0) { - inf->type = ctrl_label; - QLabel *widget = new QLabel(); - widget->setGeometry(x, y, w, h); - widget->setText(caption); - update_widget(widget, inf, rect); - } else if (strcasecmp("listbox", type) == 0 || strcasecmp("list", type) == 0) { - inf->type = ctrl_listbox; - QListView *widget = new QListView(); - DropListModel *model = new DropListModel(caption, v); - widget->setModel(model); - widget->setGeometry(x, y, w, h); - // if (model->focus_index != -1) { - // widget->value(model->focus_index); - // } - update_widget(widget, inf, rect); - // widget->when(WHEN_RELEASE_ALWAYS); - } else if (strcasecmp("dropdown", type) == 0 || strcasecmp("choice", type) == 0) { - inf->type = ctrl_dropdown; - QComboBox *widget = new QComboBox(); - DropListModel *model = new DropListModel(caption, v); - widget->setModel(model); - widget->setGeometry(x, y, w, h); - // if (model->focus_index != -1) { - // widget->value(model->focus_index); - // } - update_widget(widget, inf, rect); - } else { - ui_reset(); - rt_raise("UI: UNKNOWN BUTTON TYPE: %s", type); - } - } else { - inf->type = ctrl_button; - QPushButton *widget = new QPushButton(); - widget->setGeometry(x, y, w, h); - update_button(widget, inf, caption, rect, BN_W, BN_H); - } - } - - form_end(); - pfree2(caption, type); -} - -// TEXT x, y, w, h, variable -// When DOFORM returns the variable contains the user entered value -void cmd_text() { - var_int_t x, y, w, h; - var_t *v = 0; - - if (-1 != par_massget("IIIIP", &x, &y, &w, &h, &v)) { - form_create(); - QPlainTextEdit *widget = new QPlainTextEdit(); - QRect rect(x, y, w, h); - WidgetInfoPtr inf = new WidgetInfo(); - widget->setGeometry(rect); - inf->var = v; - inf->type = ctrl_text; - update_widget(widget, inf, rect); - if (rect.height() > (wnd->out->textHeight() + BN_H)) { - // widget->type(QPlainTextEdit::MULTILINE | QPlainTextEdit::WORDWRAP); - } - } -} - -// DOFORM [FLAG|VAR] -// Executes the form -void cmd_doform() { - if (form == 0) { - rt_raise("UI: FORM NOT READY"); - return; - } else if (mode == m_init) { - form_init(); - } - - switch (code_peek()) { - case kwTYPE_LINE: - case kwTYPE_EOC: - case kwTYPE_SEP: - form->_cmd = -1; - form->var = 0; - break; - default: - if (code_isvar()) { - form->var = code_getvarptr(); - form->_cmd = -1; - } else { - var_t var; - v_init(&var); - eval(&var); - form->_cmd = v_getint(&var); - form->var = 0; - v_free(&var); - - // apply any configuration options - switch (form->_cmd) { - case 1: - form->kb_handle = true; - return; - default: - break; - } - } - break; - }; - - form_update(form); - - if (!form->_cmd) { - ui_reset(); - } else if (wnd->out->getMouseMode()) { - mode = m_active; - QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); - } else { - // pump system messages until there is a widget callback - mode = m_active; - - if (form->kb_handle) { - dev_clrkb(); - } - while (wnd->isRunning() && mode == m_active) { - QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); - - if (form->kb_handle && keymap_kbhit()) { - break; - } - } - form_update(form); - } -} - -C_LINKAGE_END diff --git a/src/platform/qt/form_ui.h b/src/platform/qt/form_ui.h deleted file mode 100644 index d66c7d4c..00000000 --- a/src/platform/qt/form_ui.h +++ /dev/null @@ -1,52 +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 "config.h" -#include "common/sys.h" -#include "common/var.h" - -// whether a widget event has fired -bool form_event(); - -// control types available using the BUTTON command -enum ControlType { - ctrl_button, - ctrl_radio, - ctrl_check, - ctrl_text, - ctrl_label, - ctrl_listbox, - ctrl_dropdown -}; - -// binds a smallbasic variable with a QT widget -struct WidgetInfo : public QObject { - WidgetInfo(); - WidgetInfo(const WidgetInfo &winf); - ~WidgetInfo(); - - QWidget *widget; - ControlType type; - var_t *var; - bool is_group_radio; - - // startup value used to check if - // exec has altered a bound variable - union { - long i; - byte *ptr; - } orig; - - void update_var_flag(); - - public slots: - void invoked(); -}; - -typedef WidgetInfo *WidgetInfoPtr; -Q_DECLARE_METATYPE(WidgetInfoPtr); diff --git a/src/platform/qt/httpfile.cpp b/src/platform/qt/httpfile.cpp deleted file mode 100644 index a99b4c6a..00000000 --- a/src/platform/qt/httpfile.cpp +++ /dev/null @@ -1,61 +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 "httpfile.h" - -QNetworkAccessManager manager; - -HttpFile::HttpFile(HttpFileListener *listener, const QString path) : - QTemporaryFile() { - this->listener = listener; - this->url = QUrl(path); - requestFile(); -} - -HttpFile::~HttpFile() { - reply->deleteLater(); -} - -void HttpFile::requestFile() { - QNetworkRequest request; - request.setUrl(url); - request.setRawHeader("User-Agent", "SmallBASIC - QT"); - - open(QIODevice::WriteOnly); - reply = manager.get(request); - connect(reply, SIGNAL(readyRead()), this, SLOT(readyRead())); - connect(reply, SIGNAL(finished()), this, SLOT(finished())); -} - -void HttpFile::finished() { - flush(); - close(); - - QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); - if (reply->error()) { - listener->loadError(reply->errorString()); - deleteLater(); - } else if (!redirectionTarget.isNull()) { - url = url.resolved(redirectionTarget.toUrl()); - open(QIODevice::WriteOnly); - resize(0); - requestFile(); - } else { - // success - listener->loadPath(fileName(), false, true); - deleteLater(); - } -} - -// Called every time the QNetworkReply has new data. Read all of -// its new data and write it into the This uses less RAM than -// when reading it at the finished() signal of the QNetworkReply -void HttpFile::readyRead() { - write(reply->readAll()); -} diff --git a/src/platform/qt/httpfile.h b/src/platform/qt/httpfile.h deleted file mode 100644 index 87d3f32f..00000000 --- a/src/platform/qt/httpfile.h +++ /dev/null @@ -1,40 +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 -// - -#ifndef HTTPFILE_H -#define HTTPFILE_H - -#include -#include -#include - -struct HttpFileListener { - virtual void loadPath(QString path, bool showPath, bool setHistory) = 0; - virtual void loadError(QString message) = 0; -}; - -class HttpFile : public QTemporaryFile { - Q_OBJECT - -public: - HttpFile(HttpFileListener* listener, const QString path); - ~HttpFile(); - -public slots: - void finished(); - void readyRead(); - -private: - void requestFile(); - - QUrl url; - QNetworkReply *reply; - HttpFileListener *listener; -}; - -#endif diff --git a/src/platform/qt/images/home.png b/src/platform/qt/images/home.png deleted file mode 100644 index 4e4786a01d4633da6b10f842858726ab9a9b1f68..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1364 zcmZ{kdr;C@6vr=RMy7>kVuh>rQp^V^85x!jNF+5S&7uV#sHy7%@>!Xhn@Z_qjh6Ws zoXrJR4Ot)L_$({67KI31bT!w}6ho6;8#Bdhf9-$!$9`wd{meOczUQ8~bLZal_wzE) z+pPxxFz_Z5sSr)S1zZL$L(sYC?&}UfL($f?uuV`7OQL#tfO;wFJ(O55$y8qe zt{em)`vw53P$_#BfD{Y>>QDe&9sq!3Rkj5Xpbg#dQ(i=fkXAg~vmk6?kL%P+yMy=t z6n;H4A0AXQXir8)8aAM*{w8Y%W27v%c8-nZ{v%W*+L%P)86Tz^w?+n_w^2~a-s^#u zpZXv8Fr1dzZ7h_L3Z{NYElPGylU8cj($1$}T}zhHJRZc^J~zbLm9ELdOhKC{rn}-&DjfkSMxYsAt52Bt%}V|&CS0q>m9VR3LAZV zd10(odzbt!K}-{hgu-|MwMLyxL16n0Qreb*%rGQ=Z|jOQ=5k zdz2n7m&@=~>}_glDv(Dv3+w9U3QHEz%s4!18lw=+}<8Ett37}oG(%0-M$8e6GsnQRz_ zI$Wrza1xB3z7Q;8^i1^??J;pp{|h9JcVLTO-7XB9^@MJXL8IC574I2zC9^NS9FZfF z$s8Vw#p0CI)P*KVEe%e{_>2(K?8e8(xpLfx`YF60kGfI^DOk~bu6QY63$Dc0!9f%U ziBv7;(-nDP!|D&CE!}u6F`z^gE2hOqMa`5(IF6XXb;1j=9fz(}xx)>8cvN#+TU$a^ zRaMAD<+8TxM0(Q1!JJzUe+jPtp6x(y!v)j?W)=|la%*ctFuiWXM5XV@6PC_~XxVNX ziZ%2syiT6X>|#b?8-NAY-$1t^nDXUe88?F1stSnJ0!jh5oMeq3~bSqO8(nCk2N z*d01YFuF+;`db&8=;eBYtc`9>FGsw|=$d=3hVuFOd67b)$U+!WYX2woMv=?>LV_OVgMb=7XkuAN&=k&P|{2Oa2WN$|3GpwV#6(tUFg zn{{6u6`T?H4KF@3Z<$f$g24+ZULMZkEigW zH16GfFzZr@YZ`sIJ)Mx5D)5)%28?o$yO=CGvY?{T=c*i;IhcomZDX zIrVnKVHlX{RVe|OWb-%cW)rt|8{p2;C!Q2$0j!|Q%-H3N0QyW0B$Li1M}#Fux-c(A zLI92!EXEFlx5GLIVx3$Z@h&*bA&jF71~d7FYWN>Rd}2gQ)aCy-6c?$5kO6p;{D}1) Hp*jBm_846$ diff --git a/src/platform/qt/images/jump.png b/src/platform/qt/images/jump.png deleted file mode 100644 index 1d026ad16bfa129890c59ee28eb9a3c852472525..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1567 zcmZ{kYgp2E6vuz$4Q&~ZIn?G1%S=iU1qlfX5k>Jb`$s8FOGPx(ydY#3Cp<|PE5|a@ zmUwGkayk>8rX{e8X-&;dO)E1sGo(^uF7K=T+q=Ekd7g7V&pGG$KIgnR&&du6X00(> zZw3HZ0Hn7Bt|*`d*lsHRjA*o0e3ex2KaynF7^ zhNcElf&GW1PH%kt(WdroZK0bTQR{x)4yvN%2UG z7|hFw`tr`RXYZ$HWNQ;jOD->t`UeZrdS=ph&KJ$nOcsiBoUN?w)-!^RtbwX_1?6|{ z4Zsf5B@Z!%Z2MBVA{Syt;Ig{A&ni__e7;0=^Nr6*){g1!k!|lzs7{I^#963%8@dso zi7$Fpd6xH!s`~R4v)kmo7YiGe$2(t6AXF;VBaL{Mudi>BThOd`PH(=~Ieqfx5H^=x zb>P9>`+E<}yhs$H@1)PX-!aUCXRU2era9rIH|w+utrV=JNBwf!~Kx-xm~{^|O0 zGNX^k#%>NVTQDhs4)2T`x@l9fxF;=*Fj+)98M1fpg#K#LKKr(<9jT*abFx;}j9Rrl zdAQYsOkUt^y;5&Qup!ZC9zE836ls>j)s~Q2oiK>Ar3jHvve#`H)gOCBN_x6bTM?g7 zCXc+B{nztoTtWArr-qtbTsm)OtSsnD_*~E8p33y}`M+$=MD62nIN0)YmKF@QAC@T= zi@%77_`FYM>v>AA*RL<EnKp#fE+#TB> zhc*Bdqlri)3b$DJ?{+{1A^#X27?^vk>#Hml+!;2RaeX@TM9J$|eI`obAgxJlHdu8k z9G8DB$Cn^QO%@gwS{GXvpVY~$#?M4?Uh+eYOBTm$ox3G`F5&0Mw=Opam({527Ia#< z&{dluQgZrq!b6df7-iDb{z;b1&WM+oboj)QZ%NIYct&1CU5Q-%{p%+Pdub@PJRCPz zpqORh{IEXG=;ch3g);gNCnw$~0P^APc*(E6wKc<=%jJF!HlCKs12B3+B(LjRg@T$s_RHxxwfcSA~cfpfg+(;ZZ0>#6P;z8VocchvvlzH4}^O#HblE*Ac(_J^K zxN(cPgrUOXBsE2obZ`xkTzSg1-Cy^=`^Wv9^ZC5a=kq!5^L?N1AD=9$rz>1jUlRZT zcO$vbAR@mdOarPP66{wXYzQGx2mn0D*ZMn99qLu$Xs*tny4PR|YK#~p8U+B}J^<1( z0Qd@x(k21mU;vm7004g#fF03-N5|}-g~nO3s|!RZR*y8LLf8~d@{5C>e)BC=3Zl4z zZ^QU#LI}ivjezqWqT7&%RyP-dH>s=6hY+#V2dS8N?vW5YP}kI7A4skmj81dXce{(C znj0h1DBUWQ926=yYX{%vY7rS)`zXYSo6g(FLlG#^Y(3eJ zQ*xk;yYT+{vK_l*yNqZ(?{#|OvvMI>nWR*zhNguY2?WI!lE>}vII}&f+ zc|8C0%hvc=UKqN49+5Zpx$sE?dy1BfGf-sc)=Z6rT8NtWWSqw$wH0_gKD)EC6P+Gv zoh=qScz97*CT0hfw1GtnB~wW2zH~$05?MOo&0@{!5zd`6yZkJuK`a)(uAd!HY<5!< z`g*O3mGk}MU^QD>LCX$fv+%+Z5{b*_`gP~9&Z-RdX|5tuZ00t>(UF-AUKO&nX zchubL;cz%cO$l>Hx!gvUx@xX??k6Ne*ZCf=L08DHsSSCtqz#AX9&;DzstOi1y26g_ z6GaR*#u@7v+QC{H8+X>TPO#oJ%CF_V2LZ3N=?hn2}dkSC3cy@JFPrjZI5k%KBHiiW6*ev_V() z(OZ{#+4K_(fqmL5c$w--PmMX%UF(4K0b>r^xf;=@bLwTNb@w6HJdiimw$MyW53*|f zfXgGpHkpZ>U~f~V`zvl`6uf@(Y>OaubC%2PiBIpV>RC;1F*zqxPI6UWEPO)iWvK&< zOeTvS>&$IrtC!#wS)%F8y9jP0jJ?Sd59tUvPnz zeXjJ)89IG^IB(bC_ZW)QfBO9DbLxi_APmz-GPGI|h}8E(L*I=wbFm<8ya)vIcsyBZ zQ_A`tk@o>kM|;O;ZNZaF-DrAAeqJtz9Uq@EJUl%6C%-+`*sXJLcTrJM1$Do-ufM-P z0cKfz_+ej+fm|VxNT%ZG^xeT$*M??iXAusI$9}VNpPE@&Sz&d>WHSBGL?RId9?_;z z)RAR^$>QbOXAdr1==r70F;yXruua5<^rELUN&0}gEz9NfyZeDpmb$yUDTSo+=DT+# zszS*5H8u}#iH)-`%wJ|&T|tQ>KyuTC?i!j+Jjo6UWHa%MSSAEug|Wm~U~m?ew%(Rl syp1K^#>Na|g~wnjB98?AN5F~-3Jd1`zhDr%HVg@X8`0CH+BqQoA2BJKN&o-= diff --git a/src/platform/qt/images/previous.png b/src/platform/qt/images/previous.png deleted file mode 100644 index 79f5a4207d9391073ebbb1c35bc6ce73fe9a9a1a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1515 zcmZ{kdotf7dQlfhA~yK$R@2}>Dw zWgJXda;eD@O==8E<>cF47TS9=t1VZ%V{h`C^k=Zr$X2r6*3{~iJoTx)8f8%CY54&IKBJG^(Iz0U04dA&huiYDKuJJeAI^!@1yo*pvD=1;mv zyWE&pUBlgeNx`&unf}xRT$(kP)gGnVEANTY1hk>es8EkF<*SQROhQ zK*vT!iDAKX^^7fm!+CPHvY zwq#dkON%I+3Rf|mU3uAtP#14fM;E?1(-#`k71G0CFsVB+%DNKA-}mu4`FH|r$IQ+y z+kTc8(*0r?heBYDm0!JE+wAq-Pb$}^X^jfR@``tWQN`~x1sFFm)vBC~KchP}*1X)3 z8WCYMFM6;w`!KDM&C(3&@Rw46?HJsA8RR~2UX#s_+WL^kOaw?Nw5_dx)!0Zb))_vt z^oNbgjT<*qi$`l*^05`tTC|cj<7E@Ki3~M0HKYbQPIhu~lFeFPMGXcP;`dK>l1plx zGBYx+_4M>yEyPE?vhtZYU}wio3>NfWO;~;Fq<_Sn!I_;6{!J&(TEFJ!AN&l9l6eBb zj#ofHKoW(rChY3!+NLRxI-cBeuVaOmmDOc^>`D+-cN1T*+GCfV8_@da&T?__ic|_W zq=hHo^ZA0nzLXv~XIm%~u5dV;W?xjTze~Rc2c8C+YY=i&=E-)~IEPwh=VqWw$ zKfFxUDgQM_R=-uuxHk%!?s5$GN4QLy5|hcaH8eD|10Lg&+Qvq2a&;DqvPajt1`m-L?hTDk}c=2ErjwHxu_G_wTv~>0MetUA!&D6+CLgB51EM&;` z`}eIqy}TqB)=MXb7Gm3!l#~t=nl?JL-HbxRO3z**P1L#-6yjU2_r&e>J8@|Bc149% z*o6yP2NGN|FjeJnIDD@Ucl~puMG})h=$+^!cRlxETj%V{8N^hLJ*}@d;MzP}GoV${ za>wW<0av~V`LFIZG#E~;1^K<)jmaHdpg&4Y@9T+Qp5n9FXh8Ko1}j-yUfvRNZ`p3s zNup$3s})jBrBymv#lm!Ytu)MB^S}6RbJHCWK{^G)!`a!{3!fMAohft@Kj$ZAL2dXn zo8?>Iu%shp{vMW$^B6=JkB$t!5s9j*syfxIqmm&{?MQHLS4PP@TY{rkPE_#YkE-ZM)i-fcNVt#;exAw8Rj^K6g<418H9 zIZ2r#2@JrOwrlqy9OdGa1#Ni4sr*z4Q{#DN+R;g6=#SHl!}-O965~kdkXRA~V2(0F znV^oFm|1z7S)eV=(3X})D04IlRUdVV_#Xi|IyC%3;{OYH7F&Es0Gx2{SQaMu+CLGB Bt*`(9 diff --git a/src/platform/qt/images/refresh.png b/src/platform/qt/images/refresh.png deleted file mode 100644 index 4fb7ac3353b774ebbc77df6983aec6ebb405bcff..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1714 zcmZ{kcU03^7RO&0BV`Z*;u?yMxWa<8fFXonXof?GGy@SMOAUyWK!6Mkih^!7fM7r- zD@9-c4Gw*zgaK(vCxj|Q$b_a6q=?AOs1%u>```Yt-*fK!oO|E-p8L*u_uMphSI0vN z8VUe_Lrz2j86xs)$Q^{v`FQ*%2nRy!T5mwnH(i3H))GG4jD7r%9GcsX{M9H=$uHDH^?FI3Vb55kN;;TPGEk)_r?EvJzKNsybX;r+!+Y`;T zA0d-zIN^PAFOPeag>XdD=oJ;0d%I8F@7Nx!mv=2XoA$@5=+$^n`sBOTRuc;4#^K~u zOUf@SM4zS9>a4Gu-|5sel#{5phzZ zEqZmPv9e=*wr$6&3sqHGT1q{h+4pyzXAF_VEtvp za;J0|*vi3Z89vQ1Z$@Z+oWfrj3(t9;r;orJv{2Uh-~i)0uV*K;R;Q}FS`)T@-`n{plGkP$ACLputhM!Zd|SAv=GZOU`K7Ukjz?Ep+Oc`g zMFAP6+TAC8L;@sDIf|@`=nvHHwrXr_EPP-Q#eP^)0+S9G8eC8dR_Cc@^qFGA1dSCHd7GuRnjF^W00V)@iAe&97Jx(Tv}&f+m{MVO1Y{e{g)YM+y`y-;WWeI z(EN_hRiUCQuF$xci>q%8%5ZUUc8=Rlw9Y{+(tC4bw{u4x$O9n#Etq<-Xl`Q!kz3}Z z$Lm*R3^$8b&6z$QPgMuq6R+Pq?VgmB)KFU+Ra{pWV@IVOYWz-D@?E$>lHB#ZAf>3yY*4q~?&&iAPpuvs20r z%F33Y_eNQjUbURrjwGA=E`b@A6o(tJQ&rU8*QV=37B@eA(~GQ&6l31awuz@FC%@mF zpo`ZQ7Z+p1{17=^UERnAegmh8&$q`*;xyO+{hzm_Ci!PVT!llUL{kf-qOT=m-gbv; zsdL0(z>P;{Mno9SipAHLUX**xt+dSgX)4|<3!Rx+i_b8{V6mTQ-rnBQ<>h5(S*sjF zD!D28RWJT#$9|7`;k~-KhN_WsCGKt~@97Bz0)xPeJnp#n0}P$yMWN8g(Cdfo`-d1B z>`kxm@bJCiLaW-^%Z;bc{Sv?7i^gDvt1BzT#}yCGiO?bybRbO6ZVvl9& z>&p6T*B}0^ndB@74N>`3^o*8LN<0RG;jrvWQo?Zb+vI#Cq)D_;y7gJ6q9V**PR_U! z?!{6w)@FGy>{wY@W*#301_m|-IVSt#-qQ+w56eB&=_VHqLy!mc zK{SvD9-zA(6gg&vlU&<>m)`ZDjnVoTHRqHSvE-`}wn87$&OfUpshB8GN zp|D1#7*EqPICE2+ImQ5GhC`up+0@xeLa!wJf5Thxf-PhKP7bbw8hiiSe*x>R B7OnsQ diff --git a/src/platform/qt/images/stop.png b/src/platform/qt/images/stop.png deleted file mode 100644 index bf0ce0119d010af986d7e34a575b157f4803276f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1796 zcmZ{kdpr|*AIE=j%nVslF3(XZsq>0s8`hqsa$95NHWWj~h-pG$ZineiisgREJvw+9 zEh^=b+rzV+%E)mJN1NNDafTV`JjZJ0SZC90r;$JG5!D`9s$4#836190Q6(3x;<@`14zh4ypxj3kU93GE1?nN>~~AKdh)CG zZH-8c_Txr5zv%jx z1(LEa_GGT#nBmW?^CUB8=v;MzY6;_9V&QAsk@8*3TQ`@^t8ScE?-qneEqn7lQ62#S zRXND-?VzGj^DqO7C(e^-%d?_)eCgkloRVTv^g5={v`fuC@y=rBiG2U7WM4f7j5}=`(4uwMt z5km%3Sq^nE>FK+7O~mIo^lqLnJ5>; zVU6crMhD%2s~pPX9m`g^ro|w>k*B58{r&wXN={u#L+OE%CqH{6w|Y_eQ%eyss+!&b-ca3t?$N5fz+qH}3j1dW#3%Hgd4bTa#ws)Hj$f`5EqG^sb)#-@^=<7!r9bpL|o z`umO?i-67zn@8inGvQB1sLk6!Md^==VGZX-BRf<~hTWh@Y6aw_cD+V7CpwhXt32h; zP?XHy+Q>NH^q#qI+x!7mtd+?yihg+fZY-(#h2P`L^8o1K1}hrt&Y0e2voU(G12x!q zg0L-E^)ZLjxS426CzHv+*lP4X2l9GfYpEK}6T{ln9{BL#!}I!+D?%q9pXNEKG%_k` zXKnc2{^p7bqgS_<-Rvixizg>1pLF;1^t(3@r@QiL=$1E6s|cpLr{7z{p-y3bxv<;w zWETG_e_>&Plbf4cN=9s_Or%JIah_L~ldgVD?v+0Af4MF!IEE)_n6%NRpO)00gt3r- zNhW!k-O0Lh0>Nc0^DEV}>z%kfs-40kajy2he;L0jNX?k&+6QJE zinFl|jX$dEpgBSPiseW6JXGM6pQ|h1>$J(HuRL{meDv;HkxC6*1=zu}Mns&Cq#p;# zM#jcF;*Eu&`xFXgr}A|4((;&P(gYc?MrMgT2!AJthl-J_Y@e3V8r!6g>^W)wQXDqN zw8^`U&9=p0wl@a`1`awKaLF?4w9rP*5Ncq7LkJ4~1!JwyY(5 z33)W$IZQ)a{wpa>m10ikjPvbEbsY%DUD&6~FV#d?Cog;wPgo3+Ve7b zYpAKN%QWr97xRN}i8afIn~Gs{cx@&a&?Sg>rk(`t_BJ&w?~-uZ|~zwmo*u;}LPn z*Kok_KKEND+{-7PP%84kR`;oZDR4v$thpVf@AwD{DFDPm-T($*V6EnC6p-_8^UBP> z;VG2Q|9BkEH!d_dE(}Y#8Kwk4A&>|Q1jYi1_C{J^ZIDr)667J<+)bpGvs3{lac Y)N4uq-;n0CK~)-n3(n1n<3PUsAM%kj)&Kwi diff --git a/src/platform/qt/main.cpp b/src/platform/qt/main.cpp deleted file mode 100644 index 735a7b50..00000000 --- a/src/platform/qt/main.cpp +++ /dev/null @@ -1,25 +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 "mainwindow.h" -#include "form_ui.h" - -MainWindow *wnd; - -int main(int argc, char *argv[]) { - // register WidgetInfo to enable invoked() slot - qRegisterMetaType ("WidgetInfo"); - - QApplication a(argc, argv); - MainWindow w; - wnd = &w; - w.show(); - - return a.exec(); -} diff --git a/src/platform/qt/mainwindow.cpp b/src/platform/qt/mainwindow.cpp deleted file mode 100644 index 3e5cbaba..00000000 --- a/src/platform/qt/mainwindow.cpp +++ /dev/null @@ -1,698 +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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "mainwindow.h" -#include "config.h" -#include "sbapp.h" - -const char *aboutText = - "QT Version " VERSION "\n\n" - "Copyright (c) 2002-2012 Chris Warren-Smith. \n" - "Copyright (c) 2000-2006 Nicholas Christopoulos\n\n" - "http://smallbasic.sourceforge.net\n\n" - "SmallBASIC comes with ABSOLUTELY NO WARRANTY.\n" - "This program is free software; you can use it\n" - "redistribute it and/or modify it under the terms of the\n" - "GNU General Public License version 2 as published by\n" "the Free Software Foundation."; - -// post message event ids -const int DeferPathExec = QEvent::registerEventType(); -const int DeferResourceExec = QEvent::registerEventType(); - -// max number of history items -const int MaxHistory = 50; - -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), ui(new Ui::MainWindow) { - ui->setupUi(this); - wnd = this; - out = ui->ansiWidget; - out->setMouseListener(this); - - // setup the fixed layout - fixedLayout = new FixedLayout(out); - - // accept keyboard input - setFocusPolicy(Qt::ClickFocus); - setAcceptDrops(true); - - // setup the URL input widget - textInput = new QLineEdit(); - QCompleter *completer = new QCompleter(this); - QFileSystemModel *fsModel = new QFileSystemModel(completer); - fsModel->setRootPath(""); - fsModel->setNameFilters(QStringList("*.bas")); - completer->setModel(fsModel); - textInput->setCompleter(completer); - ui->toolBar->addWidget(textInput); - ui->toolBar->addAction(ui->actionStart); - - // setup dialogs - logDialog = new QDialog(); - errorUi = new Ui::ErrorConsole(); - errorUi->setupUi(logDialog); - errorUi->plainTextEdit->setReadOnly(true); - - sourceDialog = new QDialog(); - sourceUi = new Ui::SourceDialog(); - sourceUi->setupUi(sourceDialog); - sourceUi->plainTextEdit->setReadOnly(true); - - // setup additional shortcut actions - addAction(ui->focusUrl); - - // connect signals and slots - connect(ui->actionBookmarkProgram, SIGNAL(triggered()), this, SLOT(bookmarkProgram())); - connect(ui->actionExit, SIGNAL(triggered()), this, SLOT(close())); - connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(fileOpen())); - connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(helpAbout())); - connect(ui->actionCopy, SIGNAL(triggered()), ui->ansiWidget, SLOT(copySelection())); - connect(ui->actionFind, SIGNAL(triggered()), ui->ansiWidget, SLOT(findText())); - connect(ui->actionFindAgain, SIGNAL(triggered()), ui->ansiWidget, SLOT(findNextText())); - connect(ui->actionSelectAll, SIGNAL(triggered()), ui->ansiWidget, SLOT(selectAll())); - connect(ui->actionPreferences, SIGNAL(triggered()), this, SLOT(viewPreferences())); - connect(ui->actionHomePage, SIGNAL(triggered()), this, SLOT(helpHomePage())); - connect(ui->actionNewWindow, SIGNAL(triggered()), this, SLOT(newWindow())); - connect(ui->actionRefresh, SIGNAL(triggered()), this, SLOT(runRestart())); - connect(ui->actionBreak, SIGNAL(triggered()), this, SLOT(runBreak())); - connect(ui->actionHome, SIGNAL(triggered()), this, SLOT(runHome())); - connect(ui->actionStart, SIGNAL(triggered()), this, SLOT(runStart())); - connect(ui->actionBack, SIGNAL(triggered()), this, SLOT(historyBackward())); - connect(ui->actionNext, SIGNAL(triggered()), this, SLOT(historyForward())); - connect(textInput, SIGNAL(returnPressed()), this, SLOT(runStart())); - connect(ui->actionViewBookmarks, SIGNAL(triggered()), this, SLOT(viewBookmarks())); - connect(ui->actionProgramSource, SIGNAL(triggered()), this, SLOT(viewProgramSource())); - connect(ui->actionErrorConsole, SIGNAL(triggered()), this, SLOT(viewErrorConsole())); - connect(ui->focusUrl, SIGNAL(triggered()), textInput, SLOT(setFocus())); - connect(ui->focusUrl, SIGNAL(triggered()), textInput, SLOT(selectAll())); - - // setup state - resourceApp = false; - 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_file_permitted = 1; - os_graphics = 1; - - // setup history - ui->actionBack->setEnabled(false); - ui->actionNext->setEnabled(false); - historyIndex = -1; - - ui->statusbar->addWidget(&status); - showStatus(false); - - // restore settings - QCoreApplication::setOrganizationName("SmallBASIC"); - QCoreApplication::setApplicationName("SmallBASIC"); - QCoreApplication::setOrganizationDomain("sourceforge.net"); - - QSettings settings; - settings.beginGroup("MainWindow"); - resize(settings.value("size", size()).toSize()); - move(settings.value("pos", pos()).toPoint()); - settings.endGroup(); -} - -MainWindow::~MainWindow() { - delete ui; -} - -// return whether the break key was pressed -bool MainWindow::isBreakExec() { - return (runMode == break_state || runMode == quit_state || runMode == restart_state); -} - -// return whether a smallbasic program is running -bool MainWindow::isRunning() { - return (runMode == run_state || runMode == modal_state); -} - -// return whether a smallbasic program is running in modal mode -bool MainWindow::isRunModal() { - return (runMode == modal_state); -} - -// set the program modal state -void MainWindow::setRunModal(bool modal) { - if (isRunning()) { - runMode = modal ? modal_state : run_state; - } -} - -// end the program modal state -void MainWindow::endModal() { - if (isRunning()) { - runMode = run_state; - } -} - -// adds widget to the fixed layout and sets parent to this -void MainWindow::addWidget(QWidget *widget) { - fixedLayout->addWidget(widget); - widget->setParent(this); - widget->setFont(out->font()); - widget->move(mapFromGlobal(out->mapToGlobal(widget->pos()))); -} - -// removes the widget from the fixed layout -void MainWindow::removeWidget(QWidget *widget) { - fixedLayout->removeWidget(widget); -} - -// append to the log window -void MainWindow::logWrite(const char *msg) { - QString buffer = errorUi->plainTextEdit->toPlainText(); - buffer.append(msg); - errorUi->plainTextEdit->setPlainText(buffer); -} - -// ensure any running program is terminated upon closing -void MainWindow::closeEvent(QCloseEvent *) { - if (isRunning()) { - brun_break(); - runMode = quit_state; // force exit - } - - QSettings settings; - settings.beginGroup("MainWindow"); - settings.setValue("size", size()); - settings.setValue("pos", pos()); - settings.endGroup(); - - settings.beginGroup("settings"); - bool emptyEnv = settings.value("emptyEnv", true).toBool(); - settings.endGroup(); - - if (emptyEnv) { - // clear the environment - settings.beginGroup("env"); - settings.remove(""); - settings.endGroup(); - } -} - -// handle file drag and drop from a desktop file manager -void MainWindow::dragEnterEvent(QDragEnterEvent *event) { - QString path = dropFile(event->mimeData()); - if (path.length() > 0) { - event->accept(); - } else { - event->ignore(); - } -} - -// handle file drag and drop from a desktop file manager -void MainWindow::dropEvent(QDropEvent *event) { - QString path = dropFile(event->mimeData()); - if (path.length() > 0) { - loadPath(path); - } -} - -// launch home page program -bool MainWindow::event(QEvent *event) { - if (event->type() == QEvent::ShowToParent) { - QStringList args = QCoreApplication::arguments(); - if (args.count() == 2) { - loadPath(args.value(1)); - } else { - runHome(); - } - } else if (event->type() == DeferResourceExec) { - loadResource(deferPath); - } else if (event->type() == DeferPathExec) { - loadPath(deferPath, false); - } - return QMainWindow::event(event); -} - -// adds the current program to the bookmark list -void MainWindow::bookmarkProgram() { - if (programPath.length() > 0 && !programPath.contains("qt_temp")) { - QSettings settings; - - QSet < QString > paths; - int size = settings.beginReadArray("settings"); - for (int i = 0; i < size; i++) { - settings.setArrayIndex(i); - paths << settings.value("path").toString(); - } - paths << programPath; - settings.endArray(); - - settings.beginWriteArray("settings"); - QSetIterator < QString > iter(paths); - int i = 0; - while (iter.hasNext()) { - settings.setArrayIndex(i++); - settings.setValue("path", iter.next()); - } - settings.endArray(); - } -} - -// open a new file system program file -void MainWindow::fileOpen() { - QString path = QFileDialog::getOpenFileName(this, tr("Open Program"), - QString(), - tr("BASIC Files (*.bas)")); - if (QFileInfo(path).isFile() && QString::compare(programPath, path) != 0) { - loadPath(path); - } -} - -// display the about box -void MainWindow::helpAbout() { - QMessageBox::information(this, tr("SmallBASIC"), tr(aboutText), QMessageBox::Ok); -} - -// show our home page -void MainWindow::helpHomePage() { - QDesktopServices::openUrl(QUrl("http://smallbasic.sourceforge.net")); -} - -// run the previous program -void MainWindow::historyBackward() { - if (historyIndex > 0) { - ui->actionNext->setEnabled(true); - historyIndex--; - if (historyIndex == 0) { - ui->actionBack->setEnabled(false); - } - loadPath(history[historyIndex], true, false); - } -} - -// run the next program in the history buffer -void MainWindow::historyForward() { - if (historyIndex != -1 && historyIndex + 1 < history.count()) { - ui->actionBack->setEnabled(true); - historyIndex++; - if (historyIndex + 1 == history.count()) { - ui->actionNext->setEnabled(false); - } - loadPath(history[historyIndex], true, false); - } -} - -// opens a new program window -void MainWindow::newWindow() { - QProcess::startDetached(QCoreApplication::applicationFilePath()); -} - -// program break button handler -void MainWindow::runBreak() { - if (isRunning()) { - runMode = break_state; - brun_break(); - } -} - -// program home button handler -void MainWindow::runHome() { - loadResource(":/bas/home.bas"); -} - -// program restart button handler -void MainWindow::runRestart() { - switch (runMode) { - case init_state: - runStart(); - break; - case run_state: - case modal_state: - runMode = restart_state; - brun_break(); - break; - default: - break; - } -} - -// program start button handler -void MainWindow::runStart() { - loadPath(textInput->text(), false); -} - -// view bookmarks -void MainWindow::viewBookmarks() { - loadResource(":/bas/bookmarks.bas"); -} - -// view the error console -void MainWindow::viewErrorConsole() { - logDialog->show(); - logDialog->raise(); -} - -// view the preferences dialog -void MainWindow::viewPreferences() { - loadResource(":/bas/settings.bas"); -} - -// view the program source code -void MainWindow::viewProgramSource() { - sourceDialog->show(); - sourceDialog->raise(); -} - -// convert mouse press event into a smallbasic mouse press event -void MainWindow::mousePressEvent() { - if (isRunning()) { - keymap_invoke(SB_KEY_MK_PUSH); - } -} - -// convert mouse release event into a smallbasic mouse release event -void MainWindow::mouseReleaseEvent() { - if (isRunning()) { - keymap_invoke(SB_KEY_MK_RELEASE); - } -} - -// convert mouse move event into a smallbasic mouse move event -void MainWindow::mouseMoveEvent(bool down) { - if (isRunning()) { - keymap_invoke(down ? SB_KEY_MK_DRAG : SB_KEY_MK_MOVE); - } -} - -// convert keystrokes into smallbasic key events -void MainWindow::keyPressEvent(QKeyEvent *event) { - if (isRunning()) { - switch (event->key()) { - case Qt::Key_Tab: - dev_pushkey(SB_KEY_TAB); - break; - case Qt::Key_Home: - dev_pushkey(SB_KEY_KP_HOME); - break; - case Qt::Key_End: - dev_pushkey(SB_KEY_END); - break; - case Qt::Key_Insert: - dev_pushkey(SB_KEY_INSERT); - break; - case Qt::Key_Menu: - dev_pushkey(SB_KEY_MENU); - break; - case Qt::Key_multiply: - dev_pushkey(SB_KEY_KP_MUL); - break; - case Qt::Key_Plus: - dev_pushkey(SB_KEY_KP_PLUS); - break; - case Qt::Key_Minus: - dev_pushkey(SB_KEY_KP_MINUS); - break; - case Qt::Key_Slash: - dev_pushkey(SB_KEY_KP_DIV); - break; - case Qt::Key_F1: - dev_pushkey(SB_KEY_F(1)); - break; - case Qt::Key_F2: - dev_pushkey(SB_KEY_F(2)); - break; - case Qt::Key_F3: - dev_pushkey(SB_KEY_F(3)); - break; - case Qt::Key_F4: - dev_pushkey(SB_KEY_F(4)); - break; - case Qt::Key_F5: - dev_pushkey(SB_KEY_F(5)); - break; - case Qt::Key_F6: - dev_pushkey(SB_KEY_F(6)); - break; - case Qt::Key_F7: - dev_pushkey(SB_KEY_F(7)); - break; - case Qt::Key_F8: - dev_pushkey(SB_KEY_F(8)); - break; - case Qt::Key_F9: - dev_pushkey(SB_KEY_F(9)); - break; - case Qt::Key_F10: - dev_pushkey(SB_KEY_F(10)); - break; - case Qt::Key_F11: - dev_pushkey(SB_KEY_F(11)); - break; - case Qt::Key_F12: - dev_pushkey(SB_KEY_F(12)); - break; - case Qt::Key_PageUp: - dev_pushkey(SB_KEY_PGUP); - break; - case Qt::Key_PageDown: - dev_pushkey(SB_KEY_PGDN); - break; - case Qt::Key_Up: - dev_pushkey(SB_KEY_UP); - break; - case Qt::Key_Down: - dev_pushkey(SB_KEY_DN); - break; - case Qt::Key_Left: - dev_pushkey(SB_KEY_LEFT); - break; - case Qt::Key_Right: - dev_pushkey(SB_KEY_RIGHT); - break; - case Qt::Key_Backspace: - case Qt::Key_Delete: - dev_pushkey(SB_KEY_BACKSPACE); - break; - case Qt::Key_Return: - dev_pushkey(13); - break; - case Qt::Key_B: - if (event->modifiers() & Qt::ControlModifier) { - runBreak(); - break; - } - dev_pushkey(event->key()); - break; - - default: - dev_pushkey(event->key()); - break; - } - } - QMainWindow::keyPressEvent(event); -} - -// main basic program loop -void MainWindow::basicMain(QString path) { - programPath = path; - - opt_pref_width = 0; - opt_pref_height = 0; - bool success = false; - - do { - runMode = run_state; - showStatus(false); - - // start in the directory of the bas program - QString path = programPath.replace("\\", "/"); - int index = path.lastIndexOf("/"); - if (index != -1) { - if (!chdir(path.left(index).toUtf8().data())) { - path = path.right(path.length() - index - 1); - } - } - success = sbasic_main(path.toUtf8().data()); - } - while (runMode == restart_state); - - if (runMode == quit_state) { - exit(0); - } else { - runMode = init_state; - showStatus(!success); - } -} - -// whether the program start is deferred until the current program has stopped -bool MainWindow::deferExec(QString path, int event) { - bool result = isRunning(); - if (result) { - runBreak(); - deferPath = path; - QCoreApplication::postEvent(this, new QEvent((enum QEvent::Type)event), - Qt::LowEventPriority); - } - return result; -} - -// return any new .bas program filename from mimeData -QString MainWindow::dropFile(const QMimeData *mimeData) { - QString result; - if (mimeData->hasText()) { - QString path = mimeData->text().trimmed(); - if (path.startsWith("file://")) { - path = path.remove(0, 7); - } - if (QFileInfo(path).isFile() && - path.endsWith(".bas") && QString::compare(path, this->programPath) != 0) { - result = path; - } - } - return result; -} - -// loads and runs a resource program -void MainWindow::loadResource(QString path) { - if (!deferExec(path, DeferResourceExec)) { - QSettings settings; - QString homePath; - - settings.beginGroup("settings"); - homePath = settings.value(path).toString(); - settings.endGroup(); - resourceApp = true; - - if (!homePath.length()) { - // show the default home page - QTemporaryFile tmpFile; - QFile file(path); - - if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { - tmpFile.open(); - tmpFile.write(file.readAll()); - tmpFile.close(); - file.close(); - } - - homePath = tmpFile.fileName(); - loadPath(homePath, false, false); - } else { - loadPath(homePath, true, false); - } - } - resourceApp = false; -} - -// resolve the path to a local file then call basicMain -void MainWindow::loadPath(QString path, bool showPath, bool setHistory) { - bool httpPath = path.startsWith("http://") || path.startsWith("www."); - - if (!httpPath) { - int delim = path.indexOf("?"); - if (delim != -1) { - // extract web arguments - QString args = path.right(path.length() - delim - 1); - strcpy(opt_command, args.toUtf8().data()); - path = path.left(delim); - } - } - - QFileInfo pathInfo(path); - path = pathInfo.canonicalFilePath(); - - if (showPath) { - textInput->setText(path); - } - - if (!deferExec(path, DeferPathExec)) { - if (httpPath) { - updateHistory(path, setHistory); - new HttpFile(this, path); - } else if (pathInfo.isFile()) { - // populate the source view window - QFile file(path); - if (file.open(QFile::ReadOnly)) { - QTextStream stream(&file); - sourceUi->plainTextEdit->setPlainText(stream.readAll()); - } - - setFocus(); - updateHistory(path, setHistory); - basicMain(path); - } else if (pathInfo.isDir()) { - strcpy(opt_command, path.toUtf8().data()); - updateHistory(path, setHistory); - loadResource(":/bas/list.bas"); - } else { - status.setText(tr("File not found")); - } - } -} - -// called from HttpFile when a loading error occurs -void MainWindow::loadError(QString message) { - out->print(message.toUtf8().data()); -} - -// display the status depending on the current state -void MainWindow::showStatus(bool error) { - if (error) { - status.setText(gsb_last_errmsg); - } else { - switch (runMode) { - case init_state: - status.setText("Stopped"); - break; - case run_state: - status.setText("Running"); - break; - default: - break; - } - } -} - -// set or append to history -void MainWindow::updateHistory(QString path, bool setHistory) { - if (setHistory) { - if (historyIndex == -1 || history[historyIndex] != path) { - if (history.size() == MaxHistory) { - history.removeFirst(); - if (historyIndex == history.size()) { - historyIndex--; - ui->actionNext->setEnabled(false); - } - } - - history.append(path); - historyIndex++; - } - - if (historyIndex > 0) { - ui->actionBack->setEnabled(true); - } - } -} diff --git a/src/platform/qt/mainwindow.h b/src/platform/qt/mainwindow.h deleted file mode 100644 index 29b5d8c5..00000000 --- a/src/platform/qt/mainwindow.h +++ /dev/null @@ -1,120 +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 -// - -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include -#include -#include -#include - -#include "ansiwidget.h" -#include "httpfile.h" -#include "fixedlayout.h" -#include "ui_console_view.h" -#include "ui_mainwindow.h" -#include "ui_source_view.h" - -namespace Ui { - class MainWindow; -} - -#define C_LINKAGE_BEGIN extern "C" { -#define C_LINKAGE_END } -extern "C" void trace(const char *format, ...); - -enum ExecState { - init_state, - run_state, - restart_state, - modal_state, - break_state, - quit_state -}; - -struct MainWindow; -extern MainWindow *wnd; - -class MainWindow : public QMainWindow, AnsiWidgetListener, HttpFileListener { - Q_OBJECT - -public: - explicit MainWindow(QWidget *parent = 0); - ~MainWindow(); - - AnsiWidget *out; - - bool isBreakExec(); - bool isResourceApp() { return resourceApp; } - bool isRunning(); - bool isRunModal(); - void logWrite(const char *msg); - void setRunModal(bool modal); - void addWidget(QWidget *widget); - void removeWidget(QWidget *widget); - -public slots: - void bookmarkProgram(); - void endModal(); - void fileOpen(); - void helpAbout(); - void helpHomePage(); - void historyBackward(); - void historyForward(); - void newWindow(); - void runBreak(); - void runHome(); - void runRestart(); - void runStart(); - void viewBookmarks(); - void viewErrorConsole(); - void viewPreferences(); - void viewProgramSource(); - -private: - // private inherited events - void mouseMoveEvent(bool down); - void mousePressEvent(); - void mouseReleaseEvent(); - - void closeEvent(QCloseEvent *event); - void dragEnterEvent(QDragEnterEvent *event); - void dropEvent(QDropEvent *event); - bool event(QEvent *event); - void keyPressEvent(QKeyEvent *event); - - // private methods - void basicMain(QString path); - bool deferExec(QString path, int message); - QString dropFile(const QMimeData *mimeData); - void loadResource(QString path); - void loadPath(QString path, bool showPath = true, bool setHistory = true); - void loadError(QString message); - void showStatus(bool error); - void updateHistory(QString path, bool setHistory); - - // private state variables - Ui::MainWindow *ui; - Ui::ErrorConsole *errorUi; - Ui::SourceDialog *sourceUi; - - FixedLayout *fixedLayout; // for positioning child widgets - QDialog *logDialog; // log window widget - QDialog *sourceDialog; // source dialog widget - QLineEdit *textInput; // text input control - QString programPath; // path to the current program - QString deferPath; // path to the deferred program - QList history; // history buffer - int historyIndex; // history index - ExecState runMode; // current run state - QLabel status; // the status bar widget - bool resourceApp; // permission to use settings -}; - -#endif // MAINWINDOW_H diff --git a/src/platform/qt/mainwindow.ui b/src/platform/qt/mainwindow.ui deleted file mode 100644 index d951b209..00000000 --- a/src/platform/qt/mainwindow.ui +++ /dev/null @@ -1,310 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 707 - 608 - - - - SmallBASIC - - - - :/images/smallbasic.png:/images/smallbasic.png - - - - - 0 - 0 - - - - - 250 - 250 - - - - - 16777215 - 16777215 - - - - - 1 - - - - - - - - - - 0 - 0 - 707 - 23 - - - - - &File - - - - - - - - - &Help - - - - - - - - &View - - - - - - - - - - - - - - - - &Bookmarks - - - - - - - - - - - - - toolBar - - - Qt::BottomToolBarArea|Qt::TopToolBarArea - - - false - - - TopToolBarArea - - - false - - - - - - - - - - - - &Exit - - - - - &Open File... - - - - - &About SmallBASIC - - - - - &Copy - - - - - &Find - - - - - Find &Again - - - - - Select &All - - - Ctrl+A - - - - - Prefere&nces - - - - - &Home page - - - - - - :/images/stop.png:/images/stop.png - - - Break - - - Halt current program - - - Ctrl+C - - - - - - :/images/refresh.png:/images/refresh.png - - - refresh - - - Reload current program - - - - - Program &Source - - - - - Error &Console - - - - - Bookmark This Program - - - - - &New Window - - - Ctrl+N - - - - - &View &Bookmarks - - - - - - :/images/home.png:/images/home.png - - - home - - - Run the home program - - - Ctrl+H - - - - - - :/images/jump.png:/images/jump.png - - - start - - - Start the entered program - - - F5 - - - - - - :/images/previous.png:/images/previous.png - - - back - - - Go back - - - Alt+Left - - - - - - :/images/next.png:/images/next.png - - - next - - - Go forward - - - Alt+Right - - - - - focusUrl - - - Alt+D - - - - - - AnsiWidget - QWidget -
ansiwidget.h
-
-
- - - - -
diff --git a/src/platform/qt/res/bookmarks.bas b/src/platform/qt/res/bookmarks.bas deleted file mode 100644 index 85905b55..00000000 --- a/src/platform/qt/res/bookmarks.bas +++ /dev/null @@ -1,2 +0,0 @@ -# process bookmarks -print "Bookmarks" diff --git a/src/platform/qt/res/home.bas b/src/platform/qt/res/home.bas deleted file mode 100644 index 3112d7c9..00000000 --- a/src/platform/qt/res/home.bas +++ /dev/null @@ -1,2 +0,0 @@ -# home page -print "Welcome to SmallBASIC" diff --git a/src/platform/qt/res/home.png b/src/platform/qt/res/home.png deleted file mode 100644 index 4e4786a01d4633da6b10f842858726ab9a9b1f68..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1364 zcmZ{kdr;C@6vr=RMy7>kVuh>rQp^V^85x!jNF+5S&7uV#sHy7%@>!Xhn@Z_qjh6Ws zoXrJR4Ot)L_$({67KI31bT!w}6ho6;8#Bdhf9-$!$9`wd{meOczUQ8~bLZal_wzE) z+pPxxFz_Z5sSr)S1zZL$L(sYC?&}UfL($f?uuV`7OQL#tfO;wFJ(O55$y8qe zt{em)`vw53P$_#BfD{Y>>QDe&9sq!3Rkj5Xpbg#dQ(i=fkXAg~vmk6?kL%P+yMy=t z6n;H4A0AXQXir8)8aAM*{w8Y%W27v%c8-nZ{v%W*+L%P)86Tz^w?+n_w^2~a-s^#u zpZXv8Fr1dzZ7h_L3Z{NYElPGylU8cj($1$}T}zhHJRZc^J~zbLm9ELdOhKC{rn}-&DjfkSMxYsAt52Bt%}V|&CS0q>m9VR3LAZV zd10(odzbt!K}-{hgu-|MwMLyxL16n0Qreb*%rGQ=Z|jOQ=5k zdz2n7m&@=~>}_glDv(Dv3+w9U3QHEz%s4!18lw=+}<8Ett37}oG(%0-M$8e6GsnQRz_ zI$Wrza1xB3z7Q;8^i1^??J;pp{|h9JcVLTO-7XB9^@MJXL8IC574I2zC9^NS9FZfF z$s8Vw#p0CI)P*KVEe%e{_>2(K?8e8(xpLfx`YF60kGfI^DOk~bu6QY63$Dc0!9f%U ziBv7;(-nDP!|D&CE!}u6F`z^gE2hOqMa`5(IF6XXb;1j=9fz(}xx)>8cvN#+TU$a^ zRaMAD<+8TxM0(Q1!JJzUe+jPtp6x(y!v)j?W)=|la%*ctFuiWXM5XV@6PC_~XxVNX ziZ%2syiT6X>|#b?8-NAY-$1t^nDXUe88?F1stSnJ0!jh5oMeq3~bSqO8(nCk2N z*d01YFuF+;`db&8=;eBYtc`9>FGsw|=$d=3hVuFOd67b)$U+!WYX2woMv=?>LV_OVgMb=7XkuAN&=k&P|{2Oa2WN$|3GpwV#6(tUFg zn{{6u6`T?H4KF@3Z<$f$g24+ZULMZkEigW zH16GfFzZr@YZ`sIJ)Mx5D)5)%28?o$yO=CGvY?{T=c*i;IhcomZDX zIrVnKVHlX{RVe|OWb-%cW)rt|8{p2;C!Q2$0j!|Q%-H3N0QyW0B$Li1M}#Fux-c(A zLI92!EXEFlx5GLIVx3$Z@h&*bA&jF71~d7FYWN>Rd}2gQ)aCy-6c?$5kO6p;{D}1) Hp*jBm_846$ diff --git a/src/platform/qt/res/jump.png b/src/platform/qt/res/jump.png deleted file mode 100644 index 1d026ad16bfa129890c59ee28eb9a3c852472525..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1567 zcmZ{kYgp2E6vuz$4Q&~ZIn?G1%S=iU1qlfX5k>Jb`$s8FOGPx(ydY#3Cp<|PE5|a@ zmUwGkayk>8rX{e8X-&;dO)E1sGo(^uF7K=T+q=Ekd7g7V&pGG$KIgnR&&du6X00(> zZw3HZ0Hn7Bt|*`d*lsHRjA*o0e3ex2KaynF7^ zhNcElf&GW1PH%kt(WdroZK0bTQR{x)4yvN%2UG z7|hFw`tr`RXYZ$HWNQ;jOD->t`UeZrdS=ph&KJ$nOcsiBoUN?w)-!^RtbwX_1?6|{ z4Zsf5B@Z!%Z2MBVA{Syt;Ig{A&ni__e7;0=^Nr6*){g1!k!|lzs7{I^#963%8@dso zi7$Fpd6xH!s`~R4v)kmo7YiGe$2(t6AXF;VBaL{Mudi>BThOd`PH(=~Ieqfx5H^=x zb>P9>`+E<}yhs$H@1)PX-!aUCXRU2era9rIH|w+utrV=JNBwf!~Kx-xm~{^|O0 zGNX^k#%>NVTQDhs4)2T`x@l9fxF;=*Fj+)98M1fpg#K#LKKr(<9jT*abFx;}j9Rrl zdAQYsOkUt^y;5&Qup!ZC9zE836ls>j)s~Q2oiK>Ar3jHvve#`H)gOCBN_x6bTM?g7 zCXc+B{nztoTtWArr-qtbTsm)OtSsnD_*~E8p33y}`M+$=MD62nIN0)YmKF@QAC@T= zi@%77_`FYM>v>AA*RL<EnKp#fE+#TB> zhc*Bdqlri)3b$DJ?{+{1A^#X27?^vk>#Hml+!;2RaeX@TM9J$|eI`obAgxJlHdu8k z9G8DB$Cn^QO%@gwS{GXvpVY~$#?M4?Uh+eYOBTm$ox3G`F5&0Mw=Opam({527Ia#< z&{dluQgZrq!b6df7-iDb{z;b1&WM+oboj)QZ%NIYct&1CU5Q-%{p%+Pdub@PJRCPz zpqORh{IEXG=;ch3g);gNCnw$~0P^APc*(E6wKc<=%jJF!HlCKs12B3+B(LjRg@T$s_RHxxwfcSA~cfpfg+(;ZZ0>#6P;z8VocchvvlzH4}^O#HblE*Ac(_J^K zxN(cPgrUOXBsE2obZ`xkTzSg1-Cy^=`^Wv9^ZC5a=kq!5^L?N1AD=9$rz>1jUlRZT zcO$vbAR@mdOarPP66{wXYzQGx2mn0D*ZMn99qLu$Xs*tny4PR|YK#~p8U+B}J^<1( z0Qd@x(k21mU;vm7004g#fF03-N5|}-g~nO3s|!RZR*y8LLf8~d@{5C>e)BC=3Zl4z zZ^QU#LI}ivjezqWqT7&%RyP-dH>s=6hY+#V2dS8N?vW5YP}kI7A4skmj81dXce{(C znj0h1DBUWQ926=yYX{%vY7rS)`zXYSo6g(FLlG#^Y(3eJ zQ*xk;yYT+{vK_l*yNqZ(?{#|OvvMI>nWR*zhNguY2?WI!lE>}vII}&f+ zc|8C0%hvc=UKqN49+5Zpx$sE?dy1BfGf-sc)=Z6rT8NtWWSqw$wH0_gKD)EC6P+Gv zoh=qScz97*CT0hfw1GtnB~wW2zH~$05?MOo&0@{!5zd`6yZkJuK`a)(uAd!HY<5!< z`g*O3mGk}MU^QD>LCX$fv+%+Z5{b*_`gP~9&Z-RdX|5tuZ00t>(UF-AUKO&nX zchubL;cz%cO$l>Hx!gvUx@xX??k6Ne*ZCf=L08DHsSSCtqz#AX9&;DzstOi1y26g_ z6GaR*#u@7v+QC{H8+X>TPO#oJ%CF_V2LZ3N=?hn2}dkSC3cy@JFPrjZI5k%KBHiiW6*ev_V() z(OZ{#+4K_(fqmL5c$w--PmMX%UF(4K0b>r^xf;=@bLwTNb@w6HJdiimw$MyW53*|f zfXgGpHkpZ>U~f~V`zvl`6uf@(Y>OaubC%2PiBIpV>RC;1F*zqxPI6UWEPO)iWvK&< zOeTvS>&$IrtC!#wS)%F8y9jP0jJ?Sd59tUvPnz zeXjJ)89IG^IB(bC_ZW)QfBO9DbLxi_APmz-GPGI|h}8E(L*I=wbFm<8ya)vIcsyBZ zQ_A`tk@o>kM|;O;ZNZaF-DrAAeqJtz9Uq@EJUl%6C%-+`*sXJLcTrJM1$Do-ufM-P z0cKfz_+ej+fm|VxNT%ZG^xeT$*M??iXAusI$9}VNpPE@&Sz&d>WHSBGL?RId9?_;z z)RAR^$>QbOXAdr1==r70F;yXruua5<^rELUN&0}gEz9NfyZeDpmb$yUDTSo+=DT+# zszS*5H8u}#iH)-`%wJ|&T|tQ>KyuTC?i!j+Jjo6UWHa%MSSAEug|Wm~U~m?ew%(Rl syp1K^#>Na|g~wnjB98?AN5F~-3Jd1`zhDr%HVg@X8`0CH+BqQoA2BJKN&o-= diff --git a/src/platform/qt/res/previous.png b/src/platform/qt/res/previous.png deleted file mode 100644 index 79f5a4207d9391073ebbb1c35bc6ce73fe9a9a1a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1515 zcmZ{kdotf7dQlfhA~yK$R@2}>Dw zWgJXda;eD@O==8E<>cF47TS9=t1VZ%V{h`C^k=Zr$X2r6*3{~iJoTx)8f8%CY54&IKBJG^(Iz0U04dA&huiYDKuJJeAI^!@1yo*pvD=1;mv zyWE&pUBlgeNx`&unf}xRT$(kP)gGnVEANTY1hk>es8EkF<*SQROhQ zK*vT!iDAKX^^7fm!+CPHvY zwq#dkON%I+3Rf|mU3uAtP#14fM;E?1(-#`k71G0CFsVB+%DNKA-}mu4`FH|r$IQ+y z+kTc8(*0r?heBYDm0!JE+wAq-Pb$}^X^jfR@``tWQN`~x1sFFm)vBC~KchP}*1X)3 z8WCYMFM6;w`!KDM&C(3&@Rw46?HJsA8RR~2UX#s_+WL^kOaw?Nw5_dx)!0Zb))_vt z^oNbgjT<*qi$`l*^05`tTC|cj<7E@Ki3~M0HKYbQPIhu~lFeFPMGXcP;`dK>l1plx zGBYx+_4M>yEyPE?vhtZYU}wio3>NfWO;~;Fq<_Sn!I_;6{!J&(TEFJ!AN&l9l6eBb zj#ofHKoW(rChY3!+NLRxI-cBeuVaOmmDOc^>`D+-cN1T*+GCfV8_@da&T?__ic|_W zq=hHo^ZA0nzLXv~XIm%~u5dV;W?xjTze~Rc2c8C+YY=i&=E-)~IEPwh=VqWw$ zKfFxUDgQM_R=-uuxHk%!?s5$GN4QLy5|hcaH8eD|10Lg&+Qvq2a&;DqvPajt1`m-L?hTDk}c=2ErjwHxu_G_wTv~>0MetUA!&D6+CLgB51EM&;` z`}eIqy}TqB)=MXb7Gm3!l#~t=nl?JL-HbxRO3z**P1L#-6yjU2_r&e>J8@|Bc149% z*o6yP2NGN|FjeJnIDD@Ucl~puMG})h=$+^!cRlxETj%V{8N^hLJ*}@d;MzP}GoV${ za>wW<0av~V`LFIZG#E~;1^K<)jmaHdpg&4Y@9T+Qp5n9FXh8Ko1}j-yUfvRNZ`p3s zNup$3s})jBrBymv#lm!Ytu)MB^S}6RbJHCWK{^G)!`a!{3!fMAohft@Kj$ZAL2dXn zo8?>Iu%shp{vMW$^B6=JkB$t!5s9j*syfxIqmm&{?MQHLS4PP@TY{rkPE_#YkE-ZM)i-fcNVt#;exAw8Rj^K6g<418H9 zIZ2r#2@JrOwrlqy9OdGa1#Ni4sr*z4Q{#DN+R;g6=#SHl!}-O965~kdkXRA~V2(0F znV^oFm|1z7S)eV=(3X})D04IlRUdVV_#Xi|IyC%3;{OYH7F&Es0Gx2{SQaMu+CLGB Bt*`(9 diff --git a/src/platform/qt/res/refresh.png b/src/platform/qt/res/refresh.png deleted file mode 100644 index 4fb7ac3353b774ebbc77df6983aec6ebb405bcff..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1714 zcmZ{kcU03^7RO&0BV`Z*;u?yMxWa<8fFXonXof?GGy@SMOAUyWK!6Mkih^!7fM7r- zD@9-c4Gw*zgaK(vCxj|Q$b_a6q=?AOs1%u>```Yt-*fK!oO|E-p8L*u_uMphSI0vN z8VUe_Lrz2j86xs)$Q^{v`FQ*%2nRy!T5mwnH(i3H))GG4jD7r%9GcsX{M9H=$uHDH^?FI3Vb55kN;;TPGEk)_r?EvJzKNsybX;r+!+Y`;T zA0d-zIN^PAFOPeag>XdD=oJ;0d%I8F@7Nx!mv=2XoA$@5=+$^n`sBOTRuc;4#^K~u zOUf@SM4zS9>a4Gu-|5sel#{5phzZ zEqZmPv9e=*wr$6&3sqHGT1q{h+4pyzXAF_VEtvp za;J0|*vi3Z89vQ1Z$@Z+oWfrj3(t9;r;orJv{2Uh-~i)0uV*K;R;Q}FS`)T@-`n{plGkP$ACLputhM!Zd|SAv=GZOU`K7Ukjz?Ep+Oc`g zMFAP6+TAC8L;@sDIf|@`=nvHHwrXr_EPP-Q#eP^)0+S9G8eC8dR_Cc@^qFGA1dSCHd7GuRnjF^W00V)@iAe&97Jx(Tv}&f+m{MVO1Y{e{g)YM+y`y-;WWeI z(EN_hRiUCQuF$xci>q%8%5ZUUc8=Rlw9Y{+(tC4bw{u4x$O9n#Etq<-Xl`Q!kz3}Z z$Lm*R3^$8b&6z$QPgMuq6R+Pq?VgmB)KFU+Ra{pWV@IVOYWz-D@?E$>lHB#ZAf>3yY*4q~?&&iAPpuvs20r z%F33Y_eNQjUbURrjwGA=E`b@A6o(tJQ&rU8*QV=37B@eA(~GQ&6l31awuz@FC%@mF zpo`ZQ7Z+p1{17=^UERnAegmh8&$q`*;xyO+{hzm_Ci!PVT!llUL{kf-qOT=m-gbv; zsdL0(z>P;{Mno9SipAHLUX**xt+dSgX)4|<3!Rx+i_b8{V6mTQ-rnBQ<>h5(S*sjF zD!D28RWJT#$9|7`;k~-KhN_WsCGKt~@97Bz0)xPeJnp#n0}P$yMWN8g(Cdfo`-d1B z>`kxm@bJCiLaW-^%Z;bc{Sv?7i^gDvt1BzT#}yCGiO?bybRbO6ZVvl9& z>&p6T*B}0^ndB@74N>`3^o*8LN<0RG;jrvWQo?Zb+vI#Cq)D_;y7gJ6q9V**PR_U! z?!{6w)@FGy>{wY@W*#301_m|-IVSt#-qQ+w56eB&=_VHqLy!mc zK{SvD9-zA(6gg&vlU&<>m)`ZDjnVoTHRqHSvE-`}wn87$&OfUpshB8GN zp|D1#7*EqPICE2+ImQ5GhC`up+0@xeLa!wJf5Thxf-PhKP7bbw8hiiSe*x>R B7OnsQ diff --git a/src/platform/qt/res/settings.bas b/src/platform/qt/res/settings.bas deleted file mode 100644 index ea6b0859..00000000 --- a/src/platform/qt/res/settings.bas +++ /dev/null @@ -1,3 +0,0 @@ -# settings dialog -print "Settings" - diff --git a/src/platform/qt/res/stop.png b/src/platform/qt/res/stop.png deleted file mode 100644 index bf0ce0119d010af986d7e34a575b157f4803276f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1796 zcmZ{kdpr|*AIE=j%nVslF3(XZsq>0s8`hqsa$95NHWWj~h-pG$ZineiisgREJvw+9 zEh^=b+rzV+%E)mJN1NNDafTV`JjZJ0SZC90r;$JG5!D`9s$4#836190Q6(3x;<@`14zh4ypxj3kU93GE1?nN>~~AKdh)CG zZH-8c_Txr5zv%jx z1(LEa_GGT#nBmW?^CUB8=v;MzY6;_9V&QAsk@8*3TQ`@^t8ScE?-qneEqn7lQ62#S zRXND-?VzGj^DqO7C(e^-%d?_)eCgkloRVTv^g5={v`fuC@y=rBiG2U7WM4f7j5}=`(4uwMt z5km%3Sq^nE>FK+7O~mIo^lqLnJ5>; zVU6crMhD%2s~pPX9m`g^ro|w>k*B58{r&wXN={u#L+OE%CqH{6w|Y_eQ%eyss+!&b-ca3t?$N5fz+qH}3j1dW#3%Hgd4bTa#ws)Hj$f`5EqG^sb)#-@^=<7!r9bpL|o z`umO?i-67zn@8inGvQB1sLk6!Md^==VGZX-BRf<~hTWh@Y6aw_cD+V7CpwhXt32h; zP?XHy+Q>NH^q#qI+x!7mtd+?yihg+fZY-(#h2P`L^8o1K1}hrt&Y0e2voU(G12x!q zg0L-E^)ZLjxS426CzHv+*lP4X2l9GfYpEK}6T{ln9{BL#!}I!+D?%q9pXNEKG%_k` zXKnc2{^p7bqgS_<-Rvixizg>1pLF;1^t(3@r@QiL=$1E6s|cpLr{7z{p-y3bxv<;w zWETG_e_>&Plbf4cN=9s_Or%JIah_L~ldgVD?v+0Af4MF!IEE)_n6%NRpO)00gt3r- zNhW!k-O0Lh0>Nc0^DEV}>z%kfs-40kajy2he;L0jNX?k&+6QJE zinFl|jX$dEpgBSPiseW6JXGM6pQ|h1>$J(HuRL{meDv;HkxC6*1=zu}Mns&Cq#p;# zM#jcF;*Eu&`xFXgr}A|4((;&P(gYc?MrMgT2!AJthl-J_Y@e3V8r!6g>^W)wQXDqN zw8^`U&9=p0wl@a`1`awKaLF?4w9rP*5Ncq7LkJ4~1!JwyY(5 z33)W$IZQ)a{wpa>m10ikjPvbEbsY%DUD&6~FV#d?Cog;wPgo3+Ve7b zYpAKN%QWr97xRN}i8afIn~Gs{cx@&a&?Sg>rk(`t_BJ&w?~-uZ|~zwmo*u;}LPn z*Kok_KKEND+{-7PP%84kR`;oZDR4v$thpVf@AwD{DFDPm-T($*V6EnC6p-_8^UBP> z;VG2Q|9BkEH!d_dE(}Y#8Kwk4A&>|Q1jYi1_C{J^ZIDr)667J<+)bpGvs3{lac Y)N4uq-;n0CK~)-n3(n1n<3PUsAM%kj)&Kwi diff --git a/src/platform/qt/sbasic.pro b/src/platform/qt/sbasic.pro deleted file mode 100644 index e3732662..00000000 --- a/src/platform/qt/sbasic.pro +++ /dev/null @@ -1,40 +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 -# - -CONFIG += qt debug - -QT += core gui network - -TARGET = sbasicb - -TEMPLATE = app - -FORMS = mainwindow.ui \ - source_view.ui \ - console_view.ui - -SOURCES += main.cpp \ - mainwindow.cpp \ - ansiwidget.cpp \ - dev_qt.cpp \ - form_ui.cpp \ - httpfile.cpp \ - fixedlayout.cpp - -HEADERS += mainwindow.h \ - ansiwidget.h \ - form_ui.h \ - httpfile.h \ - fixedlayout.h - -INCLUDEPATH += ../../common ../.. ../../.. - -LIBS += -L../../common -lsb_common - -RESOURCES += sbasic.qrc diff --git a/src/platform/qt/sbasic.qrc b/src/platform/qt/sbasic.qrc deleted file mode 100644 index fb77f6be..00000000 --- a/src/platform/qt/sbasic.qrc +++ /dev/null @@ -1,15 +0,0 @@ - - - bas/bookmarks.bas - bas/home.bas - bas/settings.bas - bas/list.bas - images/home.png - images/jump.png - images/next.png - images/previous.png - images/refresh.png - images/stop.png - ../../../images/sb-desktop-64x64.png - - diff --git a/src/platform/qt/source_view.ui b/src/platform/qt/source_view.ui deleted file mode 100644 index 5705b84b..00000000 --- a/src/platform/qt/source_view.ui +++ /dev/null @@ -1,40 +0,0 @@ - - - SourceDialog - - - - 0 - 0 - 587 - 514 - - - - SmallBASIC - Program Source - - - - :/images/smallbasic.png:/images/smallbasic.png - - - - 0 - - - 0 - - - - - - - - - - - - - - - From 37ea8b000736b12c73d158862d36d1279c87bf8e Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Sat, 16 Aug 2014 17:44:12 +1000 Subject: [PATCH 03/21] COMMON: code clean, hotspot fixes --- .../tests/output/short-circuit.out | 2 + src/common/eval.c | 1773 +++++++++-------- src/common/smbas.h | 140 +- src/common/var.c | 56 +- src/common/var.h | 24 - src/common/var_hash.h | 8 + src/common/var_uds.h | 8 + src/platform/unix/Makefile.am | 2 +- 8 files changed, 1014 insertions(+), 999 deletions(-) create mode 100644 samples/distro-examples/tests/output/short-circuit.out diff --git a/samples/distro-examples/tests/output/short-circuit.out b/samples/distro-examples/tests/output/short-circuit.out new file mode 100644 index 00000000..5d56218f --- /dev/null +++ b/samples/distro-examples/tests/output/short-circuit.out @@ -0,0 +1,2 @@ +start of test +end of test diff --git a/src/common/eval.c b/src/common/eval.c index b08ea8e7..8af3f552 100644 --- a/src/common/eval.c +++ b/src/common/eval.c @@ -19,21 +19,11 @@ #define IP prog_ip #define CODE(x) prog_source[(x)] #define CODE_PEEK() CODE(IP) -#define V_FREE(v) \ - if ((v) && ((v)->type == V_STR || (v)->type == V_ARRAY)) { \ - v_free((v)); \ +#define V_FREE(v) \ + if ((v) && ((v)->type == V_STR || (v)->type == V_ARRAY)) { \ + v_free((v)); \ } -void eval(var_t *result); -void mat_op1(var_t *l, int op, var_num_t n); -void mat_antithetos(var_t *v); -void mat_mulN(var_t *v, var_num_t N); -void mat_op2(var_t *l, var_t *r, int op); -void mat_add(var_t *l, var_t *r); -void mat_sub(var_t *l, var_t *r); -void mat_mul(var_t *l, var_t *r); -int v_wc_match(var_t* vwc, var_t *v); - /** * matrix: convert var_t to double[r][c] */ @@ -124,7 +114,6 @@ void mat_op1(var_t *l, int op, var_num_t n) { } } - // / mat_tov(l, m, lr, lc, 1); tmp_free(m1); tmp_free(m); @@ -139,7 +128,7 @@ void mat_antithetos(var_t *v) { } /** - * M = οΏ½A + * M = A */ void mat_mulN(var_t *v, var_num_t N) { mat_op1(v, '*', N); @@ -175,7 +164,6 @@ void mat_op2(var_t *l, var_t *r, int op) { } } - // / tmp_free(m1); tmp_free(m2); if (m) { @@ -285,26 +273,853 @@ int v_wc_match(var_t *vwc, var_t *v) { return ri; } +static inline void oper_add(var_t *r, var_t *left, byte op) { + if (r->type == V_INT && v_is_type(left, V_INT)) { + if (op == '+') { + r->v.i += left->v.i; + } else { + r->v.i = left->v.i - r->v.i; + } + } else if (r->type == V_NUM && v_is_type(left, V_NUM)) { + r->type = V_NUM; + if (op == '+') { + r->v.n += left->v.n; + } else { + r->v.n = left->v.n - r->v.n; + } + } else if (r->type == V_INT && v_is_type(left, V_NUM)) { + r->type = V_NUM; + if (op == '+') { + r->v.n = r->v.i + left->v.n; + } else { + r->v.n = left->v.n - r->v.i; + } + } else if (r->type == V_NUM && v_is_type(left, V_INT)) { + if (op == '+') { + r->v.n += left->v.i; + } else { + r->v.n = left->v.i - r->v.n; + } + } else { + if (r->type == V_ARRAY || v_is_type(left, V_ARRAY)) { + // arrays + if (r->type == V_ARRAY && v_is_type(left, V_ARRAY)) { + if (op == '+') { + mat_add(r, left); + } else { + mat_sub(r, left); + } + } else { + err_matop(); + } + } else { + // not array + var_t vtmp; + v_init(&vtmp); + switch (op) { + case '+': + v_add(&vtmp, left, r); + break; + case '-': + if (vtmp.type == V_NUM) { + vtmp.type = V_NUM; + vtmp.v.n = v_getval(left) - v_getval(r); + } else { + vtmp.type = V_INT; + vtmp.v.i = v_igetval(left) - v_igetval(r); + } + break; + } + v_set(r, &vtmp); + V_FREE(&vtmp); + } + V_FREE(left); + } +} + +static inline void oper_mul(var_t *r, var_t *left, byte op) { + var_num_t lf; + var_num_t rf; + var_int_t li; + var_int_t ri; + + if (r->type == V_ARRAY || v_is_type(left, V_ARRAY)) { + // arrays + if (r->type == V_ARRAY && v_is_type(left, V_ARRAY)) { + if (op == '*') { + mat_mul(left, r); + } else { + err_matop(); + } + } else { + if (r->type == V_ARRAY) { + if (op == '*') { + mat_mulN(r, v_getval(left)); + } else { + err_matop(); + } + } else { + rf = v_getval(r); + v_set(r, left); + if (op == '*') { + mat_mulN(r, rf); + } else { + err_matop(); + } + } + } + + V_FREE(left); + } else { + // not array + lf = v_getval(left); + V_FREE(left); + rf = v_getval(r); + V_FREE(r); + + // double always + r->type = V_NUM; + switch (op) { + case '*': + r->v.n = lf * rf; + break; + case '/': + if (ABS(rf) == 0) { + err_division_by_zero(); + } else { + r->v.n = lf / rf; + } + break; + case '\\': + li = lf; + ri = rf; + if (ri == 0) { + err_division_by_zero(); + } else { + r->v.i = li / ri; + } + r->type = V_INT; + break; + case '%': + case OPLOG_MOD: + if ((var_int_t) rf == 0) { + err_division_by_zero(); + } else { + // r->v.n = fmod(lf, rf); + ri = rf; + li = (lf < 0.0) ? -floor(-lf) : floor(lf); + r->v.i = li - ri * (li / ri); + r->type = V_INT; + } + break; + case OPLOG_MDL: + if (rf == 0) { + err_division_by_zero(); + } else { + r->v.n = fmod(lf, rf) + rf * (SGN(lf) != SGN(rf)); + r->type = V_NUM; + } + break; + }; + } +} + +static inline void oper_unary(var_t *r, byte op) { + var_int_t ri; + var_num_t rf; + + switch (op) { + case '-': + if (r->type == V_INT) { + r->v.i = -r->v.i; + } else if (r->type == V_NUM) { + r->v.n = -r->v.n; + } else if (r->type == V_ARRAY) { + mat_antithetos(r); + } else { + rf = v_getval(r); + V_FREE(r); + r->v.n = -rf; + r->type = V_NUM; + } + break; + case '+': + break; + case OPLOG_INV: + // the result of ~ is always integer + ri = v_igetval(r); + V_FREE(r); + r->type = V_INT; + r->v.i = ~ri; + break; + case OPLOG_NOT: + // the result of ! is always integer + ri = v_igetval(r); + V_FREE(r); + r->type = V_INT; + r->v.i = !ri; + break; + } +} + +static inline void oper_log(var_t *r, var_t *left, byte op) { + var_int_t li; + var_int_t ri; + int i; + var_int_t a, b; + var_int_t ba, bb; + + if (op != OPLOG_IN) { + li = v_igetval(left); + ri = v_igetval(r); + } else { + li = 0; + ri = 0; + } + + switch (op) { + case OPLOG_AND: + ri = (li && ri) ? -1 : 0; + break; + case OPLOG_OR: + ri = (li || ri) ? -1 : 0; + break; + case OPLOG_EQV: + a = li; + b = ri; + ri = 0; + for (i = 0; i < sizeof(var_int_t); i++) { + ba = a & (1 << i); + bb = b & (1 << i); + if ((ba && bb) || (!ba && !bb)) { + ri |= (1 << i); + } + } + break; + case OPLOG_IMP: + a = li; + b = ri; + ri = 0; + for (i = 0; i < sizeof(var_int_t); i++) { + ba = a & (1 << i); + bb = b & (1 << i); + if (!(ba && !bb)) { + ri |= (1 << i); + } + } + break; + case OPLOG_NAND: + ri = ~(li & ri); + break; + case OPLOG_NOR: + ri = ~(li | ri); + break; + case OPLOG_XNOR: + ri = ~(li ^ ri); + break; + case OPLOG_BOR: + ri = li | ri; + break; + case OPLOG_BAND: + ri = li & ri; + break; + case OPLOG_XOR: + ri = li ^ ri; + break; + } + + // cleanup + V_FREE(left); + V_FREE(r); + + r->type = V_INT; + r->v.i = ri; +} + +static inline void oper_cmp(var_t *r, var_t *left, byte op) { + var_int_t ri; + + switch (op) { + case OPLOG_EQ: + ri = (v_compare(left, r) == 0); + break; + case OPLOG_GT: + ri = (v_compare(left, r) > 0); + break; + case OPLOG_GE: + ri = (v_compare(left, r) >= 0); + break; + case OPLOG_LT: + ri = (v_compare(left, r) < 0); + break; + case OPLOG_LE: + ri = (v_compare(left, r) <= 0); + break; + case OPLOG_NE: + ri = (v_compare(left, r) != 0); + break; + case OPLOG_IN: + ri = 0; + if (r->type == V_ARRAY) { + int i; + var_t *elem_p; + + for (i = 0; i < r->v.a.size; i++) { + elem_p = v_elem(r, i); + if (v_compare(left, elem_p) == 0) { + ri = i + 1; + break; + } + } + } else if (r->type == V_STR) { + if (v_is_type(left, V_STR)) { + if (left->v.p.ptr[0] != '\0') { + ri = (strstr(r->v.p.ptr, left->v.p.ptr) != NULL); + } else { + ri = 0; + } + } else if (v_is_type(left, V_NUM) || v_is_type(left, V_INT)) { + var_t *v; + v = v_clone(left); + v_tostr(v); + ri = (strstr(r->v.p.ptr, v->v.p.ptr) != NULL); + v_free(v); + tmp_free(v); + } + } else if (r->type == V_NUM || r->type == V_INT) { + ri = (v_compare(left, r) == 0); + } + break; + case OPLOG_LIKE: + ri = v_wc_match(r, left); + break; + } + + // cleanup + V_FREE(left); + V_FREE(r); + + r->type = V_INT; + r->v.i = ri; +} + +static inline void oper_powr(var_t *r, var_t *left) { + var_num_t rf; + + rf = pow(v_getval(left), v_getval(r)); + V_FREE(r); + r->type = V_NUM; + r->v.n = rf; + + // cleanup + V_FREE(left); +} + +static inline void eval_shortc(var_t *r, addr_t addr, byte op) { + var_int_t li; + var_int_t ri; + + // read left side result + li = v_igetval(&eval_stk[eval_sp - 1]); + ri = -1; + + switch (op) { + case OPLOG_AND: + if (!li) { + // False AND blah => result is false + ri = 0; + } + break; + case OPLOG_OR: + if (li) { + // True OR blah => result is true + ri = 1; + } + break; + } + + if (ri != -1) { + // set the result into v - if there are more expressions + // this will be kwTYPE_EVPUSH'd onto the stack + // and kwTYPE_EVAL_SC will be called again to test the + // subsequent boolean operator + V_FREE(r); + r->type = V_INT; + r->v.i = ri; + // jump to the shortcut offset + IP += (addr - ADDRSZ); + } +} + +static inline void eval_var(var_t *r, var_t *var_p) { + switch (var_p->type) { + case V_PTR: + r->type = var_p->type; + r->v.ap.p = var_p->v.ap.p; + r->v.ap.v = var_p->v.ap.v; + break; + case V_INT: + r->type = V_INT; + r->v.i = var_p->v.i; + break; + case V_NUM: + r->type = V_NUM; + r->v.n = var_p->v.n; + break; + case V_STR: + v_set(r, var_p); + break; + case V_ARRAY: + case V_UDS: + case V_HASH: + v_set(r, var_p); + break; + } +} + +static inline void eval_push(var_t *r) { + addr_t len; + + switch (r->type) { + case V_INT: + eval_stk[eval_sp].type = V_INT; + eval_stk[eval_sp].v.i = r->v.i; + break; + case V_NUM: + eval_stk[eval_sp].type = V_NUM; + eval_stk[eval_sp].v.n = r->v.n; + break; + case V_STR: + len = r->v.p.size; + eval_stk[eval_sp].type = V_STR; + eval_stk[eval_sp].v.p.ptr = tmp_alloc(len + 1); + strcpy(eval_stk[eval_sp].v.p.ptr, r->v.p.ptr); + eval_stk[eval_sp].v.p.size = len; + break; + default: + v_set(&eval_stk[eval_sp], r); + } + + // expression-stack resize + eval_sp++; + if (eval_sp == eval_size) { + eval_size += 64; + eval_stk = tmp_realloc(eval_stk, sizeof(var_t) * eval_size); + // rt_raise("EVAL: STACK OVERFLOW"); + } +} + +static inline void eval_extf(var_t *r) { + addr_t lib; + addr_t idx; + var_int_t li; + + lib = code_getaddr(); + idx = code_getaddr(); + V_FREE(r); + if (lib & UID_UNIT_BIT) { + unit_exec(lib & (~UID_UNIT_BIT), idx, r); + // if ( prog_error ) + // return; + } else { + sblmgr_funcexec(lib, prog_symtable[idx].exp_idx, r); + } +} + +static inline void eval_callf(var_t *r) { + long fcode = code_getaddr(); + var_t vtmp; + + switch (fcode) { + case kwVADDR: + // Variable's address + V_FREE(r); + if (CODE_PEEK() != kwTYPE_LEVEL_BEGIN) { + err_missing_lp(); + } else { + var_t *vp; + IP++; + vp = code_getvarptr(); + if (!prog_error) { + r->type = V_INT; + r->v.i = (intptr_t) vp->v.p.ptr; + } + if (CODE_PEEK() != kwTYPE_LEVEL_END) { + err_missing_rp(); + } else { + IP++; + } + } + break; + + case kwASC: + case kwVAL: + case kwTEXTWIDTH: + case kwTEXTHEIGHT: + case kwEXIST: + case kwISFILE: + case kwISDIR: + case kwISLINK: + case kwACCESSF: + // num FUNC(STR) + V_FREE(r); + if (CODE_PEEK() != kwTYPE_LEVEL_BEGIN) { + err_missing_lp(); + } else { + IP++; + v_init(&vtmp); + eval(&vtmp); + if (!prog_error) { + cmd_ns1(fcode, &vtmp, r); + V_FREE(&vtmp); + + if (CODE_PEEK() != kwTYPE_LEVEL_END) { + err_missing_rp(); + } else { + IP++; + } + } + } + break; + + case kwCHR: + case kwSTR: + case kwOCT: + case kwHEX: + case kwBIN: + case kwLCASE: + case kwUCASE: + case kwLTRIM: + case kwRTRIM: + case kwSPACE: + case kwTAB: + case kwCAT: + case kwENVIRONF: + case kwTRIM: + case kwBALLOC: + case kwBCS: + case kwCBS: + // str FUNC(any) + V_FREE(r); + if (CODE_PEEK() != kwTYPE_LEVEL_BEGIN) { + err_missing_lp(); + } else { + IP++; + v_init(&vtmp); + eval(&vtmp); + if (!prog_error) { + r->type = V_STR; + r->v.p.ptr = NULL; + cmd_str1(fcode, &vtmp, r); + V_FREE(&vtmp); + + if (CODE_PEEK() != kwTYPE_LEVEL_END) { + err_missing_rp(); + } else { + IP++; + } + } + } + break; + + case kwTRANSLATEF: + case kwSTRING: + case kwSQUEEZE: + case kwLEFT: + case kwRIGHT: + case kwLEFTOF: + case kwRIGHTOF: + case kwLEFTOFLAST: + case kwRIGHTOFLAST: + case kwMID: + case kwREPLACE: + case kwCHOP: + case kwRUNF: + case kwENCLOSE: + case kwDISCLOSE: + // str FUNC(...) + V_FREE(r); + if (CODE_PEEK() != kwTYPE_LEVEL_BEGIN) { + err_missing_lp(); + } else { + r->type = V_STR; + r->v.p.ptr = NULL; + + IP++; // '(' + cmd_strN(fcode, r); + if (!prog_error) { + if (CODE_PEEK() == kwTYPE_SEP) { + IP++; // ',' + } else if (CODE_PEEK() == kwTYPE_LEVEL_END) { + IP++; // ')' + } else { + err_missing_rp(); + } + } + } + break; + + case kwINKEY: + case kwTIME: + case kwDATE: + // str FUNC(void) + V_FREE(r); + cmd_str0(fcode, r); + break; + + case kwINSTR: + case kwRINSTR: + case kwLBOUND: + case kwUBOUND: + case kwLEN: + case kwEMPTY: + case kwISARRAY: + case kwISNUMBER: + case kwISSTRING: + case kwRGB: + case kwRGBF: + case kwIMGW: + case kwIMGH: + // int FUNC(...) + V_FREE(r); + if (CODE_PEEK() != kwTYPE_LEVEL_BEGIN) { + err_missing_lp(); + } else { + r->type = V_INT; + IP++; // '(' + cmd_intN(fcode, r); + if (!prog_error) { + if (CODE_PEEK() == kwTYPE_SEP) { + IP++; // ',' + } else if (CODE_PEEK() == kwTYPE_LEVEL_END) { + IP++; // ')' + } else { + err_missing_sep(); + } + } + } + break; + + case kwATAN2: + case kwPOW: + case kwROUND: + // fp FUNC(...) + V_FREE(r); + if (CODE_PEEK() != kwTYPE_LEVEL_BEGIN) { + err_missing_lp(); + } else { + r->type = V_NUM; + IP++; // '(' + cmd_numN(fcode, r); + if (!prog_error) { + if (CODE_PEEK() == kwTYPE_SEP) { + IP++; // ',' + } else if (CODE_PEEK() == kwTYPE_LEVEL_END) { + IP++; // ')' level + } else { + err_missing_sep(); + } + } + } + break; + + case kwCOS: + case kwSIN: + case kwTAN: + case kwCOSH: + case kwSINH: + case kwTANH: + case kwACOS: + case kwASIN: + case kwATAN: + case kwACOSH: + case kwASINH: + case kwATANH: + case kwSEC: + case kwSECH: + case kwASEC: + case kwASECH: + case kwCSC: + case kwCSCH: + case kwACSC: + case kwACSCH: + case kwCOT: + case kwCOTH: + case kwACOT: + case kwACOTH: + case kwSQR: + case kwABS: + case kwEXP: + case kwLOG: + case kwLOG10: + case kwFIX: + case kwINT: + case kwCDBL: + case kwDEG: + case kwRAD: + case kwPENF: + case kwFLOOR: + case kwCEIL: + case kwFRAC: + V_FREE(r); + if (CODE_PEEK() != kwTYPE_LEVEL_BEGIN) { + err_missing_lp(); + } else { + IP++; + v_init(&vtmp); + eval(&vtmp); + if (!prog_error) { + r->type = V_NUM; + r->v.n = cmd_math1(fcode, &vtmp); + V_FREE(&vtmp); + if (!prog_error) { + if (CODE_PEEK() != kwTYPE_LEVEL_END) { + err_missing_rp(); + } else { + IP++; + } + } + } + } + break; + + case kwFRE: + case kwSGN: + case kwCINT: + case kwEOF: + case kwSEEKF: + case kwLOF: + // int FUNC(fp) + V_FREE(r); + if (CODE_PEEK() != kwTYPE_LEVEL_BEGIN) { + err_missing_lp(); + } else { + IP++; + v_init(&vtmp); + eval(&vtmp); + if (!prog_error) { + r->type = V_INT; + r->v.i = cmd_imath1(fcode, &vtmp); + if (CODE_PEEK() != kwTYPE_LEVEL_END) { + err_missing_rp(); + } else { + IP++; + } + } + } + break; + + case kwXPOS: + case kwYPOS: + case kwRND: + // fp FUNC(void) + V_FREE(r); + vtmp.type = V_NUM; + vtmp.v.n = 0; + r->type = V_NUM; + r->v.n = cmd_math1(fcode, &vtmp); + break; + + case kwMAX: + case kwMIN: + case kwABSMAX: + case kwABSMIN: + case kwSUM: + case kwSUMSV: + case kwSTATMEAN: + case kwSTATMEANDEV: + case kwSTATSPREADS: + case kwSTATSPREADP: + case kwSEGCOS: + case kwSEGSIN: + case kwSEGLEN: + case kwPOLYAREA: + case kwPOLYCENT: + case kwPTDISTSEG: + case kwPTSIGN: + case kwPTDISTLN: + case kwPOINT: + case kwINPUTF: + case kwCODEARRAY: + case kwGAUSSJORDAN: + case kwFILES: + case kwINVERSE: + case kwDETERM: + case kwJULIAN: + case kwDATEFMT: + case kwWDAY: + case kwIFF: + case kwFORMAT: + case kwBGETC: + case kwSEQ: + // any FUNC(...) + V_FREE(r); + if (CODE_PEEK() != kwTYPE_LEVEL_BEGIN) { + err_missing_lp(); + } else { + IP++; + cmd_genfunc(fcode, r); + if (!prog_error) { + if (CODE_PEEK() == kwTYPE_LEVEL_END) { + IP++; + } + } + } + break; + + case kwTICKS: + case kwTICKSPERSEC: + case kwTIMER: + case kwPROGLINE: + // int FUNC(void) + V_FREE(r); + vtmp.type = V_INT; + vtmp.v.i = 0; + r->type = V_INT; + r->v.i = cmd_imath1(fcode, &vtmp); + break; + + case kwFREEFILE: + V_FREE(r); + r->type = V_INT; + r->v.i = dev_freefilehandle(); + break; + + default: + err_bfn_err(fcode); + } +} + +static inline void eval_call_udf(var_t *r) { + prog_ip--; + bc_loop(1); + if (!prog_error) { + stknode_t udf_rv; + code_pop(&udf_rv); + if (udf_rv.type != kwTYPE_RET) + err_stackmess(); + else { + v_set(r, udf_rv.x.vdvar.vptr); + // free ret-var + v_free(udf_rv.x.vdvar.vptr); + tmp_free(udf_rv.x.vdvar.vptr); + } + } +} + /** * executes the expression (Code[IP]) and returns the result (r) */ void eval(var_t *r) { code_t code; byte op; - byte level = 0; addr_t len; var_t *var_p; - var_t *left = NULL, vtmp; - addr_t eval_pos = eval_sp; - int i; - long fcode; - var_int_t li = 0, ri = 0; - var_num_t lf, rf; addr_t addr; - // / bit ops - var_int_t a, b; - var_int_t ba, bb; + var_t *left = NULL; + addr_t eval_pos = eval_sp; + byte level = 0; r->const_flag = 0; r->type = V_INT; @@ -315,21 +1130,21 @@ void eval(var_t *r) { IP++; switch (code) { case kwTYPE_INT: - // //////////// integer - constant ////////////// + // integer - constant V_FREE(r); r->type = V_INT; r->v.i = code_getint(); break; case kwTYPE_NUM: - // //////////// double - constant ////////////// + // double - constant V_FREE(r); r->type = V_NUM; r->v.n = code_getreal(); break; case kwTYPE_STR: - // //////////// string - constant ////////////// + // string - constant V_FREE(r); r->type = V_STR; len = code_getstrlen(); @@ -337,12 +1152,11 @@ void eval(var_t *r) { memcpy(r->v.p.ptr, &prog_source[prog_ip], len); *((char *) (r->v.p.ptr + len)) = '\0'; r->v.p.size = len; - IP += len; break; case kwTYPE_PTR: - // //////////// UDF pointer - constant /////////// + // UDF pointer - constant V_FREE(r); r->type = V_PTR; r->const_flag = 1; @@ -350,932 +1164,124 @@ void eval(var_t *r) { r->v.ap.v = code_getaddr(); break; - // ////////////// variable /////////////////// case kwTYPE_UDS: case kwTYPE_VAR: + // variable V_FREE(r); - IP--; var_p = code_getvarptr(); - if (prog_error) { return; } - switch (var_p->type) { - case V_PTR: - r->type = var_p->type; - r->v.ap.p = var_p->v.ap.p; - r->v.ap.v = var_p->v.ap.v; - break; - case V_INT: - r->type = V_INT; - r->v.i = var_p->v.i; - break; - case V_NUM: - r->type = V_NUM; - r->v.n = var_p->v.n; - break; - case V_STR: - v_set(r, var_p); - break; - case V_ARRAY: - case V_UDS: - case V_HASH: - v_set(r, var_p); - break; - } - ; // switch(type) - + eval_var(r, var_p); break; - // ///////////// STACK ////////////////// - case kwTYPE_EVPUSH: // PUSH RESULT - switch (r->type) { - case V_INT: - eval_stk[eval_sp].type = V_INT; - eval_stk[eval_sp].v.i = r->v.i; - break; - case V_NUM: - eval_stk[eval_sp].type = V_NUM; - eval_stk[eval_sp].v.n = r->v.n; - break; - case V_STR: - len = r->v.p.size; - eval_stk[eval_sp].type = V_STR; - eval_stk[eval_sp].v.p.ptr = tmp_alloc(len + 1); - strcpy(eval_stk[eval_sp].v.p.ptr, r->v.p.ptr); - eval_stk[eval_sp].v.p.size = len; - break; - default: - v_set(&eval_stk[eval_sp], r); - } - - // expression-stack resize - eval_sp++; - if (eval_sp == eval_size) { - eval_size += 64; - eval_stk = tmp_realloc(eval_stk, sizeof(var_t) * eval_size); - // rt_raise("EVAL: STACK OVERFLOW"); - } + case kwTYPE_EVPUSH: + // stack = push result + eval_push(r); break; - case kwTYPE_EVPOP: // POP LEFT + case kwTYPE_EVPOP: + // pop left eval_sp--; left = &eval_stk[eval_sp]; break; - // ////////////// ADD /////////////////// case kwTYPE_ADDOPR: op = CODE(IP); IP++; - - if (r->type == V_INT && v_is_type(left, V_INT)) { - if (op == '+') { - r->v.i += left->v.i; - } else { - r->v.i = left->v.i - r->v.i; - } - } else if (r->type == V_NUM && v_is_type(left, V_NUM)) { - r->type = V_NUM; - if (op == '+') { - r->v.n += left->v.n; - } else { - r->v.n = left->v.n - r->v.n; - } - } else if (r->type == V_INT && v_is_type(left, V_NUM)) { - r->type = V_NUM; - if (op == '+') { - r->v.n = r->v.i + left->v.n; - } else { - r->v.n = left->v.n - r->v.i; - } - } else if (r->type == V_NUM && v_is_type(left, V_INT)) { - if (op == '+') { - r->v.n += left->v.i; - } else { - r->v.n = left->v.i - r->v.n; - } - } else { - if (r->type == V_ARRAY || v_is_type(left, V_ARRAY)) { - // - // ARRAYS - // - if (r->type == V_ARRAY && v_is_type(left, V_ARRAY)) { - if (op == '+') { - mat_add(r, left); - } else { - mat_sub(r, left); - } - } else { - err_matop(); - } - } else { - // - // NOT ARRAY - // - v_init(&vtmp); - switch (op) { - case '+': - v_add(&vtmp, left, r); - break; - case '-': - if (vtmp.type == V_NUM) { - vtmp.type = V_NUM; - vtmp.v.n = v_getval(left) - v_getval(r); - } else { - vtmp.type = V_INT; - vtmp.v.i = v_igetval(left) - v_igetval(r); - } - break; - } - v_set(r, &vtmp); - V_FREE(&vtmp); - } - - V_FREE(left); - } - + oper_add(r, left, op); break; - // ////////////// MUL /////////////////// case kwTYPE_MULOPR: op = CODE(IP); IP++; - - if (r->type == V_ARRAY || v_is_type(left, V_ARRAY)) { - // - // ARRAYS - // - if (r->type == V_ARRAY && v_is_type(left, V_ARRAY)) { - if (op == '*') { - mat_mul(left, r); - } else { - err_matop(); - } - } else { - if (r->type == V_ARRAY) { - if (op == '*') { - mat_mulN(r, v_getval(left)); - } else { - err_matop(); - } - } else { - rf = v_getval(r); - v_set(r, left); - if (op == '*') { - mat_mulN(r, rf); - } else { - err_matop(); - } - } - } - - V_FREE(left); - } else { - // - // NOT ARRAY - // - lf = v_getval(left); - V_FREE(left); - rf = v_getval(r); - V_FREE(r); - - r->type = V_NUM; // double always - switch (op) { - case '*': - r->v.n = lf * rf; - break; - case '/': - if (ABS(rf) == 0) { - err_division_by_zero(); - } else { - r->v.n = lf / rf; - } - break; - case '\\': - li = lf; - ri = rf; - if (ri == 0) { - err_division_by_zero(); - } else { - r->v.i = li / ri; - } - r->type = V_INT; - break; - case '%': - case OPLOG_MOD: - if ((var_int_t) rf == 0) { - err_division_by_zero(); - } else { - // r->v.n = fmod(lf, rf); - ri = rf; - li = (lf < 0.0) ? -floor(-lf) : floor(lf); - r->v.i = li - ri * (li / ri); - r->type = V_INT; - } - break; - case OPLOG_MDL: - if (rf == 0) { - err_division_by_zero(); - } else { - r->v.n = fmod(lf, rf) + rf * (SGN(lf) != SGN(rf)); - r->type = V_NUM; - } - break; - }; - } - + oper_mul(r, left, op); break; - // ////////////// UNARY /////////////////// case kwTYPE_UNROPR: + // unary op = CODE(IP); IP++; - - switch (op) { - case '-': - if (r->type == V_INT) { - r->v.i = -r->v.i; - } else if (r->type == V_NUM) { - r->v.n = -r->v.n; - } else if (r->type == V_ARRAY) { - mat_antithetos(r); - } else { - rf = v_getval(r); - V_FREE(r); - r->v.n = -rf; - r->type = V_NUM; - } - break; - case '+': - break; - case OPLOG_INV: // The result of ~ is always integer - ri = v_igetval(r); - V_FREE(r); - r->type = V_INT; - r->v.i = ~ri; - break; - case OPLOG_NOT: // The result of ! is always integer - ri = v_igetval(r); - V_FREE(r); - r->type = V_INT; - r->v.i = !ri; - break; - } - - // cleanup + oper_unary(r, op); break; case kwTYPE_EVAL_SC: // short-circuit evaluation // see cev_log() in ceval.c for layout details - IP++; // skip code kwTYPE_LOGOPR - op = CODE(IP); // read operator - IP++; - li = v_igetval(&eval_stk[eval_sp - 1]); // read left side result - ri = -1; - addr = code_getaddr(); // read shortcut jump offset + // skip code kwTYPE_LOGOPR + IP++; - switch (op) { - case OPLOG_AND: - if (!li) { - ri = 0; // False AND blah => result is false - } - break; - case OPLOG_OR: - if (li) { - ri = 1; // True OR blah => result is true - } - break; - } + // read operator + op = CODE(IP); + IP++; - if (ri != -1) { - // set the result into v - if there are more expressions - // this will be kwTYPE_EVPUSH'd onto the stack - // and kwTYPE_EVAL_SC will be called again to test the - // subsequent boolean operator - V_FREE(r); - r->type = V_INT; - r->v.i = ri; - IP += (addr - ADDRSZ); // jump to the shortcut offset - } + // read shortcut jump offset + addr = code_getaddr(); + eval_shortc(r, addr, op); break; - // ////////////// LOGICAL/BIT /////////////////// case kwTYPE_LOGOPR: + // logical/bit op = CODE(IP); IP++; - - if (op != OPLOG_IN) { - li = v_igetval(left); - ri = v_igetval(r); - } - - switch (op) { - case OPLOG_AND: - ri = (li && ri) ? -1 : 0; - break; - case OPLOG_OR: - ri = (li || ri) ? -1 : 0; - break; - case OPLOG_EQV: - a = li; - b = ri; - ri = 0; - for (i = 0; i < sizeof(var_int_t); i++) { - ba = a & (1 << i); - bb = b & (1 << i); - if ((ba && bb) || (!ba && !bb)) { - ri |= (1 << i); - } - } - break; - case OPLOG_IMP: - a = li; - b = ri; - ri = 0; - for (i = 0; i < sizeof(var_int_t); i++) { - ba = a & (1 << i); - bb = b & (1 << i); - if (!(ba && !bb)) { - ri |= (1 << i); - } - } - break; - case OPLOG_NAND: - ri = ~(li & ri); - break; - case OPLOG_NOR: - ri = ~(li | ri); - break; - case OPLOG_XNOR: - ri = ~(li ^ ri); - break; - case OPLOG_BOR: - ri = li | ri; - break; - case OPLOG_BAND: - ri = li & ri; - break; - case OPLOG_XOR: - ri = li ^ ri; - break; - } - ; - - // cleanup - V_FREE(left); - V_FREE(r); - - // - r->type = V_INT; - r->v.i = ri; - + oper_log(r, left, op); break; - // ////////////// COMPARE /////////////////// case kwTYPE_CMPOPR: + // compare op = CODE(IP); IP++; - - switch (op) { - case OPLOG_EQ: - ri = (v_compare(left, r) == 0); - break; - case OPLOG_GT: - ri = (v_compare(left, r) > 0); - break; - case OPLOG_GE: - ri = (v_compare(left, r) >= 0); - break; - case OPLOG_LT: - ri = (v_compare(left, r) < 0); - break; - case OPLOG_LE: - ri = (v_compare(left, r) <= 0); - break; - case OPLOG_NE: - ri = (v_compare(left, r) != 0); - break; - case OPLOG_IN: - ri = 0; - if (r->type == V_ARRAY) { - int i; - var_t *elem_p; - - for (i = 0; i < r->v.a.size; i++) { - elem_p = v_elem(r, i); - if (v_compare(left, elem_p) == 0) { - ri = i + 1; - break; - } - } - } else if (r->type == V_STR) { - if (v_is_type(left, V_STR)) { - if (left->v.p.ptr[0] != '\0') { - ri = (strstr(r->v.p.ptr, left->v.p.ptr) != NULL); - } else { - ri = 0; - } - } else if (v_is_type(left, V_NUM) || v_is_type(left, V_INT)) { - var_t *v; - - v = v_clone(left); - v_tostr(v); - ri = (strstr(r->v.p.ptr, v->v.p.ptr) != NULL); - v_free(v); - tmp_free(v); - } - } else if (r->type == V_NUM || r->type == V_INT) { - ri = (v_compare(left, r) == 0); - } - break; - case OPLOG_LIKE: - ri = v_wc_match(r, left); - break; - } - - // cleanup - V_FREE(left); - V_FREE(r); - // - r->type = V_INT; - r->v.i = ri; + oper_cmp(r, left, op); break; - // ////////////// POW /////////////////// case kwTYPE_POWOPR: + // pow op = CODE(IP); IP++; - - rf = pow(v_getval(left), v_getval(r)); - V_FREE(r); - r->type = V_NUM; - r->v.n = rf; - - // cleanup - V_FREE(left); + oper_powr(r, left); break; - // /////////////////////////////////////////////////////////////////////////////// - - case kwTYPE_LEVEL_BEGIN: // left parenthesis + case kwTYPE_LEVEL_BEGIN: + // left parenthesis level++; break; - case kwTYPE_LEVEL_END: // right parenthesis + case kwTYPE_LEVEL_END: + // right parenthesis if (level == 0) { IP--; eval_sp = eval_pos; - return; // warning: normal exit + // warning: normal exit + return; } - level--; break; - // /////////////////////////////////////////////////////////////////////////////// - // / external functions - case kwTYPE_CALLEXTF: // [lib][index] - { - addr_t lib, idx; - - lib = code_getaddr(); - idx = code_getaddr(); - V_FREE(r); - if (lib & UID_UNIT_BIT) { - unit_exec(lib & (~UID_UNIT_BIT), idx, r); - // if ( prog_error ) - // return; - } else { - sblmgr_funcexec(lib, prog_symtable[idx].exp_idx, r); - } - } + case kwTYPE_CALLEXTF: + // [lib][index] external functions + eval_extf(r); break; - // /////////////////////////////////////////////////////////////////////////////// - // / buildin functions - case kwTYPE_CALLF: - - fcode = code_getaddr(); - - switch (fcode) { - case kwVADDR: - // Variable's address - V_FREE(r); - - if (CODE_PEEK() != kwTYPE_LEVEL_BEGIN) { - err_missing_lp(); - } else { - var_t *vp; - - IP++; - vp = code_getvarptr(); - if (!prog_error) { - r->type = V_INT; - r->v.i = (intptr_t) vp->v.p.ptr; - } - - if (CODE_PEEK() != kwTYPE_LEVEL_END) { - err_missing_rp(); - } else { - IP++; - } - } - - break; - - // num FUNC(STR) - case kwASC: - case kwVAL: - case kwTEXTWIDTH: - case kwTEXTHEIGHT: - case kwEXIST: - case kwISFILE: - case kwISDIR: - case kwISLINK: - case kwACCESSF: - V_FREE(r); - - if (CODE_PEEK() != kwTYPE_LEVEL_BEGIN) { - err_missing_lp(); - } else { - IP++; - - v_init(&vtmp); - eval(&vtmp); - if (!prog_error) { - cmd_ns1(fcode, &vtmp, r); - V_FREE(&vtmp); - - if (CODE_PEEK() != kwTYPE_LEVEL_END) { - err_missing_rp(); - } else { - IP++; - } - } - } - break; - - // str FUNC(any) - case kwCHR: - case kwSTR: - case kwOCT: - case kwHEX: - case kwBIN: - case kwLCASE: - case kwUCASE: - case kwLTRIM: - case kwRTRIM: - case kwSPACE: - case kwTAB: - case kwCAT: - case kwENVIRONF: - case kwTRIM: - case kwBALLOC: - case kwBCS: - case kwCBS: - - V_FREE(r); - - if (CODE_PEEK() != kwTYPE_LEVEL_BEGIN) { - err_missing_lp(); - } else { - IP++; - - v_init(&vtmp); - eval(&vtmp); - if (!prog_error) { - r->type = V_STR; - r->v.p.ptr = NULL; - cmd_str1(fcode, &vtmp, r); - V_FREE(&vtmp); - - if (CODE_PEEK() != kwTYPE_LEVEL_END) { - err_missing_rp(); - } else { - IP++; - } - } - } - break; - - // str FUNC(...) - case kwTRANSLATEF: - case kwSTRING: - case kwSQUEEZE: - case kwLEFT: - case kwRIGHT: - case kwLEFTOF: - case kwRIGHTOF: - case kwLEFTOFLAST: - case kwRIGHTOFLAST: - case kwMID: - case kwREPLACE: - case kwCHOP: - case kwRUNF: - case kwENCLOSE: - case kwDISCLOSE: - V_FREE(r); - - if (CODE_PEEK() != kwTYPE_LEVEL_BEGIN) { - err_missing_lp(); - } else { - r->type = V_STR; - r->v.p.ptr = NULL; - - IP++; // '(' - cmd_strN(fcode, r); - if (!prog_error) { - if (CODE_PEEK() == kwTYPE_SEP) { - IP++; // ',' - } else if (CODE_PEEK() == kwTYPE_LEVEL_END) { - IP++; // ')' - } else { - err_missing_rp(); - } - } - } - break; - - // str FUNC(void) - case kwINKEY: - case kwTIME: - case kwDATE: - V_FREE(r); - - cmd_str0(fcode, r); - break; - - // int FUNC(...) - case kwINSTR: - case kwRINSTR: - case kwLBOUND: - case kwUBOUND: - case kwLEN: - case kwEMPTY: - case kwISARRAY: - case kwISNUMBER: - case kwISSTRING: - case kwRGB: - case kwRGBF: - case kwIMGW: - case kwIMGH: - V_FREE(r); - - if (CODE_PEEK() != kwTYPE_LEVEL_BEGIN) { - err_missing_lp(); - } else { - r->type = V_INT; - - IP++; // '(' - cmd_intN(fcode, r); - if (!prog_error) { - if (CODE_PEEK() == kwTYPE_SEP) { - IP++; // ',' - } else if (CODE_PEEK() == kwTYPE_LEVEL_END) { - IP++; // ')' - } else { - err_missing_sep(); - } - } - } - break; - - // fp FUNC(...) - case kwATAN2: - case kwPOW: - case kwROUND: - V_FREE(r); - - if (CODE_PEEK() != kwTYPE_LEVEL_BEGIN) { - err_missing_lp(); - } else { - r->type = V_NUM; - - IP++; // '(' - cmd_numN(fcode, r); - if (!prog_error) { - if (CODE_PEEK() == kwTYPE_SEP) { - IP++; // ',' - } else if (CODE_PEEK() == kwTYPE_LEVEL_END) { - IP++; // ')' level - } else { - err_missing_sep(); - } - } - } - break; - - // fp FUNC(fp) - case kwCOS: - case kwSIN: - case kwTAN: - case kwCOSH: - case kwSINH: - case kwTANH: - case kwACOS: - case kwASIN: - case kwATAN: - case kwACOSH: - case kwASINH: - case kwATANH: - - case kwSEC: - case kwSECH: - case kwASEC: - case kwASECH: - case kwCSC: - case kwCSCH: - case kwACSC: - case kwACSCH: - case kwCOT: - case kwCOTH: - case kwACOT: - case kwACOTH: - - case kwSQR: - case kwABS: - case kwEXP: - case kwLOG: - case kwLOG10: - case kwFIX: - case kwINT: - case kwCDBL: - case kwDEG: - case kwRAD: - case kwPENF: - case kwFLOOR: - case kwCEIL: - case kwFRAC: - V_FREE(r); - - if (CODE_PEEK() != kwTYPE_LEVEL_BEGIN) { - err_missing_lp(); - } else { - IP++; - - v_init(&vtmp); - eval(&vtmp); - if (!prog_error) { - r->type = V_NUM; - r->v.n = cmd_math1(fcode, &vtmp); - V_FREE(&vtmp); - if (!prog_error) { - if (CODE_PEEK() != kwTYPE_LEVEL_END) { - err_missing_rp(); - } else { - IP++; - } - } - } - } - break; - - // int FUNC(fp) - case kwFRE: - case kwSGN: - case kwCINT: - case kwEOF: - case kwSEEKF: - case kwLOF: - V_FREE(r); - - if (CODE_PEEK() != kwTYPE_LEVEL_BEGIN) { - err_missing_lp(); - } else { - IP++; - - v_init(&vtmp); - eval(&vtmp); - if (!prog_error) { - r->type = V_INT; - r->v.i = cmd_imath1(fcode, &vtmp); - - if (CODE_PEEK() != kwTYPE_LEVEL_END) { - err_missing_rp(); - } else { - IP++; - } - } - } - break; - - // fp FUNC(void) - case kwXPOS: - case kwYPOS: - case kwRND: - V_FREE(r); - - vtmp.type = V_NUM; - vtmp.v.n = 0; - r->type = V_NUM; - r->v.n = cmd_math1(fcode, &vtmp); - break; - - // any FUNC(...) - case kwMAX: - case kwMIN: - case kwABSMAX: - case kwABSMIN: - case kwSUM: - case kwSUMSV: - case kwSTATMEAN: - case kwSTATMEANDEV: - case kwSTATSPREADS: - case kwSTATSPREADP: - case kwSEGCOS: - case kwSEGSIN: - case kwSEGLEN: - case kwPOLYAREA: - case kwPOLYCENT: - case kwPTDISTSEG: - case kwPTSIGN: - case kwPTDISTLN: - case kwPOINT: - case kwINPUTF: - case kwCODEARRAY: - case kwGAUSSJORDAN: - case kwFILES: - case kwINVERSE: - case kwDETERM: - case kwJULIAN: - case kwDATEFMT: - case kwWDAY: - case kwIFF: - case kwFORMAT: - case kwBGETC: - case kwSEQ: - - V_FREE(r); - if (CODE_PEEK() != kwTYPE_LEVEL_BEGIN) { - err_missing_lp(); - } else { - IP++; - - cmd_genfunc(fcode, r); - if (!prog_error) { - if (CODE_PEEK() == kwTYPE_LEVEL_END) { - IP++; - } - } - } - break; - - // int FUNC(void) - case kwTICKS: - case kwTICKSPERSEC: - case kwTIMER: - case kwPROGLINE: - V_FREE(r); - - vtmp.type = V_INT; - vtmp.v.i = 0; - r->type = V_INT; - r->v.i = cmd_imath1(fcode, &vtmp); - break; - - case kwFREEFILE: - V_FREE(r); - r->type = V_INT; - r->v.i = dev_freefilehandle(); - break; - - default: - err_bfn_err(fcode); - } - ; - - // ////////////// funcs -- end ///////////////// + case kwTYPE_CALLF: + // built-in functions + eval_callf(r); break; case kwTYPE_CALL_UDF: - prog_ip--; - bc_loop(1); - - if (!prog_error) { - stknode_t udf_rv; - - code_pop(&udf_rv); - if (udf_rv.type != kwTYPE_RET) - err_stackmess(); - else { - v_set(r, udf_rv.x.vdvar.vptr); - v_free(udf_rv.x.vdvar.vptr); // free ret-var - tmp_free(udf_rv.x.vdvar.vptr); - } - } - + eval_call_udf(r); break; - // //////////////////////////////////// default: if (kw_check_evexit(code)) { IP--; - eval_sp = eval_pos; // restore stack pointer - return; // warning: normal exit - } + // restore stack pointer + eval_sp = eval_pos; + // normal exit + return; + } rt_raise("UNKNOWN FUNC=%d", code); }; @@ -1286,5 +1292,6 @@ void eval(var_t *r) { } while (1); - eval_sp = eval_pos; // restore stack pointer + // restore stack pointer + eval_sp = eval_pos; } diff --git a/src/common/smbas.h b/src/common/smbas.h index 2dfb069e..72da60ee 100644 --- a/src/common/smbas.h +++ b/src/common/smbas.h @@ -13,6 +13,8 @@ #include "common/sys.h" #include "common/pmem.h" #include "common/var.h" +#include "common/var_uds.h" +#include "common/var_hash.h" #include "common/kw.h" #include "common/scan.h" @@ -21,10 +23,10 @@ extern "C" { #endif /** - * @ingroup exec + * @ingroup exec * - * @typedef bc_head_t - * byte-code header + * @typedef bc_head_t + * byte-code header */ typedef struct { char sign[4]; /**< always "SBEx" */ @@ -46,16 +48,14 @@ typedef struct { // ver 2 word lib_count; /**< libraries count (needed units) */ dword sym_count; /**< symbol count (linked-symbols) */ - - // char reserved[26]; } bc_head_t; /** - * @ingroup exec + * @ingroup exec * - * @typedef bc_unit_rec_t - * byte-code linked-unit record + * @typedef bc_unit_rec_t + * byte-code linked-unit record */ typedef struct { char lib[OS_FILENAME_SIZE + 1]; /**< library name */ @@ -65,10 +65,10 @@ typedef struct { } bc_lib_rec_t; /** - * @ingroup exec + * @ingroup exec * - * @typedef bc_symbol_rec_t - * byte-code linked-symbol record + * @typedef bc_symbol_rec_t + * byte-code linked-symbol record */ typedef struct { char symbol[SB_KEYWORD_SIZE + 1]; /**< symbol name */ @@ -85,7 +85,7 @@ typedef struct { #define BRUN_STOPPED 1 /**< brun_status(), an error or 'break' has already stoped the program @ingroup exec */ /* - * compiler options + * compiler options */ #if defined(BRUN_MODULE) #define EXTERN @@ -144,7 +144,6 @@ EXTERN char gsb_last_errmsg[SB_ERRMSG_SIZE + 1]; /**< last error message #define comp_file prog_file #define comp_errmsg ctask->errmsg #define prog_errmsg ctask->errmsg - #define bytecode_h ctask->bytecode_h #define prog_length ctask->sbe.exec.length #define prog_ip ctask->sbe.exec.ip @@ -168,7 +167,6 @@ 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 comp_extfunctable ctask->sbe.comp.extfunctable #define comp_extfunccount ctask->sbe.comp.extfunccount #define comp_extfuncsize ctask->sbe.comp.extfuncsize @@ -212,7 +210,6 @@ EXTERN char gsb_last_errmsg[SB_ERRMSG_SIZE + 1]; /**< last error message #define comp_unit_name ctask->sbe.comp.unit_name #define comp_first_data_ip ctask->sbe.comp.first_data_ip #define comp_file_name ctask->sbe.comp.file_name - #define tlab prog_labtable #define tvar prog_vartable #define eval_size eval_stk_size @@ -279,55 +276,126 @@ static inline var_num_t code_getnext128f() { #endif +void err_evsyntax(void); +void err_varisarray(void); + +/** + * @ingroup var + * + * returns the floating-point value of a var. + * if v is string it will converted to double. + * + * @param v the variable + * @return the numeric value of a variable + */ +static inline var_num_t v_getval(var_t *v) { + switch (v ? v->type : -1) { + case V_UDS: + return uds_to_int(v); + case V_HASH: + return hash_to_int(v); + case V_PTR: + return v->v.ap.p; + case V_INT: + return v->v.i; + case V_NUM: + return v->v.n; + case V_STR: + return numexpr_sb_strtof((char *) v->v.p.ptr); + default: + if (v == NULL) { + err_evsyntax(); + } else { + err_varisarray(); + } + } + return 0; +} + +#define v_getnum(a) v_getval((a)) + /** - * @ingroup exec + * @ingroup var * - * create a 'break' - display message, too + * returns the integer value of a var. + * if v is string it will converted to integer. * - * the 'break' will stops the program's execution + * @param v the variable + * @return the integer value of a variable + */ +static inline var_int_t v_igetval(var_t *v) { + switch (v ? v->type : -1) { + case V_UDS: + return uds_to_int(v); + case V_HASH: + return hash_to_int(v); + case V_PTR: + return v->v.ap.p; + case V_INT: + return v->v.i; + case V_NUM: + return v->v.n; + case V_STR: + return numexpr_strtol((char *) v->v.p.ptr); + default: + if (v == NULL) { + err_evsyntax(); + } else { + err_varisarray(); + } + } + return 0; +} + +/** + * @ingroup exec + * + * create a 'break' - display message, too + * + * the 'break' will stops the program's execution */ void brun_break(void); /** - * @ingroup exec + * @ingroup exec * - * stops the program's execution + * stops the program's execution */ void brun_stop(void); /** - * @ingroup exec + * @ingroup exec * - * returns the execution status (runing or stopped) + * returns the execution status (runing or stopped) * - * @return BRUN_STOPPED or BRUN_RUNNING + * @return BRUN_STOPPED or BRUN_RUNNING */ int brun_status(void); /** - * decompiler, - * dumps the code in the current task + * decompiler, + * dumps the code in the current task * - * @param output the output stream (FILE*) + * @param output the output stream (FILE*) */ void dump_bytecode(FILE *output); /** - * returns the last-modified time of the file + * returns the last-modified time of the file * - * @param file the filename - * @return the last-modified time of the file; on error returns 0L + * @param file the filename + * @return the last-modified time of the file; on error returns 0L */ time_t sys_filetime(const char *file); -/* - * search a set of directories for the given file - * directories on path must be separated with symbol ':' +/** + * search a set of directories for the given file + * directories on path must be separated with symbol ':' * - * @param path the path - * @param file the file - * @param retbuf a buffer to store the full-path-name file (can be NULL) - * @return non-zero if found + * @param path the path + * @param file the file + * @param retbuf a buffer to store the full-path-name file (can be NULL) + * @return non-zero if found */ int sys_search_path(const char *path, const char *file, char *retbuf); diff --git a/src/common/var.c b/src/common/var.c index b7d4b321..adf3d6b7 100644 --- a/src/common/var.c +++ b/src/common/var.c @@ -15,7 +15,7 @@ #include "common/var_uds.h" #include "common/var_hash.h" -#define ARR_ALLOC 256 +#define ARR_ALLOC 256 /* * creates and returns a new variable @@ -122,60 +122,6 @@ int v_length(var_t *var) { return 1; } -/* - * returns the floating-point value of the variable v - */ -var_num_t v_getval(var_t *v) { - if (v == NULL) { - err_evsyntax(); - } else { - switch (v->type) { - case V_UDS: - return uds_to_int(v); - case V_HASH: - return hash_to_int(v); - case V_PTR: - return v->v.ap.p; - case V_INT: - return v->v.i; - case V_NUM: - return v->v.n; - case V_STR: - return numexpr_sb_strtof((char *) v->v.p.ptr); - default: - err_varisarray(); - } - } - return 0; -} - -/* - * returns the integer value of the variable v - */ -var_int_t v_igetval(var_t *v) { - if (v == 0) { - err_evsyntax(); - } else { - switch (v->type) { - case V_UDS: - return uds_to_int(v); - case V_HASH: - return hash_to_int(v); - case V_PTR: - return v->v.ap.p; - case V_INT: - return v->v.i; - case V_NUM: - return v->v.n; - case V_STR: - return numexpr_strtol((char *) v->v.p.ptr); - default: - err_varisarray(); - } - } - return 0; -} - /* * return array element pointer */ diff --git a/src/common/var.h b/src/common/var.h index 2bdb3b6b..7dcafac0 100644 --- a/src/common/var.h +++ b/src/common/var.h @@ -252,30 +252,6 @@ var_t *v_new(void); */ int v_is_nonzero(var_t *v); -/** - * @ingroup var - * - * returns the floating-point value of a var. - * if v is string it will converted to double. - * - * @param v the variable - * @return the numeric value of a variable - */ -var_num_t v_getval(var_t *v); - -#define v_getnum(a) v_getval((a)) - -/** - * @ingroup var - * - * returns the integer value of a var. - * if v is string it will converted to integer. - * - * @param v the variable - * @return the integer value of a variable - */ -var_int_t v_igetval(var_t *v); - /** * @ingroup var * diff --git a/src/common/var_hash.h b/src/common/var_hash.h index 76b773ae..a9294916 100644 --- a/src/common/var_hash.h +++ b/src/common/var_hash.h @@ -12,6 +12,10 @@ #ifndef VAR_HASH_H #define VAR_HASH_H +#if defined(__cplusplus) +extern "C" { +#endif + int hash_compare(const var_p_t var_a, const var_p_t var_b); int hash_is_empty(const var_p_t var_p); int hash_to_int(const var_p_t var_p); @@ -24,5 +28,9 @@ void hash_set(var_p_t dest, const var_p_t src); void hash_to_str(const var_p_t var_p, char *out, int max_len); void hash_write(const var_p_t var_p, int method, int handle); +#if defined(__cplusplus) +} +#endif + #endif diff --git a/src/common/var_uds.h b/src/common/var_uds.h index eb26d4b8..99fae4f5 100644 --- a/src/common/var_uds.h +++ b/src/common/var_uds.h @@ -12,6 +12,10 @@ #ifndef VAR_UDS_H #define VAR_UDS_H +#if defined(__cplusplus) +extern "C" { +#endif + int uds_compare(const var_p_t var_a, const var_p_t var_b); int uds_is_empty(const var_p_t var_p); int uds_to_int(const var_p_t var_p); @@ -24,4 +28,8 @@ void uds_set(var_p_t dest, const var_p_t src); void uds_to_str(const var_p_t var_p, char *out, int max_len); void uds_write(const var_p_t var_p, int method, int handle); +#if defined(__cplusplus) +} +#endif + #endif diff --git a/src/platform/unix/Makefile.am b/src/platform/unix/Makefile.am index e1addd05..4dc5f02a 100644 --- a/src/platform/unix/Makefile.am +++ b/src/platform/unix/Makefile.am @@ -43,7 +43,7 @@ endif 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 pass1 call_tau +UNIT_TESTS=array break byref eval-test iifs matrices metaa ongoto uds pass1 call_tau short-circuit test: ${bin_PROGRAMS} @for utest in $(UNIT_TESTS); do \ From 9d8819807adca3f3fe327bebe3b0e1cf14fa1422 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Sat, 16 Aug 2014 18:17:19 +1000 Subject: [PATCH 04/21] COMMON: code clean, hotspot fixes --- src/common/brun.c | 37 ------------------------------- src/common/smbas.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++ src/common/var.h | 30 -------------------------- 3 files changed, 54 insertions(+), 67 deletions(-) diff --git a/src/common/brun.c b/src/common/brun.c index d671bd2e..815e43ba 100755 --- a/src/common/brun.c +++ b/src/common/brun.c @@ -331,43 +331,6 @@ var_t* code_resolve_varptr(var_t* var_p, int until_parens) { return var_p; } -/** - * helper for code_getvarptr - */ -var_t* code_getvarptr_parens(int until_parens) { - var_t *var_p = NULL; - - switch (code_peek()) { - case kwTYPE_VAR: - code_skipnext(); - var_p = tvar[code_getaddr()]; - switch (var_p->type) { - case V_HASH: - case V_ARRAY: - var_p = code_resolve_varptr(var_p, until_parens); - break; - default: - if (!until_parens && code_peek() == kwTYPE_LEVEL_BEGIN) { - err_varisnotarray(); - } - } - break; - - case kwTYPE_UDS: - code_skipnext(); - var_p = tvar[code_getaddr()]; - var_p = code_resolve_varptr(uds_resolve_fields(var_p), until_parens); - break; - } - - if (var_p == NULL && !prog_error) { - err_notavar(); - return tvar[0]; - } - - return var_p; -} - /** * Used by code_isvar() to retrieve an element ptr of an array */ diff --git a/src/common/smbas.h b/src/common/smbas.h index 72da60ee..86929518 100644 --- a/src/common/smbas.h +++ b/src/common/smbas.h @@ -278,6 +278,9 @@ static inline var_num_t code_getnext128f() { void err_evsyntax(void); void err_varisarray(void); +void err_varisnotarray(void); +void err_notavar(void); +var_t *code_resolve_varptr(var_t* var_p, int until_parens); /** * @ingroup var @@ -347,6 +350,57 @@ static inline var_int_t v_igetval(var_t *v) { return 0; } +/** + * @ingroup exec + * + * variant of code_getvarptr() derefence until left parenthesis found + * + * R(var_t*) <- Code[IP]; IP += 2; + * + * @return the var_t* + */ +static inline var_t* code_getvarptr_parens(int until_parens) { + var_t *var_p = NULL; + + switch (code_peek()) { + case kwTYPE_VAR: + code_skipnext(); + var_p = tvar[code_getaddr()]; + switch (var_p->type) { + case V_HASH: + case V_ARRAY: + var_p = code_resolve_varptr(var_p, until_parens); + break; + default: + if (!until_parens && code_peek() == kwTYPE_LEVEL_BEGIN) { + err_varisnotarray(); + } + } + break; + + case kwTYPE_UDS: + code_skipnext(); + var_p = tvar[code_getaddr()]; + var_p = code_resolve_varptr(uds_resolve_fields(var_p), until_parens); + break; + } + + if (var_p == NULL && !prog_error) { + err_notavar(); + return tvar[0]; + } + + return var_p; +} + +/** + * @ingroup var + * + * Returns the varptr of the next variable. if the variable is an array + * returns the element ptr + */ +#define code_getvarptr() code_getvarptr_parens(0) + /** * @ingroup exec * diff --git a/src/common/var.h b/src/common/var.h index 7dcafac0..530c6dba 100644 --- a/src/common/var.h +++ b/src/common/var.h @@ -723,28 +723,6 @@ void code_push(stknode_t *node); */ void code_pop(stknode_t *node); -/** - * @ingroup exec - * - * returns the next var_t* and moves the IP 2 bytes forward. - * - * R(var_t*) <- Code[IP]; IP += 2; - * - * @return the var_t* - */ -var_t *code_getvarptr(); - -/** - * @ingroup exec - * - * variant of code_getvarptr() derefence until left parenthesis found - * - * R(var_t*) <- Code[IP]; IP += 2; - * - * @return the var_t* - */ -var_t *code_getvarptr_parens(int until_parens); - /** * @ingroup exec * @@ -813,14 +791,6 @@ stknode_t *code_stackpeek(); #define code_getreal() code_getnext64f() /**< get real (kwTYPE_NUM) @ingroup exec */ #endif -/** - * @ingroup var - * - * Returns the varptr of the next variable. if the variable is an array - * returns the element ptr - */ -#define code_getvarptr() code_getvarptr_parens(0) - /** * @ingroup var * @page sysvar System variables From ee789cd5ed373951e88abd3f71ae49513c96a477 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Sun, 17 Aug 2014 08:44:16 +1000 Subject: [PATCH 05/21] COMMON: code clean, hotspot fixes --- src/common/brun.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/common/brun.c b/src/common/brun.c index 815e43ba..b1d011e1 100755 --- a/src/common/brun.c +++ b/src/common/brun.c @@ -772,16 +772,15 @@ void bc_loop(int isf) { proc_level++; } while (prog_ip < prog_length) { - + if (code != kwTYPE_LINE) { #if defined(_Win32) - now = GetTickCount(); + now = GetTickCount(); #else - now = clock(); + now = clock(); #endif + } - // events - // every ~50ms, check events (on some drivers that redraws the - // screen) + // check events every ~50ms if (now >= next_check) { next_check = now + evt_check_every; From a76630949b89785af79111e034140101e20a5dd5 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Sun, 17 Aug 2014 12:02:33 +1000 Subject: [PATCH 06/21] COMMON: code clean, hotspot fixes --- src/common/brun.c | 8 +++++++- src/common/eval.c | 2 +- src/common/kw.c | 5 +++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/common/brun.c b/src/common/brun.c index b1d011e1..37231dbb 100755 --- a/src/common/brun.c +++ b/src/common/brun.c @@ -772,7 +772,13 @@ void bc_loop(int isf) { proc_level++; } while (prog_ip < prog_length) { - if (code != kwTYPE_LINE) { + switch (code) { + case kwLABEL: + case kwREM: + case kwTYPE_EOC: + case kwTYPE_LINE: + break; + default: #if defined(_Win32) now = GetTickCount(); #else diff --git a/src/common/eval.c b/src/common/eval.c index 8af3f552..bea32372 100644 --- a/src/common/eval.c +++ b/src/common/eval.c @@ -1274,7 +1274,7 @@ void eval(var_t *r) { break; default: - if (kw_check_evexit(code)) { + if (code == kwTYPE_EOC || kw_check_evexit(code)) { IP--; // restore stack pointer eval_sp = eval_pos; diff --git a/src/common/kw.c b/src/common/kw.c index 8839e896..0d7f572a 100644 --- a/src/common/kw.c +++ b/src/common/kw.c @@ -54,12 +54,13 @@ fcode_t kw_noarg_func_table[] = { }; // -int kw_check(code_t * table, code_t code) { +int kw_check(code_t *table, code_t code) { register int i; for (i = 0; table[i] != 0; i++) { - if (code == table[i]) + if (code == table[i]) { return 1; + } } return 0; } From b85e2c4602e945780bcd009237338aae9a062f34 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Mon, 18 Aug 2014 21:34:17 +1000 Subject: [PATCH 07/21] COMMON: fix call by parenthesis --- src/common/scan.c | 29 ++++++++++++++++++++++++++--- src/platform/common/system.cpp | 14 +++++++++----- src/platform/common/system.h | 1 + src/platform/unix/dev_ndcfb.c | 4 ---- src/platform/unix/dev_null.c | 1 - src/platform/unix/dev_term.c | 4 ++++ src/units/README.TXT | 1 - 7 files changed, 40 insertions(+), 14 deletions(-) delete mode 100644 src/units/README.TXT diff --git a/src/common/scan.c b/src/common/scan.c index 704eccd7..e48ecfbc 100644 --- a/src/common/scan.c +++ b/src/common/scan.c @@ -1032,6 +1032,25 @@ int comp_is_function(char *name) { return result; } +/* + * return whether the name is enclosed with parenthesis characters + */ +int comp_is_parenthesized(char *name) { + int result = 0; + char *p = comp_next_char(name); + if (*p == '(') { + char last = *p; + while (*p) { + if (*p != ' ') { + last = *p; + } + p++; + } + result = (last == ')'); + } + return result; +} + /* * scan expression */ @@ -2538,10 +2557,14 @@ void comp_text_line(char *text) { } comp_push(comp_prog.count); bc_add_ctrl(&comp_prog, kwTYPE_CALL_UDP, udp, 0); - bc_add_code(&comp_prog, kwTYPE_LEVEL_BEGIN); char *next = trim_empty_parentheses(comp_bc_parm); - comp_expression(next, 0); - bc_add_code(&comp_prog, kwTYPE_LEVEL_END); + if (comp_is_parenthesized(next)) { + comp_expression(next, 0); + } else { + bc_add_code(&comp_prog, kwTYPE_LEVEL_BEGIN); + comp_expression(next, 0); + bc_add_code(&comp_prog, kwTYPE_LEVEL_END); + } } break; diff --git a/src/platform/common/system.cpp b/src/platform/common/system.cpp index 4ae0d879..3ae5750d 100644 --- a/src/platform/common/system.cpp +++ b/src/platform/common/system.cpp @@ -275,8 +275,7 @@ void System::resize() { MAExtent screenSize = maGetScrSize(); logEntered(); _output->resize(EXTENT_X(screenSize), EXTENT_Y(screenSize)); - os_graf_mx = _output->getWidth(); - os_graf_my = _output->getHeight(); + setDimensions(); dev_pushkey(SB_PKEY_SIZE_CHG); } @@ -398,13 +397,18 @@ void System::setPath(const char *filename) { } } +void System::setDimensions() { + os_graf_mx = _output->getWidth(); + os_graf_my = _output->getHeight(); + setsysvar_int(SYSVAR_XMAX, os_graf_mx - 1); + setsysvar_int(SYSVAR_YMAX, os_graf_my - 1); +} + void System::setRunning(bool running) { if (running) { dev_fgcolor = -DEFAULT_FOREGROUND; dev_bgcolor = -DEFAULT_BACKGROUND; - os_graf_mx = _output->getWidth(); - os_graf_my = _output->getHeight(); - + setDimensions(); dev_clrkb(); ui_reset(); diff --git a/src/platform/common/system.h b/src/platform/common/system.h index c12b31fe..6e697163 100755 --- a/src/platform/common/system.h +++ b/src/platform/common/system.h @@ -47,6 +47,7 @@ struct System : public IButtonListener { void runOnce(const char *startupBas); void setPath(const char *filename); bool setParentPath(); + void setDimensions(); void showCompletion(bool success); void showError(); void checkLoadError(); diff --git a/src/platform/unix/dev_ndcfb.c b/src/platform/unix/dev_ndcfb.c index bd36e27a..af8a161a 100644 --- a/src/platform/unix/dev_ndcfb.c +++ b/src/platform/unix/dev_ndcfb.c @@ -351,10 +351,6 @@ int osd_events(int wait_flag) { return 0; } -void dev_show_page() { - // empty -} - ////////// #if !defined(DRV_SOUND) diff --git a/src/platform/unix/dev_null.c b/src/platform/unix/dev_null.c index 54a79346..9a10674b 100644 --- a/src/platform/unix/dev_null.c +++ b/src/platform/unix/dev_null.c @@ -14,7 +14,6 @@ // initialize driver int osd_devinit() { - os_color = 0; // color support = false os_color_depth = 1; // bits per pixel = monochrome os_graf_mx = 80; // screen width in "pixels" (characters = // os_graf_mx / textwidth("Q")) diff --git a/src/platform/unix/dev_term.c b/src/platform/unix/dev_term.c index dfd7be9a..0b2e1069 100644 --- a/src/platform/unix/dev_term.c +++ b/src/platform/unix/dev_term.c @@ -1207,3 +1207,7 @@ void term_recalc_size() { // scr_h = peekb(0, 0x449); #endif } + +void dev_show_page() { + // empty +} diff --git a/src/units/README.TXT b/src/units/README.TXT deleted file mode 100644 index 7973e1b9..00000000 --- a/src/units/README.TXT +++ /dev/null @@ -1 +0,0 @@ -DO NOT DELETE ME \ No newline at end of file From 8f7d2edd0e03bef235b2c475388d16b74f5ec340 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Mon, 18 Aug 2014 22:20:04 +1000 Subject: [PATCH 08/21] COMMON: fix call by parenthesis --- samples/distro-examples/tests/call_tau.bas | 8 ++++++++ samples/distro-examples/tests/output/call_tau.out | 2 ++ samples/distro-examples/tests/tau.bas | 5 +++++ src/common/scan.c | 10 +++++++--- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/samples/distro-examples/tests/call_tau.bas b/samples/distro-examples/tests/call_tau.bas index aead7e19..40764d15 100644 --- a/samples/distro-examples/tests/call_tau.bas +++ b/samples/distro-examples/tests/call_tau.bas @@ -19,4 +19,12 @@ tau.build_ta rem check system-variables predef.prsys +x=PI +foyer.name= "PI" +tau.addRoom(foyer,x) +sub addRoom(the_thing, d) + print the_thing.name, d +end + +addRoom(foyer,x) diff --git a/samples/distro-examples/tests/output/call_tau.out b/samples/distro-examples/tests/output/call_tau.out index 01e233eb..f7c49523 100644 --- a/samples/distro-examples/tests/output/call_tau.out +++ b/samples/distro-examples/tests/output/call_tau.out @@ -11,3 +11,5 @@ message from tau [1,2,3,4] Predefined Variables PI =3.14159265358979 +PI 3.14159265358979 +PI 3.14159265358979 diff --git a/samples/distro-examples/tests/tau.bas b/samples/distro-examples/tests/tau.bas index 9d58cd49..5f4d8363 100644 --- a/samples/distro-examples/tests/tau.bas +++ b/samples/distro-examples/tests/tau.bas @@ -2,6 +2,7 @@ Unit Tau Import TauChild Export expvar, foof, foop +export addRoom export print_expvar, ta, build_ta, cerr expvar = "Tau's exported variable" @@ -35,6 +36,10 @@ sub cerr rte 2 end +sub addRoom(the_thing,d) + print the_thing.name,d +end + rem initialization ? "Tau::initilized" ? diff --git a/src/common/scan.c b/src/common/scan.c index e48ecfbc..beede9e3 100644 --- a/src/common/scan.c +++ b/src/common/scan.c @@ -2546,10 +2546,14 @@ void comp_text_line(char *text) { if (udp > -1) { bc_add_extpcode(&comp_prog, comp_extproctable[udp].lib_id, comp_extproctable[udp].symbol_index); - bc_add_code(&comp_prog, kwTYPE_LEVEL_BEGIN); char *next = trim_empty_parentheses(comp_bc_parm); - comp_expression(next, 0); - bc_add_code(&comp_prog, kwTYPE_LEVEL_END); + if (comp_is_parenthesized(next)) { + comp_expression(next, 0); + } else { + bc_add_code(&comp_prog, kwTYPE_LEVEL_BEGIN); + comp_expression(next, 0); + bc_add_code(&comp_prog, kwTYPE_LEVEL_END); + } } else { udp = comp_udp_id(comp_bc_name, 1); if (udp == -1) { From b32f15a8345d4c83d74f151fce6cc966268d0750 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Tue, 19 Aug 2014 22:21:39 +1000 Subject: [PATCH 09/21] COMMON: fix memory leak in uds --- src/common/var_uds.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/common/var_uds.c b/src/common/var_uds.c index 25f26419..0d896906 100644 --- a/src/common/var_uds.c +++ b/src/common/var_uds.c @@ -159,6 +159,8 @@ var_p_t uds_resolve_fields(const var_p_t var_p) { void var_free(uds_field_s* element) { if (element->var_owner_flag) { v_free(element->var); + tmp_free(element->var); + element->var = NULL; } } From 5b7eb8cb4964b7b33c52626e59a48aa977d036e2 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Tue, 19 Aug 2014 22:26:35 +1000 Subject: [PATCH 10/21] COMMON: fix memory leak in uds --- src/common/var_uds.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/common/var_uds.c b/src/common/var_uds.c index 0d896906..442eca05 100644 --- a/src/common/var_uds.c +++ b/src/common/var_uds.c @@ -156,11 +156,13 @@ var_p_t uds_resolve_fields(const var_p_t var_p) { /** * free any owned variable in element */ -void var_free(uds_field_s* element) { +void var_free(uds_field_s* element, int erase) { if (element->var_owner_flag) { v_free(element->var); - tmp_free(element->var); - element->var = NULL; + if (erase) { + tmp_free(element->var); + element->var = NULL; + } } } @@ -170,7 +172,7 @@ void var_free(uds_field_s* element) { void uds_clear(const var_p_t var) { uds_field_s *next = var->v.uds; while (next) { - var_free(next); + var_free(next, 0); next = next->next; } } @@ -181,7 +183,7 @@ void uds_clear(const var_p_t var) { void uds_free_element(uds_field_s* element) { if (element) { uds_free_element(element->next); - var_free(element); + var_free(element, 1); tmp_free(element); } } From 8c443e4da346e9551f7e91219cb1e9171945f85a Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Wed, 20 Aug 2014 19:19:10 +1000 Subject: [PATCH 11/21] COMMON: move hotspots to separate include --- src/common/hotspots.h | 193 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 src/common/hotspots.h diff --git a/src/common/hotspots.h b/src/common/hotspots.h new file mode 100644 index 00000000..144bec3d --- /dev/null +++ b/src/common/hotspots.h @@ -0,0 +1,193 @@ +// This file is part of SmallBASIC +// +// inlined hotspots +// +// This program is distributed under the terms of the GPL v2.0 or later +// Download the GNU Public License (GPL) from www.gnu.org +// +// Copyright(C) 2014 Chris Warren-Smith + +#include "common/var_uds.h" +#include "common/var_hash.h" + +void err_evsyntax(void); +void err_varisarray(void); +void err_varisnotarray(void); +void err_notavar(void); +var_t *code_resolve_varptr(var_t* var_p, int until_parens); + +/** + * @ingroup var + * + * returns the next integer and moves the IP 4 bytes forward. + * + * R(long int) <- Code[IP]; IP+=4 + */ +static inline dword code_getnext32(void) { + dword v; + memcpy(&v, prog_source + prog_ip, 4); + prog_ip += 4; + return v; +} + +/** + * @ingroup var + * + * returns the next 64bit and moves the instruction pointer to the next instruction + * + * R(double) <- Code[IP]; IP+=8 + */ +static inline double code_getnext64f() { + double v; + memcpy(&v, prog_source + prog_ip, sizeof(double)); + prog_ip += sizeof(double); + return v; +} + +#if defined(OS_PREC64) + +/** + * @ingroup var + * + * returns the next 64bit and moves the instruction pointer to the next instruction + */ +static inline var_int_t code_getnext64i() { + var_int_t v; + memcpy(&v, prog_source + prog_ip, sizeof(var_int_t)); + prog_ip += sizeof(var_int_t); + return v; +} + +/** + * @ingroup var + * + * returns the next 128bit and moves the instruction pointer to the next instruction + */ +static inline var_num_t code_getnext128f() { + var_num_t v; + memcpy(&v, prog_source + prog_ip, sizeof(var_num_t)); + prog_ip += sizeof(var_num_t); + return v; +} + +#endif + +/** + * @ingroup var + * + * returns the floating-point value of a var. + * if v is string it will converted to double. + * + * @param v the variable + * @return the numeric value of a variable + */ +static inline var_num_t v_getval(var_t *v) { + switch (v ? v->type : -1) { + case V_UDS: + return uds_to_int(v); + case V_HASH: + return hash_to_int(v); + case V_PTR: + return v->v.ap.p; + case V_INT: + return v->v.i; + case V_NUM: + return v->v.n; + case V_STR: + return numexpr_sb_strtof((char *) v->v.p.ptr); + default: + if (v == NULL) { + err_evsyntax(); + } else { + err_varisarray(); + } + } + return 0; +} + +#define v_getnum(a) v_getval((a)) + +/** + * @ingroup var + * + * returns the integer value of a var. + * if v is string it will converted to integer. + * + * @param v the variable + * @return the integer value of a variable + */ +static inline var_int_t v_igetval(var_t *v) { + switch (v ? v->type : -1) { + case V_UDS: + return uds_to_int(v); + case V_HASH: + return hash_to_int(v); + case V_PTR: + return v->v.ap.p; + case V_INT: + return v->v.i; + case V_NUM: + return v->v.n; + case V_STR: + return numexpr_strtol((char *) v->v.p.ptr); + default: + if (v == NULL) { + err_evsyntax(); + } else { + err_varisarray(); + } + } + return 0; +} + +/** + * @ingroup exec + * + * variant of code_getvarptr() derefence until left parenthesis found + * + * R(var_t*) <- Code[IP]; IP += 2; + * + * @return the var_t* + */ +static inline var_t* code_getvarptr_parens(int until_parens) { + var_t *var_p = NULL; + + switch (code_peek()) { + case kwTYPE_VAR: + code_skipnext(); + var_p = tvar[code_getaddr()]; + switch (var_p->type) { + case V_HASH: + case V_ARRAY: + var_p = code_resolve_varptr(var_p, until_parens); + break; + default: + if (!until_parens && code_peek() == kwTYPE_LEVEL_BEGIN) { + err_varisnotarray(); + } + } + break; + + case kwTYPE_UDS: + code_skipnext(); + var_p = tvar[code_getaddr()]; + var_p = code_resolve_varptr(uds_resolve_fields(var_p), until_parens); + break; + } + + if (var_p == NULL && !prog_error) { + err_notavar(); + return tvar[0]; + } + + return var_p; +} + +/** + * @ingroup var + * + * Returns the varptr of the next variable. if the variable is an array + * returns the element ptr + */ +#define code_getvarptr() code_getvarptr_parens(0) + From 22c8844b294d54af53af70fa7cb1d69620e98cfb Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Thu, 21 Aug 2014 06:40:25 +1000 Subject: [PATCH 12/21] COMMON: update changelog --- ChangeLog | 4 +- src/common/scan.c | 2 +- src/common/smbas.h | 183 +-------------------------------------------- 3 files changed, 5 insertions(+), 184 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7c2ffdaa..f90dba3a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2014-08-15 - Performance tweaks + Improved runtime performance + Fixed memory leak with UDS variables + Fixed FUNC call with parenthesis 2014-08-14 Added SHOWPAGE. code cleanup diff --git a/src/common/scan.c b/src/common/scan.c index beede9e3..04241c9b 100644 --- a/src/common/scan.c +++ b/src/common/scan.c @@ -1560,7 +1560,7 @@ int comp_single_line_if(char *text) { char *pthen, *pelse; char buf[SB_SOURCELINE_SIZE + 1]; -if( comp_error) { + if (comp_error) { return 0; } pthen = p; diff --git a/src/common/smbas.h b/src/common/smbas.h index 86929518..308c0a92 100644 --- a/src/common/smbas.h +++ b/src/common/smbas.h @@ -13,8 +13,6 @@ #include "common/sys.h" #include "common/pmem.h" #include "common/var.h" -#include "common/var_uds.h" -#include "common/var_hash.h" #include "common/kw.h" #include "common/scan.h" @@ -220,186 +218,7 @@ EXTERN char gsb_last_errmsg[SB_ERRMSG_SIZE + 1]; /**< last error message #undef EXTERN -/** - * @ingroup var - * - * returns the next integer and moves the IP 4 bytes forward. - * - * R(long int) <- Code[IP]; IP+=4 - */ -static inline dword code_getnext32(void) { - dword v; - memcpy(&v, prog_source + prog_ip, 4); - prog_ip += 4; - return v; -} - -/** - * @ingroup var - * - * returns the next 64bit and moves the instruction pointer to the next instruction - * - * R(double) <- Code[IP]; IP+=8 - */ -static inline double code_getnext64f() { - double v; - memcpy(&v, prog_source + prog_ip, sizeof(double)); - prog_ip += sizeof(double); - return v; -} - -#if defined(OS_PREC64) - -/** - * @ingroup var - * - * returns the next 64bit and moves the instruction pointer to the next instruction - */ -static inline var_int_t code_getnext64i() { - var_int_t v; - memcpy(&v, prog_source + prog_ip, sizeof(var_int_t)); - prog_ip += sizeof(var_int_t); - return v; -} - -/** - * @ingroup var - * - * returns the next 128bit and moves the instruction pointer to the next instruction - */ -static inline var_num_t code_getnext128f() { - var_num_t v; - memcpy(&v, prog_source + prog_ip, sizeof(var_num_t)); - prog_ip += sizeof(var_num_t); - return v; -} - -#endif - -void err_evsyntax(void); -void err_varisarray(void); -void err_varisnotarray(void); -void err_notavar(void); -var_t *code_resolve_varptr(var_t* var_p, int until_parens); - -/** - * @ingroup var - * - * returns the floating-point value of a var. - * if v is string it will converted to double. - * - * @param v the variable - * @return the numeric value of a variable - */ -static inline var_num_t v_getval(var_t *v) { - switch (v ? v->type : -1) { - case V_UDS: - return uds_to_int(v); - case V_HASH: - return hash_to_int(v); - case V_PTR: - return v->v.ap.p; - case V_INT: - return v->v.i; - case V_NUM: - return v->v.n; - case V_STR: - return numexpr_sb_strtof((char *) v->v.p.ptr); - default: - if (v == NULL) { - err_evsyntax(); - } else { - err_varisarray(); - } - } - return 0; -} - -#define v_getnum(a) v_getval((a)) - -/** - * @ingroup var - * - * returns the integer value of a var. - * if v is string it will converted to integer. - * - * @param v the variable - * @return the integer value of a variable - */ -static inline var_int_t v_igetval(var_t *v) { - switch (v ? v->type : -1) { - case V_UDS: - return uds_to_int(v); - case V_HASH: - return hash_to_int(v); - case V_PTR: - return v->v.ap.p; - case V_INT: - return v->v.i; - case V_NUM: - return v->v.n; - case V_STR: - return numexpr_strtol((char *) v->v.p.ptr); - default: - if (v == NULL) { - err_evsyntax(); - } else { - err_varisarray(); - } - } - return 0; -} - -/** - * @ingroup exec - * - * variant of code_getvarptr() derefence until left parenthesis found - * - * R(var_t*) <- Code[IP]; IP += 2; - * - * @return the var_t* - */ -static inline var_t* code_getvarptr_parens(int until_parens) { - var_t *var_p = NULL; - - switch (code_peek()) { - case kwTYPE_VAR: - code_skipnext(); - var_p = tvar[code_getaddr()]; - switch (var_p->type) { - case V_HASH: - case V_ARRAY: - var_p = code_resolve_varptr(var_p, until_parens); - break; - default: - if (!until_parens && code_peek() == kwTYPE_LEVEL_BEGIN) { - err_varisnotarray(); - } - } - break; - - case kwTYPE_UDS: - code_skipnext(); - var_p = tvar[code_getaddr()]; - var_p = code_resolve_varptr(uds_resolve_fields(var_p), until_parens); - break; - } - - if (var_p == NULL && !prog_error) { - err_notavar(); - return tvar[0]; - } - - return var_p; -} - -/** - * @ingroup var - * - * Returns the varptr of the next variable. if the variable is an array - * returns the element ptr - */ -#define code_getvarptr() code_getvarptr_parens(0) +#include "common/hotspots.h" /** * @ingroup exec From d2640ba54dee6bae72931aa04643217f4807ec40 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Fri, 22 Aug 2014 18:30:31 +1000 Subject: [PATCH 13/21] COMMON: fix hash, code cleanup --- samples/distro-examples/graphics/plasma2.bas | 44 +++++++++++ src/common/brun.c | 82 ++++++-------------- src/common/fs_stream.c | 16 ++-- src/common/search.c | 1 + src/common/var_hash.c | 24 +++--- src/common/var_uds.c | 4 +- src/platform/unix/Makefile.am | 3 +- 7 files changed, 92 insertions(+), 82 deletions(-) create mode 100644 samples/distro-examples/graphics/plasma2.bas diff --git a/samples/distro-examples/graphics/plasma2.bas b/samples/distro-examples/graphics/plasma2.bas new file mode 100644 index 00000000..217be7d0 --- /dev/null +++ b/samples/distro-examples/graphics/plasma2.bas @@ -0,0 +1,44 @@ +DIM r(256) +DIM g(256) +DIM b(256) +LET f=0 +CLS + +FOR x=0 TO 255 + LET r(x)=255-CEIL((SIN(PI*2*x/255)+1)*127) + LET g(x)=CEIL((SIN(PI*2*x/127)+1)*64) + LET b(x)=255-r(x) +NEXT x + +bw=xmax/3 +bh=ymax/3 +t1=timer + +while 1 + t=TICKS + FOR y=0 TO bh + FOR x=0 TO bw + LET c1=SIN(x/50+f+y/200) + LET c2=SQR((SIN(0.8*f)*400-x+400)*(SIN(0.8*f)*400-x+400)+(COS(1.2*f)*240-y+240)*(COS(1.2*f)*240-y+240)) + LET c2=SIN(c2/50) + LET c3=(c1+c2)/2 + LET res=(c3+1)*127 + + color RGB(r(res),g(res),b(res)) + pset x,y + NEXT x + NEXT y + + fps=TICKSPERSEC/(TICKS-t) + iter++ + at bw+10,0 + print format("Fps: ###.##", fps) + at bw+10,20 + print format("Cnt: ###", iter) + at bw+10,40 + print format("Elap: ###", timer-t1) + + SHOWPAGE + f += 0.1 +wend + diff --git a/src/common/brun.c b/src/common/brun.c index 37231dbb..6774aa57 100755 --- a/src/common/brun.c +++ b/src/common/brun.c @@ -34,9 +34,6 @@ void code_pop_until(int type); void code_pop_and_free(stknode_t *node); stknode_t *code_stackpeek(); void sys_before_comp(); -void sys_after_comp(); -void sys_before_run(); -void sys_after_run(); int sbasic_exec_task(int tid); int sbasic_recursive_exec(int tid); void sbasic_exec_prepare(const char *filename); @@ -45,7 +42,7 @@ 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); +var_t *code_resolve_varptr(var_t *var_p, int until_parens); static dword evt_check_every; static char fileName[OS_FILENAME_SIZE + 1]; @@ -62,7 +59,7 @@ void code_jump_label(word label_id) { /** * Put the node 'node' in stack (PUSH) */ -void code_push(stknode_t * node) { +void code_push(stknode_t *node) { #if defined(_UnixOS) && defined(_CHECK_STACK) int i; #endif @@ -88,7 +85,7 @@ void code_push(stknode_t * node) { /** * Returns and deletes the topmost node from stack (POP) */ -void code_pop(stknode_t * node) { +void code_pop(stknode_t *node) { #if defined(_UnixOS) && defined(_CHECK_STACK) int i; #endif @@ -116,7 +113,7 @@ void code_pop(stknode_t * node) { /** * Returns and deletes the topmost node from stack (POP) */ -void code_pop_and_free(stknode_t * node) { +void code_pop_and_free(stknode_t *node) { #if defined(_UnixOS) && defined(_CHECK_STACK) int i; #endif @@ -212,11 +209,14 @@ stknode_t *code_stackpeek() { /** * Convertion multi-dim index to one-dim index */ -addr_t getarrayidx(var_t* array, var_t** var_hash_val) { +addr_t getarrayidx(var_t *array, var_t **var_hash_val) { + addr_t idx = 0; + addr_t lev = 0; + addr_t m = 0; byte code; var_t var; - addr_t idx = 0, lev = 0, m = 0; - addr_t idim, i; + addr_t idim; + addr_t i; do { v_init(&var); @@ -271,7 +271,7 @@ addr_t getarrayidx(var_t* array, var_t** var_hash_val) { /** * Used by code_getvarptr() to retrieve an element ptr of an array */ -var_t *code_getvarptr_arridx(var_t* basevar_p) { +var_t *code_getvarptr_arridx(var_t *basevar_p) { addr_t array_index; var_t *var_p = NULL; @@ -315,7 +315,7 @@ 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) { +var_t *code_resolve_varptr(var_t *var_p, int until_parens) { if (var_p) { switch (code_peek()) { case kwTYPE_LEVEL_BEGIN: @@ -334,7 +334,7 @@ var_t* code_resolve_varptr(var_t* var_p, int until_parens) { /** * Used by code_isvar() to retrieve an element ptr of an array */ -var_t *code_isvar_arridx(var_t * basevar_p) { +var_t *code_isvar_arridx(var_t *basevar_p) { addr_t array_index; var_t *var_p = NULL; @@ -381,7 +381,8 @@ var_t *code_isvar_arridx(var_t * basevar_p) { * returns false */ int code_isvar() { - var_t *basevar_p, *var_p = NULL; + var_t *basevar_p; + var_t *var_p = NULL; addr_t cur_ip; cur_ip = prog_ip; // store IP @@ -658,7 +659,6 @@ void cmd_chain(void) { // compile the buffer sys_before_comp(); success = comp_compile_buffer(code); - sys_after_comp(); v_free(&var); if (code_alloc) { @@ -672,7 +672,6 @@ void cmd_chain(void) { } tid_main = brun_create_task("CH_MAIN", bytecode_h, 0); - sys_before_run(); dev_init(opt_graphics, 0); exec_sync_variables(0); @@ -680,7 +679,6 @@ void cmd_chain(void) { bc_loop(0); success = prog_error; // save tid_main status - sys_after_run(); exec_close_task(); // cleanup task data - tid_main close_task(tid_main); // cleanup task container close_task(tid_base); // cleanup task container @@ -977,15 +975,11 @@ void bc_loop(int isf) { pcode = code_getaddr(); switch (pcode) { case kwCLS: - // cdw-s 19/11/2004 - // dev_cls(); called in graph_reset() graph_reset(); break; case kwRTE: cmd_RTE(); break; - // case kwSHELL: - // break; case kwENVIRON: cmd_environ(); break; @@ -1230,20 +1224,12 @@ void bc_loop(int isf) { IF_ERR_BREAK; continue; - // ////////////// case kwLINE: cmd_line(); break; - - // third class case kwCOLOR: cmd_color(); break; - // case kwINTEGRAL: - // cmd_integral(); - // break; - - // --- at end --- case kwOPEN: cmd_fopen(); break; @@ -1283,7 +1269,6 @@ void bc_loop(int isf) { case kwTROFF: trace_flag = 0; continue; - case kwSTOP: case kwEND: if ((prog_length - 1) > prog_ip) { @@ -1369,8 +1354,9 @@ void dump_stack() { break; } } - } else + } else { break; + } } while (1); } @@ -1449,7 +1435,6 @@ int brun_create_task(const char *filename, mem_t preloaded_bc, int libf) { } // create task - tid = create_task(fname); // create a task activate_task(tid); // make it active bytecode_h = bc_h; @@ -1541,7 +1526,6 @@ int brun_create_task(const char *filename, mem_t preloaded_bc, int libf) { prog_source = cp; prog_ip = 0; - // exec_setup_predefined_variables(); // init the keyboard map @@ -1652,7 +1636,8 @@ int exec_close_task() { // clean up - prog stack while (prog_stack_count > 0) { code_pop_and_free(&node); - }tmp_free(prog_stack); + } + tmp_free(prog_stack); // clean up - variables for (i = 0; i < (int) prog_varcount; i++) { int j, shared; @@ -1773,30 +1758,13 @@ void exec_sync_variables(int dir) { void sys_before_comp() { // setup prefered screen mode variables if (dev_getenv("SBGRAF")) { - if (dev_getenv("SBGRAF")) + if (dev_getenv("SBGRAF")) { comp_preproc_grmode(dev_getenv("SBGRAF")); + } opt_graphics = 2; } } -/** - * system specific things - after compilation - */ -void sys_after_comp() { -} - -/** - * system specific things - before execution - */ -void sys_before_run() { -} - -/** - * system specific things - after execution - */ -void sys_after_run() { -} - /** * execute the code on this task */ @@ -1868,7 +1836,7 @@ void sbasic_dump_taskinfo(FILE * output) { /** * dump-bytecode */ -void sbasic_dump_bytecode(int tid, FILE * output) { +void sbasic_dump_bytecode(int tid, FILE *output) { int i; int prev_tid; @@ -1941,7 +1909,6 @@ int sbasic_compile(const char *file) { if (comp_rq) { sys_before_comp(); // system specific preparations for compilation success = comp_compile(file); - sys_after_comp(); // system specific things; after compilation } return success; } @@ -2005,7 +1972,6 @@ int sbasic_exec(const char *file) { // load everything sbasic_exec_prepare(file); - sys_before_run(); // system specific things; before run dev_init(opt_graphics, 0); // initialize output device for graphics evt_check_every = (50 * CLOCKS_PER_SEC) / 1000; // setup event checker time = 50ms srand(clock()); // randomize @@ -2020,8 +1986,6 @@ int sbasic_exec(const char *file) { exec_close(exec_tid); // clean up executor's garbages dev_restore(); // restore device - - sys_after_run(); // system specific things; after run } // update IDE when it used as external if (opt_ide == IDE_EXTERNAL) { @@ -2040,7 +2004,7 @@ int sbasic_exec(const char *file) { } } - // cdw-s 22/11/2004 return as failure for compilation errors + // return compilation errors as failure return !success ? 0 : !gsb_last_error; } diff --git a/src/common/fs_stream.c b/src/common/fs_stream.c index 9301cd2c..b74e8ae1 100644 --- a/src/common/fs_stream.c +++ b/src/common/fs_stream.c @@ -29,7 +29,7 @@ /* * open a file */ -int stream_open(dev_file_t * f) { +int stream_open(dev_file_t *f) { int osflags, osshare; if (f->open_flags == DEV_FILE_OUTPUT) { @@ -82,7 +82,7 @@ int stream_open(dev_file_t * f) { /* * close the stream */ -int stream_close(dev_file_t * f) { +int stream_close(dev_file_t *f) { int r; r = close(f->handle); @@ -95,7 +95,7 @@ int stream_close(dev_file_t * f) { /* */ -int stream_write(dev_file_t * f, byte * data, dword size) { +int stream_write(dev_file_t *f, byte *data, dword size) { int r; r = write(f->handle, data, size); @@ -108,7 +108,7 @@ int stream_write(dev_file_t * f, byte * data, dword size) { /* */ -int stream_read(dev_file_t * f, byte * data, dword size) { +int stream_read(dev_file_t *f, byte *data, dword size) { int r; r = read(f->handle, data, size); @@ -121,14 +121,14 @@ int stream_read(dev_file_t * f, byte * data, dword size) { /* * returns the current position */ -dword stream_tell(dev_file_t * f) { +dword stream_tell(dev_file_t *f) { return lseek(f->handle, 0, SEEK_CUR); } /* * returns the file-length */ -dword stream_length(dev_file_t * f) { +dword stream_length(dev_file_t *f) { long pos, endpos; pos = lseek(f->handle, 0, SEEK_CUR); @@ -144,13 +144,13 @@ dword stream_length(dev_file_t * f) { /* */ -dword stream_seek(dev_file_t * f, dword offset) { +dword stream_seek(dev_file_t *f, dword offset) { return lseek(f->handle, offset, SEEK_SET); } /* */ -int stream_eof(dev_file_t * f) { +int stream_eof(dev_file_t *f) { long pos, endpos; pos = lseek(f->handle, 0, SEEK_CUR); diff --git a/src/common/search.c b/src/common/search.c index fba8b044..59641326 100644 --- a/src/common/search.c +++ b/src/common/search.c @@ -76,6 +76,7 @@ void *tsearch(const void *vkey, void **vrootp, tcompare_cb compar) { // key not found. make new node and link to old q = malloc(sizeof(node_t)); if (q != 0) { + rootp = (node_t **)vrootp; *rootp = q; q->key = (void *)vkey; q->left = q->right = NULL; diff --git a/src/common/var_hash.c b/src/common/var_hash.c index a212e0ec..521cbd22 100644 --- a/src/common/var_hash.c +++ b/src/common/var_hash.c @@ -47,8 +47,8 @@ typedef struct Node { /** * Returns a new Element */ -Element* create_element(var_p_t key) { - Element* element = (Element*) tmp_alloc(sizeof (Element)); +Element *create_element(var_p_t key) { + Element *element = (Element *) tmp_alloc(sizeof (Element)); element->key = v_new(); v_createstr(element->key, key->v.p.ptr); element->value = NULL; @@ -58,7 +58,7 @@ Element* create_element(var_p_t key) { /** * cleanup the given element */ -void delete_element(Element* element) { +void delete_element(Element *element) { v_free(element->key); tmp_free(element->key); // cleanup v_new @@ -73,8 +73,8 @@ void delete_element(Element* element) { * Callback to compare Element's */ int cmp_fn(const void *a, const void *b) { - Element* el_a = (Element*) a; - Element* el_b = (Element*) b; + Element *el_a = (Element *)a; + Element *el_b = (Element *)b; return strcasecmp(el_a->key->v.p.ptr, el_b->key->v.p.ptr); } @@ -125,7 +125,7 @@ int hash_length(const var_p_t var_p) { void hash_elem_cb(const void *nodep, VISIT value, int level) { if (value == leaf || value == endorder) { if (cb.count++ == cb.index) { - Element* element = ((Node*) nodep)->element; + Element *element = ((Node *) nodep)->element; cb.var = element->key; } } @@ -155,7 +155,7 @@ void hash_clear(const var_p_t var) { * Helper for hash_free_var */ void hash_free_cb(void *nodep) { - Element* element = (Element*) nodep; + Element *element = (Element *) nodep; delete_element(element); } @@ -182,8 +182,8 @@ void hash_get_value(var_p_t base, var_p_t var_key, var_p_t *result) { } // create a key which will hold our name and value pairs - Element* key = create_element(var_key); - Node* node = tfind(key, &base->v.hash, cmp_fn); + Element *key = create_element(var_key); + Node *node = tfind(key, &base->v.hash, cmp_fn); if (node != NULL) { // item already exists *result = node->element->value; @@ -202,8 +202,8 @@ void hash_get_value(var_p_t base, var_p_t var_key, var_p_t *result) { void hash_set_cb(const void *nodep, VISIT value, int level) { if (value == leaf || value == endorder) { // copy the element and insert it into the destination - Element* element = ((Node*) nodep)->element; - Element* key = create_element(element->key); + Element *element = ((Node *) nodep)->element; + Element *key = create_element(element->key); key->value = v_new(); v_set(key->value, element->value); tsearch(key, &cb.hash, cmp_fn); @@ -237,7 +237,7 @@ void hash_to_str(const var_p_t var_p, char *out, int max_len) { */ void hash_write_cb(const void *nodep, VISIT value, int level) { if (value == leaf || value == endorder) { - Element* element = ((Node*) nodep)->element; + Element *element = ((Node *) nodep)->element; if (!cb.firstElement) { pv_write(",", cb.method, cb.handle); } diff --git a/src/common/var_uds.c b/src/common/var_uds.c index 442eca05..7b4f1192 100644 --- a/src/common/var_uds.c +++ b/src/common/var_uds.c @@ -156,7 +156,7 @@ var_p_t uds_resolve_fields(const var_p_t var_p) { /** * free any owned variable in element */ -void var_free(uds_field_s* element, int erase) { +void var_free(uds_field_s *element, int erase) { if (element->var_owner_flag) { v_free(element->var); if (erase) { @@ -180,7 +180,7 @@ void uds_clear(const var_p_t var) { /** * Helper for uds_free */ -void uds_free_element(uds_field_s* element) { +void uds_free_element(uds_field_s *element) { if (element) { uds_free_element(element->next); var_free(element, 1); diff --git a/src/platform/unix/Makefile.am b/src/platform/unix/Makefile.am index 4dc5f02a..97be24b0 100644 --- a/src/platform/unix/Makefile.am +++ b/src/platform/unix/Makefile.am @@ -43,7 +43,8 @@ endif 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 pass1 call_tau short-circuit +UNIT_TESTS=array break byref eval-test iifs matrices metaa ongoto \ + uds hash pass1 call_tau short-circuit test: ${bin_PROGRAMS} @for utest in $(UNIT_TESTS); do \ From e9ae3aed52b5cb9e868bd10973dca59ea487a3eb Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Fri, 22 Aug 2014 18:50:20 +1000 Subject: [PATCH 14/21] COMMON: remove obsolete code --- ChangeLog | 4 +++ src/common/bc.c | 31 ++------------------ src/common/bc.h | 4 --- src/common/blib.c | 5 ---- src/common/ceval.c | 8 ------ src/common/pmem.h | 15 ---------- src/common/scan.c | 14 +-------- src/common/sys.h | 6 ---- src/common/var.c | 54 ++++------------------------------- src/common/var.h | 66 +++++++++++++------------------------------ src/common/var_hash.c | 2 +- 11 files changed, 33 insertions(+), 176 deletions(-) diff --git a/ChangeLog b/ChangeLog index f90dba3a..f5e5c8fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2014-08-22 + Fix HASH var crash + Fix HASH var handling of mixed types + 2014-08-15 Improved runtime performance Fixed memory leak with UDS variables diff --git a/src/common/bc.c b/src/common/bc.c index 66306ad0..7da37c00 100644 --- a/src/common/bc.c +++ b/src/common/bc.c @@ -128,22 +128,14 @@ void bc_add2l(bc_t * bc, byte code, long p1) { * add buildin function call */ void bc_add_fcode(bc_t *bc, long idx) { -#if defined(OS_ADDR16) - bc_add2i(bc, kwTYPE_CALLF, idx); -#else bc_add2l(bc, kwTYPE_CALLF, idx); -#endif } /* * add buildin procedure call */ void bc_add_pcode(bc_t *bc, long idx) { -#if defined(OS_ADDR16) - bc_add2i(bc, kwTYPE_CALLP, idx); -#else bc_add2l(bc, kwTYPE_CALLP, idx); -#endif } /* @@ -151,13 +143,8 @@ void bc_add_pcode(bc_t *bc, long idx) { */ void bc_add_extfcode(bc_t *bc, int lib, long idx) { bc_add_code(bc, kwTYPE_CALLEXTF); -#if defined(OS_ADDR16) - bc_add_word(bc, lib); - bc_add_word(bc, idx); -#else bc_add_dword(bc, lib); bc_add_dword(bc, idx); -#endif } /* @@ -165,13 +152,8 @@ void bc_add_extfcode(bc_t *bc, int lib, long idx) { */ void bc_add_extpcode(bc_t *bc, int lib, long idx) { bc_add_code(bc, kwTYPE_CALLEXTP); -#if defined(OS_ADDR16) - bc_add_word(bc, lib); - bc_add_word(bc, idx); -#else bc_add_dword(bc, lib); bc_add_dword(bc, idx); -#endif } /* @@ -181,13 +163,8 @@ void bc_add_addr(bc_t *bc, addr_t idx) { if (bc->count >= bc->size - 4) { bc_resize(bc, bc->size + BC_ALLOC_INCR); } -#if defined(OS_ADDR16) - memcpy(bc->ptr + bc->count, &idx, 2); - bc->count += 2; -#else memcpy(bc->ptr + bc->count, &idx, 4); bc->count += 4; -#endif } /* @@ -236,15 +213,11 @@ void bc_add2s(bc_t *bc, byte code, const char *p1) { sc_raise("STRING TOO BIG"); } else { bc_add_code(bc, code); -#if defined(OS_ADDR16) - bc_add_word(bc, l); -#else bc_add_dword(bc, l); -#endif - if (bc->count >= bc->size - l) + if (bc->count >= bc->size - l) { bc_resize(bc, bc->size + BC_ALLOC_INCR); - + } memcpy(bc->ptr + bc->count, p1, l); bc->count += l; } diff --git a/src/common/bc.h b/src/common/bc.h index 3da85f28..dd1402df 100644 --- a/src/common/bc.h +++ b/src/common/bc.h @@ -15,11 +15,7 @@ #include "common/kw.h" #define BC_ALLOC_INCR 1024 -#if defined(OS_ADDR16) -#define BC_MAX_STORE_SIZE 0x7FFF -#else #define BC_MAX_STORE_SIZE 0x7FFFFFFF -#endif /** * @ingroup scan diff --git a/src/common/blib.c b/src/common/blib.c index d888e78a..00dfeda3 100644 --- a/src/common/blib.c +++ b/src/common/blib.c @@ -2049,12 +2049,7 @@ void cmd_read() { prog_dp += OS_REALSZ; break; case kwTYPE_STR: { -#if defined(OS_ADDR16) - word len; -#else dword len; -#endif - prog_dp++; vp->type = V_STR; diff --git a/src/common/ceval.c b/src/common/ceval.c index 67eedbf5..61436520 100644 --- a/src/common/ceval.c +++ b/src/common/ceval.c @@ -41,11 +41,7 @@ static bc_t *bc_out; */ void cev_prim() { byte code; -#if defined(OS_ADDR16) - word len; -#else dword len; -#endif if (comp_error) { return; @@ -65,11 +61,7 @@ void cev_prim() { case kwTYPE_STR: memcpy(&len, bc_in->ptr + bc_in->cp, OS_STRLEN); IP += OS_STRLEN; -#if defined(OS_ADDR16) - bc_add_word(bc_out, len); -#else bc_add_dword(bc_out, len); -#endif bc_add_n(bc_out, bc_in->ptr + bc_in->cp, len); IP += len; diff --git a/src/common/pmem.h b/src/common/pmem.h index 8e2b7b12..51f9fcb3 100644 --- a/src/common/pmem.h +++ b/src/common/pmem.h @@ -51,20 +51,6 @@ typedef unsigned int dword; // code typedef byte code_t; /**< basic code unit (unsigned) @ingroup mem */ -#if defined(OS_ADDR16) // work with 16bits -#define ADDR16 // just for short defs -typedef int16 fcode_t; // buildin function code (signed) -typedef int16 pcode_t; // buildin procedure code (signed) -typedef word addr_t; // memory address (unsigned) -#define INVALID_ADDR 0xFFFF // invalid address value (unsigned) -typedef int16 bid_t; // IDs (labels, variables, etc) (signed) -#define OS_ADDRSZ 2 // size of address pointer (always 2 - // for 16b mode) -#define OS_CODESZ 2 // size of buildin func/proc ptrs - // (always 2 for 16b mode) -#define OS_STRLEN 2 // size of strings -#else - typedef int32 fcode_t; typedef int32 pcode_t; typedef int32 bid_t; @@ -77,7 +63,6 @@ typedef dword addr_t; #define OS_ADDRSZ 4 // size of address pointer (always 4 for 32b addresses) #define OS_CODESZ 4 // size of buildin func/proc ptrs (always 4 for 32b mode) #define OS_STRLEN 4 // size of strings -#endif #define ADDRSZ OS_ADDRSZ #define CODESZ OS_CODESZ diff --git a/src/common/scan.c b/src/common/scan.c index 04241c9b..4d9c9815 100644 --- a/src/common/scan.c +++ b/src/common/scan.c @@ -1825,11 +1825,7 @@ void comp_text_line(char *text) { char *p; char *lb_end; char *last_cmd; -#if defined(OS_ADDR16) - int idx; -#else long idx; -#endif int sharp, ladd, linc, ldec, decl = 0, vattr; int leqop; char pname[SB_KEYWORD_SIZE + 1]; @@ -2592,11 +2588,7 @@ void comp_text_line(char *text) { */ addr_t comp_next_bc_cmd(addr_t ip) { code_t code; -#if defined(ADDR16) - word len; -#else dword len; -#endif code = comp_prog.ptr[ip]; ip++; @@ -4217,13 +4209,9 @@ mem_t comp_create_bin() { #else hdr.flags = 0; #endif -#if defined(OS_ADDR16) - hdr.flags |= 2; -#elif defined(OS_ADDR32) - hdr.flags |= 4; -#endif // executable header + hdr.flags |= 4; hdr.bc_count = comp_prog.count; hdr.var_count = comp_varcount; hdr.lab_count = comp_labcount; diff --git a/src/common/sys.h b/src/common/sys.h index 722a5cbd..651d428c 100644 --- a/src/common/sys.h +++ b/src/common/sys.h @@ -32,11 +32,6 @@ * OS_FILEHANDLES Number of file handles to use. * Because there is a static array with information about each handle, * use small numbers on limited systems (a value of 16 is good enough). - * - * OS_ADDR32 Use 32bit code, in anycase - * - * OS_ADDR16 Use 16bit code, in anycase - * */ #if !defined(SB_SYS_H) @@ -94,7 +89,6 @@ typedef long int var_int_t; #define OS_INTSZ sizeof(var_int_t) // size of integer #define OS_REALSZ sizeof(var_num_t) // size of real -#define OS_ADDR32 #define mem_lock(h) (void *)(h) #define mem_unlock(h) diff --git a/src/common/var.c b/src/common/var.c index adf3d6b7..3fab4c2d 100644 --- a/src/common/var.c +++ b/src/common/var.c @@ -125,12 +125,7 @@ int v_length(var_t *var) { /* * return array element pointer */ -#if defined(OS_ADDR16) -var_t *v_getelemptr(var_t *v, word index) -#else -var_t *v_getelemptr(var_t *v, dword index) -#endif -{ +var_t *v_getelemptr(var_t *v, dword index) { if (v->type == V_ARRAY) { if (index < v->v.a.size) return (var_t *) (v->v.a.ptr + (index * sizeof(var_t))); @@ -147,19 +142,10 @@ var_t *v_getelemptr(var_t *v, dword index) /* * resize an existing array */ -#if defined(OS_ADDR16) -void v_resize_array(var_t *v, word size) -#else -void v_resize_array(var_t *v, dword size) -#endif -{ +void v_resize_array(var_t *v, dword size) { byte *prev; var_t *elem; -#if defined(OS_ADDR16) - word i; -#else dword i; -#endif if (v->type == V_ARRAY) { if (size < 0) { @@ -183,15 +169,9 @@ void v_resize_array(var_t *v, dword size) v_free(elem); } -#if defined(OS_ADDR32) // do not resize array prev = NULL; -#else - // resize & copy - prev = v->v.a.ptr; - v->v.a.ptr = tmp_alloc(size * sizeof(var_t)); - memcpy(v->v.a.ptr, prev, size * sizeof(var_t)); -#endif + // array data v->v.a.size = size; v->v.a.ubound[0] = v->v.a.lbound[0] + (size - 1); @@ -203,8 +183,6 @@ void v_resize_array(var_t *v, dword size) } } else if (v->v.a.size < size) { // resize up - -#if defined(OS_ADDR32) // if there is space do not resize if (v->v.a.size == 0) { prev = v->v.a.ptr; @@ -216,17 +194,10 @@ void v_resize_array(var_t *v, dword size) v->v.a.ptr = tmp_alloc((size + ARR_ALLOC) * sizeof(var_t)); if (v->v.a.size > 0) memcpy(v->v.a.ptr, prev, v->v.a.size * sizeof(var_t)); - } else + } else { prev = NULL; + } } -#else - // resize & copy - prev = v->v.a.ptr; - v->v.a.ptr = tmp_alloc(size * sizeof(var_t)); - if (v->v.a.size > 0) { - memcpy(v->v.a.ptr, prev, v->v.a.size * sizeof(var_t)); - } -#endif // init vars for (i = v->v.a.size; i < size; i++) { @@ -289,18 +260,9 @@ var_t *v_new_matrix(int r, int c) { /* * create array */ -#if defined(OS_ADDR16) -void v_toarray1(var_t *v, word r) -#else -void v_toarray1(var_t *v, dword r) -#endif -{ +void v_toarray1(var_t *v, dword r) { var_t *e; -#if defined(OS_ADDR16) - word i; -#else dword i; -#endif v_free(v); v->type = V_ARRAY; @@ -308,11 +270,7 @@ void v_toarray1(var_t *v, dword r) if (r > 0) { // create data v->v.a.size = r; -#if defined(OS_ADDR32) v->v.a.ptr = tmp_alloc(sizeof(var_t) * (v->v.a.size + ARR_ALLOC)); -#else - v->v.a.ptr = tmp_alloc(sizeof(var_t) * v->v.a.size); -#endif for (i = 0; i < r; i++) { e = (var_t *) (v->v.a.ptr + (sizeof(var_t) * i)); v_init(e); diff --git a/src/common/var.h b/src/common/var.h index 530c6dba..b03837ac 100644 --- a/src/common/var.h +++ b/src/common/var.h @@ -66,11 +66,7 @@ * @ingroup var * @def MAXDIM Maxium number of array-dimensions */ -#if defined(OS_ADDR16) -#define MAXDIM 3 // think before increase this, (possible stack overflow) -#else -#define MAXDIM 6 // that's large enough -#endif +#define MAXDIM 6 // think before increase this, (possible stack overflow) #include "common/scan.h" // compiler structures #if defined(__cplusplus) @@ -110,27 +106,16 @@ struct var_s { // generic ptr (string) struct { byte *ptr; /**< data ptr (possibly, string pointer) */ -#if defined(OS_ADDR16) - int16 size; /**< the size of the string */ - int16 pos; /**< position in string (used by pv_* functions) */ -#else int32 size; /**< the size of string */ int32 pos; /**< position in string (used by pv_* functions) */ -#endif } p; // array struct { byte *ptr; /**< array data ptr (sizeof(var_t) * size) */ -#if defined(OS_ADDR16) - int16 size; /**< the number of elements */ - int16 lbound[MAXDIM]; /**< lower bound */ - int16 ubound[MAXDIM]; /**< upper bound */ -#else int32 size; /**< the number of elements */ int32 lbound[MAXDIM]; /**< lower bound */ int32 ubound[MAXDIM]; /**< upper bound */ -#endif byte maxdim; /**< number of dimensions */ } a; } v; @@ -349,11 +334,7 @@ int v_sign(var_t *x); * @param index is the element's index number * @return the var_t pointer of an array element */ -#if defined(OS_ADDR16) -var_t *v_getelemptr(var_t *v, word index); -#else var_t *v_getelemptr(var_t *v, dword index); -#endif /** * @ingroup var @@ -413,11 +394,7 @@ var_t *v_clone(const var_t *source); * @param v the variable * @param size the number of the elements */ -#if defined(OS_ADDR16) -void v_resize_array(var_t *v, word size); -#else void v_resize_array(var_t *v, dword size); -#endif /** * @ingroup var @@ -450,11 +427,7 @@ var_t *v_new_matrix(int r, int c); * @param v the variable * @param r the number of the elements */ -#if defined(OS_ADDR16) -void v_toarray1(var_t *v, word r); -#else void v_toarray1(var_t *v, dword r); -#endif /** * @ingroup var @@ -652,25 +625,29 @@ void v_zerostr(var_t *var); */ void v_input2var(const char *str, var_t *var); -/**< returns the var_t pointer of the element i - on the array x. i is a zero-based, one dim, index. - @ingroup var */ +/** + *< returns the var_t pointer of the element i + * on the array x. i is a zero-based, one dim, index. + * @ingroup var +*/ #define v_elem(x,i) (var_t *) ( (x)->v.a.ptr + (sizeof(var_t) * (i))) -/**< the number of the elements of the array (x) - @ingroup var */ - +/** + * < the number of the elements of the array (x) + * @ingroup var + */ #define v_asize(x) ((x)->v.a.size) -/* - * new api (dec 2001) - get value +/** + * < returns the integer value of variable v + * @ingroup var */ -/**< returns the integer value of variable v - @ingroup var */ #define v_getint(v) v_igetval((v)) -/**< returns the real value of variable v - @ingroup var */ +/** + * < returns the real value of variable v + * @ingroup var + */ #define v_getreal(v) v_getval((v)) /** @@ -771,17 +748,10 @@ stknode_t *code_stackpeek(); #define code_getsep() (prog_ip ++, prog_source[prog_ip++]) #define code_peeksep() (prog_source[prog_ip+1]) -#if defined(OS_ADDR16) -#define code_getaddr() code_getnext16() -#define code_skipaddr() code_skipnext16() -#define code_getstrlen() code_getnext16() -#define code_peekaddr(i) code_peek16((i)) -#else #define code_getaddr() code_getnext32() /**< get address value and advance @ingroup exec */ #define code_skipaddr() code_skipnext32() /**< skip address field @ingroup exec */ #define code_getstrlen() code_getnext32() /**< get strlen (kwTYPE_STR) and advance @ingroup exec */ #define code_peekaddr(i) code_peek32((i)) /**< peek address field at offset i @ingroup exec */ -#endif #if defined(OS_PREC64) #define code_getint() code_getnext64i() @@ -840,10 +810,12 @@ void setsysvar_str(int index, const char *value); * in eval.c */ var_num_t *mat_toc(var_t *v, int32 *rows, int32 *cols); + void mat_tov(var_t *v, var_num_t *m, int32 rows, int32 cols, int protect_col1); #if defined(__cplusplus) } #endif + #endif diff --git a/src/common/var_hash.c b/src/common/var_hash.c index 521cbd22..ff8479b3 100644 --- a/src/common/var_hash.c +++ b/src/common/var_hash.c @@ -75,7 +75,7 @@ void delete_element(Element *element) { int cmp_fn(const void *a, const void *b) { Element *el_a = (Element *)a; Element *el_b = (Element *)b; - return strcasecmp(el_a->key->v.p.ptr, el_b->key->v.p.ptr); + return v_compare(el_a->key, el_b->key); } /** From 0a2ab9d7ae65cc526d3569fd574c71a9cdfe4ec0 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Fri, 22 Aug 2014 19:42:57 +1000 Subject: [PATCH 15/21] COMMON: fix hash, code cleanup --- src/common/ceval.c | 1 - src/common/search.c | 29 ++++++++++--------- src/common/var.c | 69 +++++++++++++++++++-------------------------- 3 files changed, 45 insertions(+), 54 deletions(-) diff --git a/src/common/ceval.c b/src/common/ceval.c index 61436520..b968d6e9 100644 --- a/src/common/ceval.c +++ b/src/common/ceval.c @@ -63,7 +63,6 @@ void cev_prim() { IP += OS_STRLEN; bc_add_dword(bc_out, len); bc_add_n(bc_out, bc_in->ptr + bc_in->cp, len); - IP += len; break; case kwTYPE_CALL_UDP: diff --git a/src/common/search.c b/src/common/search.c index 59641326..b8144bfb 100644 --- a/src/common/search.c +++ b/src/common/search.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "search.h" @@ -67,20 +68,22 @@ void *tfind(const void *vkey, void **vrootp, tcompare_cb compar) { /* find or insert datum into search tree */ void *tsearch(const void *vkey, void **vrootp, tcompare_cb compar) { - node_t **rootp = (node_t **) tfind(vkey, vrootp, compar); - node_t *q; - - if (rootp != NULL) { - q = *rootp; - } else { - // key not found. make new node and link to old - q = malloc(sizeof(node_t)); - if (q != 0) { - rootp = (node_t **)vrootp; - *rootp = q; - q->key = (void *)vkey; - q->left = q->right = NULL; + node_t **rootp = (node_t **)vrootp; + if (rootp == NULL) { + return NULL; + } + while (*rootp != NULL) { + int r; + if ((r = compar(vkey, (*rootp)->key)) == 0) { + return *rootp; } + rootp = (r < 0) ? &(*rootp)->left : &(*rootp)->right; + } + node_t *q = malloc(sizeof(node_t)); + if (q != 0) { + *rootp = q; + q->key = (void *)vkey; + q->left = q->right = NULL; } return q; } diff --git a/src/common/var.c b/src/common/var.c index 3fab4c2d..ef5f93f9 100644 --- a/src/common/var.c +++ b/src/common/var.c @@ -177,13 +177,12 @@ void v_resize_array(var_t *v, dword size) { v->v.a.ubound[0] = v->v.a.lbound[0] + (size - 1); v->v.a.maxdim = 1; - // if (prev) { tmp_free(prev); } } else if (v->v.a.size < size) { // resize up - // if there is space do not resize + // if there is space do not resize if (v->v.a.size == 0) { prev = v->v.a.ptr; v->v.a.ptr = tmp_alloc((size + ARR_ALLOC) * sizeof(var_t)); @@ -210,7 +209,6 @@ void v_resize_array(var_t *v, dword size) { v->v.a.ubound[0] = v->v.a.lbound[0] + (size - 1); v->v.a.maxdim = 1; - // if (prev) { tmp_free(prev); } @@ -345,32 +343,36 @@ int v_compare(var_t *a, var_t *b) { return strcmp(a->v.p.ptr, b->v.p.ptr); } if ((a->type == V_STR) && (b->type == V_NUM)) { - if (a->v.p.ptr[0] == '\0' || is_number((char *) a->v.p.ptr)) { // compare - // nums + if (a->v.p.ptr[0] == '\0' || is_number((char *) a->v.p.ptr)) { + // compare nums dt = v_getval(a); - return (dt < b->v.n) ? -1 : ((dt == b->v.n) ? 0 : 1);} -return 1; + return (dt < b->v.n) ? -1 : ((dt == b->v.n) ? 0 : 1); + } + return 1; } if ((a->type == V_NUM) && (b->type == V_STR)) { - if (b->v.p.ptr[0] == '\0' || is_number((char *) b->v.p.ptr)) { // compare - // nums + if (b->v.p.ptr[0] == '\0' || is_number((char *) b->v.p.ptr)) { + // compare nums dt = v_getval(b); - return (dt < a->v.n) ? 1 : ((dt == a->v.n) ? 0 : -1);}return -- 1; + return (dt < a->v.n) ? 1 : ((dt == a->v.n) ? 0 : -1); + } + return - 1; } if ((a->type == V_STR) && (b->type == V_INT)) { - if (a->v.p.ptr[0] == '\0' || is_number((char *) a->v.p.ptr)) { // compare - // nums + if (a->v.p.ptr[0] == '\0' || is_number((char *) a->v.p.ptr)) { + // compare nums di = v_igetval(a); - return (di < b->v.i) ? -1 : ((di == b->v.i) ? 0 : 1);} -return 1; + return (di < b->v.i) ? -1 : ((di == b->v.i) ? 0 : 1); + } + return 1; } if ((a->type == V_INT) && (b->type == V_STR)) { - if (b->v.p.ptr[0] == '\0' || is_number((char *) b->v.p.ptr)) { // compare - // nums + if (b->v.p.ptr[0] == '\0' || is_number((char *) b->v.p.ptr)) { + // compare nums di = v_igetval(b); - return (di < a->v.i) ? 1 : ((di == a->v.i) ? 0 : -1);}return -- 1; + return (di < a->v.i) ? 1 : ((di == a->v.i) ? 0 : -1); + } + return - 1; } if ((a->type == V_ARRAY) && (b->type == V_ARRAY)) { // check size @@ -388,8 +390,8 @@ return 1; return ci; } } - - return 0; // equal + // equal + return 0; } if (a->type == V_UDS && b->type == V_UDS) { @@ -400,25 +402,10 @@ return 1; return hash_compare(a, b); } - err_evtype(); // ndc 01/08/2001 + err_evtype(); return 1; } -/* - */ -int v_addtype(var_t *a, var_t *b) { - if (a->type == V_STR) { - return V_STR; - } - if (a->type == V_NUM || b->type == V_NUM) { - return V_NUM; - } - if (a->type == V_INT || b->type == V_STR) { - return V_NUM; - } - return V_INT; -} - /* * add two variables * result = a + b @@ -512,6 +499,7 @@ void v_set(var_t *dest, const var_t *src) { return; } else if (dest->type == V_HASH) { // lvalue struct assigned to non-struct rvalue + fprintf(stderr, "hash_clear\n"); hash_clear(dest); return; } @@ -585,8 +573,8 @@ void v_inc(var_t *a, var_t *b) { */ int v_sign(var_t *x) { if (x->type == V_INT) { - return (x->v.i < 0) ? -1 : ((x->v.i == 0) ? 0 : 1);} -else if (x->type == V_NUM) { + return (x->v.i < 0) ? -1 : ((x->v.i == 0) ? 0 : 1); + } else if (x->type == V_NUM) { return (x->v.n < 0) ? -1 : ((x->v.n == 0) ? 0 : 1); } err_varnotnum(); @@ -794,7 +782,8 @@ void v_zerostr(var_t *r) { void v_input2var(const char *str, var_t *var) { v_free(var); - if (strlen(str) == 0) { // no data + if (strlen(str) == 0) { + // no data v_setstr(var, str); } else { char *np, *sb; From 92acc0b7db3508d899c07251cc054b3c1bfaf5c5 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Fri, 22 Aug 2014 21:36:34 +1000 Subject: [PATCH 16/21] COMMON: code cleanup, fix hash --- samples/distro-examples/tests/hash.bas | 1 + samples/distro-examples/tests/output/hash.out | 3 + src/common/brun.c | 4 +- src/common/proc.c | 91 ++++++++----------- src/common/var.c | 7 +- src/common/var_hash.c | 41 ++++++++- 6 files changed, 86 insertions(+), 61 deletions(-) create mode 100644 samples/distro-examples/tests/output/hash.out diff --git a/samples/distro-examples/tests/hash.bas b/samples/distro-examples/tests/hash.bas index 4b4ec0b0..3f426845 100644 --- a/samples/distro-examples/tests/hash.bas +++ b/samples/distro-examples/tests/hash.bas @@ -3,6 +3,7 @@ dim foo key="blah" foo(key) = "something" foo("other") = 123 +foo(100) = "cats" ? foo(key) ? foo("other") diff --git a/samples/distro-examples/tests/output/hash.out b/samples/distro-examples/tests/output/hash.out new file mode 100644 index 00000000..cedbb133 --- /dev/null +++ b/samples/distro-examples/tests/output/hash.out @@ -0,0 +1,3 @@ +something +123 +[blah=something,other=123,100=cats] diff --git a/src/common/brun.c b/src/common/brun.c index 6774aa57..815997d2 100755 --- a/src/common/brun.c +++ b/src/common/brun.c @@ -223,8 +223,8 @@ addr_t getarrayidx(var_t *array, var_t **var_hash_val) { eval(&var); IF_ERR_RETURN_0; - if (var.type == V_STR) { - // array elemement is a string - convert array to hash + if (var.type == V_STR || array->type == V_HASH) { + // array elemement is a string or element is addressing a hash hash_get_value(array, &var, var_hash_val); if (code_peek() == kwTYPE_LEVEL_END) { diff --git a/src/common/proc.c b/src/common/proc.c index 31866342..745d8867 100644 --- a/src/common/proc.c +++ b/src/common/proc.c @@ -55,9 +55,9 @@ int sys_search_path(const char *path, const char *file, char *retbuf) { #else p = strchr(ps, ';'); #endif - if (!p) + if (!p) { strcpy(cur_path, ps); - else { + } else { strncpy(cur_path, ps, p - ps); cur_path[p - ps] = '\0'; ps = p + 1; @@ -72,10 +72,11 @@ int sys_search_path(const char *path, const char *file, char *retbuf) { #if defined(_UnixOS) sprintf(cur_path, "%s/%s", getenv("HOME"), old_path); #else - if (getenv("HOME")) + if (getenv("HOME")) { sprintf(cur_path, "%s\\%s", getenv("HOME"), old_path); - else + } else { sprintf(cur_path, "%s\\%s", getenv("HOMEPATH"), old_path); + } #endif tmp_free(old_path); } @@ -87,11 +88,6 @@ int sys_search_path(const char *path, const char *file, char *retbuf) { #endif strcat(cur_path, file); - // TODO: probably in DOS/Win we must remove double dir-seps - // (c:\\home\\\\user) - - // check it -// printf("sp:[%s]\n", cur_path); if (access(cur_path, R_OK) == 0) { if (retbuf) { strcpy(retbuf, cur_path); @@ -111,7 +107,7 @@ int sys_search_path(const char *path, const char *file, char *retbuf) { * var - the variable (the X) * ip - expression's address */ -void exec_usefunc(var_t * var, addr_t ip) { +void exec_usefunc(var_t *var, addr_t ip) { var_t *old_x; // save X @@ -136,7 +132,7 @@ void exec_usefunc(var_t * var, addr_t ip) { * var2 - the second variable (the Y) * ip - expression's address */ -void exec_usefunc2(var_t * var1, var_t * var2, addr_t ip) { +void exec_usefunc2(var_t *var1, var_t *var2, addr_t ip) { var_t *old_x, *old_y; // save X @@ -168,7 +164,7 @@ void exec_usefunc2(var_t * var1, var_t * var2, addr_t ip) { * var3 - the thrid variable (the Z) * ip - expression's address */ -void exec_usefunc3(var_t * var1, var_t * var2, var_t * var3, addr_t ip) { +void exec_usefunc3(var_t *var1, var_t *var2, var_t *var3, addr_t ip) { var_t *old_x, *old_y, *old_z; // save X @@ -207,7 +203,6 @@ void lwrite(const char *buf) { int log_dev; /* logfile file handle */ char log_name[OS_PATHNAME_SIZE + 1]; /* LOGFILE filename */ - // ////// // open #if defined(_Win32) || defined(__MINGW32__) if (getenv("SBLOG")) { @@ -229,7 +224,6 @@ void lwrite(const char *buf) { panic("LOG: Error on creating log file"); } - // ///////// // write if (write(log_dev, buf, strlen(buf)) == -1) { panic("LOG: write failed"); @@ -248,7 +242,7 @@ void pv_write(char *str, int method, int handle) { switch (method) { case PV_FILE: - dev_fwrite(handle, (byte *) str, strlen(str)); + dev_fwrite(handle, (byte *)str, strlen(str)); break; case PV_LOG: lwrite(str); @@ -270,7 +264,7 @@ void pv_write(char *str, int method, int handle) { /* * just prints the value of variable 'var' */ -void pv_writevar(var_t * var, int method, int handle) { +void pv_writevar(var_t *var, int method, int handle) { char tmpsb[64]; // start with a clean buffer @@ -278,7 +272,7 @@ void pv_writevar(var_t * var, int method, int handle) { switch (var->type) { case V_STR: - pv_write((char *) var->v.p.ptr, method, handle); + pv_write((char *)var->v.p.ptr, method, handle); break; case V_UDS: uds_write(var, method, handle); @@ -302,7 +296,6 @@ void pv_writevar(var_t * var, int method, int handle) { // open array pv_write("[", method, handle); - // if (var->v.a.maxdim == 2) { int rows, cols; var_t *e; @@ -317,13 +310,14 @@ void pv_writevar(var_t * var, int method, int handle) { pos = i * cols + j; e = (var_t *) (var->v.a.ptr + (sizeof(var_t) * pos)); pv_writevar(e, method, handle); - if (j != cols - 1) + if (j != cols - 1) { pv_write(",", method, handle); // add space? + } } - if (i != rows - 1) + if (i != rows - 1) { pv_write(";", method, handle); // add space? + } } - } else { var_t *e; int i; @@ -331,8 +325,9 @@ void pv_writevar(var_t * var, int method, int handle) { for (i = 0; i < var->v.a.size; i++) { e = (var_t *) (var->v.a.ptr + (sizeof(var_t) * i)); pv_writevar(e, method, handle); - if (i != var->v.a.size - 1) + if (i != var->v.a.size - 1) { pv_write(",", method, handle); // add space? + } } } @@ -345,21 +340,21 @@ void pv_writevar(var_t * var, int method, int handle) { /* * write a variable to console */ -void print_var(var_t * v) { +void print_var(var_t *v) { pv_writevar(v, PV_CONSOLE, 0); } /* * write a variable to a file */ -void fprint_var(int handle, var_t * v) { +void fprint_var(int handle, var_t *v) { pv_writevar(v, PV_FILE, handle); } /* * write a variable to log-file */ -void logprint_var(var_t * v) { +void logprint_var(var_t *v) { pv_writevar(v, PV_LOG, 0); } @@ -368,11 +363,7 @@ void logprint_var(var_t * v) { */ void par_skip() { byte exitf = 0, code; -#if defined(ADDR16) - word len; -#else dword len; -#endif int level = 0; do { @@ -437,14 +428,12 @@ void par_skip() { prog_ip++; } } while (!exitf); - -// printf("exit at %d\n", prog_ip); } /* * get next parameter as var_t */ -void par_getvar(var_t * var) { +void par_getvar(var_t *var) { byte code; code = code_peek(); @@ -503,7 +492,7 @@ var_t *par_getvar_ptr() { /* * get next parameter as var_t */ -void par_getstr(var_t * var) { +void par_getstr(var_t *var) { byte code; code = code_peek(); @@ -713,7 +702,7 @@ ipt_t par_getipt() { /* * retrieve a 2D polyline */ -int par_getpoly(pt_t ** poly_pp) { +int par_getpoly(pt_t **poly_pp) { pt_t *poly = NULL; var_t *var, *el; int count = 0; @@ -799,9 +788,9 @@ int par_getpoly(pt_t ** poly_pp) { for (i = j = 0; i < count; i++, j += 2) { // error check - if (prog_error) + if (prog_error) { break; - + } // store point poly[i].x = v_getreal(v_elem(var, j)); poly[i].y = v_getreal(v_elem(var, j + 1)); @@ -824,7 +813,7 @@ int par_getpoly(pt_t ** poly_pp) { /* * retrieve a 2D polyline (integers) */ -int par_getipoly(ipt_t ** poly_pp) { +int par_getipoly(ipt_t **poly_pp) { ipt_t *poly = NULL; var_t *var, *el; int count = 0; @@ -944,7 +933,7 @@ int par_isonevar() { /* * destroy a parameter-table which was created by par_getparlist */ -void par_freepartable(par_t ** ptable_pp, int pcount) { +void par_freepartable(par_t **ptable_pp, int pcount) { int i; par_t *ptable; @@ -973,7 +962,7 @@ void par_freepartable(par_t ** ptable_pp, int pcount) { * YOU MUST FREE THAT TABLE BY USING par_freepartable() * IF THERE IS NO ERROR, CALL TO par_freepartable IS NOT NEEDED */ -int par_getpartable(par_t ** ptable_pp, const char *valid_sep) { +int par_getpartable(par_t **ptable_pp, const char *valid_sep) { byte ready, last_sep = 0; par_t *ptable; addr_t ofs; @@ -986,11 +975,11 @@ int par_getpartable(par_t ** ptable_pp, const char *valid_sep) { */ ptable = *ptable_pp = tmp_alloc(sizeof(par_t) * 256); - if (valid_sep) + if (valid_sep) { strcpy(vsep, valid_sep); - else + } else { strcpy(vsep, ","); - + } /* * start */ @@ -1008,18 +997,18 @@ int par_getpartable(par_t ** ptable_pp, const char *valid_sep) { // check parameters separator if (strchr(vsep, (last_sep = code_getnext())) == NULL) { - if (strlen(vsep) <= 1) + if (strlen(vsep) <= 1) { err_syntaxsep(','); - else + } else { err_syntaxanysep(vsep); - + } par_freepartable(ptable_pp, pcount); return -1; } // update par.next_sep - if (pcount) + if (pcount) { ptable[pcount - 1].next_sep = last_sep; - + } break; case kwTYPE_VAR: // variable ofs = prog_ip; // store IP @@ -1063,7 +1052,7 @@ int par_getpartable(par_t ** ptable_pp, const char *valid_sep) { /* */ -int par_massget_type_check(char fmt, par_t * par) { +int par_massget_type_check(char fmt, par_t *par) { switch (fmt) { case 'S': case 's': @@ -1137,10 +1126,11 @@ int par_massget(const char *fmt, ...) { fmt_p = (char *)fmt; rqcount = optcount = 0; while (*fmt_p) { - if (*fmt_p >= 'a') + if (*fmt_p >= 'a') { optcount++; - else + } else { rqcount++; + } fmt_p++; } @@ -1237,7 +1227,6 @@ int par_massget(const char *fmt, ...) { va_end(ap); } - // par_freepartable(&ptable, pcount); if (prog_error) { return -1; diff --git a/src/common/var.c b/src/common/var.c index ef5f93f9..d045a4d0 100644 --- a/src/common/var.c +++ b/src/common/var.c @@ -415,8 +415,8 @@ void v_add(var_t *result, var_t *a, var_t *b) { if (a->type == V_STR && b->type == V_STR) { result->type = V_STR; - result->v.p.ptr = (byte *) tmp_alloc(strlen((char *)a->v.p.ptr) + strlen((char *)b->v.p.ptr) + - 1); + result->v.p.ptr = (byte *)tmp_alloc(strlen((char *)a->v.p.ptr) + + strlen((char *)b->v.p.ptr) + 1); strcpy((char *) result->v.p.ptr, (char *) a->v.p.ptr); strcat((char *) result->v.p.ptr, (char *) b->v.p.ptr); result->v.p.size = strlen((char *) result->v.p.ptr) + 1; @@ -509,7 +509,8 @@ void v_set(var_t *dest, const var_t *src) { dest->const_flag = 0; switch (src->type) { case V_STR: - dest->v.p.ptr = (byte *) tmp_alloc(strlen((char *)src->v.p.ptr) + 1); + dest->v.p.size = strlen((char *)src->v.p.ptr) + 1; + dest->v.p.ptr = (byte *) tmp_alloc(dest->v.p.size); strcpy((char *) dest->v.p.ptr, (char *) src->v.p.ptr); break; diff --git a/src/common/var_hash.c b/src/common/var_hash.c index ff8479b3..022d796b 100644 --- a/src/common/var_hash.c +++ b/src/common/var_hash.c @@ -50,7 +50,18 @@ typedef struct Node { Element *create_element(var_p_t key) { Element *element = (Element *) tmp_alloc(sizeof (Element)); element->key = v_new(); - v_createstr(element->key, key->v.p.ptr); + v_set(element->key, key); + element->value = NULL; + return element; +} + +/** + * Returns a new Element using the integer based key + */ +Element *create_int_element(int key) { + Element *element = (Element *) tmp_alloc(sizeof (Element)); + element->key = v_new(); + v_setint(element->key, key); element->value = NULL; return element; } @@ -165,7 +176,7 @@ void hash_free_cb(void *nodep) { void hash_free_var(var_p_t var_p) { if (var_p->type == V_HASH) { tdestroy(var_p->v.hash, hash_free_cb); - var_p->v.hash = 0; + var_p->v.hash = NULL; } } @@ -174,11 +185,31 @@ void hash_free_var(var_p_t var_p) { * an empty variable that will be returned in a further call */ void hash_get_value(var_p_t base, var_p_t var_key, var_p_t *result) { - if (base->type != V_HASH) { + if (base->type == V_ARRAY && base->v.a.size) { + // convert the non-empty array to a hash + int i; + var_t *clone = v_clone(base); + + v_free(base); + base->type = V_HASH; + base->v.hash = NULL; + + for (i = 0; i < clone->v.a.size; i++) { + const var_t *element = (var_t *)(clone->v.a.ptr + (sizeof(var_t) * i)); + Element *key = create_int_element(i); + key->value = v_new(); + v_set(key->value, element); + tsearch(key, &base->v.hash, cmp_fn); + } + + // free the clone + v_free(clone); + tmp_free(clone); + } else if (base->type != V_HASH) { // initialise as hash v_free(base); base->type = V_HASH; - base->v.hash = 0; + base->v.hash = NULL; } // create a key which will hold our name and value pairs @@ -242,7 +273,7 @@ void hash_write_cb(const void *nodep, VISIT value, int level) { pv_write(",", cb.method, cb.handle); } cb.firstElement = 0; - pv_write(element->key->v.p.ptr, cb.method, cb.handle); + pv_writevar(element->key, cb.method, cb.handle); pv_write("=", cb.method, cb.handle); pv_writevar(element->value, cb.method, cb.handle); } From e8b32deefa713e97659d1de70437d3c7f914b419 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Sat, 23 Aug 2014 06:55:53 +1000 Subject: [PATCH 17/21] COMMON: code cleanup --- ChangeLog | 1 + src/common/bc.c | 24 ++++++++++----------- src/common/bc.h | 47 ++++++++++++++++++++++++------------------ src/common/eval.c | 4 ++-- src/common/fs_stream.c | 1 - src/common/scan.c | 36 ++++++++++++++++++-------------- src/common/var.c | 1 - src/common/var_uds.c | 9 ++++++-- 8 files changed, 69 insertions(+), 54 deletions(-) diff --git a/ChangeLog b/ChangeLog index f5e5c8fd..219867aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2014-08-22 Fix HASH var crash Fix HASH var handling of mixed types + Fix illegal UDS field variable names 2014-08-15 Improved runtime performance diff --git a/src/common/bc.c b/src/common/bc.c index 7da37c00..be68ed1c 100644 --- a/src/common/bc.c +++ b/src/common/bc.c @@ -114,7 +114,7 @@ void bc_add2i(bc_t *bc, byte code, word p1) { /* * add one command and one long int (32 bits) */ -void bc_add2l(bc_t * bc, byte code, long p1) { +void bc_add2l(bc_t *bc, byte code, long p1) { if (bc->count >= bc->size - 8) { bc_resize(bc, bc->size + BC_ALLOC_INCR); } @@ -207,19 +207,17 @@ void bc_add_creal(bc_t *bc, var_num_t v) { /* * add one command and one string (see: bc_store_string) */ -void bc_add2s(bc_t *bc, byte code, const char *p1) { - int l = strlen(p1); - if (l > BC_MAX_STORE_SIZE) { +void bc_add_strn(bc_t *bc, const char *str, int len) { + if (len > BC_MAX_STORE_SIZE) { sc_raise("STRING TOO BIG"); } else { - bc_add_code(bc, code); - bc_add_dword(bc, l); - - if (bc->count >= bc->size - l) { + bc_add_code(bc, kwTYPE_STR); + bc_add_dword(bc, len); + if (bc->count >= bc->size - len) { bc_resize(bc, bc->size + BC_ALLOC_INCR); } - memcpy(bc->ptr + bc->count, p1, l); - bc->count += l; + memcpy(bc->ptr + bc->count, str, len); + bc->count += len; } } @@ -255,11 +253,11 @@ char *bc_store_string(bc_t *bc, char *src) { char *cstr; cstr = cstrdup(np); tmp_free(np); - bc_add2s(bc, kwTYPE_STR, cstr); + bc_add_strn(bc, cstr, strlen(cstr)); tmp_free(cstr); } else { // normal - bc_add2s(bc, kwTYPE_STR, np); + bc_add_strn(bc, np, strlen(np)); tmp_free(np); } p++; @@ -285,7 +283,7 @@ char *bc_store_macro(bc_t *bc, char *src) { np = tmp_alloc(l + 1); strncpy(np, src + 1, l); np[l - 1] = '\0'; - bc_add2s(bc, kwTYPE_STR, np); + bc_add_strn(bc, np, strlen(np)); tmp_free(np); p++; diff --git a/src/common/bc.h b/src/common/bc.h index dd1402df..29bfdbaf 100644 --- a/src/common/bc.h +++ b/src/common/bc.h @@ -48,7 +48,7 @@ void sc_raise(const char *fmt, ...); * * @param bc the bc structure */ -void bc_create(bc_t * bc); +void bc_create(bc_t *bc); /** * @ingroup scan @@ -57,7 +57,7 @@ void bc_create(bc_t * bc); * * @param bc the bc structure */ -void bc_destroy(bc_t * bc); +void bc_destroy(bc_t *bc); /** * @ingroup scan @@ -67,7 +67,7 @@ void bc_destroy(bc_t * bc); * @param bc the bc structure * @param newsize the new size */ -void bc_resize(bc_t * bc, dword newsize); +void bc_resize(bc_t *bc, dword newsize); /** * @ingroup scan @@ -77,7 +77,7 @@ void bc_resize(bc_t * bc, dword newsize); * @param bc the bc structure * @param code the byte */ -void bc_add1(bc_t * bc, byte code); +void bc_add1(bc_t *bc, byte code); /** * @ingroup scan @@ -87,7 +87,7 @@ void bc_add1(bc_t * bc, byte code); * @param bc the bc structure * @param code the byte */ -void bc_store1(bc_t * bc, addr_t offset, byte code); +void bc_store1(bc_t *bc, addr_t offset, byte code); /** * @ingroup scan @@ -97,7 +97,7 @@ void bc_store1(bc_t * bc, addr_t offset, byte code); * @param bc the bc structure * @param code the word */ -void bc_add_word(bc_t * bc, word code); +void bc_add_word(bc_t *bc, word code); /** * @ingroup scan @@ -107,7 +107,14 @@ void bc_add_word(bc_t * bc, word code); * @param bc the bc structure * @param code the dword */ -void bc_add_dword(bc_t * bc, dword code); +void bc_add_dword(bc_t *bc, dword code); + +/** + * @ingroup scan + * + * adds a string of the given length + */ +void bc_add_strn(bc_t *bc, const char *str, int len); /** * @ingroup scan @@ -118,7 +125,7 @@ void bc_add_dword(bc_t * bc, dword code); * @param str the raw-string. the string must starts with \". the string must also contains the ending \". * @return a pointer of src to the next character after the second \" */ -char *bc_store_string(bc_t * bc, char *src); +char *bc_store_string(bc_t *bc, char *src); /** * @ingroup scan @@ -129,7 +136,7 @@ char *bc_store_string(bc_t * bc, char *src); * @param str the raw-string. the string must starts with `. the string must also contains the ending `. * @return a pointer of src to the next character after the second ` */ -char *bc_store_macro(bc_t * bc, char *src); +char *bc_store_macro(bc_t *bc, char *src); /** * @ingroup scan @@ -138,7 +145,7 @@ char *bc_store_macro(bc_t * bc, char *src); * * @param bc the bc structure */ -void bc_eoc(bc_t * bc); +void bc_eoc(bc_t *bc); /** * @ingroup scan @@ -148,7 +155,7 @@ void bc_eoc(bc_t * bc); * @param dest the destination * @param src the code to be appended to dest */ -void bc_append(bc_t * dest, bc_t * src); +void bc_append(bc_t *dest, bc_t *src); /** * @ingroup scan @@ -159,7 +166,7 @@ void bc_append(bc_t * dest, bc_t * src); * @param src the code to be appended to dest * @param n the size of the src to be copied */ -void bc_add_n(bc_t * dest, byte * src, dword n); +void bc_add_n(bc_t *dest, byte *src, dword n); /** * @ingroup scan @@ -175,7 +182,7 @@ void bc_add_n(bc_t * dest, byte * src, dword n); * @param dest the bc segment * @param idx the index of the function */ -void bc_add_fcode(bc_t * dest, long idx); +void bc_add_fcode(bc_t *dest, long idx); /** * @ingroup scan @@ -185,7 +192,7 @@ void bc_add_fcode(bc_t * dest, long idx); * @param dest the bc segment * @param idx the index of the procedure */ -void bc_add_pcode(bc_t * dest, long idx); +void bc_add_pcode(bc_t *dest, long idx); /** * @ingroup scan @@ -196,7 +203,7 @@ void bc_add_pcode(bc_t * dest, long idx); * @param lib the index of the library * @param idx the index of the function */ -void bc_add_extfcode(bc_t * dest, int lib, long idx); +void bc_add_extfcode(bc_t *dest, int lib, long idx); /** * @ingroup scan @@ -207,7 +214,7 @@ void bc_add_extfcode(bc_t * dest, int lib, long idx); * @param lib the index of the library * @param idx the index of the procedure */ -void bc_add_extpcode(bc_t * dest, int lib, long idx); +void bc_add_extpcode(bc_t *dest, int lib, long idx); /** * @ingroup scan @@ -217,7 +224,7 @@ void bc_add_extpcode(bc_t * dest, int lib, long idx); * @param bc the bc segment * @param idx the address */ -void bc_add_addr(bc_t * bc, addr_t idx); +void bc_add_addr(bc_t *bc, addr_t idx); /** * @ingroup scan @@ -229,7 +236,7 @@ void bc_add_addr(bc_t * bc, addr_t idx); * @param true_ip the jump-address when on true * @param false_ip the jump-address when on false */ -void bc_add_ctrl(bc_t * bc, code_t code, addr_t true_ip, addr_t false_ip); +void bc_add_ctrl(bc_t *bc, code_t code, addr_t true_ip, addr_t false_ip); /** * @ingroup scan @@ -239,7 +246,7 @@ void bc_add_ctrl(bc_t * bc, code_t code, addr_t true_ip, addr_t false_ip); * @param bc the bc segment * @param v the number */ -void bc_add_creal(bc_t * bc, var_num_t v); +void bc_add_creal(bc_t *bc, var_num_t v); /** * @ingroup scan @@ -249,6 +256,6 @@ void bc_add_creal(bc_t * bc, var_num_t v); * @param bc the bc segment * @param v the number */ -void bc_add_cint(bc_t * bc, var_int_t v); +void bc_add_cint(bc_t *bc, var_int_t v); #endif diff --git a/src/common/eval.c b/src/common/eval.c index bea32372..98f259d7 100644 --- a/src/common/eval.c +++ b/src/common/eval.c @@ -27,7 +27,7 @@ /** * matrix: convert var_t to double[r][c] */ -var_num_t* mat_toc(var_t *v, int32 *rows, int32 *cols) { +var_num_t *mat_toc(var_t *v, int32 *rows, int32 *cols) { int i, j, pos; var_t *e; var_num_t *m; @@ -69,7 +69,7 @@ var_num_t* mat_toc(var_t *v, int32 *rows, int32 *cols) { /** * matrix: conv. double[nr][nc] to var_t */ -void mat_tov(var_t * v, var_num_t *m, int rows, int cols, int protect_col1) { +void mat_tov(var_t *v, var_num_t *m, int rows, int cols, int protect_col1) { var_t *e; int i, j, pos; diff --git a/src/common/fs_stream.c b/src/common/fs_stream.c index b74e8ae1..1d0af4cb 100644 --- a/src/common/fs_stream.c +++ b/src/common/fs_stream.c @@ -100,7 +100,6 @@ int stream_write(dev_file_t *f, byte *data, dword size) { r = write(f->handle, data, size); if (r != (int) size) { - fprintf(stderr, "error result =%d %d\n", r, size); err_file((f->last_error = errno)); } return (r == (int) size); diff --git a/src/common/scan.c b/src/common/scan.c index 4d9c9815..ba02b8bc 100644 --- a/src/common/scan.c +++ b/src/common/scan.c @@ -19,10 +19,10 @@ #include "common/messages.h" #include "languages/keywords.en.c" -char *comp_array_uds_field(char *p, bc_t * bc); +char *comp_array_uds_field(char *p, bc_t *bc); void comp_text_line(char *text); addr_t comp_search_bc(addr_t ip, code_t code); -extern void expr_parser(bc_t * bc); +extern void expr_parser(bc_t *bc); extern void sc_raise2(const char *fmt, int line, const char *buff); // sberr #define STRLEN(s) ((sizeof(s) / sizeof(s[0])) - 1) @@ -574,14 +574,14 @@ int comp_check_lib(const char *name) { return 0; } -/* +/** + * create a new variable */ int comp_create_var(const char *name) { int idx = -1; - - if (!(is_alpha(name[0]) || name[0] == '_')) + if (!(is_alpha(name[0]) || name[0] == '_')) { sc_raise(MSG_WRONG_VARNAME, name); - else { + } else { // realloc table if it is needed if (comp_varcount >= comp_varsize) { comp_varsize += GROWSIZE; @@ -600,7 +600,8 @@ int comp_create_var(const char *name) { return idx; } -/* +/** + * add external variable */ int comp_add_external_var(const char *name, int lib_id) { int idx; @@ -729,13 +730,19 @@ int comp_get_uds_field_id(const char *field_name, int len) { } } + int result; strncpy(uds.name, field_name, len); - uds.name[len] = 0; - uds.field_id = ++comp_next_field_id; - dbt_write(comp_udstable, comp_udscount, &uds, sizeof(comp_struct_t)); - comp_udscount++; - - return uds.field_id; + if (!(is_alpha(uds.name[0]) || uds.name[0] == '_')) { + sc_raise(MSG_WRONG_VARNAME, uds.name); + result = -1; + } else { + uds.name[len] = 0; + uds.field_id = ++comp_next_field_id; + dbt_write(comp_udstable, comp_udscount, &uds, sizeof(comp_struct_t)); + comp_udscount++; + result = uds.field_id; + } + return result; } /* @@ -745,7 +752,7 @@ int comp_get_uds_field_id(const char *field_name, int len) { * then the foo variable is added as kwTYPE_UDS. * */ -void comp_add_variable(bc_t * bc, const char *var_name) { +void comp_add_variable(bc_t *bc, const char *var_name) { char *dot = strchr(var_name, '.'); if (dot != 0 && !comp_check_lib(var_name)) { @@ -779,7 +786,6 @@ void comp_add_variable(bc_t * bc, const char *var_name) { bc_add_code(bc, kwTYPE_UDS_EL); bc_add_addr(bc, var_id); } - } else if (comp_check_uds(var_name)) { // uds-container // all of var_name same as dot-less portion of existing variable diff --git a/src/common/var.c b/src/common/var.c index d045a4d0..b24e35ff 100644 --- a/src/common/var.c +++ b/src/common/var.c @@ -499,7 +499,6 @@ void v_set(var_t *dest, const var_t *src) { return; } else if (dest->type == V_HASH) { // lvalue struct assigned to non-struct rvalue - fprintf(stderr, "hash_clear\n"); hash_clear(dest); return; } diff --git a/src/common/var_uds.c b/src/common/var_uds.c index 7b4f1192..84ef8dfd 100644 --- a/src/common/var_uds.c +++ b/src/common/var_uds.c @@ -118,8 +118,13 @@ var_p_t uds_resolve_fields(const var_p_t var_p) { addr_t field_id = code_getaddr(); if (var_p->type != V_UDS) { - v_free(var_p); - var_p->type = V_UDS; + if (v_is_nonzero(var_p)) { + err_typemismatch(); + return NULL; + } else { + v_free(var_p); + var_p->type = V_UDS; + } } uds_field_s *next = var_p->v.uds; From fab4bba22526568e715ac0b895335c74b06fe514 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Sat, 23 Aug 2014 12:06:24 +1000 Subject: [PATCH 18/21] COMMON unify uds and hash --- ChangeLog | 1 + samples/distro-examples/tests/call_tau.bas | 12 +- .../distro-examples/tests/output/call_tau.out | 9 +- samples/distro-examples/tests/tau.bas | 2 +- samples/distro-examples/tests/uds.bas | 3 + src/common/blib.c | 8 +- src/common/brun.c | 45 ++-- src/common/ceval.c | 9 +- src/common/eval.c | 1 - src/common/hotspots.h | 10 +- src/common/kw.h | 1 - src/common/scan.c | 232 +++++++----------- src/common/smbas.h | 2 - src/common/tasks.h | 5 - src/common/units.c | 16 +- src/common/var.c | 13 +- src/common/var.h | 9 + src/common/var_hash.c | 103 ++++++-- src/common/var_hash.h | 3 +- 19 files changed, 251 insertions(+), 233 deletions(-) diff --git a/ChangeLog b/ChangeLog index 219867aa..bfe6e343 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ Fix HASH var crash Fix HASH var handling of mixed types Fix illegal UDS field variable names + Unitfy HASH and UDS 2014-08-15 Improved runtime performance diff --git a/samples/distro-examples/tests/call_tau.bas b/samples/distro-examples/tests/call_tau.bas index 40764d15..02f5181a 100644 --- a/samples/distro-examples/tests/call_tau.bas +++ b/samples/distro-examples/tests/call_tau.bas @@ -20,9 +20,19 @@ rem check system-variables predef.prsys x=PI -foyer.name= "PI" +dim foyer +foyer.name= "my name is PI" +? "test" +? foyer("NAME") +? foyer("name") +? foyer.Name +? foyer.name + +? "end" + tau.addRoom(foyer,x) + sub addRoom(the_thing, d) print the_thing.name, d end diff --git a/samples/distro-examples/tests/output/call_tau.out b/samples/distro-examples/tests/output/call_tau.out index f7c49523..fd08e716 100644 --- a/samples/distro-examples/tests/output/call_tau.out +++ b/samples/distro-examples/tests/output/call_tau.out @@ -11,5 +11,10 @@ message from tau [1,2,3,4] Predefined Variables PI =3.14159265358979 -PI 3.14159265358979 -PI 3.14159265358979 +test +my name is PI +my name is PI +my name is PI +my name is PI +end +my name is PI 3.14159265358979 diff --git a/samples/distro-examples/tests/tau.bas b/samples/distro-examples/tests/tau.bas index 5f4d8363..56c1de38 100644 --- a/samples/distro-examples/tests/tau.bas +++ b/samples/distro-examples/tests/tau.bas @@ -37,7 +37,7 @@ sub cerr end sub addRoom(the_thing,d) - print the_thing.name,d + end rem initialization diff --git a/samples/distro-examples/tests/uds.bas b/samples/distro-examples/tests/uds.bas index 79bdb22c..51e41321 100644 --- a/samples/distro-examples/tests/uds.bas +++ b/samples/distro-examples/tests/uds.bas @@ -32,6 +32,7 @@ sub passByVal(udsVal) end 'test with formal+actual arguments having differing names +dim _udsRef _udsRef.field1 = "initField1" _udsRef.field2 = "initField2" _udsRef.field3 = 3.0 @@ -50,6 +51,7 @@ if (_udsRef.field2 != "updatedField2") then fi 'test with formal+actual arguments with global names +dim udsRef udsRef.field1 = "initField1" udsRef.field2 = "initField2" udsRef.field3 = 3.0 @@ -68,6 +70,7 @@ if (udsRef.field2 != "updatedField2") then fi 'test complex structures - this is pretty cool :) +dim animal animal.pet.cat.legs = 4 animal.pet.cat.color = "black" diff --git a/src/common/blib.c b/src/common/blib.c index 00dfeda3..9479c37b 100644 --- a/src/common/blib.c +++ b/src/common/blib.c @@ -285,7 +285,7 @@ void cmd_lins() { // move all form idx one down for (i = var_p->v.a.size - 1; i > idx; i--) { // A(i) = A(i-1) - v_set((var_t *) (var_p->v.a.ptr + (sizeof(var_t) * i)), + v_set((var_t *) (var_p->v.a.ptr + (sizeof(var_t) * i)), (var_t *) (var_p->v.a.ptr + (sizeof(var_t) * (i - 1)))); } elem_p = (var_t *) (var_p->v.a.ptr + (sizeof(var_t) * idx)); @@ -1038,7 +1038,6 @@ void cmd_udp(int cmd) { ready = 1; // finish flag break; - case kwTYPE_UDS: case kwTYPE_VAR: // the parameter is a variable ofs = prog_ip; // keep expression's IP @@ -1149,7 +1148,6 @@ void cmd_call_unit_udp(int cmd, int udp_tid, addr_t goto_addr, addr_t rvid) { // parameters ready = 1; // finish flag break; - case kwTYPE_UDS: case kwTYPE_VAR: // the parameter is a variable ofs = prog_ip; // keep expression's IP @@ -1607,7 +1605,7 @@ void cmd_endif() { code_pop(&node); IF_ERR_BREAK; } - + if (!prog_error) { prog_ip += (ADDRSZ + ADDRSZ); } @@ -2163,7 +2161,7 @@ void cmd_pause() { long start, now; code = code_peek(); - if (code == kwTYPE_VAR || code == kwTYPE_UDS) { + if (code == kwTYPE_VAR) { x = par_getint(); if (prog_error) { return; diff --git a/src/common/brun.c b/src/common/brun.c index 815997d2..5ab2ec80 100755 --- a/src/common/brun.c +++ b/src/common/brun.c @@ -324,7 +324,7 @@ var_t *code_resolve_varptr(var_t *var_p, int until_parens) { } break; case kwTYPE_UDS_EL: - var_p = code_resolve_varptr(uds_resolve_fields(var_p), until_parens); + var_p = code_resolve_varptr(hash_resolve_fields(var_p), until_parens); break; } } @@ -383,15 +383,13 @@ var_t *code_isvar_arridx(var_t *basevar_p) { int code_isvar() { var_t *basevar_p; var_t *var_p = NULL; - addr_t cur_ip; - cur_ip = prog_ip; // store IP + // store IP + addr_t cur_ip = prog_ip; - switch (code_peek()) { - case kwTYPE_VAR: + if (code_peek() == kwTYPE_VAR) { code_skipnext(); var_p = basevar_p = tvar[code_getaddr()]; - switch (basevar_p->type) { case V_HASH: case V_ARRAY: @@ -403,23 +401,18 @@ int code_isvar() { var_p = NULL; } } - break; - - case kwTYPE_UDS: - code_skipnext(); - var_p = tvar[code_getaddr()]; - var_p = code_resolve_varptr(uds_resolve_fields(var_p), 0); - break; } if (var_p) { if (kw_check_evexit(code_peek()) || code_peek() == kwTYPE_LEVEL_END) { - prog_ip = cur_ip; // restore IP + // restore IP + prog_ip = cur_ip; return 1; } } - prog_ip = cur_ip; // restore IP + // restore IP + prog_ip = cur_ip; return 0; } @@ -552,7 +545,7 @@ void exec_setup_predefined_variables() { { static char stupid_os_envsblog[1024]; // it must be static at - // least by default on DOS + // least by default on DOS // or Win32(BCB) sprintf(stupid_os_envsblog, "SBLOG=%s%csb.log", homedir, OS_DIRSEP); putenv(stupid_os_envsblog); @@ -805,10 +798,10 @@ void bc_loop(int isf) { // debug /* - * fprintf(stderr, "\t%d: %d = ", prog_ip, code); for ( i = 0; + * fprintf(stderr, "\t%d: %d = ", prog_ip, code); for ( i = 0; * keyword_table[i].name[0] != '\0'; i ++) { if ( code == * keyword_table[i].code ) { fprintf(stderr,"%s ", - * keyword_table[i].name); break; } } fprintf(stderr,"\n"); + * keyword_table[i].name); break; } } fprintf(stderr,"\n"); */ switch (code) { @@ -948,7 +941,7 @@ void bc_loop(int isf) { /* * ----------------------------------------- * external - * procedures + * procedures */ case kwTYPE_CALLEXTP: // [lib][index] { @@ -969,7 +962,7 @@ void bc_loop(int isf) { break; /* * ----------------------------------------- * buildin - * procedures -- BEGIN + * procedures -- BEGIN */ case kwTYPE_CALLP: pcode = code_getaddr(); @@ -1362,7 +1355,7 @@ void dump_stack() { /* * RUN byte-code - * + * * ByteCode Structure (executables, not units): * * [header (bc_head_t)] @@ -1606,14 +1599,14 @@ int brun_create_task(const char *filename, mem_t preloaded_bc, int libf) { // for ( i = 0; i < prog_symcount; i ++ ) { // if ( prog_symtable[i].task_id == -1 && prog_libtable[i].type == 1 ) // panic("Symbol (unit) '%s' missing\n", prog_symtable[i].symbol); - // if ( prog_symtable[i].task_id == -1 && prog_libtable[i].type == 0 ) { + // if ( prog_symtable[i].task_id == -1 && prog_libtable[i].type == 0 ) { // if ( prog_symtable[j].exp_idx == -1 ) // panic("Symbol (module) '%s' missing\n", prog_symtable[i].symbol); // } // } // } } - // + // return tid; } @@ -1949,9 +1942,9 @@ int sbasic_exec(const char *file) { strcpy(gsb_last_file, file); strcpy(gsb_last_errmsg, ""); - // compile it - if opt_nosave, bytecode_h is a + // compile it - if opt_nosave, bytecode_h is a // memory handle of BC; otherwise you must run the file - success = sbasic_compile(file); + success = sbasic_compile(file); if (opt_syntaxcheck) // this is a command-line flag to // syntax-check only @@ -1976,7 +1969,7 @@ int sbasic_exec(const char *file) { evt_check_every = (50 * CLOCKS_PER_SEC) / 1000; // setup event checker time = 50ms srand(clock()); // randomize - // run + // run sbasic_recursive_exec(exec_tid); // normal exit diff --git a/src/common/ceval.c b/src/common/ceval.c index b968d6e9..f2a36e60 100644 --- a/src/common/ceval.c +++ b/src/common/ceval.c @@ -77,7 +77,6 @@ void cev_prim() { break; case kwTYPE_UDS_EL: - case kwTYPE_UDS: case kwTYPE_VAR: bc_add_n(bc_out, bc_in->ptr + bc_in->cp, ADDRSZ); // 1 addr IP += ADDRSZ; @@ -366,17 +365,17 @@ void expr_parser(bc_t *bc_src) { code = CODE_PEEK(); - // + // // empty! - // + // if (code == kwTYPE_LINE || code == kwTYPE_EOC) { bc_destroy(bc_out); tmp_free(bc_out); return; } - // + // // LET|CONST special code - // + // if (code == kwTYPE_CMPOPR) { IP++; if (CODE(IP) != '=') { diff --git a/src/common/eval.c b/src/common/eval.c index 98f259d7..ba52ef7b 100644 --- a/src/common/eval.c +++ b/src/common/eval.c @@ -1164,7 +1164,6 @@ void eval(var_t *r) { r->v.ap.v = code_getaddr(); break; - case kwTYPE_UDS: case kwTYPE_VAR: // variable V_FREE(r); diff --git a/src/common/hotspots.h b/src/common/hotspots.h index 144bec3d..528ec865 100644 --- a/src/common/hotspots.h +++ b/src/common/hotspots.h @@ -152,8 +152,7 @@ static inline var_int_t v_igetval(var_t *v) { static inline var_t* code_getvarptr_parens(int until_parens) { var_t *var_p = NULL; - switch (code_peek()) { - case kwTYPE_VAR: + if (code_peek() == kwTYPE_VAR) { code_skipnext(); var_p = tvar[code_getaddr()]; switch (var_p->type) { @@ -166,13 +165,6 @@ static inline var_t* code_getvarptr_parens(int until_parens) { err_varisnotarray(); } } - break; - - case kwTYPE_UDS: - code_skipnext(); - var_p = tvar[code_getaddr()]; - var_p = code_resolve_varptr(uds_resolve_fields(var_p), until_parens); - break; } if (var_p == NULL && !prog_error) { diff --git a/src/common/kw.h b/src/common/kw.h index be24fa5e..618a2fb4 100644 --- a/src/common/kw.h +++ b/src/common/kw.h @@ -63,7 +63,6 @@ enum keyword { // line 50 kwTYPE_POWOPR, /* POW(x,y) operator */ kwTYPE_UNROPR, /* Unary operator */ kwTYPE_VAR, /* Variable */ - kwTYPE_UDS, /* Structure */ kwTYPE_UDS_EL, /* Structure element */ kwTYPE_SEP, /* Separator */ kwTYPE_LINE, /* Debug info: SOURCE LINE */ diff --git a/src/common/scan.c b/src/common/scan.c index ba02b8bc..d157fe74 100644 --- a/src/common/scan.c +++ b/src/common/scan.c @@ -377,7 +377,7 @@ bid_t comp_add_udp(const char *proc_name) { * #if !defined(OS_LIMITED) // check variables for conflict for ( i = * 0; i < comp_varcount; i ++ ) { if ( strcmp(comp_vartable[i].name, * name) == 0 ) { sc_raise("User-defined function/procedure name, - * '%s', conflicts with variable", name); break; } } #endif + * '%s', conflicts with variable", name); break; } } #endif */ // search @@ -632,7 +632,7 @@ int comp_add_external_var(const char *name, int lib_id) { * * if there is no such variable then creates a new one * - * if a new variable must created then if the var_name includes the path then + * if a new variable must created then if the var_name includes the path then * the new variable created at local space otherwise at globale space */ bid_t comp_var_getID(const char *var_name) { @@ -648,12 +648,12 @@ bid_t comp_var_getID(const char *var_name) { sc_raise(MSG_MEMBER_DOES_NOT_EXISTS, tmp); return 0; } - // + // // check for external // external variables are recognized by the 'class' name // example: my_unit.my_var - // - // If the name is not found in comp_libtable then it + // + // If the name is not found in comp_libtable then it // is treated as a structure reference if (dot != 0 && comp_check_lib(tmp)) { for (i = 0; i < comp_varcount; i++) { @@ -665,12 +665,12 @@ bid_t comp_var_getID(const char *var_name) { sc_raise(MSG_MEMBER_DOES_NOT_EXISTS, tmp); return 0; } - // + // // search in global name-space - // + // // Note: local space is dynamic, // however a global var-ID per var-name is required - // + // strcpy(name, tmp); for (i = 0; i < comp_varcount; i++) { @@ -700,74 +700,27 @@ bid_t comp_var_getID(const char *var_name) { return idx; } -/* - * returns true if 'name' is a user defined structure - */ -int comp_check_uds(const char *name) { - int i; - comp_struct_t uds; - - for (i = 0; i < comp_udscount; i++) { - dbt_read(comp_udstable, i, &uds, sizeof(comp_struct_t)); - if (uds.field_id == -1 && strcasecmp(uds.name, name) == 0) { - return 1; - } - } - return 0; -} - -/* - * returns the shared field_id for the given field name - */ -int comp_get_uds_field_id(const char *field_name, int len) { - int i; - comp_struct_t uds; - - for (i = 0; i < comp_udscount; i++) { - dbt_read(comp_udstable, i, &uds, sizeof(comp_struct_t)); - if (uds.field_id != -1 && strlen(uds.name) == len && strncasecmp(uds.name, field_name, len) == 0) { - return uds.field_id; - } - } - - int result; - strncpy(uds.name, field_name, len); - if (!(is_alpha(uds.name[0]) || uds.name[0] == '_')) { - sc_raise(MSG_WRONG_VARNAME, uds.name); - result = -1; - } else { - uds.name[len] = 0; - uds.field_id = ++comp_next_field_id; - dbt_write(comp_udstable, comp_udscount, &uds, sizeof(comp_struct_t)); - comp_udscount++; - result = uds.field_id; - } - return result; -} - /* * add the named variable to the current position in the byte code stream - * + * * if the name 'foo' has already been used in a struct context, eg 'foo.x' * then the foo variable is added as kwTYPE_UDS. - * + * */ void comp_add_variable(bc_t *bc, const char *var_name) { char *dot = strchr(var_name, '.'); if (dot != 0 && !comp_check_lib(var_name)) { - // uds-element (or sub-element eg foo.x.y.z) + // uds-element (or sub-element eg foo.x.y.z) // record the uds-parent + int len = dot - var_name; comp_struct_t uds; strncpy(uds.name, var_name, len); uds.name[len] = 0; - uds.field_id = -1; - dbt_write(comp_udstable, comp_udscount, &uds, sizeof(comp_struct_t)); - comp_udscount++; bid_t var_id = comp_var_getID(uds.name); - bc_add_code(bc, kwTYPE_UDS); + bc_add_code(bc, kwTYPE_VAR); bc_add_addr(bc, var_id); while (dot && dot[0]) { @@ -775,24 +728,22 @@ void comp_add_variable(bc_t *bc, const char *var_name) { if (dot_end) { // next sub-element len = (dot_end - dot) - 1; - var_id = comp_get_uds_field_id(dot + 1, len); - dot = dot_end; } else { // final element len = strlen(dot + 1); - var_id = comp_get_uds_field_id(dot + 1, len); - dot = 0; } + bc_add_code(bc, kwTYPE_UDS_EL); - bc_add_addr(bc, var_id); + bc_add_strn(bc, dot + 1, len); + + if (dot_end) { + dot = dot_end; + } else { + dot = NULL; + } } - } else if (comp_check_uds(var_name)) { - // uds-container - // all of var_name same as dot-less portion of existing variable - bc_add_code(bc, kwTYPE_UDS); - bc_add_addr(bc, comp_var_getID(var_name)); } else { - // regular variable + // regular variable or uds-container bc_add_code(bc, kwTYPE_VAR); bc_add_addr(bc, comp_var_getID(var_name)); } @@ -814,7 +765,7 @@ void comp_push(addr_t ip) { } /* - * returns the keyword code + * returns the keyword code */ int comp_is_keyword(const char *name) { int i, idx; @@ -953,7 +904,7 @@ char *comp_prev_char(const char *root, const char *ptr) { * get next word * if buffer's len is zero, then the next element is not a word * - * @param text the source + * @param text the source * @param dest the buffer to store the result * @return pointer of text to the next element */ @@ -995,7 +946,7 @@ const char *comp_next_word(const char *text, char *dest) { } } // Code to kill the $ - // if ( *p == '$' ) + // if ( *p == '$' ) // p ++; // Code to enable the $ if (*p == '$') { @@ -1097,7 +1048,7 @@ void comp_expression(char *expr, byte no_parser) { } else if (*ptr == '\'' /* || *ptr == '#' */) { // remarks break; } else if (is_alpha(*ptr) || *ptr == '?' || *ptr == '_') { - // A NAME + // A NAME ptr = (char *)comp_next_word(ptr, comp_bc_name); idx = comp_is_func(comp_bc_name); // special case for INPUT @@ -1285,7 +1236,7 @@ void comp_expression(char *expr, byte no_parser) { break; } else if (strncmp(ptr, "==", 2) == 0) { // support == syntax to prevent java or c programmers - // getting used to single = thus causing embarrasing + // getting used to single = thus causing embarrasing // coding errors in their normal work :) bc_add_code(&bc, kwTYPE_CMPOPR); bc_add_code(&bc, *ptr); @@ -1456,7 +1407,7 @@ void comp_data_seg(char *source) { } /* - * Scans the 'source' for "names" separated by 'delims' and returns + * Scans the 'source' for "names" separated by 'delims' and returns * the elements (pointer in source) into args array. * * Returns the number of items @@ -1598,7 +1549,7 @@ int comp_single_line_if(char *text) { bc_add_code(&comp_prog, kwTYPE_EOC); // bc_eoc(); - // auto-goto + // auto-goto p = pthen + 6; SKIP_SPACES(p); @@ -1637,7 +1588,7 @@ int comp_single_line_if(char *text) { } else strcat(buf, p); - // + // break; } else { pelse = strstr(pelse + 1, LCN_ELSE); @@ -1669,7 +1620,7 @@ int comp_single_line_if(char *text) { /** * Referencing a UDS field via array, eg foo(10).x */ -char *comp_array_uds_field(char *p, bc_t * bc) { +char *comp_array_uds_field(char *p, bc_t *bc) { char *p_begin = p; while (1) { @@ -1677,7 +1628,7 @@ char *comp_array_uds_field(char *p, bc_t * bc) { int len = (p - p_begin); if (len) { bc_add_code(bc, kwTYPE_UDS_EL); - bc_add_addr(bc, comp_get_uds_field_id(p_begin, len)); + bc_add_strn(bc, p_begin, len); } if (*p == '.') { p_begin = p + 1; @@ -1692,7 +1643,7 @@ char *comp_array_uds_field(char *p, bc_t * bc) { } /* - * array's args + * array's args */ void comp_array_params(char *src) { char *p = src; @@ -1736,7 +1687,7 @@ void comp_array_params(char *src) { p++; } - // + // if (level > 0) { sc_raise(MSG_ARRAY_MIS_RP); } else if (level < 0) { @@ -1782,7 +1733,7 @@ void comp_cmd_option(char *src) { bc_add_code(&comp_prog, OPTION_MATCH); bc_add_addr(&comp_prog, 0); } else if (CHKOPT(LCN_PREDEF_WRS) || CHKOPT(LCN_IMPORT_WRS)) { - ; // ignore it + ; // ignore it } else { sc_raise(MSG_OPTION_ERR, src); } @@ -1862,7 +1813,7 @@ void comp_text_line(char *text) { last_cmd = p; p = get_param_sect(p, ":", comp_bc_parm); - // check old style labels + // check old style labels if (is_all_digits(comp_bc_name)) { str_alltrim(comp_bc_name); idx = comp_label_getID(comp_bc_name); @@ -1882,7 +1833,7 @@ void comp_text_line(char *text) { } p = get_param_sect(p, ":", comp_bc_parm); } - // what's this ? + // what's this ? idx = comp_is_keyword(comp_bc_name); if (idx == kwREM) { return; // remarks... return @@ -1942,7 +1893,7 @@ void comp_text_line(char *text) { } sharp = (comp_bc_parm[0] == '#'); // if # -> file commands - ladd = (strncmp(comp_bc_parm, "<<", 2) == 0); // if << -> array, + ladd = (strncmp(comp_bc_parm, "<<", 2) == 0); // if << -> array, // append linc = (strncmp(comp_bc_parm, "++", 2) == 0); @@ -1958,13 +1909,13 @@ void comp_text_line(char *text) { return; } - if ((idx == kwCONST) || - ((comp_bc_parm[0] == '=' || + if ((idx == kwCONST) || + ((comp_bc_parm[0] == '=' || (comp_bc_parm[0] == '(' && !comp_is_function(comp_bc_name)) || ladd || linc || ldec || leqop) && (idx == -1))) { - // + // // LET/CONST commands - // + // char *parms = comp_bc_parm; if (idx == kwCONST) { // const a=10: b=10 @@ -2067,9 +2018,9 @@ void comp_text_line(char *text) { case kwPROC: case kwFUNC: - // + // // USER-DEFINED PROCEDURES/FUNCTIONS - // + // // single-line function (DEF FN) if ((eq_ptr = strchr(comp_bc_parm, '='))) { *eq_ptr = '\0'; @@ -2097,7 +2048,7 @@ void comp_text_line(char *text) { pidx = comp_add_udp(pname); comp_udp_setip(pname, comp_prog.count); } - // put JMP to the next command after the END + // put JMP to the next command after the END // (now we just keep the rq space, pass2 will // update that) bc_add_code(&comp_prog, kwGOTO); @@ -2261,9 +2212,9 @@ void comp_text_line(char *text) { break; case kwON: - // + // // ON x GOTO|GOSUB ... - // + // idx = kwONJMP; // WARNING! comp_push(comp_prog.count); bc_add_ctrl(&comp_prog, idx, 0, 0); @@ -2318,9 +2269,9 @@ void comp_text_line(char *text) { break; case kwFOR: - // + // // FOR - // + // p = strchr(comp_bc_parm, '='); p_do = strstr(comp_bc_parm, LCN_DO_WS); @@ -2401,7 +2352,7 @@ void comp_text_line(char *text) { break; case kwREPEAT: - // WHILE & REPEAT DOES NOT USE STACK + // WHILE & REPEAT DOES NOT USE STACK comp_block_level++; comp_block_id++; comp_push(comp_prog.count); @@ -2546,7 +2497,7 @@ void comp_text_line(char *text) { // EXTERNAL OR USER-DEFINED PROCEDURE udp = comp_is_external_proc(comp_bc_name); if (udp > -1) { - bc_add_extpcode(&comp_prog, comp_extproctable[udp].lib_id, + bc_add_extpcode(&comp_prog, comp_extproctable[udp].lib_id, comp_extproctable[udp].symbol_index); char *next = trim_empty_parentheses(comp_bc_parm); if (comp_is_parenthesized(next)) { @@ -2635,7 +2586,6 @@ addr_t comp_next_bc_cmd(addr_t ip) { case kwGOSUB: case kwTYPE_LINE: case kwTYPE_VAR: // [addr|id] - case kwTYPE_UDS: case kwTYPE_UDS_EL: ip += ADDRSZ; break; @@ -2953,15 +2903,15 @@ void comp_pass2_scan() { // if (node.pos == 360 || node.pos == 361) // trace("=== stack code %d\n", code); - if (code != kwGOTO && - code != kwRESTORE && - code != kwSELECT && - code != kwONJMP && - code != kwTYPE_PTR && - code != kwTYPE_CALL_UDP && - code != kwTYPE_CALL_UDF && - code != kwPROC && - code != kwFUNC && + if (code != kwGOTO && + code != kwRESTORE && + code != kwSELECT && + code != kwONJMP && + code != kwTYPE_PTR && + code != kwTYPE_CALL_UDP && + code != kwTYPE_CALL_UDF && + code != kwPROC && + code != kwFUNC && code != kwTYPE_RET) { // default - calculate true-ip true_ip = comp_search_bc_eoc(node.pos + (BC_CTRLSZ + 1)); @@ -3033,7 +2983,7 @@ void comp_pass2_scan() { // number of POPs comp_prog.ptr[node.pos + (ADDRSZ + 1)] = level - label.level; } else { - // number of POPs + // number of POPs comp_prog.ptr[node.pos + (ADDRSZ + 1)] = 0; } break; @@ -3186,7 +3136,7 @@ void comp_pass2_scan() { // avoid finding another CASE or CASE ELSE on the same level, but after END SELECT j = comp_search_bc_stack(i + 1, kwENDSELECT, node.level, node.block_id); - + if (false_ip == INVALID_ADDR || false_ip > j) { false_ip = comp_search_bc_stack(i + 1, kwCASE_ELSE, node.level, node.block_id); if (false_ip == INVALID_ADDR || false_ip > j) { @@ -3265,8 +3215,6 @@ void comp_init() { comp_impcount = 0; comp_libcount = 0; comp_varcount = 0; - comp_udscount = 0; - comp_next_field_id = 0; comp_sp = 0; comp_udpcount = 0; comp_block_level = 0; @@ -3289,8 +3237,6 @@ void comp_init() { comp_imptable = dbt_create(comp_bc_temp, 0); sprintf(comp_bc_temp, "SBI-EXP%d", ctask->tid); comp_exptable = dbt_create(comp_bc_temp, 0); - sprintf(comp_bc_temp, "SBI-UDS%d", ctask->tid); - comp_udstable = dbt_create(comp_bc_temp, 0); comp_varsize = comp_udpsize = GROWSIZE; comp_varcount = comp_labcount = comp_sp = comp_udpcount = 0; @@ -3310,7 +3256,6 @@ void comp_init() { assert(comp_labtable != -1); assert(comp_udptable != 0); assert(comp_stack != -1); - assert(comp_udstable != -1); #endif dbt_prealloc(comp_labtable, os_cclabs1, sizeof(comp_label_t)); @@ -3357,7 +3302,6 @@ void comp_close() { dbt_close(comp_imptable); dbt_close(comp_libtable); dbt_close(comp_stack); - dbt_close(comp_udstable); tmp_free(comp_udptable); comp_varcount = comp_labcount = comp_sp = comp_udpcount = 0; @@ -3382,7 +3326,7 @@ char *comp_load(const char *file_name) { strcpy(comp_file_name, file_name); #if defined(IMPL_DEV_READ) buf = dev_read(file_name); -#else +#else h = open(comp_file_name, O_BINARY | O_RDONLY, 0644); if (h == -1) { buf = NULL; @@ -3559,7 +3503,7 @@ void comp_preproc_grmode(const char *source) { while (*p) { // while *p is not '\0' if (*p == '\n' || *p == ':') { // yeap, we must close the string // here (enter or - // command-seperator) + // command-seperator) // it is supposed that remarks had already removed from source *p = '\0'; // terminate the string break; @@ -3575,9 +3519,9 @@ void comp_preproc_grmode(const char *source) { v = p; // 'v' points to first letter of 'width', // (1024x768) // ........................................^ <- p, v - p = strchr(v, 'X'); // search for the end of 'width' parameter - // - // + p = strchr(v, 'X'); // search for the end of 'width' parameter + // + // // (1024x768). Remeber that the string is // in upper-case // .............................................^ <- p @@ -3590,9 +3534,9 @@ void comp_preproc_grmode(const char *source) { *p = '\0'; // we close the string at X position // (example: "1024x768" it will be // "1024\0768") - x = xstrtol(v); // now the v points to a string-of-digits, - // - // + x = xstrtol(v); // now the v points to a string-of-digits, + // + // // we can perform atoi() // (xstrtol()=atoi()) p++; @@ -3609,9 +3553,9 @@ void comp_preproc_grmode(const char *source) { // different path *p = '\0'; // we close the string at second's X // position - y = xstrtol(v); // now the v points to a string-of-digits, - // - // + y = xstrtol(v); // now the v points to a string-of-digits, + // + // // we can perform atoi() // (xstrtol()=atoi()) @@ -3635,9 +3579,9 @@ void comp_preproc_grmode(const char *source) { // trimmed } else { // there was no 'X' delimiter after the // 'height', so, bpp is undefined - y = xstrtol(v); // now the v points to a string-of-digits, - // - // + y = xstrtol(v); // now the v points to a string-of-digits, + // + // // we can perform atoi() // (xstrtol()=atoi()) b = 0; // bpp is undefined (value 0) @@ -3780,9 +3724,9 @@ void comp_preproc_include(char *p) { } char *fp = fileName; int size = 0; - while (*p != '\n' && - *p != '\"' && - *p != '\0' && + while (*p != '\n' && + *p != '\"' && + *p != '\0' && ++size < OS_PATHNAME_SIZE) { *fp++ = *p++; } @@ -3889,7 +3833,7 @@ char *comp_preproc_func_begin(char *p) { char *dp; int single_line_f = 0; char pname[SB_KEYWORD_SIZE + 1]; - + if (strncmp(LCN_SUB_WRS, p, LEN_SUB_WRS) == 0) { p += LEN_SUB_WRS; } else if (strncmp(LCN_FUNC_WRS, p, LEN_FUNC_WRS) == 0) { @@ -3898,14 +3842,14 @@ char *comp_preproc_func_begin(char *p) { p += LEN_DEF_WRS; } SKIP_SPACES(p); - + // copy proc/func name dp = pname; while (is_alnum(*p) || *p == '_') { *dp++ = *p++; } *dp = '\0'; - + // search for '=' while (*p != '\n' && *p != '=') { p++; @@ -3916,7 +3860,7 @@ char *comp_preproc_func_begin(char *p) { p++; } } - + // add declaration if (comp_udp_getip(pname) == INVALID_ADDR) { comp_add_udp(pname); @@ -3931,7 +3875,7 @@ char *comp_preproc_func_begin(char *p) { } else { strcpy(comp_bc_proc, pname); } - + if (!single_line_f) { comp_proc_level++; } else { @@ -3972,7 +3916,7 @@ void comp_preproc_pass1(char *p) { while (*p) { if (strncmp(LCN_OPTION, p, LEN_OPTION) == 0) { // options - p = comp_preproc_options(p + LEN_OPTION); + p = comp_preproc_options(p + LEN_OPTION); } else if (strncmp(LCN_IMPORT_WRS, p, LEN_IMPORT) == 0) { // import comp_preproc_import(p + LEN_IMPORT); @@ -4048,7 +3992,7 @@ int comp_pass1(const char *section, const char *text) { char *code_line = tmp_alloc(SB_SOURCELINE_SIZE + 1); char *new_text = comp_format_text(text); - + comp_preproc_pass1(new_text); if (!comp_error) { @@ -4134,7 +4078,7 @@ int comp_pass2_exports() { sym.address = comp_udptable[pid].ip; sym.vid = comp_udptable[pid].vid; } else { - // look on variables + // look on variables pid = -1; for (j = 0; j < comp_varcount; j++) { if (strcmp(comp_vartable[j].name, sym.symbol) == 0) { @@ -4206,7 +4150,7 @@ mem_t comp_create_bin() { log_printf(MSG_CREATING_BC); } } - // + // memcpy(&hdr.sign, "SBEx", 4); hdr.ver = 2; hdr.sbver = SB_DWORD_VER; diff --git a/src/common/smbas.h b/src/common/smbas.h index 308c0a92..4d5363fc 100644 --- a/src/common/smbas.h +++ b/src/common/smbas.h @@ -196,8 +196,6 @@ EXTERN char gsb_last_errmsg[SB_ERRMSG_SIZE + 1]; /**< last error message #define comp_udptable ctask->sbe.comp.udptable #define comp_udpcount ctask->sbe.comp.udpcount #define comp_udpsize ctask->sbe.comp.udpsize -#define comp_udstable ctask->sbe.comp.udstable -#define comp_udscount ctask->sbe.comp.udscount #define comp_next_field_id ctask->sbe.comp.next_field_id #define comp_uds_tab_ip ctask->sbe.comp.uds_tab_ip #define comp_use_global_vartable ctask->sbe.comp.use_global_vartable diff --git a/src/common/tasks.h b/src/common/tasks.h index ed7b6d6e..0e64549e 100644 --- a/src/common/tasks.h +++ b/src/common/tasks.h @@ -106,11 +106,6 @@ typedef struct { bid_t udpcount; bid_t udpsize; - // user defined structures - dbt_t udstable; - bid_t udscount; - int next_field_id; - // pass2 stack dbt_t stack; bid_t stack_count; diff --git a/src/common/units.c b/src/common/units.c index ca5e366b..04d25e70 100644 --- a/src/common/units.c +++ b/src/common/units.c @@ -128,13 +128,15 @@ int open_unit(const char *file) { unitname[strlen(bas_file) - 4] = 0; strcat(unitname, ".sbu"); - if ((ut = sys_filetime(unitname)) == 0L) { // binary not found - comp_rq = 1; // compile it + if ((ut = sys_filetime(unitname)) == 0L) { + // binary not found - compile + comp_rq = 1; } else { - if ((st = sys_filetime(bas_file))) { // source found + if ((st = sys_filetime(bas_file))) { + // source found if (ut < st) { - comp_rq = 1; // executable is older than source; - // compile it + // executable is older than source - compile + comp_rq = 1; } } } @@ -281,7 +283,7 @@ int unit_exec(int lib_id, int index, var_t * ret) { ps = &prog_symtable[index]; us = &(taskinfo(ps->task_id)->sbe.exec.exptable[ps->exp_idx]); - // + // switch (ps->type) { case stt_variable: break; @@ -333,7 +335,7 @@ int unit_exec(int lib_id, int index, var_t * ret) { tmp_free(udf_rv.x.vdvar.vptr); } - // + // activate_task(my_tid); exec_sync_variables(0); break; diff --git a/src/common/var.c b/src/common/var.c index b24e35ff..a24a7832 100644 --- a/src/common/var.c +++ b/src/common/var.c @@ -415,7 +415,7 @@ void v_add(var_t *result, var_t *a, var_t *b) { if (a->type == V_STR && b->type == V_STR) { result->type = V_STR; - result->v.p.ptr = (byte *)tmp_alloc(strlen((char *)a->v.p.ptr) + + result->v.p.ptr = (byte *)tmp_alloc(strlen((char *)a->v.p.ptr) + strlen((char *)b->v.p.ptr) + 1); strcpy((char *) result->v.p.ptr, (char *) a->v.p.ptr); strcat((char *) result->v.p.ptr, (char *) b->v.p.ptr); @@ -805,3 +805,14 @@ void v_input2var(const char *str, var_t *var) { tmp_free(sb); } } + +void v_eval_str(var_p_t v) { + int len = code_getstrlen(); + v->type = V_STR; + v->v.p.size = len; + v->v.p.ptr = tmp_alloc(len + 1); + memcpy(v->v.p.ptr, &prog_source[prog_ip], len); + *((char *)(v->v.p.ptr + len)) = '\0'; + prog_ip += len; +} + diff --git a/src/common/var.h b/src/common/var.h index b03837ac..d9a3cf0d 100644 --- a/src/common/var.h +++ b/src/common/var.h @@ -670,6 +670,15 @@ char *v_getstr(var_t *v); */ #define v_is_type(v, t) (v != NULL && v->type == t) +/** + * @ingroup var + * + * populates the var to string from bytecode + * + * @param v is the variable + */ +void v_eval_str(var_p_t v); + /* * low-level byte-code parsing * diff --git a/src/common/var_hash.c b/src/common/var_hash.c index 022d796b..354daa0e 100644 --- a/src/common/var_hash.c +++ b/src/common/var_hash.c @@ -6,7 +6,7 @@ // This program is distributed under the terms of the GPL v2.0 or later // Download the GNU Public License (GPL) from www.gnu.org // -// Copyright(C) 2010 Chris Warren-Smith. [http://tinyurl.com/ja2ss] +// Copyright(C) 2010-2014 Chris Warren-Smith. [http://tinyurl.com/ja2ss] #include "common/sys.h" #include "common/var.h" @@ -45,7 +45,7 @@ typedef struct Node { } Node; /** - * Returns a new Element + * Returns a new Element */ Element *create_element(var_p_t key) { Element *element = (Element *) tmp_alloc(sizeof (Element)); @@ -77,7 +77,7 @@ void delete_element(Element *element) { v_free(element->value); tmp_free(element->value); // cleanup v_new } - tmp_free(element); // cleanup create_element() + tmp_free(element); // cleanup create_element() } /** @@ -86,7 +86,14 @@ void delete_element(Element *element) { int cmp_fn(const void *a, const void *b) { Element *el_a = (Element *)a; Element *el_b = (Element *)b; - return v_compare(el_a->key, el_b->key); + + int result; + if (el_a->key->type == V_STR && el_b->key->type == V_STR) { + result = strcasecmp(el_a->key->v.p.ptr, el_b->key->v.p.ptr); + } else { + result = v_compare(el_a->key, el_b->key); + } + return result; } /** @@ -180,6 +187,65 @@ void hash_free_var(var_p_t var_p) { } } +/** + * Inserts the variable into the b-tree, set result to the key value + */ +void hash_insert_key(var_p_t base, var_p_t var_key, var_p_t *result) { + Element *key = create_element(var_key); + Node *node = tfind(key, &(base->v.hash), cmp_fn); + if (node != NULL) { + // item already exists + *result = node->element->value; + delete_element(key); + } + else { + key->value = *result = v_new(); + tsearch(key, &(base->v.hash), cmp_fn); + } +} + +/** + * Returns the final element eg z in foo.x.y.z + * + * Scan byte code for node kwTYPE_UDS_EL and attach as field elements + * if they don't already exist. + */ +var_p_t hash_resolve_fields(const var_p_t base) { + var_p_t field = 0; + if (code_peek() == kwTYPE_UDS_EL) { + code_skipnext(); + if (code_peek() != kwTYPE_STR) { + err_stackmess(); + return NULL; + } else { + code_skipnext(); + } + + if (base->type != V_HASH) { + if (v_is_nonzero(base)) { + err_typemismatch(); + return NULL; + } else { + v_free(base); + base->type = V_HASH; + base->v.hash = NULL; + } + } + + // evaluate the variable 'key' name + var_t key; + v_eval_str(&key); + hash_insert_key(base, &key, &field); + v_free(&key); + + // evaluate the next sub-element + field = hash_resolve_fields(field); + } else { + field = base; + } + return field; +} + /** * Return the variable in base keyed by key, if not found then creates * an empty variable that will be returned in a further call @@ -206,25 +272,18 @@ void hash_get_value(var_p_t base, var_p_t var_key, var_p_t *result) { v_free(clone); tmp_free(clone); } else if (base->type != V_HASH) { - // initialise as hash - v_free(base); - base->type = V_HASH; - base->v.hash = NULL; + if (v_is_nonzero(base)) { + err_typemismatch(); + return; + } else { + // initialise as hash + v_free(base); + base->type = V_HASH; + base->v.hash = NULL; + } } - // create a key which will hold our name and value pairs - Element *key = create_element(var_key); - Node *node = tfind(key, &base->v.hash, cmp_fn); - if (node != NULL) { - // item already exists - *result = node->element->value; - delete_element(key); - } - else { - // add key to the tree - key->value = *result = v_new(); - tsearch(key, &base->v.hash, cmp_fn); - } + hash_insert_key(base, var_key, result); } /** @@ -260,7 +319,7 @@ void hash_set(var_p_t dest, const var_p_t src) { * Return the contents of the structure as a string */ void hash_to_str(const var_p_t var_p, char *out, int max_len) { - sprintf(out, "HASH:%d", hash_to_int(var_p)); + sprintf(out, "UDS:%d", hash_to_int(var_p)); } /** diff --git a/src/common/var_hash.h b/src/common/var_hash.h index a9294916..ed717759 100644 --- a/src/common/var_hash.h +++ b/src/common/var_hash.h @@ -5,7 +5,7 @@ // This program is distributed under the terms of the GPL v2.0 or later // Download the GNU Public License (GPL) from www.gnu.org // -// Copyright(C) 2007 Chris Warren-Smith. [http://tinyurl.com/ja2ss] +// Copyright(C) 2007-2014 Chris Warren-Smith. [http://tinyurl.com/ja2ss] #include "common/var.h" @@ -21,6 +21,7 @@ int hash_is_empty(const var_p_t var_p); int hash_to_int(const var_p_t var_p); int hash_length(const var_p_t var_p); var_p_t hash_elem(const var_p_t var_p, int index); +var_p_t hash_resolve_fields(const var_p_t base); void hash_clear(const var_p_t var_p); void hash_free_var(var_p_t var_p); void hash_get_value(var_p_t base, var_p_t key, var_p_t *result); From 9ac038298a2d2c9876f8c52add9acd0850a3c0a9 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Sat, 23 Aug 2014 15:20:44 +1000 Subject: [PATCH 19/21] COMMON: Unitfy HASH and UDS --- src/common/Makefile.am | 1 - src/common/bc.c | 46 +++---- src/common/blib.c | 10 -- src/common/brun.c | 1 - src/common/eval.c | 9 +- src/common/hotspots.h | 5 - src/common/proc.c | 90 ++++++------- src/common/scan.c | 3 - src/common/smbas.h | 1 - src/common/var.c | 38 +----- src/common/var.h | 3 +- src/common/var_uds.c | 253 ------------------------------------ src/common/var_uds.h | 35 ----- src/languages/keywords.en.c | 1 - 14 files changed, 71 insertions(+), 425 deletions(-) delete mode 100644 src/common/var_uds.c delete mode 100644 src/common/var_uds.h diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 5aa940ee..4394b08c 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -78,7 +78,6 @@ libsb_common_a_SOURCES = \ str.c str.h \ tasks.c tasks.h \ search.c search.h \ - var_uds.c var_uds.h \ var_hash.c var_hash.h \ keymap.c keymap.h \ units.c units.h \ diff --git a/src/common/bc.c b/src/common/bc.c index be68ed1c..1f2610d4 100644 --- a/src/common/bc.c +++ b/src/common/bc.c @@ -227,39 +227,30 @@ void bc_add_strn(bc_t *bc, const char *str, int len) { */ char *bc_store_string(bc_t *bc, char *src) { char *p = src; - char *np = 0; + char *np = NULL; char *base = src + 1; - int l = 0; // total length - int seglen = 0; // length of segment between escapes + int len = 0; - p++; // == '\"' + // skip past opening quotes + p++; while (*p) { if (*p == '\\' && ((*(p + 1) == '\"') || *(p + 1) == '\\')) { // escaped quote " or escaped escape - seglen = p - base; - np = np ? tmp_realloc(np, l + seglen + 1) : tmp_alloc(seglen + 1); - strncpy(np + l, base, seglen); - l += seglen; // add next segment - np[l] = 0; - base = ++p; // include " (or \ ) in next segment + int seglen = p - base; + np = np ? tmp_realloc(np, len + seglen + 1) : tmp_alloc(seglen + 1); + strncpy(np + len, base, seglen); + // add next segment + len += seglen; + np[len] = 0; + // include " (or \ ) in next segment + base = ++p; } else if (*p == '\"') { // end of string detected - seglen = p - base; - np = np ? tmp_realloc(np, l + seglen + 1) : tmp_alloc(seglen + 1); - strncpy(np + l, base, seglen); - np[l + seglen] = 0; - if (opt_cstr) { - // c-style special char syntax - char *cstr; - cstr = cstrdup(np); - tmp_free(np); - bc_add_strn(bc, cstr, strlen(cstr)); - tmp_free(cstr); - } else { - // normal - bc_add_strn(bc, np, strlen(np)); - tmp_free(np); - } + int seglen = p - base; + np = np ? tmp_realloc(np, len + seglen + 1) : tmp_alloc(seglen + 1); + memcpy(np + len, base, seglen); + bc_add_strn(bc, np, len + seglen); + tmp_free(np); p++; return p; } @@ -299,10 +290,7 @@ char *bc_store_macro(bc_t *bc, char *src) { * adds an EOC mark at the current position */ void bc_eoc(bc_t *bc) { - // if ( bc->count ) { - // if ( bc->ptr[bc->count-1] != kwTYPE_EOC ) bc_add1(bc, kwTYPE_EOC); - // } } /* diff --git a/src/common/blib.c b/src/common/blib.c index 9479c37b..ab7a6146 100644 --- a/src/common/blib.c +++ b/src/common/blib.c @@ -11,7 +11,6 @@ #include "common/kw.h" #include "common/var.h" #include "common/var_hash.h" -#include "common/var_uds.h" #include "common/device.h" #include "common/blib.h" #include "common/pproc.h" @@ -1752,10 +1751,6 @@ void cmd_for() { var_elem_ptr = hash_elem(array_p, 0); break; - case V_UDS: - var_elem_ptr = uds_elem(array_p, 0); - break; - case V_ARRAY: if (array_p->v.a.size > 0) { var_elem_ptr = v_elem(array_p, 0); @@ -1950,11 +1945,6 @@ void cmd_next() { var_elem_ptr = hash_elem(array_p, node.x.vfor.step_expr_ip); break; - case V_UDS: - node.x.vfor.step_expr_ip++; // element-index - var_elem_ptr = uds_elem(array_p, node.x.vfor.step_expr_ip); - break; - case V_ARRAY: node.x.vfor.step_expr_ip++; // element-index diff --git a/src/common/brun.c b/src/common/brun.c index 5ab2ec80..7e26b497 100755 --- a/src/common/brun.c +++ b/src/common/brun.c @@ -24,7 +24,6 @@ #include "common/messages.h" #include "common/device.h" #include "common/pproc.h" -#include "common/var_uds.h" int brun_create_task(const char *filename, mem_t preloaded_bc, int libf); int exec_close_task(); diff --git a/src/common/eval.c b/src/common/eval.c index ba52ef7b..ae4a9713 100644 --- a/src/common/eval.c +++ b/src/common/eval.c @@ -670,7 +670,6 @@ static inline void eval_var(var_t *r, var_t *var_p) { v_set(r, var_p); break; case V_ARRAY: - case V_UDS: case V_HASH: v_set(r, var_p); break; @@ -1146,13 +1145,7 @@ void eval(var_t *r) { case kwTYPE_STR: // string - constant V_FREE(r); - r->type = V_STR; - len = code_getstrlen(); - r->v.p.ptr = tmp_alloc(len + 1); - memcpy(r->v.p.ptr, &prog_source[prog_ip], len); - *((char *) (r->v.p.ptr + len)) = '\0'; - r->v.p.size = len; - IP += len; + v_eval_str(r); break; case kwTYPE_PTR: diff --git a/src/common/hotspots.h b/src/common/hotspots.h index 528ec865..9d12af64 100644 --- a/src/common/hotspots.h +++ b/src/common/hotspots.h @@ -7,7 +7,6 @@ // // Copyright(C) 2014 Chris Warren-Smith -#include "common/var_uds.h" #include "common/var_hash.h" void err_evsyntax(void); @@ -83,8 +82,6 @@ static inline var_num_t code_getnext128f() { */ static inline var_num_t v_getval(var_t *v) { switch (v ? v->type : -1) { - case V_UDS: - return uds_to_int(v); case V_HASH: return hash_to_int(v); case V_PTR: @@ -118,8 +115,6 @@ static inline var_num_t v_getval(var_t *v) { */ static inline var_int_t v_igetval(var_t *v) { switch (v ? v->type : -1) { - case V_UDS: - return uds_to_int(v); case V_HASH: return hash_to_int(v); case V_PTR: diff --git a/src/common/proc.c b/src/common/proc.c index 745d8867..e265e854 100644 --- a/src/common/proc.c +++ b/src/common/proc.c @@ -10,7 +10,6 @@ #include "common/sys.h" #include "common/pproc.h" #include "common/messages.h" -#include "common/var_uds.h" #include "common/var_hash.h" #include @@ -261,6 +260,51 @@ void pv_write(char *str, int method, int handle) { } } +/* + * print the array variable + */ +void pv_write_array(var_t *var, int method, int handle) { + pv_write("[", method, handle); + + if (var->v.a.maxdim == 2) { + int rows, cols; + var_t *e; + int i, j, pos; + + // NxN + rows = ABS(var->v.a.ubound[0] - var->v.a.lbound[0]) + 1; + cols = ABS(var->v.a.ubound[1] - var->v.a.lbound[1]) + 1; + + for (i = 0; i < rows; i++) { + for (j = 0; j < cols; j++) { + pos = i * cols + j; + e = (var_t *) (var->v.a.ptr + (sizeof(var_t) * pos)); + pv_writevar(e, method, handle); + if (j != cols - 1) { + pv_write(",", method, handle); // add space? + } + } + if (i != rows - 1) { + pv_write(";", method, handle); // add space? + } + } + } else { + var_t *e; + int i; + + for (i = 0; i < var->v.a.size; i++) { + e = (var_t *) (var->v.a.ptr + (sizeof(var_t) * i)); + pv_writevar(e, method, handle); + if (i != var->v.a.size - 1) { + pv_write(",", method, handle); // add space? + } + } + } + + // close array + pv_write("]", method, handle); +} + /* * just prints the value of variable 'var' */ @@ -274,9 +318,6 @@ void pv_writevar(var_t *var, int method, int handle) { case V_STR: pv_write((char *)var->v.p.ptr, method, handle); break; - case V_UDS: - uds_write(var, method, handle); - break; case V_HASH: hash_write(var, method, handle); break; @@ -293,46 +334,7 @@ void pv_writevar(var_t *var, int method, int handle) { pv_write(tmpsb, method, handle); break; case V_ARRAY: - // open array - pv_write("[", method, handle); - - if (var->v.a.maxdim == 2) { - int rows, cols; - var_t *e; - int i, j, pos; - - // NxN - rows = ABS(var->v.a.ubound[0] - var->v.a.lbound[0]) + 1; - cols = ABS(var->v.a.ubound[1] - var->v.a.lbound[1]) + 1; - - for (i = 0; i < rows; i++) { - for (j = 0; j < cols; j++) { - pos = i * cols + j; - e = (var_t *) (var->v.a.ptr + (sizeof(var_t) * pos)); - pv_writevar(e, method, handle); - if (j != cols - 1) { - pv_write(",", method, handle); // add space? - } - } - if (i != rows - 1) { - pv_write(";", method, handle); // add space? - } - } - } else { - var_t *e; - int i; - - for (i = 0; i < var->v.a.size; i++) { - e = (var_t *) (var->v.a.ptr + (sizeof(var_t) * i)); - pv_writevar(e, method, handle); - if (i != var->v.a.size - 1) { - pv_write(",", method, handle); // add space? - } - } - } - - // close array - pv_write("]", method, handle); + pv_write_array(var, method, handle); break; } } diff --git a/src/common/scan.c b/src/common/scan.c index d157fe74..60934ce5 100644 --- a/src/common/scan.c +++ b/src/common/scan.c @@ -40,7 +40,6 @@ extern void sc_raise2(const char *fmt, int line, const char *buff); // sberr #define LEN_QUIET STRLEN(LCN_QUIET) #define LEN_GRMODE STRLEN(LCN_GRMODE) #define LEN_TEXTMODE STRLEN(LCN_TEXTMODE) -#define LEN_CSTR STRLEN(LCN_CSTR) #define LEN_COMMAND STRLEN(LCN_COMMAND) #define LEN_SHOWPAGE STRLEN(LCN_SHOWPAGE) @@ -3779,8 +3778,6 @@ char *comp_preproc_options(char *p) { opt_graphics = 1; } else if (strncmp(LCN_TEXTMODE, p, LEN_TEXTMODE) == 0) { opt_graphics = 0; - } else if (strncmp(LCN_CSTR, p, LEN_CSTR) == 0) { - opt_cstr = 1; } else if (strncmp(LCN_COMMAND, p, LEN_COMMAND) == 0) { p += LEN_COMMAND; SKIP_SPACES(p); diff --git a/src/common/smbas.h b/src/common/smbas.h index 4d5363fc..c4ee5411 100644 --- a/src/common/smbas.h +++ b/src/common/smbas.h @@ -95,7 +95,6 @@ typedef struct { #define OPT_MOD_SZ 1024 EXTERN byte opt_graphics; /**< command-line option: start in graphics mode @ingroup sys */ -EXTERN byte opt_cstr; /**< C-style special characters by default @ingroup sys */ EXTERN byte opt_quiet; /**< command-line option: quiet @ingroup sys */ EXTERN int opt_retval; /**< return-value (ERRORLEVEL) @ingroup sys */ EXTERN byte opt_decomp; /**< decompile @ingroup sys */ diff --git a/src/common/var.c b/src/common/var.c index a24a7832..7d5cddd4 100644 --- a/src/common/var.c +++ b/src/common/var.c @@ -12,7 +12,6 @@ #include "common/var.h" #include "common/smbas.h" #include "common/sberr.h" -#include "common/var_uds.h" #include "common/var_hash.h" #define ARR_ALLOC 256 @@ -21,9 +20,7 @@ * creates and returns a new variable */ var_t *v_new() { - var_t *ptr; - - ptr = (var_t *) tmp_alloc(sizeof(var_t)); + var_t *ptr = (var_t *)tmp_alloc(sizeof(var_t)); v_init(ptr); return ptr; } @@ -57,9 +54,6 @@ void v_free(var_t *v) { } } break; - case V_UDS: - uds_free(v); - break; case V_HASH: hash_free_var(v); break; @@ -78,8 +72,6 @@ int v_isempty(var_t *var) { return (strlen((char *) var->v.p.ptr) == 0); case V_INT: return (var->v.i == 0); - case V_UDS: - return uds_is_empty(var); case V_HASH: return hash_is_empty(var); case V_PTR: @@ -102,8 +94,6 @@ int v_length(var_t *var) { switch (var->type) { case V_STR: return strlen((char *) var->v.p.ptr); - case V_UDS: - return uds_length(var); case V_HASH: return hash_length(var); case V_PTR: @@ -298,8 +288,6 @@ int v_is_nonzero(var_t *v) { return (ABS(v->v.n) > 1E-308); case V_STR: return (v->v.p.size != 0); - case V_UDS: - return !uds_is_empty(v); case V_HASH: return !hash_is_empty(v); case V_PTR: @@ -394,10 +382,6 @@ int v_compare(var_t *a, var_t *b) { return 0; } - if (a->type == V_UDS && b->type == V_UDS) { - return uds_compare(a, b); - } - if (a->type == V_HASH && b->type == V_HASH) { return hash_compare(a, b); } @@ -487,14 +471,7 @@ void v_set(var_t *dest, const var_t *src) { int i; var_t *dest_vp, *src_vp; - if (src->type == V_UDS) { - uds_set(dest, (const var_p_t) src); - return; - } else if (dest->type == V_UDS) { - // lvalue struct assigned to non-struct rvalue - uds_clear(dest); - return; - } else if (src->type == V_HASH) { + if (src->type == V_HASH) { hash_set(dest, (const var_p_t) src); return; } else if (dest->type == V_HASH) { @@ -599,16 +576,10 @@ void v_createstr(var_t *v, const char *src) { */ void v_tostr(var_t *arg) { if (arg->type != V_STR) { - char *tmp; int l; - - tmp = tmp_alloc(64); + char *tmp = tmp_alloc(64); switch (arg->type) { - case V_UDS: - uds_to_str(arg, tmp, 64); - uds_free(arg); - break; case V_HASH: hash_to_str(arg, tmp, 64); hash_free_var(arg); @@ -806,6 +777,9 @@ void v_input2var(const char *str, var_t *var) { } } +/* + * evaluate the pcode string + */ void v_eval_str(var_p_t v) { int len = code_getstrlen(); v->type = V_STR; diff --git a/src/common/var.h b/src/common/var.h index d9a3cf0d..6461e029 100644 --- a/src/common/var.h +++ b/src/common/var.h @@ -38,8 +38,7 @@ #define V_ARRAY 4 /**< variable type, array of variables @ingroup var */ #define V_PTR 5 /**< variable type, pointer to UDF or label @ingroup var */ #define V_LIST 6 /**< variable type, dynamic list - N/A @ingroup var */ -#define V_UDS 7 /**< variable type, user defined structure @ingroup var */ -#define V_HASH 8 /**< variable type, hash @ingroup var */ +#define V_HASH 7 /**< variable type, hash @ingroup var */ /* * predefined system variables - index diff --git a/src/common/var_uds.c b/src/common/var_uds.c deleted file mode 100644 index 84ef8dfd..00000000 --- a/src/common/var_uds.c +++ /dev/null @@ -1,253 +0,0 @@ -// This file is part of SmallBASIC -// -// user-defined structures -// -// This program is distributed under the terms of the GPL v2.0 or later -// Download the GNU Public License (GPL) from www.gnu.org -// -// Copyright(C) 2007 Chris Warren-Smith. [http://tinyurl.com/ja2ss] - -#include "common/sys.h" -#include "common/var.h" -#include "common/smbas.h" - -/** - * Compare one UDS to another. see v_compare comments for return spec. - */ -int uds_compare(const var_p_t var_a, const var_p_t var_b) { - uds_field_s *next_a = var_a->v.uds; - - while (next_a) { - uds_field_s *next_b = var_b->v.uds; - while (next_b) { - if (next_a->field_id == next_b->field_id) { - int comp = v_compare(next_a->var, next_b->var); - if (comp != 0) { - return comp; - } - } - next_b = next_b->next; - } - next_a = next_a->next; - } - - // must have the same number of elements to fully match - return uds_to_int(var_a) == uds_to_int(var_b) ? 0 : -1; -} - -/** - * Return true if the structure is empty - */ -int uds_is_empty(var_p_t var_p) { - return (var_p->v.uds == 0); -} - -/** - * Return the contents of the structure as an integer - */ -int uds_to_int(const var_p_t var_p) { - int n = 0; - if (var_p->type == V_UDS) { - uds_field_s *next = var_p->v.uds; - while (next) { - n += uds_to_int(next->var) + 1; - next = next->next; - } - } - return n; -} - -/** - * Return the number of elements - */ -int uds_length(const var_p_t var_p) { - int n = 0; - if (var_p->type == V_UDS) { - uds_field_s *next = var_p->v.uds; - while (next) { - n += 1; - next = next->next; - } - } - return n; -} - -/** - * return the element at the nth position - */ -var_p_t uds_elem(const var_p_t var_p, int index) { - var_p_t result = 0; - if (var_p->type == V_UDS) { - uds_field_s *next = var_p->v.uds; - int count = 0; - while (next) { - if (count++ == index) { - result = next->var; - next = 0; - } else { - next = next->next; - } - } - } - return result; -} - -/** - * helper for uds_resolve_fields - */ -uds_field_s *uds_new_field(addr_t field_id, byte owner_flag) { - uds_field_s *field; - field = tmp_alloc(sizeof(uds_field_s)); - field->next = 0; - field->field_id = field_id; - field->var = owner_flag ? v_new() : 0; - field->var_owner_flag = owner_flag; - return field; -} - -/** - * Scan byte code for node kwTYPE_UDS_EL and attach as field elements - * if they don't already exist. - * returns the final element eg z in foo.x.y.z - */ -var_p_t uds_resolve_fields(const var_p_t var_p) { - var_p_t field = 0; // for code "foo.x.y.z" return "z" - - if (code_peek() == kwTYPE_UDS_EL) { - code_skipnext(); - addr_t field_id = code_getaddr(); - - if (var_p->type != V_UDS) { - if (v_is_nonzero(var_p)) { - err_typemismatch(); - return NULL; - } else { - v_free(var_p); - var_p->type = V_UDS; - } - } - - uds_field_s *next = var_p->v.uds; - uds_field_s *last = 0; - - while (next) { - last = next; // save tail - if (next->field_id == field_id) { - field = next->var; - break; - } - next = next->next; - } - if (field == 0) { - // append field to list - if (last != 0) { - // append to existing list of elements - last->next = uds_new_field(field_id, 1); - field = last->next->var; - } else { - // create first node on var_p->v.uds - var_p->v.uds = uds_new_field(field_id, 1); - field = var_p->v.uds->var; - } - } - field = uds_resolve_fields(field); - } else { - field = var_p; - } - - return field; -} - -/** - * free any owned variable in element - */ -void var_free(uds_field_s *element, int erase) { - if (element->var_owner_flag) { - v_free(element->var); - if (erase) { - tmp_free(element->var); - element->var = NULL; - } - } -} - -/** - * empty struct values - */ -void uds_clear(const var_p_t var) { - uds_field_s *next = var->v.uds; - while (next) { - var_free(next, 0); - next = next->next; - } -} - -/** - * Helper for uds_free - */ -void uds_free_element(uds_field_s *element) { - if (element) { - uds_free_element(element->next); - var_free(element, 1); - tmp_free(element); - } -} - -/** - * Delete the given structure - */ -void uds_free(var_p_t var_p) { - uds_free_element(var_p->v.uds); - var_p->v.uds = 0; -} - -/** - * copy values from one structure to another - */ -void uds_set(var_p_t dest, const var_p_t src) { - v_free(dest); - dest->type = V_UDS; - - uds_field_s *dest_node = 0; - uds_field_s *src_node = src->v.uds; - - while (src_node) { - if (dest->v.uds == 0) { - // head of the list - dest->v.uds = uds_new_field(src_node->field_id, 1); - v_set(dest->v.uds->var, src_node->var); - dest_node = dest->v.uds; - } else { - // subsequent list item - dest_node->next = uds_new_field(src_node->field_id, 1); - v_set(dest_node->next->var, src_node->var); - dest_node = dest_node->next; - } - src_node = src_node->next; - } -} - -/** - * Return the contents of the structure as a string - */ -void uds_to_str(const var_p_t var_p, char *out, int max_len) { - sprintf(out, "UDS:%d", uds_to_int(var_p)); -} - -/** - * Print the contents of the structure - */ -void uds_write(const var_p_t var_p, int method, int handle) { - pv_write("(", method, handle); - uds_field_s *next = var_p->v.uds; - while (next) { - pv_writevar(next->var, method, handle); - next = next->next; - if (next) { - pv_write(",", method, handle); - } - } - pv_write(")", method, handle); -} - - diff --git a/src/common/var_uds.h b/src/common/var_uds.h deleted file mode 100644 index 99fae4f5..00000000 --- a/src/common/var_uds.h +++ /dev/null @@ -1,35 +0,0 @@ -// This file is part of SmallBASIC -// -// user-defined structures -// -// This program is distributed under the terms of the GPL v2.0 or later -// Download the GNU Public License (GPL) from www.gnu.org -// -// Copyright(C) 2007 Chris Warren-Smith. [http://tinyurl.com/ja2ss] - -#include "common/var.h" - -#ifndef VAR_UDS_H -#define VAR_UDS_H - -#if defined(__cplusplus) -extern "C" { -#endif - -int uds_compare(const var_p_t var_a, const var_p_t var_b); -int uds_is_empty(const var_p_t var_p); -int uds_to_int(const var_p_t var_p); -int uds_length(const var_p_t var_p); -var_p_t uds_elem(const var_p_t var, int index); -var_p_t uds_resolve_fields(const var_p_t var_p); -void uds_clear(const var_p_t var); -void uds_free(var_p_t var_p); -void uds_set(var_p_t dest, const var_p_t src); -void uds_to_str(const var_p_t var_p, char *out, int max_len); -void uds_write(const var_p_t var_p, int method, int handle); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/src/languages/keywords.en.c b/src/languages/keywords.en.c index c699a464..8e85c3ec 100644 --- a/src/languages/keywords.en.c +++ b/src/languages/keywords.en.c @@ -474,7 +474,6 @@ struct proc_keyword_s proc_table[] = { #define LCN_QUIET "QUIET" #define LCN_GRMODE "GRMODE" #define LCN_TEXTMODE "TEXTMODE" -#define LCN_CSTR "CSTR" #define LCN_UNIT_PATH "UNITPATH" #define LCN_COMMAND "COMMAND" #define LCN_INC "INCLUDE" From 4248945b7937be5a9fabd8fdb7b40c3dae17817d Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Sat, 23 Aug 2014 16:57:27 +1000 Subject: [PATCH 20/21] COMMON: Unitfy HASH and UDS --- src/common/scan.c | 14 ++++++++++---- src/common/var.h | 16 ---------------- src/languages/messages.en.h | 1 + 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/common/scan.c b/src/common/scan.c index 60934ce5..dc56977a 100644 --- a/src/common/scan.c +++ b/src/common/scan.c @@ -642,7 +642,7 @@ bid_t comp_var_getID(const char *var_name) { comp_prepare_name(tmp, baseof(var_name, '/'), SB_KEYWORD_SIZE); char *dot = strchr(tmp, '.'); - if (dot != 0 && *(dot + 1) == 0) { + if (dot != NULL && *(dot + 1) == 0) { // name ends with dot sc_raise(MSG_MEMBER_DOES_NOT_EXISTS, tmp); return 0; @@ -654,7 +654,7 @@ bid_t comp_var_getID(const char *var_name) { // // If the name is not found in comp_libtable then it // is treated as a structure reference - if (dot != 0 && comp_check_lib(tmp)) { + if (dot != NULL && comp_check_lib(tmp)) { for (i = 0; i < comp_varcount; i++) { if (strcmp(comp_vartable[i].name, tmp) == 0) { return i; @@ -709,7 +709,7 @@ bid_t comp_var_getID(const char *var_name) { void comp_add_variable(bc_t *bc, const char *var_name) { char *dot = strchr(var_name, '.'); - if (dot != 0 && !comp_check_lib(var_name)) { + if (dot != NULL && !comp_check_lib(var_name)) { // uds-element (or sub-element eg foo.x.y.z) // record the uds-parent @@ -4038,7 +4038,13 @@ int comp_pass1(const char *section, const char *text) { for (i = 0; i < comp_udpcount; i++) { if (comp_udptable[i].ip == INVALID_ADDR) { comp_line = comp_udptable[i].pline; - sc_raise(MSG_UNDEFINED_UDP, comp_udptable[i].name); + char *dot = strchr(comp_udptable[i].name, '.'); + if (dot) { + sc_raise(MSG_UNDEFINED_HASH, comp_udptable[i].name); + } else { + sc_raise(MSG_UNDEFINED_UDP, comp_udptable[i].name); + } + break; } } } diff --git a/src/common/var.h b/src/common/var.h index 6461e029..c677d278 100644 --- a/src/common/var.h +++ b/src/common/var.h @@ -72,9 +72,6 @@ extern "C" { #endif -// the following prototype is declared later below -typedef struct uds_field_s uds_field_s; - /** * @ingroup var * @typedef var_s @@ -96,9 +93,6 @@ struct var_s { addr_t v; /** return-var ID */ } ap; - // user defined structure - uds_field_s *uds; /** pointer to the "structure" */ - // hash map void* hash; /** pointer the hash structure */ @@ -123,16 +117,6 @@ struct var_s { typedef struct var_s var_t; typedef var_t *var_p_t; -/* - * user defined structures - */ -struct uds_field_s { - uds_field_s *next; // next structure element - addr_t field_id; // the element id - var_p_t var; // the variable - byte var_owner_flag; // whether var is owned by this node -}; - /* * label */ diff --git a/src/languages/messages.en.h b/src/languages/messages.en.h index 711c94c4..f38551d4 100644 --- a/src/languages/messages.en.h +++ b/src/languages/messages.en.h @@ -103,6 +103,7 @@ #define MSG_PASS1 "Pass1...\n" #define MSG_PASS1_COUNT "\rPASS1: Line %d" #define MSG_UNDEFINED_UDP "Undefined SUB/FUNC code: %s" +#define MSG_UNDEFINED_HASH "Undefined HASH: %s, (Use DIM)" #define MSG_PASS1_FIN "\rPASS1: Line %d; finished\n" #define MSG_EXP_SYM_NOT_FOUND "Export symbol '%s' not found" #define MSG_PASS2 "PASS2..." From 2e013a0a00533f13fdca81362f9502185ce4d4af Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Sun, 24 Aug 2014 08:19:26 +1000 Subject: [PATCH 21/21] COMMON code cleanup --- src/common/scan.c | 2 +- src/common/var_hash.c | 38 ++++++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/common/scan.c b/src/common/scan.c index dc56977a..72ecb260 100644 --- a/src/common/scan.c +++ b/src/common/scan.c @@ -1623,7 +1623,7 @@ char *comp_array_uds_field(char *p, bc_t *bc) { char *p_begin = p; while (1) { - if (*p == 0 || !isalnum(*p)) { + if (*p == 0 || (*p != '_' && !isalnum(*p))) { int len = (p - p_begin); if (len) { bc_add_code(bc, kwTYPE_UDS_EL); diff --git a/src/common/var_hash.c b/src/common/var_hash.c index 354daa0e..188b7fca 100644 --- a/src/common/var_hash.c +++ b/src/common/var_hash.c @@ -70,14 +70,18 @@ Element *create_int_element(int key) { * cleanup the given element */ void delete_element(Element *element) { + // cleanup v_new v_free(element->key); - tmp_free(element->key); // cleanup v_new + tmp_free(element->key); + // cleanup v_new if (element->value) { v_free(element->value); - tmp_free(element->value); // cleanup v_new + tmp_free(element->value); } - tmp_free(element); // cleanup create_element() + + // cleanup create_element() + tmp_free(element); } /** @@ -107,7 +111,7 @@ int hash_compare(const var_p_t var_a, const var_p_t var_b) { * Return true if the structure is empty */ int hash_is_empty(const var_p_t var_p) { - return (var_p->v.hash == 0); + return (var_p->v.hash == NULL); } /** @@ -155,7 +159,7 @@ void hash_elem_cb(const void *nodep, VISIT value, int level) { var_p_t hash_elem(const var_p_t var_p, int index) { cb.count = 0; cb.index = index; - cb.var = 0; + cb.var = NULL; if (var_p->type == V_HASH) { twalk(var_p->v.hash, hash_elem_cb); } @@ -211,7 +215,7 @@ void hash_insert_key(var_p_t base, var_p_t var_key, var_p_t *result) { * if they don't already exist. */ var_p_t hash_resolve_fields(const var_p_t base) { - var_p_t field = 0; + var_p_t field = NULL; if (code_peek() == kwTYPE_UDS_EL) { code_skipnext(); if (code_peek() != kwTYPE_STR) { @@ -265,7 +269,7 @@ void hash_get_value(var_p_t base, var_p_t var_key, var_p_t *result) { Element *key = create_int_element(i); key->value = v_new(); v_set(key->value, element); - tsearch(key, &base->v.hash, cmp_fn); + tsearch(key, &(base->v.hash), cmp_fn); } // free the clone @@ -296,23 +300,25 @@ void hash_set_cb(const void *nodep, VISIT value, int level) { Element *key = create_element(element->key); key->value = v_new(); v_set(key->value, element->value); - tsearch(key, &cb.hash, cmp_fn); + tsearch(key, &(cb.hash), cmp_fn); } } /** - * Reference values from one structure to another + * copy values from one structure to another */ void hash_set(var_p_t dest, const var_p_t src) { - v_free(dest); - cb.hash = 0; + if (dest != src) { + v_free(dest); + cb.hash = NULL; - if (src->type == V_HASH) { - twalk(src->v.hash, hash_set_cb); - } + if (src->type == V_HASH) { + twalk(src->v.hash, hash_set_cb); + } - dest->type = V_HASH; - dest->v.hash = cb.hash; + dest->type = V_HASH; + dest->v.hash = cb.hash; + } } /**