made tests green
This commit is contained in:
parent
ed3c509484
commit
1a3b730bf5
8 changed files with 56 additions and 53 deletions
|
|
@ -3,7 +3,7 @@ import
|
||||||
|
|
||||||
var hCurl = easy_init()
|
var hCurl = easy_init()
|
||||||
if hCurl != nil:
|
if hCurl != nil:
|
||||||
discard easy_setopt(hCurl, OPT_VERBOSE, True)
|
discard easy_setopt(hCurl, OPT_VERBOSE, true)
|
||||||
discard easy_setopt(hCurl, OPT_URL, "http://force7.de/nimrod")
|
discard easy_setopt(hCurl, OPT_URL, "http://force7.de/nimrod")
|
||||||
discard easy_perform(hCurl)
|
discard easy_perform(hCurl)
|
||||||
easy_cleanup(hCurl)
|
easy_cleanup(hCurl)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ if paramCount() < 1:
|
||||||
quit("Usage: htmlrefs filename[.html]")
|
quit("Usage: htmlrefs filename[.html]")
|
||||||
|
|
||||||
var links = 0 # count the number of links
|
var links = 0 # count the number of links
|
||||||
var filename = addFileExt(ParamStr(1), "html")
|
var filename = addFileExt(paramStr(1), "html")
|
||||||
var s = newFileStream(filename, fmRead)
|
var s = newFileStream(filename, fmRead)
|
||||||
if s == nil: quit("cannot open the file " & filename)
|
if s == nil: quit("cannot open the file " & filename)
|
||||||
var x: XmlParser
|
var x: XmlParser
|
||||||
|
|
@ -43,12 +43,12 @@ block mainLoop:
|
||||||
while x.kind == xmlCharData:
|
while x.kind == xmlCharData:
|
||||||
desc.add(x.charData)
|
desc.add(x.charData)
|
||||||
x.next()
|
x.next()
|
||||||
Echo(desc & ": " & link)
|
echo(desc & ": " & link)
|
||||||
else:
|
else:
|
||||||
x.next()
|
x.next()
|
||||||
of xmlEof: break # end of file reached
|
of xmlEof: break # end of file reached
|
||||||
of xmlError:
|
of xmlError:
|
||||||
Echo(errorMsg(x))
|
echo(errorMsg(x))
|
||||||
x.next()
|
x.next()
|
||||||
else: x.next() # skip other events
|
else: x.next() # skip other events
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,19 +7,19 @@ const
|
||||||
type
|
type
|
||||||
TRequestMethod = enum reqGet, reqPost
|
TRequestMethod = enum reqGet, reqPost
|
||||||
TServer* = object ## contains the current server state
|
TServer* = object ## contains the current server state
|
||||||
socket: TSocket
|
s: Socket
|
||||||
job: seq[TJob]
|
job: seq[TJob]
|
||||||
TJob* = object
|
TJob* = object
|
||||||
client: TSocket
|
client: Socket
|
||||||
process: PProcess
|
process: Process
|
||||||
|
|
||||||
# --------------- output messages --------------------------------------------
|
# --------------- output messages --------------------------------------------
|
||||||
|
|
||||||
proc sendTextContentType(client: TSocket) =
|
proc sendTextContentType(client: Socket) =
|
||||||
send(client, "Content-type: text/html" & wwwNL)
|
send(client, "Content-type: text/html" & wwwNL)
|
||||||
send(client, wwwNL)
|
send(client, wwwNL)
|
||||||
|
|
||||||
proc badRequest(client: TSocket) =
|
proc badRequest(client: Socket) =
|
||||||
# Inform the client that a request it has made has a problem.
|
# Inform the client that a request it has made has a problem.
|
||||||
send(client, "HTTP/1.0 400 BAD REQUEST" & wwwNL)
|
send(client, "HTTP/1.0 400 BAD REQUEST" & wwwNL)
|
||||||
sendTextContentType(client)
|
sendTextContentType(client)
|
||||||
|
|
@ -27,19 +27,19 @@ proc badRequest(client: TSocket) =
|
||||||
"such as a POST without a Content-Length.</p>" & wwwNL)
|
"such as a POST without a Content-Length.</p>" & wwwNL)
|
||||||
|
|
||||||
|
|
||||||
proc cannotExec(client: TSocket) =
|
proc cannotExec(client: Socket) =
|
||||||
send(client, "HTTP/1.0 500 Internal Server Error" & wwwNL)
|
send(client, "HTTP/1.0 500 Internal Server Error" & wwwNL)
|
||||||
sendTextContentType(client)
|
sendTextContentType(client)
|
||||||
send(client, "<P>Error prohibited CGI execution.</p>" & wwwNL)
|
send(client, "<P>Error prohibited CGI execution.</p>" & wwwNL)
|
||||||
|
|
||||||
|
|
||||||
proc headers(client: TSocket, filename: string) =
|
proc headers(client: Socket, filename: string) =
|
||||||
# XXX could use filename to determine file type
|
# XXX could use filename to determine file type
|
||||||
send(client, "HTTP/1.0 200 OK" & wwwNL)
|
send(client, "HTTP/1.0 200 OK" & wwwNL)
|
||||||
send(client, ServerSig)
|
send(client, ServerSig)
|
||||||
sendTextContentType(client)
|
sendTextContentType(client)
|
||||||
|
|
||||||
proc notFound(client: TSocket, path: string) =
|
proc notFound(client: Socket, path: string) =
|
||||||
send(client, "HTTP/1.0 404 NOT FOUND" & wwwNL)
|
send(client, "HTTP/1.0 404 NOT FOUND" & wwwNL)
|
||||||
send(client, ServerSig)
|
send(client, ServerSig)
|
||||||
sendTextContentType(client)
|
sendTextContentType(client)
|
||||||
|
|
@ -50,7 +50,7 @@ proc notFound(client: TSocket, path: string) =
|
||||||
send(client, "</body></html>" & wwwNL)
|
send(client, "</body></html>" & wwwNL)
|
||||||
|
|
||||||
|
|
||||||
proc unimplemented(client: TSocket) =
|
proc unimplemented(client: Socket) =
|
||||||
send(client, "HTTP/1.0 501 Method Not Implemented" & wwwNL)
|
send(client, "HTTP/1.0 501 Method Not Implemented" & wwwNL)
|
||||||
send(client, ServerSig)
|
send(client, ServerSig)
|
||||||
sendTextContentType(client)
|
sendTextContentType(client)
|
||||||
|
|
@ -62,24 +62,25 @@ proc unimplemented(client: TSocket) =
|
||||||
|
|
||||||
# ----------------- file serving ---------------------------------------------
|
# ----------------- file serving ---------------------------------------------
|
||||||
|
|
||||||
proc discardHeaders(client: TSocket) = skip(client)
|
proc discardHeaders(client: Socket) = skip(client)
|
||||||
|
|
||||||
proc serveFile(client: TSocket, filename: string) =
|
proc serveFile(client: Socket, filename: string) =
|
||||||
discardHeaders(client)
|
discardHeaders(client)
|
||||||
|
|
||||||
var f: TFile
|
var f: File
|
||||||
if open(f, filename):
|
if open(f, filename):
|
||||||
headers(client, filename)
|
headers(client, filename)
|
||||||
const bufSize = 8000 # != 8K might be good for memory manager
|
const bufSize = 8000 # != 8K might be good for memory manager
|
||||||
var buf = alloc(bufsize)
|
var buf = alloc(bufsize)
|
||||||
while True:
|
while true:
|
||||||
var bytesread = readBuffer(f, buf, bufsize)
|
var bytesread = readBuffer(f, buf, bufsize)
|
||||||
if bytesread > 0:
|
if bytesread > 0:
|
||||||
var byteswritten = send(client, buf, bytesread)
|
var byteswritten = send(client, buf, bytesread)
|
||||||
if bytesread != bytesWritten:
|
if bytesread != bytesWritten:
|
||||||
|
let err = osLastError()
|
||||||
dealloc(buf)
|
dealloc(buf)
|
||||||
close(f)
|
close(f)
|
||||||
OSError()
|
raiseOSError(err)
|
||||||
if bytesread != bufSize: break
|
if bytesread != bufSize: break
|
||||||
dealloc(buf)
|
dealloc(buf)
|
||||||
close(f)
|
close(f)
|
||||||
|
|
@ -89,7 +90,7 @@ proc serveFile(client: TSocket, filename: string) =
|
||||||
|
|
||||||
# ------------------ CGI execution -------------------------------------------
|
# ------------------ CGI execution -------------------------------------------
|
||||||
|
|
||||||
proc executeCgi(server: var TServer, client: TSocket, path, query: string,
|
proc executeCgi(server: var TServer, client: Socket, path, query: string,
|
||||||
meth: TRequestMethod) =
|
meth: TRequestMethod) =
|
||||||
var env = newStringTable(modeCaseInsensitive)
|
var env = newStringTable(modeCaseInsensitive)
|
||||||
var contentLength = -1
|
var contentLength = -1
|
||||||
|
|
@ -132,8 +133,9 @@ proc executeCgi(server: var TServer, client: TSocket, path, query: string,
|
||||||
# get from client and post to CGI program:
|
# get from client and post to CGI program:
|
||||||
var buf = alloc(contentLength)
|
var buf = alloc(contentLength)
|
||||||
if recv(client, buf, contentLength) != contentLength:
|
if recv(client, buf, contentLength) != contentLength:
|
||||||
|
let err = osLastError()
|
||||||
dealloc(buf)
|
dealloc(buf)
|
||||||
OSError()
|
raiseOSError(err)
|
||||||
var inp = process.inputStream
|
var inp = process.inputStream
|
||||||
inp.writeData(buf, contentLength)
|
inp.writeData(buf, contentLength)
|
||||||
dealloc(buf)
|
dealloc(buf)
|
||||||
|
|
@ -163,7 +165,7 @@ proc animate(server: var TServer) =
|
||||||
|
|
||||||
# --------------- Server Setup -----------------------------------------------
|
# --------------- Server Setup -----------------------------------------------
|
||||||
|
|
||||||
proc acceptRequest(server: var TServer, client: TSocket) =
|
proc acceptRequest(server: var TServer, client: Socket) =
|
||||||
var cgi = false
|
var cgi = false
|
||||||
var query = ""
|
var query = ""
|
||||||
var buf = ""
|
var buf = ""
|
||||||
|
|
@ -197,7 +199,7 @@ proc acceptRequest(server: var TServer, client: TSocket) =
|
||||||
if path[path.len-1] == '/' or existsDir(path):
|
if path[path.len-1] == '/' or existsDir(path):
|
||||||
path = path / "index.html"
|
path = path / "index.html"
|
||||||
|
|
||||||
if not ExistsFile(path):
|
if not existsFile(path):
|
||||||
discardHeaders(client)
|
discardHeaders(client)
|
||||||
notFound(client, path)
|
notFound(client, path)
|
||||||
client.close()
|
client.close()
|
||||||
|
|
@ -215,26 +217,24 @@ proc acceptRequest(server: var TServer, client: TSocket) =
|
||||||
else:
|
else:
|
||||||
executeCgi(server, client, path, query, meth)
|
executeCgi(server, client, path, query, meth)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
var port = 80
|
var port = 80
|
||||||
|
|
||||||
var server: TServer
|
var server: TServer
|
||||||
server.job = @[]
|
server.job = @[]
|
||||||
server.socket = socket(AF_INET)
|
server.s = socket(AF_INET)
|
||||||
if server.socket == InvalidSocket: OSError()
|
if server.s == invalidSocket: raiseOSError(osLastError())
|
||||||
server.socket.bindAddr(port=TPort(port))
|
server.s.bindAddr(port=Port(port))
|
||||||
listen(server.socket)
|
listen(server.s)
|
||||||
echo("server up on port " & $port)
|
echo("server up on port " & $port)
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
# check for new new connection & handle it
|
# check for new new connection & handle it
|
||||||
var list: seq[TSocket] = @[server.socket]
|
var list: seq[Socket] = @[server.s]
|
||||||
if select(list, 10) > 0:
|
if select(list, 10) > 0:
|
||||||
var client: TSocket
|
var client: Socket
|
||||||
new(client)
|
new(client)
|
||||||
accept(server.socket, client)
|
accept(server.s, client)
|
||||||
try:
|
try:
|
||||||
acceptRequest(server, client)
|
acceptRequest(server, client)
|
||||||
except:
|
except:
|
||||||
|
|
@ -244,4 +244,4 @@ when isMainModule:
|
||||||
animate(server)
|
animate(server)
|
||||||
# some slack for CPU
|
# some slack for CPU
|
||||||
sleep(10)
|
sleep(10)
|
||||||
server.socket.close()
|
server.s.close()
|
||||||
|
|
|
||||||
|
|
@ -9,21 +9,21 @@ var
|
||||||
event: TEvent
|
event: TEvent
|
||||||
bgColor = colChocolate.int32
|
bgColor = colChocolate.int32
|
||||||
|
|
||||||
if Init(INIT_VIDEO) != 0:
|
if init(INIT_VIDEO) != 0:
|
||||||
quit "SDL failed to initialize!"
|
quit "SDL failed to initialize!"
|
||||||
|
|
||||||
screen = SetVideoMode(640, 480, 16, SWSURFACE or ANYFORMAT)
|
screen = setVideoMode(640, 480, 16, SWSURFACE or ANYFORMAT)
|
||||||
if screen.isNil:
|
if screen.isNil:
|
||||||
quit($sdl.GetError())
|
quit($sdl.getError())
|
||||||
|
|
||||||
greeting = IMG_load("tux.png")
|
greeting = imgLoad("tux.png")
|
||||||
if greeting.isNil:
|
if greeting.isNil:
|
||||||
echo "Failed to load tux.png"
|
echo "Failed to load tux.png"
|
||||||
else:
|
else:
|
||||||
## convert the image to alpha and free the old one
|
## convert the image to alpha and free the old one
|
||||||
var s = greeting.DisplayFormatAlpha()
|
var s = greeting.displayFormatAlpha()
|
||||||
swap(greeting, s)
|
swap(greeting, s)
|
||||||
s.FreeSurface()
|
s.freeSurface()
|
||||||
|
|
||||||
r.x = 0
|
r.x = 0
|
||||||
r.y = 0
|
r.y = 0
|
||||||
|
|
@ -31,22 +31,22 @@ r.y = 0
|
||||||
block game_loop:
|
block game_loop:
|
||||||
while true:
|
while true:
|
||||||
|
|
||||||
while PollEvent(addr event) > 0:
|
while pollEvent(addr event) > 0:
|
||||||
case event.kind
|
case event.kind
|
||||||
of QUITEV:
|
of QUITEV:
|
||||||
break game_loop
|
break game_loop
|
||||||
of KEYDOWN:
|
of KEYDOWN:
|
||||||
if EvKeyboard(addr event).keysym.sym == K_ESCAPE:
|
if evKeyboard(addr event).keysym.sym == K_ESCAPE:
|
||||||
break game_loop
|
break game_loop
|
||||||
else:
|
else:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
discard FillRect(screen, nil, bgColor)
|
discard fillRect(screen, nil, bgColor)
|
||||||
discard BlitSurface(greeting, nil, screen, addr r)
|
discard blitSurface(greeting, nil, screen, addr r)
|
||||||
discard Flip(screen)
|
discard flip(screen)
|
||||||
|
|
||||||
greeting.FreeSurface()
|
greeting.freeSurface()
|
||||||
screen.FreeSurface()
|
screen.freeSurface()
|
||||||
sdl.Quit()
|
sdl.quit()
|
||||||
|
|
||||||
## fowl wuz here 10/2012
|
## fowl wuz here 10/2012
|
||||||
|
|
@ -94,7 +94,7 @@ type
|
||||||
idx: int
|
idx: int
|
||||||
|
|
||||||
FlowVarBase* = ref FlowVarBaseObj ## untyped base class for 'FlowVar[T]'
|
FlowVarBase* = ref FlowVarBaseObj ## untyped base class for 'FlowVar[T]'
|
||||||
FlowVarBaseObj = object of TObject
|
FlowVarBaseObj = object of RootObj
|
||||||
ready, usesCondVar: bool
|
ready, usesCondVar: bool
|
||||||
cv: CondVar #\
|
cv: CondVar #\
|
||||||
# for 'awaitAny' support
|
# for 'awaitAny' support
|
||||||
|
|
@ -164,7 +164,7 @@ proc cleanFlowVars(w: ptr Worker) =
|
||||||
let q = addr(w.q)
|
let q = addr(w.q)
|
||||||
acquire(q.lock)
|
acquire(q.lock)
|
||||||
for i in 0 .. <q.len:
|
for i in 0 .. <q.len:
|
||||||
GC_unref(cast[PObject](q.data[i]))
|
GC_unref(cast[RootRef](q.data[i]))
|
||||||
q.len = 0
|
q.len = 0
|
||||||
release(q.lock)
|
release(q.lock)
|
||||||
signal(q.empty)
|
signal(q.empty)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
line: 2136
|
line: 2169
|
||||||
file: "system.nim"
|
file: "system.nim"
|
||||||
errormsg: "can raise an unlisted exception: ref IOError"
|
errormsg: "can raise an unlisted exception: ref IOError"
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
discard """
|
discard """
|
||||||
line: 15
|
line: 16
|
||||||
errormsg: "'mainUnsafe' is not GC-safe"
|
errormsg: "'mainUnsafe' is not GC-safe"
|
||||||
|
cmd: "nim $target --hints:on --threads:on $options $file"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc mymap(x: proc ()) =
|
proc mymap(x: proc ()) =
|
||||||
|
|
|
||||||
6
todo.txt
6
todo.txt
|
|
@ -3,13 +3,13 @@ version 0.10
|
||||||
|
|
||||||
- Test nimfix on various babel packages
|
- Test nimfix on various babel packages
|
||||||
- Pegs do not work at compile-time
|
- Pegs do not work at compile-time
|
||||||
|
- deprecate recursive tuples; tuple needs laxer type checking
|
||||||
|
- string case should require an 'else'
|
||||||
- # echo type.int
|
- # echo type.int
|
||||||
|
|
||||||
version 0.9.6
|
version 0.9.6
|
||||||
=============
|
=============
|
||||||
|
|
||||||
- allow simple read accesses to global variables --> difficult to ensure that
|
|
||||||
no data races happen
|
|
||||||
- split idetools into separate tool
|
- split idetools into separate tool
|
||||||
- split docgen into separate tool
|
- split docgen into separate tool
|
||||||
- .benign pragma
|
- .benign pragma
|
||||||
|
|
@ -63,6 +63,8 @@ version 0.9.x
|
||||||
|
|
||||||
- implicit deref for parameter matching
|
- implicit deref for parameter matching
|
||||||
- overloading of '='; general lift mechanism
|
- overloading of '='; general lift mechanism
|
||||||
|
- allow simple read accesses to global variables --> difficult to ensure that
|
||||||
|
no data races happen
|
||||||
- pragmas need 'bindSym' support
|
- pragmas need 'bindSym' support
|
||||||
- pragmas need re-work: 'push' is dangerous, 'hasPragma' does not work
|
- pragmas need re-work: 'push' is dangerous, 'hasPragma' does not work
|
||||||
reliably with user-defined pragmas
|
reliably with user-defined pragmas
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue