diff options
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/hallo.nim | 3 | ||||
-rwxr-xr-x | examples/htmlrefs.nim | 57 | ||||
-rwxr-xr-x | examples/htmltitle.nim | 36 | ||||
-rwxr-xr-x | examples/keyval.nim | 9 | ||||
-rwxr-xr-x | examples/luaex.nim | 15 | ||||
-rwxr-xr-x | examples/maximum.nim | 6 | ||||
-rwxr-xr-x | examples/myfile.txt | 11 | ||||
-rwxr-xr-x | examples/pythonex.nim | 12 | ||||
-rwxr-xr-x | examples/readme.txt | 5 | ||||
-rwxr-xr-x | examples/statcsv.nim | 60 | ||||
-rwxr-xr-x | examples/tclex.nim | 25 |
11 files changed, 0 insertions, 239 deletions
diff --git a/examples/hallo.nim b/examples/hallo.nim deleted file mode 100755 index 20aa4695c..000000000 --- a/examples/hallo.nim +++ /dev/null @@ -1,3 +0,0 @@ -# Hallo world program - -echo "Hallo world!" diff --git a/examples/htmlrefs.nim b/examples/htmlrefs.nim deleted file mode 100755 index b1695ee7a..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 = appendFileExt(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 ae023e379..000000000 --- a/examples/htmltitle.nim +++ /dev/null @@ -1,36 +0,0 @@ -# Example program to show the new 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 = appendFileExt(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 - -quit("Could not determine title!") -x.close() - diff --git a/examples/keyval.nim b/examples/keyval.nim deleted file mode 100755 index 99a410e8c..000000000 --- a/examples/keyval.nim +++ /dev/null @@ -1,9 +0,0 @@ -# Filter key=value pairs from "myfile.txt" -import regexprs - -for x in lines("myfile.txt"): - if x =~ r"(\w+)=(.*)": - echo "Key: ", matches[1], - " Value: ", matches[2] - - diff --git a/examples/luaex.nim b/examples/luaex.nim deleted file mode 100755 index a71f0fb05..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 = luaL_newstate() -luaL_openlibs(L) -discard luaL_loadbuffer(L, code, code.len, "line") -discard lua_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/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/statcsv.nim b/examples/statcsv.nim deleted file mode 100755 index e2f272a21..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 = appendFileExt(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 6d6d45b8f..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" -} -""" - -Tcl_FindExecutable(getApplicationFilename()) -var interp = Tcl_CreateInterp() -if interp == nil: quit("cannot create TCL interpreter") -if Tcl_Init(interp) != TCL_OK: - quit("cannot init interpreter") -if Tcl_Eval(interp, myScript) != TCL_OK: - quit("cannot execute script.tcl") - - |