fix some warnings (#16952)
This commit is contained in:
parent
910720b0d4
commit
f140c92409
22 changed files with 119 additions and 119 deletions
|
|
@ -488,7 +488,7 @@ proc transformFile*(infile, outfile: string,
|
||||||
## reads in the file ``infile``, performs a parallel replacement (calls
|
## reads in the file ``infile``, performs a parallel replacement (calls
|
||||||
## ``parallelReplace``) and writes back to ``outfile``. Raises ``IOError`` if an
|
## ``parallelReplace``) and writes back to ``outfile``. Raises ``IOError`` if an
|
||||||
## error occurs. This is supposed to be used for quick scripting.
|
## error occurs. This is supposed to be used for quick scripting.
|
||||||
var x = readFile(infile).string
|
var x = readFile(infile)
|
||||||
writeFile(outfile, x.multiReplace(subs))
|
writeFile(outfile, x.multiReplace(subs))
|
||||||
|
|
||||||
iterator split*(s: string, sep: Regex; maxsplit = -1): string =
|
iterator split*(s: string, sep: Regex; maxsplit = -1): string =
|
||||||
|
|
|
||||||
|
|
@ -423,7 +423,7 @@ when defined(createNimHcr):
|
||||||
if modules.contains(name):
|
if modules.contains(name):
|
||||||
unloadDll(name)
|
unloadDll(name)
|
||||||
else:
|
else:
|
||||||
modules.add(name, newModuleDesc())
|
modules[name] = newModuleDesc()
|
||||||
|
|
||||||
let copiedName = name & ".copy." & dllExt
|
let copiedName = name & ".copy." & dllExt
|
||||||
copyFileWithPermissions(name, copiedName)
|
copyFileWithPermissions(name, copiedName)
|
||||||
|
|
@ -601,7 +601,7 @@ when defined(createNimHcr):
|
||||||
|
|
||||||
proc hcrAddModule*(module: cstring) {.nimhcr.} =
|
proc hcrAddModule*(module: cstring) {.nimhcr.} =
|
||||||
if not modules.contains($module):
|
if not modules.contains($module):
|
||||||
modules.add($module, newModuleDesc())
|
modules[$module] = newModuleDesc()
|
||||||
|
|
||||||
proc hcrGeneration*(): int {.nimhcr.} =
|
proc hcrGeneration*(): int {.nimhcr.} =
|
||||||
generation
|
generation
|
||||||
|
|
|
||||||
|
|
@ -917,7 +917,7 @@ when isMainModule:
|
||||||
# Try to work running in both the subdir or at the root.
|
# Try to work running in both the subdir or at the root.
|
||||||
for filename in ["doc/keywords.txt", "../../../doc/keywords.txt"]:
|
for filename in ["doc/keywords.txt", "../../../doc/keywords.txt"]:
|
||||||
try:
|
try:
|
||||||
let input = string(readFile(filename))
|
let input = readFile(filename)
|
||||||
keywords = input.splitWhitespace()
|
keywords = input.splitWhitespace()
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
|
|
|
||||||
|
|
@ -1870,7 +1870,7 @@ proc dirInclude(p: var RstParser): PRstNode =
|
||||||
result = newRstNode(rnLiteralBlock)
|
result = newRstNode(rnLiteralBlock)
|
||||||
result.add(newRstNode(rnLeaf, readFile(path)))
|
result.add(newRstNode(rnLeaf, readFile(path)))
|
||||||
else:
|
else:
|
||||||
let inputString = readFile(path).string()
|
let inputString = readFile(path)
|
||||||
let startPosition =
|
let startPosition =
|
||||||
block:
|
block:
|
||||||
let searchFor = n.getFieldValue("start-after").strip()
|
let searchFor = n.getFieldValue("start-after").strip()
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,7 @@ proc expectReply(ftp: AsyncFtpClient): Future[string] {.async.} =
|
||||||
while line.len > 3 and line[3] == '-':
|
while line.len > 3 and line[3] == '-':
|
||||||
## Multi-line reply.
|
## Multi-line reply.
|
||||||
line = await ftp.csock.recvLine()
|
line = await ftp.csock.recvLine()
|
||||||
string(result).add("\n" & line)
|
result.add("\n" & line)
|
||||||
count.inc()
|
count.inc()
|
||||||
if count >= multiLineLimit:
|
if count >= multiLineLimit:
|
||||||
raise newException(ReplyError, "Reached maximum multi-line reply count.")
|
raise newException(ReplyError, "Reached maximum multi-line reply count.")
|
||||||
|
|
@ -163,7 +163,7 @@ proc assertReply(received: string, expected: varargs[string]) =
|
||||||
if received.startsWith(i): return
|
if received.startsWith(i): return
|
||||||
raise newException(ReplyError,
|
raise newException(ReplyError,
|
||||||
"Expected reply '$1' got: $2" %
|
"Expected reply '$1' got: $2" %
|
||||||
[expected.join("' or '"), received.string])
|
[expected.join("' or '"), received])
|
||||||
|
|
||||||
proc pasv(ftp: AsyncFtpClient) {.async.} =
|
proc pasv(ftp: AsyncFtpClient) {.async.} =
|
||||||
## Negotiate a data connection.
|
## Negotiate a data connection.
|
||||||
|
|
@ -171,7 +171,7 @@ proc pasv(ftp: AsyncFtpClient) {.async.} =
|
||||||
|
|
||||||
var pasvMsg = (await ftp.send("PASV")).strip
|
var pasvMsg = (await ftp.send("PASV")).strip
|
||||||
assertReply(pasvMsg, "227")
|
assertReply(pasvMsg, "227")
|
||||||
var betweenParens = captureBetween(pasvMsg.string, '(', ')')
|
var betweenParens = captureBetween(pasvMsg, '(', ')')
|
||||||
var nums = betweenParens.split(',')
|
var nums = betweenParens.split(',')
|
||||||
var ip = nums[0 .. ^3]
|
var ip = nums[0 .. ^3]
|
||||||
var port = nums[^2 .. ^1]
|
var port = nums[^2 .. ^1]
|
||||||
|
|
@ -187,7 +187,7 @@ proc connect*(ftp: AsyncFtpClient) {.async.} =
|
||||||
await ftp.csock.connect(ftp.address, ftp.port)
|
await ftp.csock.connect(ftp.address, ftp.port)
|
||||||
|
|
||||||
var reply = await ftp.expectReply()
|
var reply = await ftp.expectReply()
|
||||||
if string(reply).startsWith("120"):
|
if reply.startsWith("120"):
|
||||||
# 120 Service ready in nnn minutes.
|
# 120 Service ready in nnn minutes.
|
||||||
# We wait until we receive 220.
|
# We wait until we receive 220.
|
||||||
reply = await ftp.expectReply()
|
reply = await ftp.expectReply()
|
||||||
|
|
@ -221,10 +221,10 @@ proc getLines(ftp: AsyncFtpClient): Future[string] {.async.} =
|
||||||
assert ftp.dsockConnected
|
assert ftp.dsockConnected
|
||||||
while ftp.dsockConnected:
|
while ftp.dsockConnected:
|
||||||
let r = await ftp.dsock.recvLine()
|
let r = await ftp.dsock.recvLine()
|
||||||
if r.string == "":
|
if r == "":
|
||||||
ftp.dsockConnected = false
|
ftp.dsockConnected = false
|
||||||
else:
|
else:
|
||||||
result.add(r.string & "\n")
|
result.add(r & "\n")
|
||||||
|
|
||||||
assertReply(await(ftp.expectReply()), "226")
|
assertReply(await(ftp.expectReply()), "226")
|
||||||
|
|
||||||
|
|
@ -346,10 +346,10 @@ proc retrFile*(ftp: AsyncFtpClient, file, dest: string,
|
||||||
await ftp.pasv()
|
await ftp.pasv()
|
||||||
var reply = await ftp.send("RETR " & file.normalizePathSep)
|
var reply = await ftp.send("RETR " & file.normalizePathSep)
|
||||||
assertReply reply, ["125", "150"]
|
assertReply reply, ["125", "150"]
|
||||||
if {'(', ')'} notin reply.string:
|
if {'(', ')'} notin reply:
|
||||||
raise newException(ReplyError, "Reply has no file size.")
|
raise newException(ReplyError, "Reply has no file size.")
|
||||||
var fileSize: BiggestInt
|
var fileSize: BiggestInt
|
||||||
if reply.string.captureBetween('(', ')').parseBiggestInt(fileSize) == 0:
|
if reply.captureBetween('(', ')').parseBiggestInt(fileSize) == 0:
|
||||||
raise newException(ReplyError, "Reply has no file size.")
|
raise newException(ReplyError, "Reply has no file size.")
|
||||||
|
|
||||||
await getFile(ftp, destFile, fileSize, onProgressChanged)
|
await getFile(ftp, destFile, fileSize, onProgressChanged)
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ proc openDefaultBrowserImpl(url: string) =
|
||||||
else:
|
else:
|
||||||
var u = quoteShell(prepare url)
|
var u = quoteShell(prepare url)
|
||||||
if execShellCmd(osOpenCmd & " " & u) == 0: return
|
if execShellCmd(osOpenCmd & " " & u) == 0: return
|
||||||
for b in getEnv("BROWSER").string.split(PathSep):
|
for b in getEnv("BROWSER").split(PathSep):
|
||||||
try:
|
try:
|
||||||
# we use ``startProcess`` here because we don't want to block!
|
# we use ``startProcess`` here because we don't want to block!
|
||||||
discard startProcess(command = b, args = [url], options = {poUsePath})
|
discard startProcess(command = b, args = [url], options = {poUsePath})
|
||||||
|
|
|
||||||
|
|
@ -63,11 +63,11 @@ proc cgiError*(msg: string) {.noreturn.} =
|
||||||
raise newException(CgiError, msg)
|
raise newException(CgiError, msg)
|
||||||
|
|
||||||
proc getEncodedData(allowedMethods: set[RequestMethod]): string =
|
proc getEncodedData(allowedMethods: set[RequestMethod]): string =
|
||||||
case getEnv("REQUEST_METHOD").string
|
case getEnv("REQUEST_METHOD")
|
||||||
of "POST":
|
of "POST":
|
||||||
if methodPost notin allowedMethods:
|
if methodPost notin allowedMethods:
|
||||||
cgiError("'REQUEST_METHOD' 'POST' is not supported")
|
cgiError("'REQUEST_METHOD' 'POST' is not supported")
|
||||||
var L = parseInt(getEnv("CONTENT_LENGTH").string)
|
var L = parseInt(getEnv("CONTENT_LENGTH"))
|
||||||
if L == 0:
|
if L == 0:
|
||||||
return ""
|
return ""
|
||||||
result = newString(L)
|
result = newString(L)
|
||||||
|
|
@ -76,7 +76,7 @@ proc getEncodedData(allowedMethods: set[RequestMethod]): string =
|
||||||
of "GET":
|
of "GET":
|
||||||
if methodGet notin allowedMethods:
|
if methodGet notin allowedMethods:
|
||||||
cgiError("'REQUEST_METHOD' 'GET' is not supported")
|
cgiError("'REQUEST_METHOD' 'GET' is not supported")
|
||||||
result = getEnv("QUERY_STRING").string
|
result = getEnv("QUERY_STRING")
|
||||||
else:
|
else:
|
||||||
if methodNone notin allowedMethods:
|
if methodNone notin allowedMethods:
|
||||||
cgiError("'REQUEST_METHOD' must be 'POST' or 'GET'")
|
cgiError("'REQUEST_METHOD' must be 'POST' or 'GET'")
|
||||||
|
|
@ -102,13 +102,13 @@ proc readData*(allowedMethods: set[RequestMethod] =
|
||||||
## `allowedMethods` set, a `CgiError` exception is raised.
|
## `allowedMethods` set, a `CgiError` exception is raised.
|
||||||
result = newStringTable()
|
result = newStringTable()
|
||||||
for name, value in decodeData(allowedMethods):
|
for name, value in decodeData(allowedMethods):
|
||||||
result[name.string] = value.string
|
result[name] = value
|
||||||
|
|
||||||
proc readData*(data: string): StringTableRef =
|
proc readData*(data: string): StringTableRef =
|
||||||
## Reads CGI data from a string.
|
## Reads CGI data from a string.
|
||||||
result = newStringTable()
|
result = newStringTable()
|
||||||
for name, value in decodeData(data):
|
for name, value in decodeData(data):
|
||||||
result[name.string] = value.string
|
result[name] = value
|
||||||
|
|
||||||
proc validateData*(data: StringTableRef, validKeys: varargs[string]) =
|
proc validateData*(data: StringTableRef, validKeys: varargs[string]) =
|
||||||
## Validates data; raises `CgiError` if this fails. This checks that each variable
|
## Validates data; raises `CgiError` if this fails. This checks that each variable
|
||||||
|
|
@ -119,131 +119,131 @@ proc validateData*(data: StringTableRef, validKeys: varargs[string]) =
|
||||||
|
|
||||||
proc getContentLength*(): string =
|
proc getContentLength*(): string =
|
||||||
## Returns contents of the `CONTENT_LENGTH` environment variable.
|
## Returns contents of the `CONTENT_LENGTH` environment variable.
|
||||||
return getEnv("CONTENT_LENGTH").string
|
return getEnv("CONTENT_LENGTH")
|
||||||
|
|
||||||
proc getContentType*(): string =
|
proc getContentType*(): string =
|
||||||
## Returns contents of the `CONTENT_TYPE` environment variable.
|
## Returns contents of the `CONTENT_TYPE` environment variable.
|
||||||
return getEnv("CONTENT_Type").string
|
return getEnv("CONTENT_Type")
|
||||||
|
|
||||||
proc getDocumentRoot*(): string =
|
proc getDocumentRoot*(): string =
|
||||||
## Returns contents of the `DOCUMENT_ROOT` environment variable.
|
## Returns contents of the `DOCUMENT_ROOT` environment variable.
|
||||||
return getEnv("DOCUMENT_ROOT").string
|
return getEnv("DOCUMENT_ROOT")
|
||||||
|
|
||||||
proc getGatewayInterface*(): string =
|
proc getGatewayInterface*(): string =
|
||||||
## Returns contents of the `GATEWAY_INTERFACE` environment variable.
|
## Returns contents of the `GATEWAY_INTERFACE` environment variable.
|
||||||
return getEnv("GATEWAY_INTERFACE").string
|
return getEnv("GATEWAY_INTERFACE")
|
||||||
|
|
||||||
proc getHttpAccept*(): string =
|
proc getHttpAccept*(): string =
|
||||||
## Returns contents of the `HTTP_ACCEPT` environment variable.
|
## Returns contents of the `HTTP_ACCEPT` environment variable.
|
||||||
return getEnv("HTTP_ACCEPT").string
|
return getEnv("HTTP_ACCEPT")
|
||||||
|
|
||||||
proc getHttpAcceptCharset*(): string =
|
proc getHttpAcceptCharset*(): string =
|
||||||
## Returns contents of the `HTTP_ACCEPT_CHARSET` environment variable.
|
## Returns contents of the `HTTP_ACCEPT_CHARSET` environment variable.
|
||||||
return getEnv("HTTP_ACCEPT_CHARSET").string
|
return getEnv("HTTP_ACCEPT_CHARSET")
|
||||||
|
|
||||||
proc getHttpAcceptEncoding*(): string =
|
proc getHttpAcceptEncoding*(): string =
|
||||||
## Returns contents of the `HTTP_ACCEPT_ENCODING` environment variable.
|
## Returns contents of the `HTTP_ACCEPT_ENCODING` environment variable.
|
||||||
return getEnv("HTTP_ACCEPT_ENCODING").string
|
return getEnv("HTTP_ACCEPT_ENCODING")
|
||||||
|
|
||||||
proc getHttpAcceptLanguage*(): string =
|
proc getHttpAcceptLanguage*(): string =
|
||||||
## Returns contents of the `HTTP_ACCEPT_LANGUAGE` environment variable.
|
## Returns contents of the `HTTP_ACCEPT_LANGUAGE` environment variable.
|
||||||
return getEnv("HTTP_ACCEPT_LANGUAGE").string
|
return getEnv("HTTP_ACCEPT_LANGUAGE")
|
||||||
|
|
||||||
proc getHttpConnection*(): string =
|
proc getHttpConnection*(): string =
|
||||||
## Returns contents of the `HTTP_CONNECTION` environment variable.
|
## Returns contents of the `HTTP_CONNECTION` environment variable.
|
||||||
return getEnv("HTTP_CONNECTION").string
|
return getEnv("HTTP_CONNECTION")
|
||||||
|
|
||||||
proc getHttpCookie*(): string =
|
proc getHttpCookie*(): string =
|
||||||
## Returns contents of the `HTTP_COOKIE` environment variable.
|
## Returns contents of the `HTTP_COOKIE` environment variable.
|
||||||
return getEnv("HTTP_COOKIE").string
|
return getEnv("HTTP_COOKIE")
|
||||||
|
|
||||||
proc getHttpHost*(): string =
|
proc getHttpHost*(): string =
|
||||||
## Returns contents of the `HTTP_HOST` environment variable.
|
## Returns contents of the `HTTP_HOST` environment variable.
|
||||||
return getEnv("HTTP_HOST").string
|
return getEnv("HTTP_HOST")
|
||||||
|
|
||||||
proc getHttpReferer*(): string =
|
proc getHttpReferer*(): string =
|
||||||
## Returns contents of the `HTTP_REFERER` environment variable.
|
## Returns contents of the `HTTP_REFERER` environment variable.
|
||||||
return getEnv("HTTP_REFERER").string
|
return getEnv("HTTP_REFERER")
|
||||||
|
|
||||||
proc getHttpUserAgent*(): string =
|
proc getHttpUserAgent*(): string =
|
||||||
## Returns contents of the `HTTP_USER_AGENT` environment variable.
|
## Returns contents of the `HTTP_USER_AGENT` environment variable.
|
||||||
return getEnv("HTTP_USER_AGENT").string
|
return getEnv("HTTP_USER_AGENT")
|
||||||
|
|
||||||
proc getPathInfo*(): string =
|
proc getPathInfo*(): string =
|
||||||
## Returns contents of the `PATH_INFO` environment variable.
|
## Returns contents of the `PATH_INFO` environment variable.
|
||||||
return getEnv("PATH_INFO").string
|
return getEnv("PATH_INFO")
|
||||||
|
|
||||||
proc getPathTranslated*(): string =
|
proc getPathTranslated*(): string =
|
||||||
## Returns contents of the `PATH_TRANSLATED` environment variable.
|
## Returns contents of the `PATH_TRANSLATED` environment variable.
|
||||||
return getEnv("PATH_TRANSLATED").string
|
return getEnv("PATH_TRANSLATED")
|
||||||
|
|
||||||
proc getQueryString*(): string =
|
proc getQueryString*(): string =
|
||||||
## Returns contents of the `QUERY_STRING` environment variable.
|
## Returns contents of the `QUERY_STRING` environment variable.
|
||||||
return getEnv("QUERY_STRING").string
|
return getEnv("QUERY_STRING")
|
||||||
|
|
||||||
proc getRemoteAddr*(): string =
|
proc getRemoteAddr*(): string =
|
||||||
## Returns contents of the `REMOTE_ADDR` environment variable.
|
## Returns contents of the `REMOTE_ADDR` environment variable.
|
||||||
return getEnv("REMOTE_ADDR").string
|
return getEnv("REMOTE_ADDR")
|
||||||
|
|
||||||
proc getRemoteHost*(): string =
|
proc getRemoteHost*(): string =
|
||||||
## Returns contents of the `REMOTE_HOST` environment variable.
|
## Returns contents of the `REMOTE_HOST` environment variable.
|
||||||
return getEnv("REMOTE_HOST").string
|
return getEnv("REMOTE_HOST")
|
||||||
|
|
||||||
proc getRemoteIdent*(): string =
|
proc getRemoteIdent*(): string =
|
||||||
## Returns contents of the `REMOTE_IDENT` environment variable.
|
## Returns contents of the `REMOTE_IDENT` environment variable.
|
||||||
return getEnv("REMOTE_IDENT").string
|
return getEnv("REMOTE_IDENT")
|
||||||
|
|
||||||
proc getRemotePort*(): string =
|
proc getRemotePort*(): string =
|
||||||
## Returns contents of the `REMOTE_PORT` environment variable.
|
## Returns contents of the `REMOTE_PORT` environment variable.
|
||||||
return getEnv("REMOTE_PORT").string
|
return getEnv("REMOTE_PORT")
|
||||||
|
|
||||||
proc getRemoteUser*(): string =
|
proc getRemoteUser*(): string =
|
||||||
## Returns contents of the `REMOTE_USER` environment variable.
|
## Returns contents of the `REMOTE_USER` environment variable.
|
||||||
return getEnv("REMOTE_USER").string
|
return getEnv("REMOTE_USER")
|
||||||
|
|
||||||
proc getRequestMethod*(): string =
|
proc getRequestMethod*(): string =
|
||||||
## Returns contents of the `REQUEST_METHOD` environment variable.
|
## Returns contents of the `REQUEST_METHOD` environment variable.
|
||||||
return getEnv("REQUEST_METHOD").string
|
return getEnv("REQUEST_METHOD")
|
||||||
|
|
||||||
proc getRequestURI*(): string =
|
proc getRequestURI*(): string =
|
||||||
## Returns contents of the `REQUEST_URI` environment variable.
|
## Returns contents of the `REQUEST_URI` environment variable.
|
||||||
return getEnv("REQUEST_URI").string
|
return getEnv("REQUEST_URI")
|
||||||
|
|
||||||
proc getScriptFilename*(): string =
|
proc getScriptFilename*(): string =
|
||||||
## Returns contents of the `SCRIPT_FILENAME` environment variable.
|
## Returns contents of the `SCRIPT_FILENAME` environment variable.
|
||||||
return getEnv("SCRIPT_FILENAME").string
|
return getEnv("SCRIPT_FILENAME")
|
||||||
|
|
||||||
proc getScriptName*(): string =
|
proc getScriptName*(): string =
|
||||||
## Returns contents of the `SCRIPT_NAME` environment variable.
|
## Returns contents of the `SCRIPT_NAME` environment variable.
|
||||||
return getEnv("SCRIPT_NAME").string
|
return getEnv("SCRIPT_NAME")
|
||||||
|
|
||||||
proc getServerAddr*(): string =
|
proc getServerAddr*(): string =
|
||||||
## Returns contents of the `SERVER_ADDR` environment variable.
|
## Returns contents of the `SERVER_ADDR` environment variable.
|
||||||
return getEnv("SERVER_ADDR").string
|
return getEnv("SERVER_ADDR")
|
||||||
|
|
||||||
proc getServerAdmin*(): string =
|
proc getServerAdmin*(): string =
|
||||||
## Returns contents of the `SERVER_ADMIN` environment variable.
|
## Returns contents of the `SERVER_ADMIN` environment variable.
|
||||||
return getEnv("SERVER_ADMIN").string
|
return getEnv("SERVER_ADMIN")
|
||||||
|
|
||||||
proc getServerName*(): string =
|
proc getServerName*(): string =
|
||||||
## Returns contents of the `SERVER_NAME` environment variable.
|
## Returns contents of the `SERVER_NAME` environment variable.
|
||||||
return getEnv("SERVER_NAME").string
|
return getEnv("SERVER_NAME")
|
||||||
|
|
||||||
proc getServerPort*(): string =
|
proc getServerPort*(): string =
|
||||||
## Returns contents of the `SERVER_PORT` environment variable.
|
## Returns contents of the `SERVER_PORT` environment variable.
|
||||||
return getEnv("SERVER_PORT").string
|
return getEnv("SERVER_PORT")
|
||||||
|
|
||||||
proc getServerProtocol*(): string =
|
proc getServerProtocol*(): string =
|
||||||
## Returns contents of the `SERVER_PROTOCOL` environment variable.
|
## Returns contents of the `SERVER_PROTOCOL` environment variable.
|
||||||
return getEnv("SERVER_PROTOCOL").string
|
return getEnv("SERVER_PROTOCOL")
|
||||||
|
|
||||||
proc getServerSignature*(): string =
|
proc getServerSignature*(): string =
|
||||||
## Returns contents of the `SERVER_SIGNATURE` environment variable.
|
## Returns contents of the `SERVER_SIGNATURE` environment variable.
|
||||||
return getEnv("SERVER_SIGNATURE").string
|
return getEnv("SERVER_SIGNATURE")
|
||||||
|
|
||||||
proc getServerSoftware*(): string =
|
proc getServerSoftware*(): string =
|
||||||
## Returns contents of the `SERVER_SOFTWARE` environment variable.
|
## Returns contents of the `SERVER_SOFTWARE` environment variable.
|
||||||
return getEnv("SERVER_SOFTWARE").string
|
return getEnv("SERVER_SOFTWARE")
|
||||||
|
|
||||||
proc setTestData*(keysvalues: varargs[string]) =
|
proc setTestData*(keysvalues: varargs[string]) =
|
||||||
## Fills the appropriate environment variables to test your CGI application.
|
## Fills the appropriate environment variables to test your CGI application.
|
||||||
|
|
|
||||||
|
|
@ -415,7 +415,7 @@ proc addFiles*(p: MultipartData, xs: openArray[tuple[name, file: string]],
|
||||||
let (_, fName, ext) = splitFile(file)
|
let (_, fName, ext) = splitFile(file)
|
||||||
if ext.len > 0:
|
if ext.len > 0:
|
||||||
contentType = mimeDb.getMimetype(ext[1..ext.high], "")
|
contentType = mimeDb.getMimetype(ext[1..ext.high], "")
|
||||||
let content = if useStream: file else: readFile(file).string
|
let content = if useStream: file else: readFile(file)
|
||||||
p.add(name, content, fName & ext, contentType, useStream = useStream)
|
p.add(name, content, fName & ext, contentType, useStream = useStream)
|
||||||
result = p
|
result = p
|
||||||
|
|
||||||
|
|
@ -455,8 +455,8 @@ proc sendFile(socket: Socket | AsyncSocket,
|
||||||
var buffer: string
|
var buffer: string
|
||||||
while true:
|
while true:
|
||||||
buffer =
|
buffer =
|
||||||
when socket is AsyncSocket: (await read(file, chunkSize)).string
|
when socket is AsyncSocket: (await read(file, chunkSize))
|
||||||
else: readStr(file, chunkSize).string
|
else: readStr(file, chunkSize)
|
||||||
if buffer.len == 0: break
|
if buffer.len == 0: break
|
||||||
await socket.send(buffer)
|
await socket.send(buffer)
|
||||||
file.close()
|
file.close()
|
||||||
|
|
@ -690,7 +690,7 @@ proc parseChunks(client: HttpClient | AsyncHttpClient): Future[void]
|
||||||
{.multisync.} =
|
{.multisync.} =
|
||||||
while true:
|
while true:
|
||||||
var chunkSize = 0
|
var chunkSize = 0
|
||||||
var chunkSizeStr = (await client.socket.recvLine()).string
|
var chunkSizeStr = await client.socket.recvLine()
|
||||||
var i = 0
|
var i = 0
|
||||||
if chunkSizeStr == "":
|
if chunkSizeStr == "":
|
||||||
httpError("Server terminated connection prematurely")
|
httpError("Server terminated connection prematurely")
|
||||||
|
|
@ -789,9 +789,9 @@ proc parseResponse(client: HttpClient | AsyncHttpClient,
|
||||||
while true:
|
while true:
|
||||||
linei = 0
|
linei = 0
|
||||||
when client is HttpClient:
|
when client is HttpClient:
|
||||||
line = (await client.socket.recvLine(client.timeout)).string
|
line = await client.socket.recvLine(client.timeout)
|
||||||
else:
|
else:
|
||||||
line = (await client.socket.recvLine()).string
|
line = await client.socket.recvLine()
|
||||||
if line == "":
|
if line == "":
|
||||||
# We've been disconnected.
|
# We've been disconnected.
|
||||||
client.close()
|
client.close()
|
||||||
|
|
|
||||||
|
|
@ -443,9 +443,9 @@ iterator lines*(mfile: MemFile, buf: var string, delim = '\l',
|
||||||
## echo line
|
## echo line
|
||||||
|
|
||||||
for ms in memSlices(mfile, delim, eat):
|
for ms in memSlices(mfile, delim, eat):
|
||||||
setLen(buf.string, ms.size)
|
setLen(buf, ms.size)
|
||||||
if ms.size > 0:
|
if ms.size > 0:
|
||||||
copyMem(addr string(buf)[0], ms.data, ms.size)
|
copyMem(addr buf[0], ms.data, ms.size)
|
||||||
yield buf
|
yield buf
|
||||||
|
|
||||||
iterator lines*(mfile: MemFile, delim = '\l', eat = '\r'): string {.inline.} =
|
iterator lines*(mfile: MemFile, delim = '\l', eat = '\r'): string {.inline.} =
|
||||||
|
|
|
||||||
|
|
@ -1513,23 +1513,23 @@ proc readLine*(socket: Socket, line: var string, timeout = -1,
|
||||||
|
|
||||||
template addNLIfEmpty() =
|
template addNLIfEmpty() =
|
||||||
if line.len == 0:
|
if line.len == 0:
|
||||||
line.string.add("\c\L")
|
line.add("\c\L")
|
||||||
|
|
||||||
template raiseSockError() {.dirty.} =
|
template raiseSockError() {.dirty.} =
|
||||||
let lastError = getSocketError(socket)
|
let lastError = getSocketError(socket)
|
||||||
if flags.isDisconnectionError(lastError):
|
if flags.isDisconnectionError(lastError):
|
||||||
setLen(line.string, 0)
|
setLen(line, 0)
|
||||||
socket.socketError(n, lastError = lastError, flags = flags)
|
socket.socketError(n, lastError = lastError, flags = flags)
|
||||||
|
|
||||||
var waited: Duration
|
var waited: Duration
|
||||||
|
|
||||||
setLen(line.string, 0)
|
setLen(line, 0)
|
||||||
while true:
|
while true:
|
||||||
var c: char
|
var c: char
|
||||||
discard waitFor(socket, waited, timeout, 1, "readLine")
|
discard waitFor(socket, waited, timeout, 1, "readLine")
|
||||||
var n = recv(socket, addr(c), 1)
|
var n = recv(socket, addr(c), 1)
|
||||||
if n < 0: raiseSockError()
|
if n < 0: raiseSockError()
|
||||||
elif n == 0: setLen(line.string, 0); return
|
elif n == 0: setLen(line, 0); return
|
||||||
if c == '\r':
|
if c == '\r':
|
||||||
discard waitFor(socket, waited, timeout, 1, "readLine")
|
discard waitFor(socket, waited, timeout, 1, "readLine")
|
||||||
n = peekChar(socket, c)
|
n = peekChar(socket, c)
|
||||||
|
|
@ -1541,10 +1541,10 @@ proc readLine*(socket: Socket, line: var string, timeout = -1,
|
||||||
elif c == '\L':
|
elif c == '\L':
|
||||||
addNLIfEmpty()
|
addNLIfEmpty()
|
||||||
return
|
return
|
||||||
add(line.string, c)
|
add(line, c)
|
||||||
|
|
||||||
# Verify that this isn't a DOS attack: #3847.
|
# Verify that this isn't a DOS attack: #3847.
|
||||||
if line.string.len > maxLength: break
|
if line.len > maxLength: break
|
||||||
|
|
||||||
proc recvLine*(socket: Socket, timeout = -1,
|
proc recvLine*(socket: Socket, timeout = -1,
|
||||||
flags = {SocketFlag.SafeDisconn},
|
flags = {SocketFlag.SafeDisconn},
|
||||||
|
|
|
||||||
|
|
@ -903,8 +903,8 @@ proc getHomeDir*(): string {.rtl, extern: "nos$1",
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
assert getHomeDir() == expandTilde("~")
|
assert getHomeDir() == expandTilde("~")
|
||||||
|
|
||||||
when defined(windows): return string(getEnv("USERPROFILE")) & "\\"
|
when defined(windows): return getEnv("USERPROFILE") & "\\"
|
||||||
else: return string(getEnv("HOME")) & "/"
|
else: return getEnv("HOME") & "/"
|
||||||
|
|
||||||
proc getConfigDir*(): string {.rtl, extern: "nos$1",
|
proc getConfigDir*(): string {.rtl, extern: "nos$1",
|
||||||
tags: [ReadEnvEffect, ReadIOEffect].} =
|
tags: [ReadEnvEffect, ReadIOEffect].} =
|
||||||
|
|
@ -925,9 +925,9 @@ proc getConfigDir*(): string {.rtl, extern: "nos$1",
|
||||||
## * `getCurrentDir proc <#getCurrentDir>`_
|
## * `getCurrentDir proc <#getCurrentDir>`_
|
||||||
## * `setCurrentDir proc <#setCurrentDir,string>`_
|
## * `setCurrentDir proc <#setCurrentDir,string>`_
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
result = getEnv("APPDATA").string
|
result = getEnv("APPDATA")
|
||||||
else:
|
else:
|
||||||
result = getEnv("XDG_CONFIG_HOME", getEnv("HOME").string / ".config").string
|
result = getEnv("XDG_CONFIG_HOME", getEnv("HOME") / ".config")
|
||||||
result.normalizePathEnd(trailingSep = true)
|
result.normalizePathEnd(trailingSep = true)
|
||||||
|
|
||||||
proc getTempDir*(): string {.rtl, extern: "nos$1",
|
proc getTempDir*(): string {.rtl, extern: "nos$1",
|
||||||
|
|
@ -951,10 +951,10 @@ proc getTempDir*(): string {.rtl, extern: "nos$1",
|
||||||
when defined(tempDir):
|
when defined(tempDir):
|
||||||
const tempDir {.strdefine.}: string = tempDirDefault
|
const tempDir {.strdefine.}: string = tempDirDefault
|
||||||
result = tempDir
|
result = tempDir
|
||||||
elif defined(windows): result = string(getEnv("TEMP"))
|
elif defined(windows): result = getEnv("TEMP")
|
||||||
elif defined(android): result = getHomeDir()
|
elif defined(android): result = getHomeDir()
|
||||||
else:
|
else:
|
||||||
if existsEnv("TMPDIR"): result = string(getEnv("TMPDIR"))
|
if existsEnv("TMPDIR"): result = getEnv("TMPDIR")
|
||||||
normalizePathEnd(result, trailingSep=true)
|
normalizePathEnd(result, trailingSep=true)
|
||||||
|
|
||||||
proc expandTilde*(path: string): string {.
|
proc expandTilde*(path: string): string {.
|
||||||
|
|
@ -1186,7 +1186,7 @@ proc findExe*(exe: string, followSymlinks: bool = true;
|
||||||
if '/' in exe: checkCurrentDir()
|
if '/' in exe: checkCurrentDir()
|
||||||
else:
|
else:
|
||||||
checkCurrentDir()
|
checkCurrentDir()
|
||||||
let path = string(getEnv("PATH"))
|
let path = getEnv("PATH")
|
||||||
for candidate in split(path, PathSep):
|
for candidate in split(path, PathSep):
|
||||||
if candidate.len == 0: continue
|
if candidate.len == 0: continue
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
|
|
@ -2936,7 +2936,7 @@ when not weirdTarget and defined(openbsd):
|
||||||
|
|
||||||
# POSIX guaranties that this contains the executable
|
# POSIX guaranties that this contains the executable
|
||||||
# as it has been executed by the calling process
|
# as it has been executed by the calling process
|
||||||
let exePath = string(paramStr(0))
|
let exePath = paramStr(0)
|
||||||
|
|
||||||
if len(exePath) == 0:
|
if len(exePath) == 0:
|
||||||
return ""
|
return ""
|
||||||
|
|
@ -2955,7 +2955,7 @@ when not weirdTarget and defined(openbsd):
|
||||||
return expandFilename(result)
|
return expandFilename(result)
|
||||||
|
|
||||||
# search in path
|
# search in path
|
||||||
for p in split(string(getEnv("PATH")), {PathSep}):
|
for p in split(getEnv("PATH"), {PathSep}):
|
||||||
var x = joinPath(p, exePath)
|
var x = joinPath(p, exePath)
|
||||||
if fileExists(x):
|
if fileExists(x):
|
||||||
return expandFilename(x)
|
return expandFilename(x)
|
||||||
|
|
@ -2965,12 +2965,12 @@ when not weirdTarget and defined(openbsd):
|
||||||
when not (defined(windows) or defined(macosx) or weirdTarget):
|
when not (defined(windows) or defined(macosx) or weirdTarget):
|
||||||
proc getApplHeuristic(): string =
|
proc getApplHeuristic(): string =
|
||||||
when declared(paramStr):
|
when declared(paramStr):
|
||||||
result = string(paramStr(0))
|
result = paramStr(0)
|
||||||
# POSIX guaranties that this contains the executable
|
# POSIX guaranties that this contains the executable
|
||||||
# as it has been executed by the calling process
|
# as it has been executed by the calling process
|
||||||
if len(result) > 0 and result[0] != DirSep: # not an absolute path?
|
if len(result) > 0 and result[0] != DirSep: # not an absolute path?
|
||||||
# iterate over any path in the $PATH environment variable
|
# iterate over any path in the $PATH environment variable
|
||||||
for p in split(string(getEnv("PATH")), {PathSep}):
|
for p in split(getEnv("PATH"), {PathSep}):
|
||||||
var x = joinPath(p, result)
|
var x = joinPath(p, result)
|
||||||
if fileExists(x): return x
|
if fileExists(x): return x
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -514,8 +514,8 @@ when not defined(useNimRtl):
|
||||||
while true:
|
while true:
|
||||||
# FIXME: converts CR-LF to LF.
|
# FIXME: converts CR-LF to LF.
|
||||||
if outp.readLine(line):
|
if outp.readLine(line):
|
||||||
result.string.add(line.string)
|
result.add(line)
|
||||||
result.string.add("\n")
|
result.add("\n")
|
||||||
elif not running(p): break
|
elif not running(p): break
|
||||||
close(p)
|
close(p)
|
||||||
|
|
||||||
|
|
@ -932,7 +932,7 @@ elif not defined(useNimRtl):
|
||||||
result = cast[cstringArray](alloc0((counter + 1) * sizeof(cstring)))
|
result = cast[cstringArray](alloc0((counter + 1) * sizeof(cstring)))
|
||||||
var i = 0
|
var i = 0
|
||||||
for key, val in envPairs():
|
for key, val in envPairs():
|
||||||
var x = key.string & "=" & val.string
|
var x = key & "=" & val
|
||||||
result[i] = cast[cstring](alloc(x.len+1))
|
result[i] = cast[cstring](alloc(x.len+1))
|
||||||
copyMem(result[i], addr(x[0]), x.len+1)
|
copyMem(result[i], addr(x[0]), x.len+1)
|
||||||
inc(i)
|
inc(i)
|
||||||
|
|
@ -1623,8 +1623,8 @@ proc execCmdEx*(command: string, options: set[ProcessOption] = {
|
||||||
var line = newStringOfCap(120)
|
var line = newStringOfCap(120)
|
||||||
while true:
|
while true:
|
||||||
if outp.readLine(line):
|
if outp.readLine(line):
|
||||||
result[0].string.add(line.string)
|
result[0].add(line)
|
||||||
result[0].string.add("\n")
|
result[0].add("\n")
|
||||||
else:
|
else:
|
||||||
result[1] = peekExitCode(p)
|
result[1] = peekExitCode(p)
|
||||||
if result[1] != -1: break
|
if result[1] != -1: break
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,7 @@ when declared(os.paramCount):
|
||||||
else:
|
else:
|
||||||
result.cmds = newSeq[string](os.paramCount())
|
result.cmds = newSeq[string](os.paramCount())
|
||||||
for i in countup(1, os.paramCount()):
|
for i in countup(1, os.paramCount()):
|
||||||
result.cmds[i-1] = os.paramStr(i).string
|
result.cmds[i-1] = os.paramStr(i)
|
||||||
|
|
||||||
result.kind = cmdEnd
|
result.kind = cmdEnd
|
||||||
result.key = ""
|
result.key = ""
|
||||||
|
|
@ -261,11 +261,11 @@ when declared(os.paramCount):
|
||||||
if cmdline.len != 0:
|
if cmdline.len != 0:
|
||||||
result.cmds = newSeq[string](cmdline.len)
|
result.cmds = newSeq[string](cmdline.len)
|
||||||
for i in 0..<cmdline.len:
|
for i in 0..<cmdline.len:
|
||||||
result.cmds[i] = cmdline[i].string
|
result.cmds[i] = cmdline[i]
|
||||||
else:
|
else:
|
||||||
result.cmds = newSeq[string](os.paramCount())
|
result.cmds = newSeq[string](os.paramCount())
|
||||||
for i in countup(1, os.paramCount()):
|
for i in countup(1, os.paramCount()):
|
||||||
result.cmds[i-1] = os.paramStr(i).string
|
result.cmds[i-1] = os.paramStr(i)
|
||||||
result.kind = cmdEnd
|
result.kind = cmdEnd
|
||||||
result.key = ""
|
result.key = ""
|
||||||
result.val = ""
|
result.val = ""
|
||||||
|
|
@ -274,14 +274,14 @@ proc handleShortOption(p: var OptParser; cmd: string) =
|
||||||
var i = p.pos
|
var i = p.pos
|
||||||
p.kind = cmdShortOption
|
p.kind = cmdShortOption
|
||||||
if i < cmd.len:
|
if i < cmd.len:
|
||||||
add(p.key.string, cmd[i])
|
add(p.key, cmd[i])
|
||||||
inc(i)
|
inc(i)
|
||||||
p.inShortState = true
|
p.inShortState = true
|
||||||
while i < cmd.len and cmd[i] in {'\t', ' '}:
|
while i < cmd.len and cmd[i] in {'\t', ' '}:
|
||||||
inc(i)
|
inc(i)
|
||||||
p.inShortState = false
|
p.inShortState = false
|
||||||
if i < cmd.len and (cmd[i] in {':', '='} or
|
if i < cmd.len and (cmd[i] in {':', '='} or
|
||||||
card(p.shortNoVal) > 0 and p.key.string[0] notin p.shortNoVal):
|
card(p.shortNoVal) > 0 and p.key[0] notin p.shortNoVal):
|
||||||
if i < cmd.len and cmd[i] in {':', '='}:
|
if i < cmd.len and cmd[i] in {':', '='}:
|
||||||
inc(i)
|
inc(i)
|
||||||
p.inShortState = false
|
p.inShortState = false
|
||||||
|
|
@ -319,8 +319,8 @@ proc next*(p: var OptParser) {.rtl, extern: "npo$1".} =
|
||||||
var i = p.pos
|
var i = p.pos
|
||||||
while i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {'\t', ' '}: inc(i)
|
while i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {'\t', ' '}: inc(i)
|
||||||
p.pos = i
|
p.pos = i
|
||||||
setLen(p.key.string, 0)
|
setLen(p.key, 0)
|
||||||
setLen(p.val.string, 0)
|
setLen(p.val, 0)
|
||||||
if p.inShortState:
|
if p.inShortState:
|
||||||
p.inShortState = false
|
p.inShortState = false
|
||||||
if i >= p.cmds[p.idx].len:
|
if i >= p.cmds[p.idx].len:
|
||||||
|
|
@ -338,7 +338,7 @@ proc next*(p: var OptParser) {.rtl, extern: "npo$1".} =
|
||||||
if i < p.cmds[p.idx].len and p.cmds[p.idx][i] == '-':
|
if i < p.cmds[p.idx].len and p.cmds[p.idx][i] == '-':
|
||||||
p.kind = cmdLongOption
|
p.kind = cmdLongOption
|
||||||
inc(i)
|
inc(i)
|
||||||
i = parseWord(p.cmds[p.idx], i, p.key.string, {' ', '\t', ':', '='})
|
i = parseWord(p.cmds[p.idx], i, p.key, {' ', '\t', ':', '='})
|
||||||
while i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {'\t', ' '}: inc(i)
|
while i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {'\t', ' '}: inc(i)
|
||||||
if i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {':', '='}:
|
if i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {':', '='}:
|
||||||
inc(i)
|
inc(i)
|
||||||
|
|
@ -350,7 +350,7 @@ proc next*(p: var OptParser) {.rtl, extern: "npo$1".} =
|
||||||
i = 0
|
i = 0
|
||||||
if p.idx < p.cmds.len:
|
if p.idx < p.cmds.len:
|
||||||
p.val = p.cmds[p.idx].substr(i)
|
p.val = p.cmds[p.idx].substr(i)
|
||||||
elif len(p.longNoVal) > 0 and p.key.string notin p.longNoVal and p.idx+1 < p.cmds.len:
|
elif len(p.longNoVal) > 0 and p.key notin p.longNoVal and p.idx+1 < p.cmds.len:
|
||||||
p.val = p.cmds[p.idx+1]
|
p.val = p.cmds[p.idx+1]
|
||||||
inc p.idx
|
inc p.idx
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1332,7 +1332,7 @@ when not defined(js):
|
||||||
## error occurs. This is supposed to be used for quick scripting.
|
## error occurs. This is supposed to be used for quick scripting.
|
||||||
##
|
##
|
||||||
## **Note**: this proc does not exist while using the JS backend.
|
## **Note**: this proc does not exist while using the JS backend.
|
||||||
var x = readFile(infile).string
|
var x = readFile(infile)
|
||||||
writeFile(outfile, x.parallelReplace(subs))
|
writeFile(outfile, x.parallelReplace(subs))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ proc debugRecv*(smtp: Smtp | AsyncSmtp): Future[string] {.multisync.} =
|
||||||
|
|
||||||
result = await smtp.sock.recvLine()
|
result = await smtp.sock.recvLine()
|
||||||
if smtp.debug:
|
if smtp.debug:
|
||||||
echo("S:" & result.string)
|
echo("S:" & result)
|
||||||
|
|
||||||
proc quitExcpt(smtp: Smtp, msg: string) =
|
proc quitExcpt(smtp: Smtp, msg: string) =
|
||||||
smtp.debugSend("QUIT")
|
smtp.debugSend("QUIT")
|
||||||
|
|
|
||||||
|
|
@ -924,7 +924,7 @@ proc readStrPrivate(s: Stream, length: int, str: var string) =
|
||||||
when defined(js):
|
when defined(js):
|
||||||
let L = readData(s, addr(str), length)
|
let L = readData(s, addr(str), length)
|
||||||
else:
|
else:
|
||||||
let L = readData(s, cstring(str.string), length)
|
let L = readData(s, cstring(str), length)
|
||||||
if L != len(str): setLen(str, L)
|
if L != len(str): setLen(str, L)
|
||||||
|
|
||||||
proc readStr*(s: Stream, length: int, str: var string) {.since: (1, 3).} =
|
proc readStr*(s: Stream, length: int, str: var string) {.since: (1, 3).} =
|
||||||
|
|
@ -950,7 +950,7 @@ proc peekStrPrivate(s: Stream, length: int, str: var string) =
|
||||||
when defined(js):
|
when defined(js):
|
||||||
let L = peekData(s, addr(str), length)
|
let L = peekData(s, addr(str), length)
|
||||||
else:
|
else:
|
||||||
let L = peekData(s, cstring(str.string), length)
|
let L = peekData(s, cstring(str), length)
|
||||||
if L != len(str): setLen(str, L)
|
if L != len(str): setLen(str, L)
|
||||||
|
|
||||||
proc peekStr*(s: Stream, length: int, str: var string) {.since: (1, 3).} =
|
proc peekStr*(s: Stream, length: int, str: var string) {.since: (1, 3).} =
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ proc posReadLine[T](s: Stream, line: var string): bool =
|
||||||
assert s.baseReadLineImpl != nil
|
assert s.baseReadLineImpl != nil
|
||||||
|
|
||||||
let n = s.buffer.len
|
let n = s.buffer.len
|
||||||
line.string.setLen(0)
|
line.setLen(0)
|
||||||
for i in 0..<n:
|
for i in 0..<n:
|
||||||
var c = s.buffer.popFirst
|
var c = s.buffer.popFirst
|
||||||
if c == '\c':
|
if c == '\c':
|
||||||
|
|
@ -40,7 +40,7 @@ proc posReadLine[T](s: Stream, line: var string): bool =
|
||||||
elif c == '\L': return true
|
elif c == '\L': return true
|
||||||
elif c == '\0':
|
elif c == '\0':
|
||||||
return line.len > 0
|
return line.len > 0
|
||||||
line.string.add(c)
|
line.add(c)
|
||||||
|
|
||||||
var line2: string
|
var line2: string
|
||||||
result = s.baseReadLineImpl(s, line2)
|
result = s.baseReadLineImpl(s, line2)
|
||||||
|
|
|
||||||
|
|
@ -304,7 +304,7 @@ proc getValue(t: StringTableRef, flags: set[FormatFlag], key: string): string =
|
||||||
when defined(js) or defined(nimscript) or defined(Standalone):
|
when defined(js) or defined(nimscript) or defined(Standalone):
|
||||||
result = ""
|
result = ""
|
||||||
else:
|
else:
|
||||||
if useEnvironment in flags: result = getEnv(key).string
|
if useEnvironment in flags: result = getEnv(key)
|
||||||
else: result = ""
|
else: result = ""
|
||||||
if result.len == 0:
|
if result.len == 0:
|
||||||
if useKey in flags: result = '$' & key
|
if useKey in flags: result = '$' & key
|
||||||
|
|
|
||||||
|
|
@ -253,7 +253,7 @@ else:
|
||||||
discard close(fd)
|
discard close(fd)
|
||||||
if w > 0: return w
|
if w > 0: return w
|
||||||
var s = getEnv("COLUMNS") #Try standard env var
|
var s = getEnv("COLUMNS") #Try standard env var
|
||||||
if len(s) > 0 and parseInt(string(s), w) > 0 and w > 0:
|
if len(s) > 0 and parseInt(s, w) > 0 and w > 0:
|
||||||
return w
|
return w
|
||||||
return 80 #Finally default to venerable value
|
return 80 #Finally default to venerable value
|
||||||
|
|
||||||
|
|
@ -271,7 +271,7 @@ else:
|
||||||
discard close(fd)
|
discard close(fd)
|
||||||
if h > 0: return h
|
if h > 0: return h
|
||||||
var s = getEnv("LINES") # Try standard env var
|
var s = getEnv("LINES") # Try standard env var
|
||||||
if len(s) > 0 and parseInt(string(s), h) > 0 and h > 0:
|
if len(s) > 0 and parseInt(s, h) > 0 and h > 0:
|
||||||
return h
|
return h
|
||||||
return 0 # Could not determine height
|
return 0 # Could not determine height
|
||||||
|
|
||||||
|
|
@ -776,7 +776,7 @@ when defined(windows):
|
||||||
## Reads a `password` from stdin without printing it. `password` must not
|
## Reads a `password` from stdin without printing it. `password` must not
|
||||||
## be ``nil``! Returns ``false`` if the end of the file has been reached,
|
## be ``nil``! Returns ``false`` if the end of the file has been reached,
|
||||||
## ``true`` otherwise.
|
## ``true`` otherwise.
|
||||||
password.string.setLen(0)
|
password.setLen(0)
|
||||||
stdout.write(prompt)
|
stdout.write(prompt)
|
||||||
let hi = createFileA("CONIN$",
|
let hi = createFileA("CONIN$",
|
||||||
GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, 0, 0)
|
GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, 0, 0)
|
||||||
|
|
@ -799,7 +799,7 @@ else:
|
||||||
|
|
||||||
proc readPasswordFromStdin*(prompt: string, password: var string):
|
proc readPasswordFromStdin*(prompt: string, password: var string):
|
||||||
bool {.tags: [ReadIOEffect, WriteIOEffect].} =
|
bool {.tags: [ReadIOEffect, WriteIOEffect].} =
|
||||||
password.string.setLen(0)
|
password.setLen(0)
|
||||||
let fd = stdin.getFileHandle()
|
let fd = stdin.getFileHandle()
|
||||||
var cur, old: Termios
|
var cur, old: Termios
|
||||||
discard fd.tcGetAttr(cur.addr)
|
discard fd.tcGetAttr(cur.addr)
|
||||||
|
|
@ -882,7 +882,7 @@ proc enableTrueColors*() =
|
||||||
else:
|
else:
|
||||||
term.trueColorIsEnabled = true
|
term.trueColorIsEnabled = true
|
||||||
else:
|
else:
|
||||||
term.trueColorIsSupported = string(getEnv("COLORTERM")).toLowerAscii() in [
|
term.trueColorIsSupported = getEnv("COLORTERM").toLowerAscii() in [
|
||||||
"truecolor", "24bit"]
|
"truecolor", "24bit"]
|
||||||
term.trueColorIsEnabled = term.trueColorIsSupported
|
term.trueColorIsEnabled = term.trueColorIsSupported
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.string
|
translationTable[i] = line
|
||||||
inc(i)
|
inc(i)
|
||||||
|
|
||||||
proc unidecode*(s: string): string =
|
proc unidecode*(s: string): string =
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ type
|
||||||
region: MemRegion
|
region: MemRegion
|
||||||
PRawChannel = ptr RawChannel
|
PRawChannel = ptr RawChannel
|
||||||
LoadStoreMode = enum mStore, mLoad
|
LoadStoreMode = enum mStore, mLoad
|
||||||
Channel* {.gcsafe.}[TMsg] = RawChannel ## a channel for thread communication
|
Channel*[TMsg] {.gcsafe.} = RawChannel ## a channel for thread communication
|
||||||
|
|
||||||
const ChannelDeadMask = -2
|
const ChannelDeadMask = -2
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -434,19 +434,19 @@ proc readLine*(f: File, line: var string): bool {.tags: [ReadIOEffect],
|
||||||
var pos = 0
|
var pos = 0
|
||||||
|
|
||||||
# Use the currently reserved space for a first try
|
# Use the currently reserved space for a first try
|
||||||
var sp = max(line.string.len, 80)
|
var sp = max(line.len, 80)
|
||||||
line.string.setLen(sp)
|
line.setLen(sp)
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
# memset to \L so that we can tell how far fgets wrote, even on EOF, where
|
# memset to \L so that we can tell how far fgets wrote, even on EOF, where
|
||||||
# fgets doesn't append an \L
|
# fgets doesn't append an \L
|
||||||
for i in 0..<sp: line.string[pos+i] = '\L'
|
for i in 0..<sp: line[pos+i] = '\L'
|
||||||
|
|
||||||
var fgetsSuccess: bool
|
var fgetsSuccess: bool
|
||||||
while true:
|
while true:
|
||||||
# fixes #9634; this pattern may need to be abstracted as a template if reused;
|
# fixes #9634; this pattern may need to be abstracted as a template if reused;
|
||||||
# likely other io procs need this for correctness.
|
# likely other io procs need this for correctness.
|
||||||
fgetsSuccess = c_fgets(addr line.string[pos], sp.cint, f) != nil
|
fgetsSuccess = c_fgets(addr line[pos], sp.cint, f) != nil
|
||||||
if fgetsSuccess: break
|
if fgetsSuccess: break
|
||||||
when not defined(NimScript):
|
when not defined(NimScript):
|
||||||
if errno == EINTR:
|
if errno == EINTR:
|
||||||
|
|
@ -456,20 +456,20 @@ proc readLine*(f: File, line: var string): bool {.tags: [ReadIOEffect],
|
||||||
checkErr(f)
|
checkErr(f)
|
||||||
break
|
break
|
||||||
|
|
||||||
let m = c_memchr(addr line.string[pos], '\L'.ord, cast[csize_t](sp))
|
let m = c_memchr(addr line[pos], '\L'.ord, cast[csize_t](sp))
|
||||||
if m != nil:
|
if m != nil:
|
||||||
# \l found: Could be our own or the one by fgets, in any case, we're done
|
# \l found: Could be our own or the one by fgets, in any case, we're done
|
||||||
var last = cast[ByteAddress](m) - cast[ByteAddress](addr line.string[0])
|
var last = cast[ByteAddress](m) - cast[ByteAddress](addr line[0])
|
||||||
if last > 0 and line.string[last-1] == '\c':
|
if last > 0 and line[last-1] == '\c':
|
||||||
line.string.setLen(last-1)
|
line.setLen(last-1)
|
||||||
return last > 1 or fgetsSuccess
|
return last > 1 or fgetsSuccess
|
||||||
# We have to distinguish between two possible cases:
|
# We have to distinguish between two possible cases:
|
||||||
# \0\l\0 => line ending in a null character.
|
# \0\l\0 => line ending in a null character.
|
||||||
# \0\l\l => last line without newline, null was put there by fgets.
|
# \0\l\l => last line without newline, null was put there by fgets.
|
||||||
elif last > 0 and line.string[last-1] == '\0':
|
elif last > 0 and line[last-1] == '\0':
|
||||||
if last < pos + sp - 1 and line.string[last+1] != '\0':
|
if last < pos + sp - 1 and line[last+1] != '\0':
|
||||||
dec last
|
dec last
|
||||||
line.string.setLen(last)
|
line.setLen(last)
|
||||||
return last > 0 or fgetsSuccess
|
return last > 0 or fgetsSuccess
|
||||||
else:
|
else:
|
||||||
# fgets will have inserted a null byte at the end of the string.
|
# fgets will have inserted a null byte at the end of the string.
|
||||||
|
|
@ -477,7 +477,7 @@ proc readLine*(f: File, line: var string): bool {.tags: [ReadIOEffect],
|
||||||
# No \l found: Increase buffer and read more
|
# No \l found: Increase buffer and read more
|
||||||
inc pos, sp
|
inc pos, sp
|
||||||
sp = 128 # read in 128 bytes at a time
|
sp = 128 # read in 128 bytes at a time
|
||||||
line.string.setLen(pos+sp)
|
line.setLen(pos+sp)
|
||||||
|
|
||||||
proc readLine*(f: File): string {.tags: [ReadIOEffect], benign.} =
|
proc readLine*(f: File): string {.tags: [ReadIOEffect], benign.} =
|
||||||
## reads a line of text from the file `f`. May throw an IO exception.
|
## reads a line of text from the file `f`. May throw an IO exception.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue