SQLite wrapper

This commit is contained in:
Andreas Rumpf 2010-02-24 01:04:39 +01:00
commit f41bd71e61
43 changed files with 321 additions and 93 deletions

View file

@ -1,14 +0,0 @@
import cairo
var surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 240, 80)
var cr = cairo_create(surface)
cairo_select_font_face(cr, "serif", CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_BOLD)
cairo_set_font_size(cr, 32.0)
cairo_set_source_rgb(cr, 0.0, 0.0, 1.0)
cairo_move_to(cr, 10.0, 50.0)
cairo_show_text(cr, "Hello, world")
cairo_destroy(cr)
discard cairo_surface_write_to_png(surface, "hello.png")
cairo_surface_destroy(surface)

View file

@ -1,15 +0,0 @@
# Test the new CGI module
import strtabs, cgi
#setTestData("name", "the andreas", "password", "rumpf\t\ttab")
var myData = readData()
validateData(myData, "name", "password")
writeContentType()
write(stdout, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n")
write(stdout, "<html><head><title>Test</title></head><body>\n")
writeln(stdout, "name: " & myData["name"])
writeln(stdout, "password: " & myData["password"])
writeln(stdout, "</body></html>")

View file

@ -1,10 +0,0 @@
import
libcurl
var hCurl = curl_easy_init()
if hCurl != nil:
discard curl_easy_setopt(hCurl, CURLOPT_VERBOSE, True)
discard curl_easy_setopt(hCurl, CURLOPT_URL, "http://nimrod.ethexor.com")
discard curl_easy_perform(hCurl)
curl_easy_cleanup(hCurl)

View file

@ -1,14 +0,0 @@
import
cairo, glib2, gtk2
proc destroy(widget: pGtkWidget, data: pgpointer) {.cdecl.} =
gtk_main_quit()
var
window: pGtkWidget
gtk_nimrod_init()
window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
discard gtk_signal_connect(GTKOBJECT(window), "destroy",
GTK_SIGNAL_FUNC(destroy), nil)
gtk_widget_show(window)
gtk_main()

View file

@ -1,21 +0,0 @@
import
glib2, gtk2
proc destroy(widget: pGtkWidget, data: pgpointer){.cdecl.} =
gtk_main_quit()
var
window: PGtkWidget
button: PGtkWidget
gtk_nimrod_init()
window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
button = gtk_button_new_with_label("Click me")
gtk_container_set_border_width(GTK_CONTAINER(Window), 5)
gtk_container_add(GTK_Container(window), button)
discard gtk_signal_connect(GTKOBJECT(window), "destroy",
GTK_SIGNAL_FUNC(destroy), nil)
gtk_widget_show(button)
gtk_widget_show(window)
gtk_main()

View file

@ -1,39 +0,0 @@
import
glib2, gtk2
proc newbutton(ALabel: cstring): PGtkWidget =
Result = gtk_button_new_with_label(ALabel)
gtk_widget_show(result)
proc destroy(widget: pGtkWidget, data: pgpointer){.cdecl.} =
gtk_main_quit()
var
window, totalbox, hbox, vbox: PgtkWidget
gtk_nimrod_init()
window = gtk_window_new(GTK_WINDOW_TOPLEVEL) # Box to divide window in 2 halves:
totalbox = gtk_vbox_new(true, 10)
gtk_widget_show(totalbox) # A box for each half of the screen:
hbox = gtk_hbox_new(false, 5)
gtk_widget_show(hbox)
vbox = gtk_vbox_new(true, 5)
gtk_widget_show(vbox) # Put boxes in their halves
gtk_box_pack_start(GTK_BOX(totalbox), hbox, true, true, 0)
gtk_box_pack_start(GTK_BOX(totalbox), vbox, true, true, 0) # Now fill boxes with buttons.
# Horizontal box
gtk_box_pack_start(GTK_BOX(hbox), newbutton("Button 1"), false, false, 0)
gtk_box_pack_start(GTK_BOX(hbox), newbutton("Button 2"), false, false, 0)
gtk_box_pack_start(GTK_BOX(hbox), newbutton("Button 3"), false, false, 0) #
# Vertical box
gtk_box_pack_start(GTK_BOX(vbox), newbutton("Button A"), true, true, 0)
gtk_box_pack_start(GTK_BOX(vbox), newbutton("Button B"), true, true, 0)
gtk_box_pack_start(GTK_BOX(vbox), newbutton("Button C"), true, true, 0) # Put
# totalbox in window
gtk_container_set_border_width(GTK_CONTAINER(Window), 5)
gtk_container_add(GTK_Container(window), totalbox)
discard gtk_signal_connect(GTKOBJECT(window), "destroy",
GTK_SIGNAL_FUNC(destroy), nil)
gtk_widget_show(window)
gtk_main()

View file

@ -1,31 +0,0 @@
import
glib2, gtk2
proc newbutton(ALabel: cstring): PGtkWidget =
Result = gtk_button_new_with_label(ALabel)
gtk_widget_show(result)
proc destroy(widget: pGtkWidget, data: pgpointer){.cdecl.} =
gtk_main_quit()
var
window, maintable: PgtkWidget
proc AddToTable(Widget: PGtkWidget, Left, Right, Top, Bottom: guint) =
gtk_table_attach_defaults(GTK_TABLE(MainTable), Widget, Left, right, top,
bottom)
gtk_nimrod_init()
window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
Maintable = gtk_table_new(6, 6, True)
gtk_widget_show(MainTable)
AddToTable(newbutton("1,1 At 1,1"), 1, 2, 1, 2)
AddToTable(newbutton("2,2 At 3,1"), 3, 5, 1, 3)
AddToTable(newbutton("4,1 At 4,1"), 1, 5, 4, 5) # Put all in window
gtk_container_set_border_width(GTK_CONTAINER(Window), 5)
gtk_container_add(GTK_Container(window), maintable)
discard gtk_signal_connect(GTKOBJECT(window), "destroy",
GTK_SIGNAL_FUNC(destroy), nil)
gtk_widget_show(window)
gtk_main()

View file

@ -1,24 +0,0 @@
import
glib2, gtk2
proc destroy(widget: pGtkWidget, data: pgpointer){.cdecl.} =
gtk_main_quit()
var
window: PGtkWidget
button: PGtkWidget
gtk_nimrod_init()
window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
button = gtk_button_new_with_label("Click me")
gtk_container_set_border_width(GTK_CONTAINER(Window), 5)
gtk_container_add(GTK_Container(window), button)
discard gtk_signal_connect(GTKOBJECT(window), "destroy",
GTK_SIGNAL_FUNC(destroy), nil)
discard gtk_signal_connect_object(GTKOBJECT(button), "clicked",
GTK_SIGNAL_FUNC(gtk_widget_destroy),
GTKOBJECT(window))
gtk_widget_show(button)
gtk_widget_show(window)
gtk_main()

View file

@ -1,52 +0,0 @@
import
glib2, gtk2
type
TButtonSignalState = record
Obj: PgtkObject
SignalID: int32
Disable: bool
PButtonSignalState = ptr TButtonSignalState
proc destroy(widget: pGtkWidget, data: pgpointer){.cdecl.} =
gtk_main_quit()
proc disablesignal(widget: pGtkWidget, data: pgpointer){.cdecl.} =
if PButtonSignalState(Data).Disable:
gtk_signal_handler_block(PButtonSignalState(Data).Obj, SignalID)
else:
gtk_signal_handler_unblock(PButtonSignalState(Data).Obj, SignalID)
PButtonSignalState(Data).disable = not PButtonSignalState(Data).disable
var
window: PGtkWidget
quitbutton: PGtkWidget
disablebutton: PGTKWidget
windowbox: PGTKWidget
quitsignal: guint
QuitState: TButtonSignalState
gtk_nimrod_init()
window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
quitbutton = gtk_button_new_with_label("Quit program")
disablebutton = gtk_button_new_with_label("Disable button")
windowbox = gtk_vbox_new(TRUE, 10)
gtk_box_pack_start(GTK_BOX(windowbox), disablebutton, True, false, 0)
gtk_box_pack_start(GTK_BOX(windowbox), quitbutton, True, false, 0)
gtk_container_set_border_width(GTK_CONTAINER(Window), 10)
gtk_container_add(GTK_Container(window), windowbox)
gtk_signal_connect(GTKOBJECT(window), "destroy",
GTK_SIGNAL_FUNC(destroy), nil)
QuitState.Obj = GTKObject(QuitButton)
SignalID = gtk_signal_connect_object(QuitState.Obj, "clicked", GTK_SIGNAL_FUNC(
gtk_widget_destroy), GTKOBJECT(window))
QuitState.Disable = True
discard gtk_signal_connect(GTKOBJECT(disablebutton), "clicked",
GTK_SIGNAL_FUNC(disablesignal), addr(QuitState))
gtk_widget_show(quitbutton)
gtk_widget_show(disablebutton)
gtk_widget_show(windowbox)
gtk_widget_show(window)
gtk_main()

View file

@ -1,43 +0,0 @@
import
gdk2, glib2, gtk2
proc destroy(widget: pGtkWidget, data: pgpointer){.cdecl.} =
gtk_main_quit()
const
Inside: cstring = "Mouse is over label"
OutSide: cstring = "Mouse is not over label"
var
OverLabel: bool
window, box1, box2, stackbox, label1, Label2: PGtkWidget
proc ChangeLabel(P: PGtkWidget, Event: PGdkEventCrossing,
Data: var bool){.cdecl.} =
if not Data: gtk_label_set_text(GTKLABEL(Label2), Inside)
else: gtk_label_set_text(GTKLABEL(Label2), Outside)
Data = not Data
gtk_nimrod_init()
window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
stackbox = gtk_vbox_new(TRUE, 10)
box1 = gtk_event_box_new()
label1 = gtk_label_new("Move mouse over label")
gtk_container_add(GTK_CONTAINER(box1), label1)
box2 = gtk_event_box_new()
label2 = gtk_label_new(OutSide)
gtk_container_add(GTK_CONTAINER(box2), label2)
gtk_box_pack_start(GTK_BOX(stackbox), box1, TRUE, TRUE, 0)
gtk_box_pack_start(GTK_BOX(stackbox), box2, TRUE, TRUE, 0)
gtk_container_set_border_width(GTK_CONTAINER(Window), 5)
gtk_container_add(GTK_Container(window), stackbox)
discard gtk_signal_connect(GTKOBJECT(window), "destroy",
GTK_SIGNAL_FUNC(destroy), nil)
overlabel = False
discard gtk_signal_connect(GTKOBJECT(box1), "enter_notify_event",
GTK_SIGNAL_FUNC(ChangeLabel), addr(Overlabel))
discard gtk_signal_connect(GTKOBJECT(box1), "leave_notify_event",
GTK_SIGNAL_FUNC(ChangeLabel), addr(Overlabel))
gtk_widget_show_all(window)
gtk_main()

View file

@ -1,32 +0,0 @@
import
glib2, gtk2
proc destroy(widget: pGtkWidget, data: pgpointer){.cdecl.} =
gtk_main_quit()
var
window, stackbox, label1, Label2: PGtkWidget
labelstyle: pgtkstyle
gtk_nimrod_init()
window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
stackbox = gtk_vbox_new(TRUE, 10)
label1 = gtk_label_new("Red label text")
labelstyle = gtk_style_copy(gtk_widget_get_style(label1))
LabelStyle.fg[GTK_STATE_NORMAL].pixel = 0
LabelStyle.fg[GTK_STATE_NORMAL].red = 0x0000FFFF
LabelStyle.fg[GTK_STATE_NORMAL].blue = 0
LabelStyle.fg[GTK_STATE_NORMAL].green = 0
gtk_widget_set_style(label1, labelstyle) # Uncomment this to see the effect of setting the default style.
#
# gtk_widget_set_default_style(labelstyle)
label2 = gtk_label_new("Black label text")
gtk_box_pack_start(GTK_BOX(stackbox), label1, TRUE, TRUE, 0)
gtk_box_pack_start(GTK_BOX(stackbox), label2, TRUE, TRUE, 0)
gtk_container_set_border_width(GTK_CONTAINER(Window), 5)
gtk_container_add(GTK_Container(window), stackbox)
discard gtk_signal_connect(GTKOBJECT(window), "destroy",
GTK_SIGNAL_FUNC(destroy), nil)
gtk_widget_show_all(window)
gtk_main()

View file

@ -1,47 +0,0 @@
import
gdk2, glib2, gtk2
proc destroy(widget: pGtkWidget, data: pgpointer){.cdecl.} =
gtk_main_quit()
const
Inside: cstring = "Mouse is over label"
OutSide: cstring = "Mouse is not over label"
var
window, button1, Button2, Alabel, stackbox: PGtkWidget
buttonstyle: pgtkstyle
OverButton: bool
proc ChangeLabel(P: PGtkWidget, Event: PGdkEventCrossing, Data: var bool){.cdecl.} =
if Not Data: gtk_label_set_text(GTKLABEL(ALabel), Inside)
else: gtk_label_set_text(GTKLABEL(ALabel), Outside)
Data = Not Data
gtk_nimrod_init()
window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
stackbox = gtk_vbox_new(TRUE, 10)
button1 = gtk_button_new_with_label("Move mouse over button")
buttonstyle = gtk_style_copy(gtk_widget_get_style(Button1))
ButtonStyle.bg[GTK_STATE_PRELIGHT].pixel = 0
ButtonStyle.bg[GTK_STATE_PRELIGHT].red = 0x0000FFFF'i16
ButtonStyle.bg[GTK_STATE_PRELIGHT].blue = 0'i16
ButtonStyle.bg[GTK_STATE_PRELIGHT].green = 0'i16
gtk_widget_set_style(button1, buttonstyle)
button2 = gtk_button_new()
ALabel = gtk_label_new(Outside)
gtk_container_add(GTK_CONTAINER(button2), ALAbel)
gtk_box_pack_start(GTK_BOX(stackbox), button1, TRUE, TRUE, 0)
gtk_box_pack_start(GTK_BOX(stackbox), button2, TRUE, TRUE, 0)
gtk_container_set_border_width(GTK_CONTAINER(Window), 5)
gtk_container_add(GTK_Container(window), stackbox)
discard gtk_signal_connect(GTKOBJECT(window), "destroy",
GTK_SIGNAL_FUNC(destroy), nil)
overbutton = False
discard gtk_signal_connect(GTKOBJECT(button1), "enter_notify_event",
GTK_SIGNAL_FUNC(ChangeLabel), addr(OverButton))
discard gtk_signal_connect(GTKOBJECT(button1), "leave_notify_event",
GTK_SIGNAL_FUNC(ChangeLabel), addr(OverButton))
gtk_widget_show_all(window)
gtk_main()

View file

@ -1,34 +0,0 @@
# Hallo world program
echo("Hi! What's your name?")
var name = readLine(stdin)
if name == "Andreas":
echo("What a nice name!")
elif name == "":
echo("Don't you have a name?")
else:
echo("Your name is not Andreas...")
for i in 0..name.len-1:
if name[i] == 'm':
echo("hey, there is an *m* in your name!")
echo("Please give your password: (12345)")
var pw = readLine(stdin)
while pw != "12345":
echo("Wrong password! Next try: ")
pw = readLine(stdin)
echo("""Login complete!
What do you want to do?
delete-everything
restart-computer
go-for-a-walk""")
case readline(stdin)
of "delete-everything", "restart-computer":
echo("permission denied")
of "go-for-a-walk": echo("please yourself")
else: echo("unknown command")

5
tests/reject/tatomic.nim Normal file
View file

@ -0,0 +1,5 @@
var
atomic: int
echo atomic

View file

@ -1,26 +0,0 @@
# Test the SDL interface:
import
SDL
var
screen, greeting: PSDL_Surface
r: TSDL_Rect
if SDL_Init(SDL_INIT_VIDEO) == 0:
screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE or SDL_ANYFORMAT)
if screen == nil:
write(stdout, "screen is nil!\n")
else:
greeting = SDL_LoadBmp("backgrnd.bmp")
if greeting == nil:
write(stdout, "greeting is nil!")
r.x = 0'i16
r.y = 0'i16
discard SDL_blitSurface(greeting, nil, screen, addr(r))
discard SDL_flip(screen)
SDL_Delay(3000)
else:
write(stdout, "SDL_Init failed!\n")
SDL_Quit()

14
tests/testdata/doc1.xml vendored Normal file
View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<tag>
<test arg="blah" arg2="test"/>
<test2>
bla ah absy hsh
hsh
sjj
</test2>
<test><teh>bla</teh></test>
</tag>
</root>

View file

@ -1,9 +0,0 @@
# test a Windows GUI application
import
windows, shellapi, nb30, mmsystem, shfolder
#proc MessageBox(hWnd: int, lpText, lpCaption: CString, uType: uint): int
# {stdcall, import: "MessageBox", header: "<windows.h>"}
discard MessageBox(0, "Hallo World!", "Nimrod GUI application", 0)

View file

@ -1,71 +0,0 @@
import xlib, xutil, x, keysym
const
WINDOW_WIDTH = 400
WINDOW_HEIGHT = 300
var
width, height: int
display: PDisplay
screen: cint
depth: int
win: TWindow
sizeHints: TXSizeHints
proc create_window =
width = WINDOW_WIDTH
height = WINDOW_HEIGHT
display = XOpenDisplay(nil)
if display == nil:
echo("Verbindung zum X-Server fehlgeschlagen")
quit(1)
screen = XDefaultScreen(display)
depth = XDefaultDepth(display, screen)
var rootwin = XRootWindow(display, screen)
win = XCreateSimpleWindow(display, rootwin, 100, 10,
width, height, 5,
XBlackPixel(display, screen),
XWhitePixel(display, screen))
size_hints.flags = PSize or PMinSize or PMaxSize
size_hints.min_width = width
size_hints.max_width = width
size_hints.min_height = height
size_hints.max_height = height
discard XSetStandardProperties(display, win, "Simple Window", "window",
0, nil, 0, addr(size_hints))
discard XSelectInput(display, win, ButtonPressMask or KeyPressMask or
PointerMotionMask)
discard XMapWindow(display, win)
proc close_window =
discard XDestroyWindow(display, win)
discard XCloseDisplay(display)
var
xev: TXEvent
proc process_event =
var key: TKeySym
case int(xev.theType)
of KeyPress:
key = XLookupKeysym(cast[ptr TXKeyEvent](addr(xev)), 0)
if key != 0:
echo("keyboard event")
of ButtonPressMask, PointerMotionMask:
Echo("Mouse event")
else: nil
proc eventloop =
discard XFlush(display)
var num_events = int(XPending(display))
while num_events != 0:
dec(num_events)
discard XNextEvent(display, addr(xev))
process_event()
create_window()
while true:
eventloop()
close_window()