mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 05:50:30 +00:00
fix some warnings (#16952)
This commit is contained in:
@@ -488,7 +488,7 @@ proc transformFile*(infile, outfile: string,
|
||||
## reads in the file ``infile``, performs a parallel replacement (calls
|
||||
## ``parallelReplace``) and writes back to ``outfile``. Raises ``IOError`` if an
|
||||
## 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))
|
||||
|
||||
iterator split*(s: string, sep: Regex; maxsplit = -1): string =
|
||||
|
||||
@@ -423,7 +423,7 @@ when defined(createNimHcr):
|
||||
if modules.contains(name):
|
||||
unloadDll(name)
|
||||
else:
|
||||
modules.add(name, newModuleDesc())
|
||||
modules[name] = newModuleDesc()
|
||||
|
||||
let copiedName = name & ".copy." & dllExt
|
||||
copyFileWithPermissions(name, copiedName)
|
||||
@@ -601,7 +601,7 @@ when defined(createNimHcr):
|
||||
|
||||
proc hcrAddModule*(module: cstring) {.nimhcr.} =
|
||||
if not modules.contains($module):
|
||||
modules.add($module, newModuleDesc())
|
||||
modules[$module] = newModuleDesc()
|
||||
|
||||
proc hcrGeneration*(): int {.nimhcr.} =
|
||||
generation
|
||||
|
||||
@@ -917,7 +917,7 @@ when isMainModule:
|
||||
# Try to work running in both the subdir or at the root.
|
||||
for filename in ["doc/keywords.txt", "../../../doc/keywords.txt"]:
|
||||
try:
|
||||
let input = string(readFile(filename))
|
||||
let input = readFile(filename)
|
||||
keywords = input.splitWhitespace()
|
||||
break
|
||||
except:
|
||||
|
||||
@@ -1870,7 +1870,7 @@ proc dirInclude(p: var RstParser): PRstNode =
|
||||
result = newRstNode(rnLiteralBlock)
|
||||
result.add(newRstNode(rnLeaf, readFile(path)))
|
||||
else:
|
||||
let inputString = readFile(path).string()
|
||||
let inputString = readFile(path)
|
||||
let startPosition =
|
||||
block:
|
||||
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] == '-':
|
||||
## Multi-line reply.
|
||||
line = await ftp.csock.recvLine()
|
||||
string(result).add("\n" & line)
|
||||
result.add("\n" & line)
|
||||
count.inc()
|
||||
if count >= multiLineLimit:
|
||||
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
|
||||
raise newException(ReplyError,
|
||||
"Expected reply '$1' got: $2" %
|
||||
[expected.join("' or '"), received.string])
|
||||
[expected.join("' or '"), received])
|
||||
|
||||
proc pasv(ftp: AsyncFtpClient) {.async.} =
|
||||
## Negotiate a data connection.
|
||||
@@ -171,7 +171,7 @@ proc pasv(ftp: AsyncFtpClient) {.async.} =
|
||||
|
||||
var pasvMsg = (await ftp.send("PASV")).strip
|
||||
assertReply(pasvMsg, "227")
|
||||
var betweenParens = captureBetween(pasvMsg.string, '(', ')')
|
||||
var betweenParens = captureBetween(pasvMsg, '(', ')')
|
||||
var nums = betweenParens.split(',')
|
||||
var ip = nums[0 .. ^3]
|
||||
var port = nums[^2 .. ^1]
|
||||
@@ -187,7 +187,7 @@ proc connect*(ftp: AsyncFtpClient) {.async.} =
|
||||
await ftp.csock.connect(ftp.address, ftp.port)
|
||||
|
||||
var reply = await ftp.expectReply()
|
||||
if string(reply).startsWith("120"):
|
||||
if reply.startsWith("120"):
|
||||
# 120 Service ready in nnn minutes.
|
||||
# We wait until we receive 220.
|
||||
reply = await ftp.expectReply()
|
||||
@@ -221,10 +221,10 @@ proc getLines(ftp: AsyncFtpClient): Future[string] {.async.} =
|
||||
assert ftp.dsockConnected
|
||||
while ftp.dsockConnected:
|
||||
let r = await ftp.dsock.recvLine()
|
||||
if r.string == "":
|
||||
if r == "":
|
||||
ftp.dsockConnected = false
|
||||
else:
|
||||
result.add(r.string & "\n")
|
||||
result.add(r & "\n")
|
||||
|
||||
assertReply(await(ftp.expectReply()), "226")
|
||||
|
||||
@@ -346,10 +346,10 @@ proc retrFile*(ftp: AsyncFtpClient, file, dest: string,
|
||||
await ftp.pasv()
|
||||
var reply = await ftp.send("RETR " & file.normalizePathSep)
|
||||
assertReply reply, ["125", "150"]
|
||||
if {'(', ')'} notin reply.string:
|
||||
if {'(', ')'} notin reply:
|
||||
raise newException(ReplyError, "Reply has no file size.")
|
||||
var fileSize: BiggestInt
|
||||
if reply.string.captureBetween('(', ')').parseBiggestInt(fileSize) == 0:
|
||||
if reply.captureBetween('(', ')').parseBiggestInt(fileSize) == 0:
|
||||
raise newException(ReplyError, "Reply has no file size.")
|
||||
|
||||
await getFile(ftp, destFile, fileSize, onProgressChanged)
|
||||
|
||||
@@ -43,7 +43,7 @@ proc openDefaultBrowserImpl(url: string) =
|
||||
else:
|
||||
var u = quoteShell(prepare url)
|
||||
if execShellCmd(osOpenCmd & " " & u) == 0: return
|
||||
for b in getEnv("BROWSER").string.split(PathSep):
|
||||
for b in getEnv("BROWSER").split(PathSep):
|
||||
try:
|
||||
# we use ``startProcess`` here because we don't want to block!
|
||||
discard startProcess(command = b, args = [url], options = {poUsePath})
|
||||
|
||||
@@ -63,11 +63,11 @@ proc cgiError*(msg: string) {.noreturn.} =
|
||||
raise newException(CgiError, msg)
|
||||
|
||||
proc getEncodedData(allowedMethods: set[RequestMethod]): string =
|
||||
case getEnv("REQUEST_METHOD").string
|
||||
case getEnv("REQUEST_METHOD")
|
||||
of "POST":
|
||||
if methodPost notin allowedMethods:
|
||||
cgiError("'REQUEST_METHOD' 'POST' is not supported")
|
||||
var L = parseInt(getEnv("CONTENT_LENGTH").string)
|
||||
var L = parseInt(getEnv("CONTENT_LENGTH"))
|
||||
if L == 0:
|
||||
return ""
|
||||
result = newString(L)
|
||||
@@ -76,7 +76,7 @@ proc getEncodedData(allowedMethods: set[RequestMethod]): string =
|
||||
of "GET":
|
||||
if methodGet notin allowedMethods:
|
||||
cgiError("'REQUEST_METHOD' 'GET' is not supported")
|
||||
result = getEnv("QUERY_STRING").string
|
||||
result = getEnv("QUERY_STRING")
|
||||
else:
|
||||
if methodNone notin allowedMethods:
|
||||
cgiError("'REQUEST_METHOD' must be 'POST' or 'GET'")
|
||||
@@ -102,13 +102,13 @@ proc readData*(allowedMethods: set[RequestMethod] =
|
||||
## `allowedMethods` set, a `CgiError` exception is raised.
|
||||
result = newStringTable()
|
||||
for name, value in decodeData(allowedMethods):
|
||||
result[name.string] = value.string
|
||||
result[name] = value
|
||||
|
||||
proc readData*(data: string): StringTableRef =
|
||||
## Reads CGI data from a string.
|
||||
result = newStringTable()
|
||||
for name, value in decodeData(data):
|
||||
result[name.string] = value.string
|
||||
result[name] = value
|
||||
|
||||
proc validateData*(data: StringTableRef, validKeys: varargs[string]) =
|
||||
## 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 =
|
||||
## Returns contents of the `CONTENT_LENGTH` environment variable.
|
||||
return getEnv("CONTENT_LENGTH").string
|
||||
return getEnv("CONTENT_LENGTH")
|
||||
|
||||
proc getContentType*(): string =
|
||||
## Returns contents of the `CONTENT_TYPE` environment variable.
|
||||
return getEnv("CONTENT_Type").string
|
||||
return getEnv("CONTENT_Type")
|
||||
|
||||
proc getDocumentRoot*(): string =
|
||||
## Returns contents of the `DOCUMENT_ROOT` environment variable.
|
||||
return getEnv("DOCUMENT_ROOT").string
|
||||
return getEnv("DOCUMENT_ROOT")
|
||||
|
||||
proc getGatewayInterface*(): string =
|
||||
## Returns contents of the `GATEWAY_INTERFACE` environment variable.
|
||||
return getEnv("GATEWAY_INTERFACE").string
|
||||
return getEnv("GATEWAY_INTERFACE")
|
||||
|
||||
proc getHttpAccept*(): string =
|
||||
## Returns contents of the `HTTP_ACCEPT` environment variable.
|
||||
return getEnv("HTTP_ACCEPT").string
|
||||
return getEnv("HTTP_ACCEPT")
|
||||
|
||||
proc getHttpAcceptCharset*(): string =
|
||||
## Returns contents of the `HTTP_ACCEPT_CHARSET` environment variable.
|
||||
return getEnv("HTTP_ACCEPT_CHARSET").string
|
||||
return getEnv("HTTP_ACCEPT_CHARSET")
|
||||
|
||||
proc getHttpAcceptEncoding*(): string =
|
||||
## Returns contents of the `HTTP_ACCEPT_ENCODING` environment variable.
|
||||
return getEnv("HTTP_ACCEPT_ENCODING").string
|
||||
return getEnv("HTTP_ACCEPT_ENCODING")
|
||||
|
||||
proc getHttpAcceptLanguage*(): string =
|
||||
## Returns contents of the `HTTP_ACCEPT_LANGUAGE` environment variable.
|
||||
return getEnv("HTTP_ACCEPT_LANGUAGE").string
|
||||
return getEnv("HTTP_ACCEPT_LANGUAGE")
|
||||
|
||||
proc getHttpConnection*(): string =
|
||||
## Returns contents of the `HTTP_CONNECTION` environment variable.
|
||||
return getEnv("HTTP_CONNECTION").string
|
||||
return getEnv("HTTP_CONNECTION")
|
||||
|
||||
proc getHttpCookie*(): string =
|
||||
## Returns contents of the `HTTP_COOKIE` environment variable.
|
||||
return getEnv("HTTP_COOKIE").string
|
||||
return getEnv("HTTP_COOKIE")
|
||||
|
||||
proc getHttpHost*(): string =
|
||||
## Returns contents of the `HTTP_HOST` environment variable.
|
||||
return getEnv("HTTP_HOST").string
|
||||
return getEnv("HTTP_HOST")
|
||||
|
||||
proc getHttpReferer*(): string =
|
||||
## Returns contents of the `HTTP_REFERER` environment variable.
|
||||
return getEnv("HTTP_REFERER").string
|
||||
return getEnv("HTTP_REFERER")
|
||||
|
||||
proc getHttpUserAgent*(): string =
|
||||
## Returns contents of the `HTTP_USER_AGENT` environment variable.
|
||||
return getEnv("HTTP_USER_AGENT").string
|
||||
return getEnv("HTTP_USER_AGENT")
|
||||
|
||||
proc getPathInfo*(): string =
|
||||
## Returns contents of the `PATH_INFO` environment variable.
|
||||
return getEnv("PATH_INFO").string
|
||||
return getEnv("PATH_INFO")
|
||||
|
||||
proc getPathTranslated*(): string =
|
||||
## Returns contents of the `PATH_TRANSLATED` environment variable.
|
||||
return getEnv("PATH_TRANSLATED").string
|
||||
return getEnv("PATH_TRANSLATED")
|
||||
|
||||
proc getQueryString*(): string =
|
||||
## Returns contents of the `QUERY_STRING` environment variable.
|
||||
return getEnv("QUERY_STRING").string
|
||||
return getEnv("QUERY_STRING")
|
||||
|
||||
proc getRemoteAddr*(): string =
|
||||
## Returns contents of the `REMOTE_ADDR` environment variable.
|
||||
return getEnv("REMOTE_ADDR").string
|
||||
return getEnv("REMOTE_ADDR")
|
||||
|
||||
proc getRemoteHost*(): string =
|
||||
## Returns contents of the `REMOTE_HOST` environment variable.
|
||||
return getEnv("REMOTE_HOST").string
|
||||
return getEnv("REMOTE_HOST")
|
||||
|
||||
proc getRemoteIdent*(): string =
|
||||
## Returns contents of the `REMOTE_IDENT` environment variable.
|
||||
return getEnv("REMOTE_IDENT").string
|
||||
return getEnv("REMOTE_IDENT")
|
||||
|
||||
proc getRemotePort*(): string =
|
||||
## Returns contents of the `REMOTE_PORT` environment variable.
|
||||
return getEnv("REMOTE_PORT").string
|
||||
return getEnv("REMOTE_PORT")
|
||||
|
||||
proc getRemoteUser*(): string =
|
||||
## Returns contents of the `REMOTE_USER` environment variable.
|
||||
return getEnv("REMOTE_USER").string
|
||||
return getEnv("REMOTE_USER")
|
||||
|
||||
proc getRequestMethod*(): string =
|
||||
## Returns contents of the `REQUEST_METHOD` environment variable.
|
||||
return getEnv("REQUEST_METHOD").string
|
||||
return getEnv("REQUEST_METHOD")
|
||||
|
||||
proc getRequestURI*(): string =
|
||||
## Returns contents of the `REQUEST_URI` environment variable.
|
||||
return getEnv("REQUEST_URI").string
|
||||
return getEnv("REQUEST_URI")
|
||||
|
||||
proc getScriptFilename*(): string =
|
||||
## Returns contents of the `SCRIPT_FILENAME` environment variable.
|
||||
return getEnv("SCRIPT_FILENAME").string
|
||||
return getEnv("SCRIPT_FILENAME")
|
||||
|
||||
proc getScriptName*(): string =
|
||||
## Returns contents of the `SCRIPT_NAME` environment variable.
|
||||
return getEnv("SCRIPT_NAME").string
|
||||
return getEnv("SCRIPT_NAME")
|
||||
|
||||
proc getServerAddr*(): string =
|
||||
## Returns contents of the `SERVER_ADDR` environment variable.
|
||||
return getEnv("SERVER_ADDR").string
|
||||
return getEnv("SERVER_ADDR")
|
||||
|
||||
proc getServerAdmin*(): string =
|
||||
## Returns contents of the `SERVER_ADMIN` environment variable.
|
||||
return getEnv("SERVER_ADMIN").string
|
||||
return getEnv("SERVER_ADMIN")
|
||||
|
||||
proc getServerName*(): string =
|
||||
## Returns contents of the `SERVER_NAME` environment variable.
|
||||
return getEnv("SERVER_NAME").string
|
||||
return getEnv("SERVER_NAME")
|
||||
|
||||
proc getServerPort*(): string =
|
||||
## Returns contents of the `SERVER_PORT` environment variable.
|
||||
return getEnv("SERVER_PORT").string
|
||||
return getEnv("SERVER_PORT")
|
||||
|
||||
proc getServerProtocol*(): string =
|
||||
## Returns contents of the `SERVER_PROTOCOL` environment variable.
|
||||
return getEnv("SERVER_PROTOCOL").string
|
||||
return getEnv("SERVER_PROTOCOL")
|
||||
|
||||
proc getServerSignature*(): string =
|
||||
## Returns contents of the `SERVER_SIGNATURE` environment variable.
|
||||
return getEnv("SERVER_SIGNATURE").string
|
||||
return getEnv("SERVER_SIGNATURE")
|
||||
|
||||
proc getServerSoftware*(): string =
|
||||
## Returns contents of the `SERVER_SOFTWARE` environment variable.
|
||||
return getEnv("SERVER_SOFTWARE").string
|
||||
return getEnv("SERVER_SOFTWARE")
|
||||
|
||||
proc setTestData*(keysvalues: varargs[string]) =
|
||||
## 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)
|
||||
if ext.len > 0:
|
||||
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)
|
||||
result = p
|
||||
|
||||
@@ -455,8 +455,8 @@ proc sendFile(socket: Socket | AsyncSocket,
|
||||
var buffer: string
|
||||
while true:
|
||||
buffer =
|
||||
when socket is AsyncSocket: (await read(file, chunkSize)).string
|
||||
else: readStr(file, chunkSize).string
|
||||
when socket is AsyncSocket: (await read(file, chunkSize))
|
||||
else: readStr(file, chunkSize)
|
||||
if buffer.len == 0: break
|
||||
await socket.send(buffer)
|
||||
file.close()
|
||||
@@ -690,7 +690,7 @@ proc parseChunks(client: HttpClient | AsyncHttpClient): Future[void]
|
||||
{.multisync.} =
|
||||
while true:
|
||||
var chunkSize = 0
|
||||
var chunkSizeStr = (await client.socket.recvLine()).string
|
||||
var chunkSizeStr = await client.socket.recvLine()
|
||||
var i = 0
|
||||
if chunkSizeStr == "":
|
||||
httpError("Server terminated connection prematurely")
|
||||
@@ -789,9 +789,9 @@ proc parseResponse(client: HttpClient | AsyncHttpClient,
|
||||
while true:
|
||||
linei = 0
|
||||
when client is HttpClient:
|
||||
line = (await client.socket.recvLine(client.timeout)).string
|
||||
line = await client.socket.recvLine(client.timeout)
|
||||
else:
|
||||
line = (await client.socket.recvLine()).string
|
||||
line = await client.socket.recvLine()
|
||||
if line == "":
|
||||
# We've been disconnected.
|
||||
client.close()
|
||||
|
||||
@@ -443,9 +443,9 @@ iterator lines*(mfile: MemFile, buf: var string, delim = '\l',
|
||||
## echo line
|
||||
|
||||
for ms in memSlices(mfile, delim, eat):
|
||||
setLen(buf.string, ms.size)
|
||||
setLen(buf, ms.size)
|
||||
if ms.size > 0:
|
||||
copyMem(addr string(buf)[0], ms.data, ms.size)
|
||||
copyMem(addr buf[0], ms.data, ms.size)
|
||||
yield buf
|
||||
|
||||
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() =
|
||||
if line.len == 0:
|
||||
line.string.add("\c\L")
|
||||
line.add("\c\L")
|
||||
|
||||
template raiseSockError() {.dirty.} =
|
||||
let lastError = getSocketError(socket)
|
||||
if flags.isDisconnectionError(lastError):
|
||||
setLen(line.string, 0)
|
||||
setLen(line, 0)
|
||||
socket.socketError(n, lastError = lastError, flags = flags)
|
||||
|
||||
var waited: Duration
|
||||
|
||||
setLen(line.string, 0)
|
||||
setLen(line, 0)
|
||||
while true:
|
||||
var c: char
|
||||
discard waitFor(socket, waited, timeout, 1, "readLine")
|
||||
var n = recv(socket, addr(c), 1)
|
||||
if n < 0: raiseSockError()
|
||||
elif n == 0: setLen(line.string, 0); return
|
||||
elif n == 0: setLen(line, 0); return
|
||||
if c == '\r':
|
||||
discard waitFor(socket, waited, timeout, 1, "readLine")
|
||||
n = peekChar(socket, c)
|
||||
@@ -1541,10 +1541,10 @@ proc readLine*(socket: Socket, line: var string, timeout = -1,
|
||||
elif c == '\L':
|
||||
addNLIfEmpty()
|
||||
return
|
||||
add(line.string, c)
|
||||
add(line, c)
|
||||
|
||||
# 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,
|
||||
flags = {SocketFlag.SafeDisconn},
|
||||
|
||||
@@ -903,8 +903,8 @@ proc getHomeDir*(): string {.rtl, extern: "nos$1",
|
||||
runnableExamples:
|
||||
assert getHomeDir() == expandTilde("~")
|
||||
|
||||
when defined(windows): return string(getEnv("USERPROFILE")) & "\\"
|
||||
else: return string(getEnv("HOME")) & "/"
|
||||
when defined(windows): return getEnv("USERPROFILE") & "\\"
|
||||
else: return getEnv("HOME") & "/"
|
||||
|
||||
proc getConfigDir*(): string {.rtl, extern: "nos$1",
|
||||
tags: [ReadEnvEffect, ReadIOEffect].} =
|
||||
@@ -925,9 +925,9 @@ proc getConfigDir*(): string {.rtl, extern: "nos$1",
|
||||
## * `getCurrentDir proc <#getCurrentDir>`_
|
||||
## * `setCurrentDir proc <#setCurrentDir,string>`_
|
||||
when defined(windows):
|
||||
result = getEnv("APPDATA").string
|
||||
result = getEnv("APPDATA")
|
||||
else:
|
||||
result = getEnv("XDG_CONFIG_HOME", getEnv("HOME").string / ".config").string
|
||||
result = getEnv("XDG_CONFIG_HOME", getEnv("HOME") / ".config")
|
||||
result.normalizePathEnd(trailingSep = true)
|
||||
|
||||
proc getTempDir*(): string {.rtl, extern: "nos$1",
|
||||
@@ -951,10 +951,10 @@ proc getTempDir*(): string {.rtl, extern: "nos$1",
|
||||
when defined(tempDir):
|
||||
const tempDir {.strdefine.}: string = tempDirDefault
|
||||
result = tempDir
|
||||
elif defined(windows): result = string(getEnv("TEMP"))
|
||||
elif defined(windows): result = getEnv("TEMP")
|
||||
elif defined(android): result = getHomeDir()
|
||||
else:
|
||||
if existsEnv("TMPDIR"): result = string(getEnv("TMPDIR"))
|
||||
if existsEnv("TMPDIR"): result = getEnv("TMPDIR")
|
||||
normalizePathEnd(result, trailingSep=true)
|
||||
|
||||
proc expandTilde*(path: string): string {.
|
||||
@@ -1186,7 +1186,7 @@ proc findExe*(exe: string, followSymlinks: bool = true;
|
||||
if '/' in exe: checkCurrentDir()
|
||||
else:
|
||||
checkCurrentDir()
|
||||
let path = string(getEnv("PATH"))
|
||||
let path = getEnv("PATH")
|
||||
for candidate in split(path, PathSep):
|
||||
if candidate.len == 0: continue
|
||||
when defined(windows):
|
||||
@@ -2936,7 +2936,7 @@ when not weirdTarget and defined(openbsd):
|
||||
|
||||
# POSIX guaranties that this contains the executable
|
||||
# as it has been executed by the calling process
|
||||
let exePath = string(paramStr(0))
|
||||
let exePath = paramStr(0)
|
||||
|
||||
if len(exePath) == 0:
|
||||
return ""
|
||||
@@ -2955,7 +2955,7 @@ when not weirdTarget and defined(openbsd):
|
||||
return expandFilename(result)
|
||||
|
||||
# search in path
|
||||
for p in split(string(getEnv("PATH")), {PathSep}):
|
||||
for p in split(getEnv("PATH"), {PathSep}):
|
||||
var x = joinPath(p, exePath)
|
||||
if fileExists(x):
|
||||
return expandFilename(x)
|
||||
@@ -2965,12 +2965,12 @@ when not weirdTarget and defined(openbsd):
|
||||
when not (defined(windows) or defined(macosx) or weirdTarget):
|
||||
proc getApplHeuristic(): string =
|
||||
when declared(paramStr):
|
||||
result = string(paramStr(0))
|
||||
result = paramStr(0)
|
||||
# POSIX guaranties that this contains the executable
|
||||
# as it has been executed by the calling process
|
||||
if len(result) > 0 and result[0] != DirSep: # not an absolute path?
|
||||
# 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)
|
||||
if fileExists(x): return x
|
||||
else:
|
||||
|
||||
@@ -514,8 +514,8 @@ when not defined(useNimRtl):
|
||||
while true:
|
||||
# FIXME: converts CR-LF to LF.
|
||||
if outp.readLine(line):
|
||||
result.string.add(line.string)
|
||||
result.string.add("\n")
|
||||
result.add(line)
|
||||
result.add("\n")
|
||||
elif not running(p): break
|
||||
close(p)
|
||||
|
||||
@@ -932,7 +932,7 @@ elif not defined(useNimRtl):
|
||||
result = cast[cstringArray](alloc0((counter + 1) * sizeof(cstring)))
|
||||
var i = 0
|
||||
for key, val in envPairs():
|
||||
var x = key.string & "=" & val.string
|
||||
var x = key & "=" & val
|
||||
result[i] = cast[cstring](alloc(x.len+1))
|
||||
copyMem(result[i], addr(x[0]), x.len+1)
|
||||
inc(i)
|
||||
@@ -1623,8 +1623,8 @@ proc execCmdEx*(command: string, options: set[ProcessOption] = {
|
||||
var line = newStringOfCap(120)
|
||||
while true:
|
||||
if outp.readLine(line):
|
||||
result[0].string.add(line.string)
|
||||
result[0].string.add("\n")
|
||||
result[0].add(line)
|
||||
result[0].add("\n")
|
||||
else:
|
||||
result[1] = peekExitCode(p)
|
||||
if result[1] != -1: break
|
||||
|
||||
@@ -228,7 +228,7 @@ when declared(os.paramCount):
|
||||
else:
|
||||
result.cmds = newSeq[string](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.key = ""
|
||||
@@ -261,11 +261,11 @@ when declared(os.paramCount):
|
||||
if cmdline.len != 0:
|
||||
result.cmds = newSeq[string](cmdline.len)
|
||||
for i in 0..<cmdline.len:
|
||||
result.cmds[i] = cmdline[i].string
|
||||
result.cmds[i] = cmdline[i]
|
||||
else:
|
||||
result.cmds = newSeq[string](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.key = ""
|
||||
result.val = ""
|
||||
@@ -274,14 +274,14 @@ proc handleShortOption(p: var OptParser; cmd: string) =
|
||||
var i = p.pos
|
||||
p.kind = cmdShortOption
|
||||
if i < cmd.len:
|
||||
add(p.key.string, cmd[i])
|
||||
add(p.key, cmd[i])
|
||||
inc(i)
|
||||
p.inShortState = true
|
||||
while i < cmd.len and cmd[i] in {'\t', ' '}:
|
||||
inc(i)
|
||||
p.inShortState = false
|
||||
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 {':', '='}:
|
||||
inc(i)
|
||||
p.inShortState = false
|
||||
@@ -319,8 +319,8 @@ proc next*(p: var OptParser) {.rtl, extern: "npo$1".} =
|
||||
var i = p.pos
|
||||
while i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {'\t', ' '}: inc(i)
|
||||
p.pos = i
|
||||
setLen(p.key.string, 0)
|
||||
setLen(p.val.string, 0)
|
||||
setLen(p.key, 0)
|
||||
setLen(p.val, 0)
|
||||
if p.inShortState:
|
||||
p.inShortState = false
|
||||
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] == '-':
|
||||
p.kind = cmdLongOption
|
||||
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)
|
||||
if i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {':', '='}:
|
||||
inc(i)
|
||||
@@ -350,7 +350,7 @@ proc next*(p: var OptParser) {.rtl, extern: "npo$1".} =
|
||||
i = 0
|
||||
if p.idx < p.cmds.len:
|
||||
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]
|
||||
inc p.idx
|
||||
else:
|
||||
|
||||
@@ -1332,7 +1332,7 @@ when not defined(js):
|
||||
## error occurs. This is supposed to be used for quick scripting.
|
||||
##
|
||||
## **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))
|
||||
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ proc debugRecv*(smtp: Smtp | AsyncSmtp): Future[string] {.multisync.} =
|
||||
|
||||
result = await smtp.sock.recvLine()
|
||||
if smtp.debug:
|
||||
echo("S:" & result.string)
|
||||
echo("S:" & result)
|
||||
|
||||
proc quitExcpt(smtp: Smtp, msg: string) =
|
||||
smtp.debugSend("QUIT")
|
||||
|
||||
@@ -924,7 +924,7 @@ proc readStrPrivate(s: Stream, length: int, str: var string) =
|
||||
when defined(js):
|
||||
let L = readData(s, addr(str), length)
|
||||
else:
|
||||
let L = readData(s, cstring(str.string), length)
|
||||
let L = readData(s, cstring(str), length)
|
||||
if L != len(str): setLen(str, L)
|
||||
|
||||
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):
|
||||
let L = peekData(s, addr(str), length)
|
||||
else:
|
||||
let L = peekData(s, cstring(str.string), length)
|
||||
let L = peekData(s, cstring(str), length)
|
||||
if L != len(str): setLen(str, L)
|
||||
|
||||
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
|
||||
|
||||
let n = s.buffer.len
|
||||
line.string.setLen(0)
|
||||
line.setLen(0)
|
||||
for i in 0..<n:
|
||||
var c = s.buffer.popFirst
|
||||
if c == '\c':
|
||||
@@ -40,7 +40,7 @@ proc posReadLine[T](s: Stream, line: var string): bool =
|
||||
elif c == '\L': return true
|
||||
elif c == '\0':
|
||||
return line.len > 0
|
||||
line.string.add(c)
|
||||
line.add(c)
|
||||
|
||||
var line2: string
|
||||
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):
|
||||
result = ""
|
||||
else:
|
||||
if useEnvironment in flags: result = getEnv(key).string
|
||||
if useEnvironment in flags: result = getEnv(key)
|
||||
else: result = ""
|
||||
if result.len == 0:
|
||||
if useKey in flags: result = '$' & key
|
||||
|
||||
@@ -253,7 +253,7 @@ else:
|
||||
discard close(fd)
|
||||
if w > 0: return w
|
||||
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 80 #Finally default to venerable value
|
||||
|
||||
@@ -271,7 +271,7 @@ else:
|
||||
discard close(fd)
|
||||
if h > 0: return h
|
||||
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 0 # Could not determine height
|
||||
|
||||
@@ -776,7 +776,7 @@ when defined(windows):
|
||||
## Reads a `password` from stdin without printing it. `password` must not
|
||||
## be ``nil``! Returns ``false`` if the end of the file has been reached,
|
||||
## ``true`` otherwise.
|
||||
password.string.setLen(0)
|
||||
password.setLen(0)
|
||||
stdout.write(prompt)
|
||||
let hi = createFileA("CONIN$",
|
||||
GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, 0, 0)
|
||||
@@ -799,7 +799,7 @@ else:
|
||||
|
||||
proc readPasswordFromStdin*(prompt: string, password: var string):
|
||||
bool {.tags: [ReadIOEffect, WriteIOEffect].} =
|
||||
password.string.setLen(0)
|
||||
password.setLen(0)
|
||||
let fd = stdin.getFileHandle()
|
||||
var cur, old: Termios
|
||||
discard fd.tcGetAttr(cur.addr)
|
||||
@@ -882,7 +882,7 @@ proc enableTrueColors*() =
|
||||
else:
|
||||
term.trueColorIsEnabled = true
|
||||
else:
|
||||
term.trueColorIsSupported = string(getEnv("COLORTERM")).toLowerAscii() in [
|
||||
term.trueColorIsSupported = getEnv("COLORTERM").toLowerAscii() in [
|
||||
"truecolor", "24bit"]
|
||||
term.trueColorIsEnabled = term.trueColorIsSupported
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ proc loadUnidecodeTable*(datafile = "unidecode.dat") =
|
||||
newSeq(translationTable, 0xffff)
|
||||
var i = 0
|
||||
for line in lines(datafile):
|
||||
translationTable[i] = line.string
|
||||
translationTable[i] = line
|
||||
inc(i)
|
||||
|
||||
proc unidecode*(s: string): string =
|
||||
|
||||
@@ -151,7 +151,7 @@ type
|
||||
region: MemRegion
|
||||
PRawChannel = ptr RawChannel
|
||||
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
|
||||
|
||||
@@ -248,7 +248,7 @@ when not usesDestructors:
|
||||
dstseq.reserved = seq.len
|
||||
for i in 0..seq.len-1:
|
||||
storeAux(
|
||||
cast[pointer](dst +% align(GenericSeqSize, mt.base.align) +% i*% mt.base.size),
|
||||
cast[pointer](dst +% align(GenericSeqSize, mt.base.align) +% i *% mt.base.size),
|
||||
cast[pointer](cast[ByteAddress](s2) +% align(GenericSeqSize, mt.base.align) +%
|
||||
i *% mt.base.size),
|
||||
mt.base, t, mode)
|
||||
@@ -265,8 +265,8 @@ when not usesDestructors:
|
||||
storeAux(dest, src, mt.node, t, mode)
|
||||
of tyArray, tyArrayConstr:
|
||||
for i in 0..(mt.size div mt.base.size)-1:
|
||||
storeAux(cast[pointer](d +% i*% mt.base.size),
|
||||
cast[pointer](s +% i*% mt.base.size), mt.base, t, mode)
|
||||
storeAux(cast[pointer](d +% i *% mt.base.size),
|
||||
cast[pointer](s +% i *% mt.base.size), mt.base, t, mode)
|
||||
of tyRef:
|
||||
var s = cast[PPointer](src)[]
|
||||
var x = cast[PPointer](dest)
|
||||
|
||||
@@ -434,19 +434,19 @@ proc readLine*(f: File, line: var string): bool {.tags: [ReadIOEffect],
|
||||
var pos = 0
|
||||
|
||||
# Use the currently reserved space for a first try
|
||||
var sp = max(line.string.len, 80)
|
||||
line.string.setLen(sp)
|
||||
var sp = max(line.len, 80)
|
||||
line.setLen(sp)
|
||||
|
||||
while true:
|
||||
# memset to \L so that we can tell how far fgets wrote, even on EOF, where
|
||||
# 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
|
||||
while true:
|
||||
# fixes #9634; this pattern may need to be abstracted as a template if reused;
|
||||
# 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
|
||||
when not defined(NimScript):
|
||||
if errno == EINTR:
|
||||
@@ -456,20 +456,20 @@ proc readLine*(f: File, line: var string): bool {.tags: [ReadIOEffect],
|
||||
checkErr(f)
|
||||
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:
|
||||
# \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])
|
||||
if last > 0 and line.string[last-1] == '\c':
|
||||
line.string.setLen(last-1)
|
||||
var last = cast[ByteAddress](m) - cast[ByteAddress](addr line[0])
|
||||
if last > 0 and line[last-1] == '\c':
|
||||
line.setLen(last-1)
|
||||
return last > 1 or fgetsSuccess
|
||||
# We have to distinguish between two possible cases:
|
||||
# \0\l\0 => line ending in a null character.
|
||||
# \0\l\l => last line without newline, null was put there by fgets.
|
||||
elif last > 0 and line.string[last-1] == '\0':
|
||||
if last < pos + sp - 1 and line.string[last+1] != '\0':
|
||||
elif last > 0 and line[last-1] == '\0':
|
||||
if last < pos + sp - 1 and line[last+1] != '\0':
|
||||
dec last
|
||||
line.string.setLen(last)
|
||||
line.setLen(last)
|
||||
return last > 0 or fgetsSuccess
|
||||
else:
|
||||
# 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
|
||||
inc pos, sp
|
||||
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.} =
|
||||
## reads a line of text from the file `f`. May throw an IO exception.
|
||||
|
||||
Reference in New Issue
Block a user