diff options
Diffstat (limited to 'examples')
33 files changed, 0 insertions, 1044 deletions
diff --git a/examples/allany.nim b/examples/allany.nim deleted file mode 100755 index 4747ce0d6..000000000 --- a/examples/allany.nim +++ /dev/null @@ -1,17 +0,0 @@ -# All and any - -template all(container, cond: expr): expr = - block: - var result = true - for item in items(container): - if not cond(item): - result = false - break - result - -if all("mystring", {'a'..'z'}.contains): - echo "works" -else: - echo "does not work" - - diff --git a/examples/cairoex.nim b/examples/cairoex.nim deleted file mode 100755 index 492428705..000000000 --- a/examples/cairoex.nim +++ /dev/null @@ -1,15 +0,0 @@ -import cairo - -var surface = image_surface_create(FORMAT_ARGB32, 240, 80) -var cr = create(surface) - -select_font_face(cr, "serif", FONT_SLANT_NORMAL, - FONT_WEIGHT_BOLD) -set_font_size(cr, 32.0) -set_source_rgb(cr, 0.0, 0.0, 1.0) -move_to(cr, 10.0, 50.0) -show_text(cr, "Hello, world") -destroy(cr) -discard write_to_png(surface, "hello.png") -destroy(surface) - diff --git a/examples/cgiex.nim b/examples/cgiex.nim deleted file mode 100755 index 857caa8ef..000000000 --- a/examples/cgiex.nim +++ /dev/null @@ -1,15 +0,0 @@ -# Test/show 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>") diff --git a/examples/curlex.nim b/examples/curlex.nim deleted file mode 100755 index 1d0f18ddd..000000000 --- a/examples/curlex.nim +++ /dev/null @@ -1,10 +0,0 @@ -import - libcurl - -var hCurl = easy_init() -if hCurl != nil: - discard easy_setopt(hCurl, OPT_VERBOSE, True) - discard easy_setopt(hCurl, OPT_URL, "http://force7.de/nimrod") - discard easy_perform(hCurl) - easy_cleanup(hCurl) - diff --git a/examples/filterex.nim b/examples/filterex.nim deleted file mode 100755 index 3713f4b64..000000000 --- a/examples/filterex.nim +++ /dev/null @@ -1,23 +0,0 @@ -#! stdtmpl | standard -#proc generateHTMLPage(title, currentTab, content: string, -# tabs: openArray[string]): string = -# result = "" -<head><title>$title</title></head> -<body> - <div id="menu"> - <ul> - #for tab in items(tabs): - #if currentTab == tab: - <li><a id="selected" - #else: - <li><a - #end if - href="${tab}.html" title = "$title - $tab">$tab</a></li> - #end for - </ul> - </div> - <div id="content"> - $content - A dollar: $$. - </div> -</body> diff --git a/examples/gtk/ex1.nim b/examples/gtk/ex1.nim deleted file mode 100755 index deabffa3e..000000000 --- a/examples/gtk/ex1.nim +++ /dev/null @@ -1,14 +0,0 @@ -import - cairo, glib2, gtk2 - -proc destroy(widget: pWidget, data: pgpointer) {.cdecl.} = - main_quit() - -var - window: pWidget -nimrod_init() -window = window_new(WINDOW_TOPLEVEL) -discard signal_connect(window, "destroy", - SIGNAL_FUNC(ex1.destroy), nil) -show(window) -main() diff --git a/examples/gtk/ex2.nim b/examples/gtk/ex2.nim deleted file mode 100755 index fab64cef5..000000000 --- a/examples/gtk/ex2.nim +++ /dev/null @@ -1,22 +0,0 @@ - -import - glib2, gtk2 - -proc destroy(widget: pWidget, data: pgpointer){.cdecl.} = - main_quit() - -var - window: PWidget - button: PWidget - -nimrod_init() -window = window_new(WINDOW_TOPLEVEL) -button = button_new("Click me") -set_border_width(PContainer(Window), 5) -add(PContainer(window), button) -discard signal_connect(window, "destroy", - SIGNAL_FUNC(ex2.destroy), nil) -show(button) -show(window) -main() - diff --git a/examples/gtk/ex3.nim b/examples/gtk/ex3.nim deleted file mode 100755 index 3b39c07ce..000000000 --- a/examples/gtk/ex3.nim +++ /dev/null @@ -1,34 +0,0 @@ - -import - glib2, gtk2 - -proc newbutton(ALabel: cstring): PWidget = - Result = button_new(ALabel) - show(result) - -proc destroy(widget: pWidget, data: pgpointer){.cdecl.} = - main_quit() - -nimrod_init() -var window = window_new(WINDOW_TOPLEVEL) # Box to divide window in 2 halves: -var totalbox = vbox_new(true, 10) -show(totalbox) # A box for each half of the screen: -var hbox = hbox_new(false, 5) -show(hbox) -var vbox = vbox_new(true, 5) -show(vbox) # Put boxes in their halves -pack_start(totalbox, hbox, true, true, 0) -pack_start(totalbox, vbox, true, true, 0) # Now fill boxes with buttons. - -pack_start(hbox, newbutton("Button 1"), false, false, 0) -pack_start(hbox, newbutton("Button 2"), false, false, 0) -pack_start(hbox, newbutton("Button 3"), false, false, 0) # Vertical box -pack_start(vbox, newbutton("Button A"), true, true, 0) -pack_start(vbox, newbutton("Button B"), true, true, 0) -pack_start(vbox, newbutton("Button C"), true, true, 0) # Put totalbox in window -set_border_width(PCONTAINER(Window), 5) -add(PContainer(window), totalbox) -discard signal_connect(window, "destroy", SIGNAL_FUNC(ex3.destroy), nil) -show(window) -main() - diff --git a/examples/gtk/ex4.nim b/examples/gtk/ex4.nim deleted file mode 100755 index 2964042de..000000000 --- a/examples/gtk/ex4.nim +++ /dev/null @@ -1,29 +0,0 @@ - -import - glib2, gtk2 - -proc newbutton(ALabel: cstring): PWidget = - Result = button_new(ALabel) - show(result) - -proc destroy(widget: pWidget, data: pgpointer){.cdecl.} = - main_quit() - -nimrod_init() -var window = window_new(WINDOW_TOPLEVEL) -var Maintable = table_new(6, 6, True) - -proc AddToTable(Widget: PWidget, Left, Right, Top, Bottom: guint) = - attach_defaults(MainTable, Widget, Left, right, top, bottom) - -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 -set_border_width(Window, 5) -add(window, maintable) -discard signal_connect(window, "destroy", - SignalFunc(ex4.destroy), nil) -show(window) -main() - diff --git a/examples/gtk/ex5.nim b/examples/gtk/ex5.nim deleted file mode 100755 index 841ebc681..000000000 --- a/examples/gtk/ex5.nim +++ /dev/null @@ -1,24 +0,0 @@ - -import - glib2, gtk2 - -proc destroy(widget: pWidget, data: pgpointer){.cdecl.} = - main_quit() - -proc widgetDestroy(w: PWidget) {.cdecl.} = - destroy(w) - -nimrod_init() -var window = window_new(WINDOW_TOPLEVEL) -var button = button_new("Click me") -set_border_width(Window, 5) -add(window, button) -discard signal_connect(window, "destroy", - SIGNAL_FUNC(ex5.destroy), nil) -discard signal_connect_object(button, "clicked", - SIGNAL_FUNC(widgetDestroy), - window) -show(button) -show(window) -main() - diff --git a/examples/gtk/ex6.nim b/examples/gtk/ex6.nim deleted file mode 100755 index 4e4c3e864..000000000 --- a/examples/gtk/ex6.nim +++ /dev/null @@ -1,50 +0,0 @@ - -import - glib2, gtk2 - -type - TButtonSignalState = object - Obj: gtk2.PObject - SignalID: int32 - Disable: bool - - PButtonSignalState = ptr TButtonSignalState - -proc destroy(widget: pWidget, data: pgpointer){.cdecl.} = - main_quit() - -proc widgetDestroy(w: PWidget) {.cdecl.} = destroy(w) - -proc disablesignal(widget: pWidget, data: pgpointer){.cdecl.} = - var s = cast[PButtonSignalState](Data) - if s.Disable: - signal_handler_block(s.Obj, s.SignalID) - else: - signal_handler_unblock(s.Obj, s.SignalID) - s.disable = not s.disable - -var - QuitState: TButtonSignalState - -nimrod_init() -var window = window_new(WINDOW_TOPLEVEL) -var quitbutton = button_new("Quit program") -var disablebutton = button_new("Disable button") -var windowbox = vbox_new(TRUE, 10) -pack_start(windowbox, disablebutton, True, false, 0) -pack_start(windowbox, quitbutton, True, false, 0) -set_border_width(Window, 10) -add(window, windowbox) -discard signal_connect(window, "destroy", SIGNAL_FUNC(ex6.destroy), nil) -QuitState.Obj = QuitButton -quitState.SignalID = signal_connect_object(QuitState.Obj, "clicked", - SIGNAL_FUNC(widgetDestroy), window) -QuitState.Disable = True -discard signal_connect(disablebutton, "clicked", - SIGNAL_FUNC(disablesignal), addr(QuitState)) -show(quitbutton) -show(disablebutton) -show(windowbox) -show(window) -main() - diff --git a/examples/gtk/ex7.nim b/examples/gtk/ex7.nim deleted file mode 100755 index 852d80a41..000000000 --- a/examples/gtk/ex7.nim +++ /dev/null @@ -1,46 +0,0 @@ - -import - gdk2, glib2, gtk2 - -proc destroy(widget: pWidget, data: pgpointer){.cdecl.} = - main_quit() - -const - Inside: cstring = "Mouse is over label" - OutSide: cstring = "Mouse is not over label" - -var - OverLabel: bool - -nimrod_init() -var window = window_new(gtk2.WINDOW_TOPLEVEL) -var stackbox = vbox_new(TRUE, 10) -var box1 = event_box_new() -var label1 = label_new("Move mouse over label") -add(box1, label1) -var box2 = event_box_new() -var label2 = label_new(OutSide) -add(box2, label2) -pack_start(stackbox, box1, TRUE, TRUE, 0) -pack_start(stackbox, box2, TRUE, TRUE, 0) -set_border_width(Window, 5) -add(window, stackbox) -discard signal_connect(window, "destroy", - SIGNAL_FUNC(ex7.destroy), nil) -overlabel = False - - -proc ChangeLabel(P: PWidget, Event: gdk2.PEventCrossing, - Data: var bool){.cdecl.} = - if not Data: set_text(Label1, Inside) - else: set_text(Label2, Outside) - Data = not Data - - -discard signal_connect(box1, "enter_notify_event", - SIGNAL_FUNC(ChangeLabel), addr(Overlabel)) -discard signal_connect(box1, "leave_notify_event", - SIGNAL_FUNC(ChangeLabel), addr(Overlabel)) -show_all(window) -main() - diff --git a/examples/gtk/ex8.nim b/examples/gtk/ex8.nim deleted file mode 100755 index 242a15393..000000000 --- a/examples/gtk/ex8.nim +++ /dev/null @@ -1,29 +0,0 @@ - -import - glib2, gtk2 - -proc destroy(widget: pWidget, data: pgpointer){.cdecl.} = - main_quit() - -nimrod_init() -var window = window_new(WINDOW_TOPLEVEL) -var stackbox = vbox_new(TRUE, 10) -var label1 = label_new("Red label text") -var labelstyle = copy(get_style(label1)) -LabelStyle.fg[STATE_NORMAL].pixel = 0 -LabelStyle.fg[STATE_NORMAL].red = -1'i16 -LabelStyle.fg[STATE_NORMAL].blue = 0'i16 -LabelStyle.fg[STATE_NORMAL].green = 0'i16 -set_style(label1, labelstyle) -# Uncomment this to see the effect of setting the default style. -# set_default_style(labelstyle) -var label2 = label_new("Black label text") -pack_start(stackbox, label1, TRUE, TRUE, 0) -pack_start(stackbox, label2, TRUE, TRUE, 0) -set_border_width(Window, 5) -add(window, stackbox) -discard signal_connect(window, "destroy", - SIGNAL_FUNC(ex8.destroy), nil) -show_all(window) -main() - diff --git a/examples/gtk/ex9.nim b/examples/gtk/ex9.nim deleted file mode 100755 index 1481e6be1..000000000 --- a/examples/gtk/ex9.nim +++ /dev/null @@ -1,49 +0,0 @@ - -import - gdk2, glib2, gtk2 - -proc destroy(widget: pWidget, data: pgpointer){.cdecl.} = - main_quit() - -const - Inside: cstring = "Mouse is over label" - OutSide: cstring = "Mouse is not over label" - -var - OverButton: bool - -nimrod_init() -var window = window_new(gtk2.WINDOW_TOPLEVEL) -var stackbox = vbox_new(TRUE, 10) -var button1 = button_new("Move mouse over button") -var buttonstyle = copy(get_style(Button1)) -ButtonStyle.bg[STATE_PRELIGHT].pixel = 0 -ButtonStyle.bg[STATE_PRELIGHT].red = -1'i16 -ButtonStyle.bg[STATE_PRELIGHT].blue = 0'i16 -ButtonStyle.bg[STATE_PRELIGHT].green = 0'i16 -set_style(button1, buttonstyle) -var button2 = button_new() -var ALabel = label_new(Outside) - - -proc ChangeLabel(P: PWidget, Event: gdk2.PEventCrossing, - Data: var bool){.cdecl.} = - if Not Data: set_text(ALabel, Inside) - else: set_text(ALabel, Outside) - Data = Not Data - - -add(button2, ALAbel) -pack_start(stackbox, button1, TRUE, TRUE, 0) -pack_start(stackbox, button2, TRUE, TRUE, 0) -set_border_width(Window, 5) -add(window, stackbox) -discard signal_connect(window, "destroy", - SIGNAL_FUNC(ex9.destroy), nil) -overbutton = False -discard signal_connect(button1, "enter_notify_event", - SIGNAL_FUNC(ChangeLabel), addr(OverButton)) -discard signal_connect(button1, "leave_notify_event", - SIGNAL_FUNC(ChangeLabel), addr(OverButton)) -show_all(window) -main() diff --git a/examples/hallo.nim b/examples/hallo.nim deleted file mode 100755 index 58b7f6281..000000000 --- a/examples/hallo.nim +++ /dev/null @@ -1,3 +0,0 @@ -# Hello world program - -echo "Hello world!" diff --git a/examples/htmlrefs.nim b/examples/htmlrefs.nim deleted file mode 100755 index 824c1d8c7..000000000 --- a/examples/htmlrefs.nim +++ /dev/null @@ -1,57 +0,0 @@ -# Example program to show the new parsexml module -# This program reads an HTML file and writes all its used links to stdout. -# Errors and whitespace are ignored. - -import os, streams, parsexml, strutils - -proc `=?=` (a, b: string): bool = - # little trick: define our own comparator that ignores case - return cmpIgnoreCase(a, b) == 0 - -if paramCount() < 1: - quit("Usage: htmlrefs filename[.html]") - -var links = 0 # count the number of links -var filename = addFileExt(ParamStr(1), "html") -var s = newFileStream(filename, fmRead) -if s == nil: quit("cannot open the file " & filename) -var x: TXmlParser -open(x, s, filename) -next(x) # get first event -block mainLoop: - while true: - case x.kind - of xmlElementOpen: - # the <a href = "xyz"> tag we are interested in always has an attribute, - # thus we search for ``xmlElementOpen`` and not for ``xmlElementStart`` - if x.elementName =?= "a": - x.next() - if x.kind == xmlAttribute: - if x.attrKey =?= "href": - var link = x.attrValue - inc(links) - # skip until we have an ``xmlElementClose`` event - while true: - x.next() - case x.kind - of xmlEof: break mainLoop - of xmlElementClose: break - else: nil - x.next() # skip ``xmlElementClose`` - # now we have the description for the ``a`` element - var desc = "" - while x.kind == xmlCharData: - desc.add(x.charData) - x.next() - Echo(desc & ": " & link) - else: - x.next() - of xmlEof: break # end of file reached - of xmlError: - Echo(errorMsg(x)) - x.next() - else: x.next() # skip other events - -echo($links & " link(s) found!") -x.close() - diff --git a/examples/htmltitle.nim b/examples/htmltitle.nim deleted file mode 100755 index f3c672382..000000000 --- a/examples/htmltitle.nim +++ /dev/null @@ -1,36 +0,0 @@ -# Example program to show the parsexml module -# This program reads an HTML file and writes its title to stdout. -# Errors and whitespace are ignored. - -import os, streams, parsexml, strutils - -if paramCount() < 1: - quit("Usage: htmltitle filename[.html]") - -var filename = addFileExt(ParamStr(1), "html") -var s = newFileStream(filename, fmRead) -if s == nil: quit("cannot open the file " & filename) -var x: TXmlParser -open(x, s, filename) -while true: - x.next() - case x.kind - of xmlElementStart: - if cmpIgnoreCase(x.elementName, "title") == 0: - var title = "" - x.next() # skip "<title>" - while x.kind == xmlCharData: - title.add(x.charData) - x.next() - if x.kind == xmlElementEnd and cmpIgnoreCase(x.elementName, "title") == 0: - Echo("Title: " & title) - quit(0) # Success! - else: - echo(x.errorMsgExpected("/title")) - - of xmlEof: break # end of file reached - else: nil # ignore other events - -x.close() -quit("Could not determine title!") - diff --git a/examples/httpserver2.nim b/examples/httpserver2.nim deleted file mode 100644 index 0604e6a83..000000000 --- a/examples/httpserver2.nim +++ /dev/null @@ -1,245 +0,0 @@ -import strutils, os, osproc, strtabs, streams, sockets - -const - wwwNL* = "\r\L" - ServerSig = "Server: httpserver.nim/1.0.0" & wwwNL - -type - TRequestMethod = enum reqGet, reqPost - TServer* = object ## contains the current server state - socket: TSocket - job: seq[TJob] - TJob* = object - client: TSocket - process: PProcess - -# --------------- output messages -------------------------------------------- - -proc sendTextContentType(client: TSocket) = - send(client, "Content-type: text/html" & wwwNL) - send(client, wwwNL) - -proc badRequest(client: TSocket) = - # Inform the client that a request it has made has a problem. - send(client, "HTTP/1.0 400 BAD REQUEST" & wwwNL) - sendTextContentType(client) - send(client, "<p>Your browser sent a bad request, " & - "such as a POST without a Content-Length.</p>" & wwwNL) - - -proc cannotExec(client: TSocket) = - send(client, "HTTP/1.0 500 Internal Server Error" & wwwNL) - sendTextContentType(client) - send(client, "<P>Error prohibited CGI execution.</p>" & wwwNL) - - -proc headers(client: TSocket, filename: string) = - # XXX could use filename to determine file type - send(client, "HTTP/1.0 200 OK" & wwwNL) - send(client, ServerSig) - sendTextContentType(client) - -proc notFound(client: TSocket, path: string) = - send(client, "HTTP/1.0 404 NOT FOUND" & wwwNL) - send(client, ServerSig) - sendTextContentType(client) - send(client, "<html><title>Not Found</title>" & wwwNL) - send(client, "<body><p>The server could not fulfill" & wwwNL) - send(client, "your request because the resource <b>" & path & "</b>" & wwwNL) - send(client, "is unavailable or nonexistent.</p>" & wwwNL) - send(client, "</body></html>" & wwwNL) - - -proc unimplemented(client: TSocket) = - send(client, "HTTP/1.0 501 Method Not Implemented" & wwwNL) - send(client, ServerSig) - sendTextContentType(client) - send(client, "<html><head><title>Method Not Implemented" & - "</title></head>" & - "<body><p>HTTP request method not supported.</p>" & - "</body></HTML>" & wwwNL) - - -# ----------------- file serving --------------------------------------------- - -proc discardHeaders(client: TSocket) = skip(client) - -proc serveFile(client: TSocket, filename: string) = - discardHeaders(client) - - var f: TFile - if open(f, filename): - headers(client, filename) - const bufSize = 8000 # != 8K might be good for memory manager - var buf = alloc(bufsize) - while True: - var bytesread = readBuffer(f, buf, bufsize) - if bytesread > 0: - var byteswritten = send(client, buf, bytesread) - if bytesread != bytesWritten: - dealloc(buf) - close(f) - OSError() - if bytesread != bufSize: break - dealloc(buf) - close(f) - client.close() - else: - notFound(client, filename) - -# ------------------ CGI execution ------------------------------------------- - -proc executeCgi(server: var TServer, client: TSocket, path, query: string, - meth: TRequestMethod) = - var env = newStringTable(modeCaseInsensitive) - var contentLength = -1 - case meth - of reqGet: - discardHeaders(client) - - env["REQUEST_METHOD"] = "GET" - env["QUERY_STRING"] = query - of reqPost: - var buf = "" - var dataAvail = true - while dataAvail: - dataAvail = recvLine(client, buf) - if buf.len == 0: - break - var L = toLower(buf) - if L.startsWith("content-length:"): - var i = len("content-length:") - while L[i] in Whitespace: inc(i) - contentLength = parseInt(copy(L, i)) - - if contentLength < 0: - badRequest(client) - return - - env["REQUEST_METHOD"] = "POST" - env["CONTENT_LENGTH"] = $contentLength - - send(client, "HTTP/1.0 200 OK" & wwwNL) - - var process = startProcess(command=path, env=env) - - var job: TJob - job.process = process - job.client = client - server.job.add(job) - - if meth == reqPost: - # get from client and post to CGI program: - var buf = alloc(contentLength) - if recv(client, buf, contentLength) != contentLength: - dealloc(buf) - OSError() - var inp = process.inputStream - inp.writeData(inp, buf, contentLength) - dealloc(buf) - -proc animate(server: var TServer) = - # checks list of jobs, removes finished ones (pretty sloppy by seq copying) - var active_jobs: seq[TJob] = @[] - for i in 0..server.job.len-1: - var job = server.job[i] - if running(job.process): - active_jobs.add(job) - else: - # read process output stream and send it to client - var outp = job.process.outputStream - while true: - var line = outp.readstr(1024) - if line.len == 0: - break - else: - try: - send(job.client, line) - except: - echo("send failed, client diconnected") - close(job.client) - - server.job = active_jobs - -# --------------- Server Setup ----------------------------------------------- - -proc acceptRequest(server: var TServer, client: TSocket) = - var cgi = false - var query = "" - var buf = "" - discard recvLine(client, buf) - var path = "" - var data = buf.split() - var meth = reqGet - var q = find(data[1], '?') - - # extract path - if q >= 0: - # strip "?..." from path, this may be found in both POST and GET - path = data[1].copy(0, q-1) - else: - path = data[1] - # path starts with "/", by adding "." in front of it we serve files from cwd - path = "." & path - - echo("accept: " & path) - - if cmpIgnoreCase(data[0], "GET") == 0: - if q >= 0: - cgi = true - query = data[1].copy(q+1) - elif cmpIgnoreCase(data[0], "POST") == 0: - cgi = true - meth = reqPost - else: - unimplemented(client) - - if path[path.len-1] == '/' or existsDir(path): - path = path / "index.html" - - if not ExistsFile(path): - discardHeaders(client) - notFound(client, path) - client.close() - else: - when defined(Windows): - var ext = splitFile(path).ext.toLower - if ext == ".exe" or ext == ".cgi": - # XXX: extract interpreter information here? - cgi = true - else: - if {fpUserExec, fpGroupExec, fpOthersExec} * path.getFilePermissions != {}: - cgi = true - if not cgi: - serveFile(client, path) - else: - executeCgi(server, client, path, query, meth) - - - -when isMainModule: - var port = 80 - - var server: TServer - server.job = @[] - server.socket = socket(AF_INET) - if server.socket == InvalidSocket: OSError() - server.socket.bindAddr(port=TPort(port)) - listen(server.socket) - echo("server up on port " & $port) - - while true: - # check for new new connection & handle it - var list: seq[TSocket] = @[server.socket] - if select(list, 10) > 0: - var client = accept(server.socket) - try: - acceptRequest(server, client) - except: - echo("failed to accept client request") - - # pooling events - animate(server) - # some slack for CPU - sleep(10) - server.socket.close() diff --git a/examples/iupex1.nim b/examples/iupex1.nim deleted file mode 100755 index bf7ed2f1c..000000000 --- a/examples/iupex1.nim +++ /dev/null @@ -1,37 +0,0 @@ -# Example IUP program - -# IupTabs: Creates a IupTabs control. - -import iup - -discard iup.Open(nil, nil) - -var vbox1 = Iup.Vbox(Iup.Label("Inside Tab A"), Iup.Button("Button A", ""), nil) -var vbox2 = Iup.Vbox(Iup.Label("Inside Tab B"), Iup.Button("Button B", ""), nil) - -Iup.SetAttribute(vbox1, "TABTITLE", "Tab A") -Iup.SetAttribute(vbox2, "TABTITLE", "Tab B") - -var tabs1 = Iup.Tabs(vbox1, vbox2, nil) - -vbox1 = Iup.Vbox(Iup.Label("Inside Tab C"), Iup.Button("Button C", ""), nil) -vbox2 = Iup.Vbox(Iup.Label("Inside Tab D"), Iup.Button("Button D", ""), nil) - -Iup.SetAttribute(vbox1, "TABTITLE", "Tab C") -Iup.SetAttribute(vbox2, "TABTITLE", "Tab D") - -var tabs2 = Iup.Tabs(vbox1, vbox2, nil) -Iup.SetAttribute(tabs2, "TABTYPE", "LEFT") - -var box = Iup.Hbox(tabs1, tabs2, nil) -Iup.SetAttribute(box, "MARGIN", "10x10") -Iup.SetAttribute(box, "GAP", "10") - -var dlg = Iup.Dialog(box) -Iup.SetAttribute(dlg, "TITLE", "IupTabs") -Iup.SetAttribute(dlg, "SIZE", "200x100") - -discard ShowXY(dlg, IUP_CENTER, IUP_CENTER) -discard MainLoop() -Close() - diff --git a/examples/keyval.nim b/examples/keyval.nim deleted file mode 100755 index 19a430a1e..000000000 --- a/examples/keyval.nim +++ /dev/null @@ -1,9 +0,0 @@ -# Filter key=value pairs from "myfile.txt" -import re - -for x in lines("myfile.txt"): - if x =~ re"(\w+)=(.*)": - echo "Key: ", matches[0], - " Value: ", matches[1] - - diff --git a/examples/keyval2.nim b/examples/keyval2.nim deleted file mode 100755 index 5e7d0ea4a..000000000 --- a/examples/keyval2.nim +++ /dev/null @@ -1,7 +0,0 @@ -# Filter key=value pairs from "myfile.txt" -import pegs - -for x in lines("myfile.txt"): - if x =~ peg"{\ident} \s* '=' \s* {.*}": - echo "Key: ", matches[1], - " Value: ", matches[2] diff --git a/examples/luaex.nim b/examples/luaex.nim deleted file mode 100755 index 7628ddd12..000000000 --- a/examples/luaex.nim +++ /dev/null @@ -1,15 +0,0 @@ -# Embedds Lua into a Nimrod application - -import - lua, lualib, lauxlib - -const - code = """ -print 'hi' -""" - -var L = newstate() -openlibs(L) -discard loadbuffer(L, code, code.len, "line") -discard pcall(L, 0, 0, 0) - diff --git a/examples/maximum.nim b/examples/maximum.nim deleted file mode 100755 index 1e26ee1a7..000000000 --- a/examples/maximum.nim +++ /dev/null @@ -1,6 +0,0 @@ -# Test high level features - -import strutils - -echo "Give a list of numbers (separated by spaces): " -stdin.readLine.split.each(parseInt).max.`$`.echo(" is the maximum!") diff --git a/examples/myfile.txt b/examples/myfile.txt deleted file mode 100755 index 1df0d56f8..000000000 --- a/examples/myfile.txt +++ /dev/null @@ -1,11 +0,0 @@ -kladsfa - -asdflksadlfasf - - -adsfljksadfl - - -key=/usr/bin/value -key2=/ha/ha - diff --git a/examples/parsecfgex.nim b/examples/parsecfgex.nim deleted file mode 100755 index 618ecadd6..000000000 --- a/examples/parsecfgex.nim +++ /dev/null @@ -1,25 +0,0 @@ - -import - os, parsecfg, strutils, streams - -var f = newFileStream(paramStr(1), fmRead) -if f != nil: - var p: TCfgParser - open(p, f, paramStr(1)) - while true: - var e = next(p) - case e.kind - of cfgEof: - echo("EOF!") - break - of cfgSectionStart: ## a ``[section]`` has been parsed - echo("new section: " & e.section) - of cfgKeyValuePair: - echo("key-value-pair: " & e.key & ": " & e.value) - of cfgOption: - echo("command: " & e.key & ": " & e.value) - of cfgError: - echo(e.msg) - close(p) -else: - echo("cannot open: " & paramStr(1)) diff --git a/examples/pythonex.nim b/examples/pythonex.nim deleted file mode 100755 index e2664f350..000000000 --- a/examples/pythonex.nim +++ /dev/null @@ -1,12 +0,0 @@ -# Example to embed Python into your application - -import python - -# IMPORTANT: Python on Windows does not like CR characters, so -# we use only \L here. - -Py_Initialize() -discard PyRun_SimpleString("from time import time,ctime\L" & - "print 'Today is',ctime(time())\L") -Py_Finalize() - diff --git a/examples/readme.txt b/examples/readme.txt deleted file mode 100755 index e6e47c1d1..000000000 --- a/examples/readme.txt +++ /dev/null @@ -1,5 +0,0 @@ -In this directory you will find several examples for how to use the Nimrod -library. - -Copyright (c) 2004-2009 Andreas Rumpf. -All rights reserved. diff --git a/examples/sdlex.nim b/examples/sdlex.nim deleted file mode 100755 index 3c20fc004..000000000 --- a/examples/sdlex.nim +++ /dev/null @@ -1,26 +0,0 @@ -# Test the SDL interface: - -import - SDL - -var - screen, greeting: PSurface - r: TRect - -if Init(INIT_VIDEO) == 0: - screen = SetVideoMode(640, 480, 16, SWSURFACE or ANYFORMAT) - if screen == nil: - write(stdout, "screen is nil!\n") - else: - greeting = LoadBmp("backgrnd.bmp") - if greeting == nil: - write(stdout, "greeting is nil!") - r.x = 0'i16 - r.y = 0'i16 - discard blitSurface(greeting, nil, screen, addr(r)) - discard flip(screen) - Delay(3000) -else: - write(stdout, "SDL_Init failed!\n") - -sdl.Quit() diff --git a/examples/statcsv.nim b/examples/statcsv.nim deleted file mode 100755 index 48c4ea0cc..000000000 --- a/examples/statcsv.nim +++ /dev/null @@ -1,60 +0,0 @@ -# Example program to show the parsecsv module -# This program reads a CSV file and computes sum, mean, minimum, maximum and -# the standard deviation of its columns. -# The CSV file can have a header which is then used for the output. - -import os, streams, parsecsv, strutils, math - -if paramCount() < 1: - quit("Usage: statcsv filename[.csv]") - -var filename = addFileExt(ParamStr(1), "csv") -var s = newFileStream(filename, fmRead) -if s == nil: quit("cannot open the file " & filename) - -var - x: TCsvParser - header: seq[string] - res: seq[TRunningStat] -open(x, s, filename, separator=';', skipInitialSpace = true) -while readRow(x): - if processedRows(x) == 1: - newSeq(res, x.row.len) # allocate space for the result - if validIdentifier(x.row[0]): - # header line: - header = x.row - else: - newSeq(header, x.row.len) - for i in 0..x.row.len-1: header[i] = "Col " & $(i+1) - else: - # data line: - for i in 0..x.row.len-1: - push(res[i], parseFloat(x.row[i])) -x.close() - -# Write results: -for i in 0..header.len-1: - stdout.write("\t") - stdout.write(header[i]) -stdout.write("\nSum") -for i in 0..header.len-1: - stdout.write("\t") - stdout.write(res[i].sum) -stdout.write("\nMean") -for i in 0..header.len-1: - stdout.write("\t") - stdout.write(res[i].mean) -stdout.write("\nMin") -for i in 0..header.len-1: - stdout.write("\t") - stdout.write(res[i].min) -stdout.write("\nMax") -for i in 0..header.len-1: - stdout.write("\t") - stdout.write(res[i].max) -stdout.write("\nStdDev") -for i in 0..header.len-1: - stdout.write("\t") - stdout.write(res[i].standardDeviation) -stdout.write("\n") - diff --git a/examples/tclex.nim b/examples/tclex.nim deleted file mode 100755 index 8abdb7d9c..000000000 --- a/examples/tclex.nim +++ /dev/null @@ -1,25 +0,0 @@ -# Example to embed TCL in Nimrod - -import tcl, os - -const - myScript = """puts "Hello, World - In quotes" """ - myScript2 = """ -package require Tk -pack [entry .e -textvar e -width 50] -bind .e <Return> { - set e [regsub { *=.*} $e ""] ;# remove evaluation (Chris) - catch {expr [string map {/ *1./} $e]} res - append e " = $res" -} -""" - -FindExecutable(getApplicationFilename()) -var interp = CreateInterp() -if interp == nil: quit("cannot create TCL interpreter") -if Init(interp) != TCL_OK: - quit("cannot init interpreter") -if Eval(interp, myScript) != TCL_OK: - quit("cannot execute script.tcl") - - diff --git a/examples/transff.nim b/examples/transff.nim deleted file mode 100755 index 32d17e52c..000000000 --- a/examples/transff.nim +++ /dev/null @@ -1,8 +0,0 @@ -# Shows how to transform a file - -import pegs - -transformFile("infile.txt", "outfile.txt", - [(peg"""S <- {typedesc} \s* {\ident} \s* ',' - typedesc <- \ident '*'* """, r"$2: $1")]) - diff --git a/examples/wingui.nim b/examples/wingui.nim deleted file mode 100755 index 2c2c387bb..000000000 --- a/examples/wingui.nim +++ /dev/null @@ -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, "Hello World!", "Nimrod GUI Application", 0) diff --git a/examples/x11ex.nim b/examples/x11ex.nim deleted file mode 100755 index db51df2e0..000000000 --- a/examples/x11ex.nim +++ /dev/null @@ -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() |