further steps to get rid of deprecated endOfFile and readLine
This commit is contained in:
parent
a489161b16
commit
e261a88d07
11 changed files with 35 additions and 21 deletions
|
|
@ -219,8 +219,8 @@ proc LoadConfigs*(cfg = "nimrod.cfg") =
|
||||||
if libpath == "":
|
if libpath == "":
|
||||||
# choose default libpath:
|
# choose default libpath:
|
||||||
var prefix = getPrefixDir()
|
var prefix = getPrefixDir()
|
||||||
if (prefix == "/usr"): libpath = "/usr/lib/nimrod"
|
if prefix == "/usr": libpath = "/usr/lib/nimrod"
|
||||||
elif (prefix == "/usr/local"): libpath = "/usr/local/lib/nimrod"
|
elif prefix == "/usr/local": libpath = "/usr/local/lib/nimrod"
|
||||||
else: libpath = joinPath(prefix, "lib")
|
else: libpath = joinPath(prefix, "lib")
|
||||||
|
|
||||||
if optSkipConfigFile notin gGlobalOptions:
|
if optSkipConfigFile notin gGlobalOptions:
|
||||||
|
|
|
||||||
|
|
@ -144,10 +144,12 @@ proc executeCgi(client: TSocket, path, query: string, meth: TRequestMethod) =
|
||||||
dealloc(buf)
|
dealloc(buf)
|
||||||
|
|
||||||
var outp = process.outputStream
|
var outp = process.outputStream
|
||||||
while running(process) or not atEnd(outp):
|
var line = newStringOfCap(120).TaintedString
|
||||||
var line = outp.readLine()
|
while true:
|
||||||
send(client, line.string)
|
if outp.readLine(line):
|
||||||
send(client, wwwNL)
|
send(client, line.string)
|
||||||
|
send(client, wwwNL)
|
||||||
|
elif not running(process): break
|
||||||
|
|
||||||
# --------------- Server Setup -----------------------------------------------
|
# --------------- Server Setup -----------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -414,7 +414,7 @@ proc isRootDir*(path: string): bool {.
|
||||||
var p = parentDir(path)
|
var p = parentDir(path)
|
||||||
result = p == path or p.len == 0
|
result = p == path or p.len == 0
|
||||||
|
|
||||||
iterator parentDirs*(path: string, fromRoot = false, inclusive = true): string =
|
iterator parentDirs*(path: string, fromRoot=false, inclusive=true): string =
|
||||||
## Walks over all parent directories of a given `path`
|
## Walks over all parent directories of a given `path`
|
||||||
##
|
##
|
||||||
## If `fromRoot` is set, the traversal will start from the file system root
|
## If `fromRoot` is set, the traversal will start from the file system root
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,7 @@ proc execProcesses*(cmds: openArray[string],
|
||||||
## that execute in parallel. The highest return value of all processes
|
## that execute in parallel. The highest return value of all processes
|
||||||
## is returned.
|
## is returned.
|
||||||
when defined(posix):
|
when defined(posix):
|
||||||
# poParentStreams causes problems on Posix, so we disable it simply:
|
# poParentStreams causes problems on Posix, so we simply disable it:
|
||||||
var options = options - {poParentStreams}
|
var options = options - {poParentStreams}
|
||||||
|
|
||||||
assert n > 0
|
assert n > 0
|
||||||
|
|
@ -218,12 +218,16 @@ when not defined(useNimRtl):
|
||||||
var p = startCmd(command, options=options)
|
var p = startCmd(command, options=options)
|
||||||
var outp = outputStream(p)
|
var outp = outputStream(p)
|
||||||
result = TaintedString""
|
result = TaintedString""
|
||||||
while running(p) or not atEnd(outp):
|
var line = newStringOfCap(120).TaintedString
|
||||||
result.string.add(outp.readLine().string)
|
while true:
|
||||||
result.string.add("\n")
|
if outp.readLine(line):
|
||||||
|
result.string.add(line.string)
|
||||||
|
result.string.add("\n")
|
||||||
|
elif not running(p): break
|
||||||
close(outp)
|
close(outp)
|
||||||
close(p)
|
close(p)
|
||||||
|
|
||||||
|
|
||||||
when defined(Windows) and not defined(useNimRtl):
|
when defined(Windows) and not defined(useNimRtl):
|
||||||
# We need to implement a handle stream for Windows:
|
# We need to implement a handle stream for Windows:
|
||||||
type
|
type
|
||||||
|
|
@ -718,11 +722,14 @@ proc execCmdEx*(command: string, options: set[TProcessOption] = {
|
||||||
var p = startCmd(command, options)
|
var p = startCmd(command, options)
|
||||||
var outp = outputStream(p)
|
var outp = outputStream(p)
|
||||||
result = (TaintedString"", -1)
|
result = (TaintedString"", -1)
|
||||||
|
var line = newStringOfCap(120).TaintedString
|
||||||
while true:
|
while true:
|
||||||
if result[1] == -1: result[1] = peekExitCode(p)
|
if outp.readLine(line):
|
||||||
if result[1] != -1 and atEnd(outp): break
|
result[0].string.add(line.string)
|
||||||
result[0].string.add(outp.readLine().string)
|
result[0].string.add("\n")
|
||||||
result[0].string.add("\n")
|
else:
|
||||||
|
result[1] = peekExitCode(p)
|
||||||
|
if result[1] != -1: break
|
||||||
close(outp)
|
close(outp)
|
||||||
close(p)
|
close(p)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ proc read[T](s: PStream, result: var T) =
|
||||||
proc readChar*(s: PStream): char =
|
proc readChar*(s: PStream): char =
|
||||||
## reads a char from the stream `s`. Raises `EIO` if an error occured.
|
## reads a char from the stream `s`. Raises `EIO` if an error occured.
|
||||||
## Returns '\0' as an EOF marker.
|
## Returns '\0' as an EOF marker.
|
||||||
discard readData(s, addr(result), sizeof(result))
|
if readData(s, addr(result), sizeof(result)) != 1: result = '\0'
|
||||||
|
|
||||||
proc readBool*(s: PStream): bool =
|
proc readBool*(s: PStream): bool =
|
||||||
## reads a bool from the stream `s`. Raises `EIO` if an error occured.
|
## reads a bool from the stream `s`. Raises `EIO` if an error occured.
|
||||||
|
|
@ -238,7 +238,9 @@ type
|
||||||
|
|
||||||
proc fsClose(s: PStream) = close(PFileStream(s).f)
|
proc fsClose(s: PStream) = close(PFileStream(s).f)
|
||||||
proc fsFlush(s: PStream) = flushFile(PFileStream(s).f)
|
proc fsFlush(s: PStream) = flushFile(PFileStream(s).f)
|
||||||
|
{.push warning[Deprecated]: off.}
|
||||||
proc fsAtEnd(s: PStream): bool = return EndOfFile(PFileStream(s).f)
|
proc fsAtEnd(s: PStream): bool = return EndOfFile(PFileStream(s).f)
|
||||||
|
{.pop.}
|
||||||
proc fsSetPosition(s: PStream, pos: int) = setFilePos(PFileStream(s).f, pos)
|
proc fsSetPosition(s: PStream, pos: int) = setFilePos(PFileStream(s).f, pos)
|
||||||
proc fsGetPosition(s: PStream): int = return int(getFilePos(PFileStream(s).f))
|
proc fsGetPosition(s: PStream): int = return int(getFilePos(PFileStream(s).f))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ proc loadUnidecodeTable*(datafile = "unidecode.dat") =
|
||||||
newSeq(translationTable, 0xffff)
|
newSeq(translationTable, 0xffff)
|
||||||
var i = 0
|
var i = 0
|
||||||
for line in lines(datafile):
|
for line in lines(datafile):
|
||||||
translationTable[i] = line
|
translationTable[i] = line.string
|
||||||
inc(i)
|
inc(i)
|
||||||
|
|
||||||
proc unidecode*(s: string): string =
|
proc unidecode*(s: string): string =
|
||||||
|
|
|
||||||
|
|
@ -797,6 +797,8 @@ when taintMode:
|
||||||
## turned on. Use the ``-d:taintMode``
|
## turned on. Use the ``-d:taintMode``
|
||||||
## command line switch to turn the taint
|
## command line switch to turn the taint
|
||||||
## mode on.
|
## mode on.
|
||||||
|
|
||||||
|
proc len*(s: TaintedString): int {.borrow.}
|
||||||
else:
|
else:
|
||||||
type TaintedString* = string
|
type TaintedString* = string
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
discard """
|
discard """
|
||||||
line: 9
|
line: 9
|
||||||
errmsg: "'a' is deprecated [Deprecated]"
|
errormsg: "'a' is deprecated [Deprecated]"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
var
|
var
|
||||||
|
|
|
||||||
|
|
@ -117,8 +117,8 @@ proc callCompiler(cmdTemplate, filename, options: string): TSpec =
|
||||||
var outp = p.outputStream
|
var outp = p.outputStream
|
||||||
var suc = ""
|
var suc = ""
|
||||||
var err = ""
|
var err = ""
|
||||||
while running(p) or not atEnd(outp):
|
var x = newStringOfCap(120)
|
||||||
var x = outp.readLine().string
|
while outp.readLine(x.TaintedString) or running(p):
|
||||||
if x =~ pegOfInterest:
|
if x =~ pegOfInterest:
|
||||||
# `s` should contain the last error/warning message
|
# `s` should contain the last error/warning message
|
||||||
err = x
|
err = x
|
||||||
|
|
|
||||||
1
todo.txt
1
todo.txt
|
|
@ -1,6 +1,7 @@
|
||||||
version 0.8.14
|
version 0.8.14
|
||||||
==============
|
==============
|
||||||
|
|
||||||
|
- bug: compiler uses full file names again
|
||||||
- stdlib and compiler should not use deprecated endOfFile and readline
|
- stdlib and compiler should not use deprecated endOfFile and readline
|
||||||
|
|
||||||
version 0.9.0
|
version 0.9.0
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ Changes affecting backwards compatibility
|
||||||
raise hooks.
|
raise hooks.
|
||||||
- Changed exception handling/error reporting for ``os.removeFile`` and
|
- Changed exception handling/error reporting for ``os.removeFile`` and
|
||||||
``os.removeDir``.
|
``os.removeDir``.
|
||||||
- The algorithm for searching and loading configuration files have been changed
|
- The algorithm for searching and loading configuration files has been changed.
|
||||||
- Operators now have diffent precedence rules: Assignment-like operators
|
- Operators now have diffent precedence rules: Assignment-like operators
|
||||||
(like ``*=``) are now special-cased.
|
(like ``*=``) are now special-cased.
|
||||||
- The fields in ``TStream`` have been renamed to have an ``Impl`` suffix
|
- The fields in ``TStream`` have been renamed to have an ``Impl`` suffix
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue