' SQLite3 Test Script
DECLARE SUB DLL ALIAS "_idll" LIB "gtk-server"
DECLARE SUB REQUIRE ALIAS "_idll_require" LIB "gtk-server"
DECLARE SUB DEFINE ALIAS "_idll_define" LIB "gtk-server"
DECLARE SUB VARPTR ALIAS "varptr" LIB "gtk-server"
REQUIRE "libsqlite3.so"
DEFINE "sqlite3_open NONE INT 2 STRING LONG"
DEFINE "sqlite3_exec NONE INT 5 LONG STRING INT NULL PTR_STRING"
DEFINE "sqlite3_prepare_v2 NONE INT 5 LONG STRING INT PTR_LONG NULL"
DEFINE "sqlite3_step NONE INT 1 LONG"
DEFINE "sqlite3_column_text NONE STRING 2 LONG INT"
DEFINE "sqlite3_close NONE INT 1 LONG"
CONST SQLITE_ROW = 100
db = 0
dberr = 0
stmt = 0
DLL("sqlite3_open \"testsql\" " & VARPTR(db))
errmsg = DLL("sqlite3_exec " & db & " \"CREATE TABLE demo(someval INTEGER, sometxt TEXT);\" 0 0 " & VARPTR(dberr))
PRINT "DB ERROR: ",errmsg,"\n"
DLL("sqlite3_exec " & db & " \"INSERT INTO demo VALUES (123, 'Hello');\" 0 0 " & VARPTR(dberr))
DLL("sqlite3_exec " & db & " \"INSERT INTO demo VALUES (234, 'cruel');\" 0 0 " & VARPTR(dberr))
DLL("sqlite3_exec " & db & " \"INSERT INTO demo VALUES (345, 'world');\" 0 0 " & VARPTR(dberr))
result = DLL("sqlite3_prepare_v2 " & db & " \"SELECT * FROM demo;\" -1 " & VARPTR(stmt) & " 0")
SPLIT result BY " " TO ok, stmt
WHILE DLL("sqlite3_step " & stmt) = SQLITE_ROW
PRINT DLL("sqlite3_column_text " & stmt & " " & 0) & " - " & DLL("sqlite3_column_text " & stmt & " " & 1),"\n"
WEND
DLL("sqlite3_close " & db)
#ifdef GTK_SERVER_SCRIPTBASIC
besVERSION_NEGOTIATE
return (int)INTERFACE_VERSION;
besEND
besSUB_START
besEND
besSUB_FINISH
besEND
besFUNCTION(_idll)
VARIABLE ptr;
char* arg0;
char* retstr;
if(besARGNR>1) return EX_ERROR_TOO_MANY_ARGUMENTS;
if(besARGNR<1) return EX_ERROR_TOO_FEW_ARGUMENTS;
ptr = besARGUMENT(1);
besDEREFERENCE(ptr);
arg0 = besCONVERT2ZCHAR(besCONVERT2STRING(ptr),arg0);
retstr = (char*)gtk(arg0);
besALLOC_RETURN_STRING(strlen(retstr));
memcpy(STRINGVALUE(besRETURNVALUE),retstr,strlen(retstr));
besFREE(arg0);
besEND
besFUNCTION(varptr)
VARIABLE ptr;
if(besARGNR>1) return EX_ERROR_TOO_MANY_ARGUMENTS;
if(besARGNR<1) return EX_ERROR_TOO_FEW_ARGUMENTS;
besALLOC_RETURN_LONG
ptr = besARGUMENT(1);
besDEREFERENCE(ptr);
LONGVALUE(besRETURNVALUE) = (int)ptr;
besEND
besFUNCTION(_idll_require)
VARIABLE ptr;
char* arg0;
char* retstr;
char sb_require[64];
strcpy (sb_require,"gtk_server_require ");
if(besARGNR>1) return EX_ERROR_TOO_MANY_ARGUMENTS;
if(besARGNR<1) return EX_ERROR_TOO_FEW_ARGUMENTS;
ptr = besARGUMENT(1);
besDEREFERENCE(ptr);
arg0 = besCONVERT2ZCHAR(besCONVERT2STRING(ptr),arg0);
strcat (sb_require,arg0);
retstr = (char*)gtk(sb_require);
besALLOC_RETURN_STRING(strlen(retstr));
memcpy(STRINGVALUE(besRETURNVALUE),retstr,strlen(retstr));
besFREE(arg0);
besEND
besFUNCTION(_idll_define)
VARIABLE ptr;
char* arg0;
char* retstr;
char sb_define[256];
strcpy (sb_define,"gtk_server_define ");
if(besARGNR>1) return EX_ERROR_TOO_MANY_ARGUMENTS;
if(besARGNR<1) return EX_ERROR_TOO_FEW_ARGUMENTS;
ptr = besARGUMENT(1);
besDEREFERENCE(ptr);
arg0 = besCONVERT2ZCHAR(besCONVERT2STRING(ptr),arg0);
strcat (sb_define,arg0);
retstr = (char*)gtk(sb_define);
besALLOC_RETURN_STRING(strlen(retstr));
memcpy(STRINGVALUE(besRETURNVALUE),retstr,strlen(retstr));
besFREE(arg0);
besEND
/* Needed to compile standalone Scriptbasic programs */
SLFST VISIO_SLFST[] = {
{"versmodu", versmodu},
{"bootmodu", bootmodu},
{"finimodu", finimodu},
{"_idll", _idll},
{"varptr",varptr},
{"_idll_require", _idll_require},
{"_idll_define", _idll_define},
{NULL, NULL}
};
#endif /* End of ScriptBasic code */
#include <gtk/gtk.h>
static gboolean delete_event (GtkWidget *widget, GdkEvent *event, gpointer data)
{
gtk_main_quit ();
return FALSE;
}
int main (int argc, char *argv[])
{
GtkWidget *window;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "delete-event", G_CALLBACK (delete_event), NULL);
gtk_widget_show (window);
gtk_main ();
return 0;
}
' *************************************
' Demo program using the GTK-Server HUG
' *************************************
IMPORT gtk.bas
CONST nl = "\n"
' Window prototype: window(title, xsize, ysize) -> returns windowID
win = GTK::window("Hello world!", 400, 250)
' Button prototype: button(label, xsize, ysize -> returns buttonID
exit_but = GTK::button("Exit", 100, 50)
' Foreground/background color prototype: fg_color(widget, r, g, b) -> no returnvalue
GTK::fg_color(exit_but, 0, 65535, 0)
GTK::bg_color(exit_but, 10240, 32768, 10240)
' Attach widget to parent prototype: attach(widget, parent, xpos, ypos) -> no returnvalue
GTK::attach(exit_but, win, 290, 190)
print_but = GTK::button("Print text", 100, 50)
GTK::attach(print_but, win, 10, 190)
' Frame prototype: frame(text, xsize, ysize) -> returns frameID
fr = GTK::frame(" Frame ", 120, 50)
GTK::attach(fr, win, 150, 190)
GTK::fg_color(fr, 65535, 0, 0)
' Separator widget prototype: separator(length) -> returns separatorID
sep = GTK::separator(400)
GTK::attach(sep, win, 0, 180)
GTK::bg_color(sep, 65535, 65535, 0)
' Entry/password prototype: entry(xsize, ysize) - or - password(xsize, ysize) -> returns entryID
entry = GTK::entry(205, 25)
GTK::attach(entry, win, 10, 10)
GTK::bg_color(entry, 65535, 65535, 0)
' Label prototype: label(text, xsize, ysize) -> returns labelID
lab = GTK::label("This is a demo", 110, 20)
GTK::attach(lab, win, 10, 50)
GTK::fg_color(lab, 49152, 0, 49152)
' Check button prototype: check(text, xsize, ysize) -> returns checkbuttonID
c_but = GTK::check("Option here", 110, 20)
GTK::attach(c_but, win, 10, 80)
GTK::fg_color(c_but, 0, 0, 65535)
' Set value of check/option button: select(button) -> no returnvalue
GTK::set_value(c_but)
' Radio button prototype: radio(text, xsize, ysize, group) -> returns radiobuttonID
' (First radiobutton should be attached to group "NULL")
r1_but = GTK::radio("Selection 1", 110, 20, "NULL")
GTK::attach(r1_but, win, 120, 50)
GTK::bg_color(r1_but, 65535, 0, 0)
r2_but = GTK::radio("Selection 2", 110, 20, r1_but)
GTK::attach(r2_but, win, 120, 70)
r3_but = GTK::radio("Selection 3", 110, 20, r1_but)
GTK::attach(r3_but, win, 120, 90)
GTK::disable(r3_but)
' Droplist prototype: droplist(array, xsize, ysize) -> returns droplistID
a[1] = "value one"
a[2] = "value two"
a[3] = "value three"
drop = GTK::droplist(a, 205, 30)
GTK::attach(drop, win, 10, 130)
b[1] = "peter"
b[2] = "van"
b[3] = "eerten surname"
GTK::set_text(drop, b)
GTK::set_value(drop, 2)
GTK::bg_color(drop, 0,0,65535)
list = GTK::list(b, 150, 150)
GTK::attach(list, win, 240, 10)
GTK::bg_color(list, 0,65535,0)
GTK::fg_color(list, 0,0,65535)
GTK::set_value(list, 0)
' Focus prototype: focus(widget) -> no returnvalue
GTK::focus(entry)
' Event Processing - gtk_main() / callback encapsulation
REPEAT
' Event prototype: event() -> returns widgetID on which event occured
action = GTK::event()
IF action = print_but THEN PRINT GTK::get_text(list), nl
' Selected prototype: get_value(widget) -> returns 0 or 1 depending on state
IF GTK::get_value(r2_but) THEN PRINT "Radio button 2!", nl
UNTIL action = exit_but OR action = win
END
$dll
$execon "-static -I /home/jrs/sb/scriptbasic /home/jrs/sb/scriptbasic/lmt_none.c -lscriba"
#include <scriba.h>
#include <getopt.h>
Global pProgram as pSbProgram
function sb_new() as pSbProgram export
function = scriba_new(malloc,free)
end function
DECLARE SUB DLL ALIAS "_idll" LIB "gtk-server"
DECLARE SUB REQUIRE ALIAS "_idll_require" LIB "gtk-server"
DECLARE SUB DEFINE ALIAS "_idll_define" LIB "gtk-server"
REQUIRE "libiDLL.so"
DEFINE "sb_new NONE POINTER 0"
DEFINE "scriba_LoadConfiguration NONE INT 2 POINTER STRING"
DEFINE "scriba_SetFileName NONE INT 2 POINTER STRING"
DEFINE "scriba_Run NONE INT 2 POINTER STRING"
DEFINE "scriba_LoadSourceProgram NONE INT 1 POINTER"
DEFINE "scriba_destroy NONE NONE 1 POINTER"
pProgram = DLL("sb_new")
DLL("scriba_LoadConfiguration " & pProgram & " \"/etc/scriba/basic.conf\"")
DLL("scriba_SetFileName " & pProgram & " \"E01.sb\"")
DLL("scriba_LoadSourceProgram " & pProgram)
DLL("scriba_Run " & pProgram & " \"JRS\"")
DLL("scriba_destroy " & pProgram)
cmd = COMMAND()
PRINT "ARG = ",cmd,"\n"
FOR x = 1 TO 10
PRINT x,"\n"
NEXT