case consistency part 1
This commit is contained in:
parent
9e92455a53
commit
2df9b442c6
88 changed files with 1266 additions and 1144 deletions
|
|
@ -50,7 +50,7 @@ proc mustRehash(length, counter: int): bool {.inline.} =
|
|||
proc nextTry(h, maxHash: THash): THash {.inline.} =
|
||||
result = ((5 * h) + 1) and maxHash
|
||||
|
||||
proc IntSetGet(t: TIntSet, key: int): PTrunk =
|
||||
proc intSetGet(t: TIntSet, key: int): PTrunk =
|
||||
var h = key and t.max
|
||||
while t.data[h] != nil:
|
||||
if t.data[h].key == key:
|
||||
|
|
@ -58,7 +58,7 @@ proc IntSetGet(t: TIntSet, key: int): PTrunk =
|
|||
h = nextTry(h, t.max)
|
||||
result = nil
|
||||
|
||||
proc IntSetRawInsert(t: TIntSet, data: var TTrunkSeq, desc: PTrunk) =
|
||||
proc intSetRawInsert(t: TIntSet, data: var TTrunkSeq, desc: PTrunk) =
|
||||
var h = desc.key and t.max
|
||||
while data[h] != nil:
|
||||
assert(data[h] != desc)
|
||||
|
|
@ -66,7 +66,7 @@ proc IntSetRawInsert(t: TIntSet, data: var TTrunkSeq, desc: PTrunk) =
|
|||
assert(data[h] == nil)
|
||||
data[h] = desc
|
||||
|
||||
proc IntSetEnlarge(t: var TIntSet) =
|
||||
proc intSetEnlarge(t: var TIntSet) =
|
||||
var n: TTrunkSeq
|
||||
var oldMax = t.max
|
||||
t.max = ((t.max + 1) * 2) - 1
|
||||
|
|
@ -75,7 +75,7 @@ proc IntSetEnlarge(t: var TIntSet) =
|
|||
if t.data[i] != nil: IntSetRawInsert(t, n, t.data[i])
|
||||
swap(t.data, n)
|
||||
|
||||
proc IntSetPut(t: var TIntSet, key: int): PTrunk =
|
||||
proc intSetPut(t: var TIntSet, key: int): PTrunk =
|
||||
var h = key and t.max
|
||||
while t.data[h] != nil:
|
||||
if t.data[h].key == key:
|
||||
|
|
|
|||
|
|
@ -41,19 +41,19 @@ type
|
|||
|
||||
proc initSinglyLinkedList*[T](): TSinglyLinkedList[T] =
|
||||
## creates a new singly linked list that is empty.
|
||||
nil
|
||||
discard
|
||||
|
||||
proc initDoublyLinkedList*[T](): TDoublyLinkedList[T] =
|
||||
## creates a new doubly linked list that is empty.
|
||||
nil
|
||||
discard
|
||||
|
||||
proc initSinglyLinkedRing*[T](): TSinglyLinkedRing[T] =
|
||||
## creates a new singly linked ring that is empty.
|
||||
nil
|
||||
discard
|
||||
|
||||
proc initDoublyLinkedRing*[T](): TDoublyLinkedRing[T] =
|
||||
## creates a new doubly linked ring that is empty.
|
||||
nil
|
||||
discard
|
||||
|
||||
proc newDoublyLinkedNode*[T](value: T): PDoublyLinkedNode[T] =
|
||||
## creates a new doubly linked node with the given `value`.
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ template rawInsertImpl() {.dirty.} =
|
|||
data[h].val = val
|
||||
data[h].slot = seFilled
|
||||
|
||||
proc RawGet[A, B](t: TTable[A, B], key: A): int =
|
||||
proc rawGet[A, B](t: TTable[A, B], key: A): int =
|
||||
rawGetImpl()
|
||||
|
||||
proc `[]`*[A, B](t: TTable[A, B], key: A): B =
|
||||
|
|
@ -93,13 +93,13 @@ proc `[]`*[A, B](t: TTable[A, B], key: A): B =
|
|||
## default empty value for the type `B` is returned
|
||||
## and no exception is raised. One can check with ``hasKey`` whether the key
|
||||
## exists.
|
||||
var index = RawGet(t, key)
|
||||
var index = rawGet(t, key)
|
||||
if index >= 0: result = t.data[index].val
|
||||
|
||||
proc mget*[A, B](t: var TTable[A, B], key: A): var B =
|
||||
## retrieves the value at ``t[key]``. The value can be modified.
|
||||
## If `key` is not in `t`, the ``EInvalidKey`` exception is raised.
|
||||
var index = RawGet(t, key)
|
||||
var index = rawGet(t, key)
|
||||
if index >= 0: result = t.data[index].val
|
||||
else: raise newException(EInvalidKey, "key not found: " & $key)
|
||||
|
||||
|
|
@ -107,39 +107,39 @@ proc hasKey*[A, B](t: TTable[A, B], key: A): bool =
|
|||
## returns true iff `key` is in the table `t`.
|
||||
result = rawGet(t, key) >= 0
|
||||
|
||||
proc RawInsert[A, B](t: var TTable[A, B], data: var TKeyValuePairSeq[A, B],
|
||||
proc rawInsert[A, B](t: var TTable[A, B], data: var TKeyValuePairSeq[A, B],
|
||||
key: A, val: B) =
|
||||
rawInsertImpl()
|
||||
|
||||
proc Enlarge[A, B](t: var TTable[A, B]) =
|
||||
proc enlarge[A, B](t: var TTable[A, B]) =
|
||||
var n: TKeyValuePairSeq[A, B]
|
||||
newSeq(n, len(t.data) * growthFactor)
|
||||
for i in countup(0, high(t.data)):
|
||||
if t.data[i].slot == seFilled: RawInsert(t, n, t.data[i].key, t.data[i].val)
|
||||
if t.data[i].slot == seFilled: rawInsert(t, n, t.data[i].key, t.data[i].val)
|
||||
swap(t.data, n)
|
||||
|
||||
template AddImpl() {.dirty.} =
|
||||
if mustRehash(len(t.data), t.counter): Enlarge(t)
|
||||
RawInsert(t, t.data, key, val)
|
||||
template addImpl() {.dirty.} =
|
||||
if mustRehash(len(t.data), t.counter): enlarge(t)
|
||||
rawInsert(t, t.data, key, val)
|
||||
inc(t.counter)
|
||||
|
||||
template PutImpl() {.dirty.} =
|
||||
var index = RawGet(t, key)
|
||||
template putImpl() {.dirty.} =
|
||||
var index = rawGet(t, key)
|
||||
if index >= 0:
|
||||
t.data[index].val = val
|
||||
else:
|
||||
AddImpl()
|
||||
addImpl()
|
||||
|
||||
when false:
|
||||
# not yet used:
|
||||
template HasKeyOrPutImpl() {.dirty.} =
|
||||
var index = RawGet(t, key)
|
||||
template hasKeyOrPutImpl() {.dirty.} =
|
||||
var index = rawGet(t, key)
|
||||
if index >= 0:
|
||||
t.data[index].val = val
|
||||
result = true
|
||||
else:
|
||||
if mustRehash(len(t.data), t.counter): Enlarge(t)
|
||||
RawInsert(t, t.data, key, val)
|
||||
if mustRehash(len(t.data), t.counter): enlarge(t)
|
||||
rawInsert(t, t.data, key, val)
|
||||
inc(t.counter)
|
||||
result = false
|
||||
|
||||
|
|
@ -149,11 +149,11 @@ proc `[]=`*[A, B](t: var TTable[A, B], key: A, val: B) =
|
|||
|
||||
proc add*[A, B](t: var TTable[A, B], key: A, val: B) =
|
||||
## puts a new (key, value)-pair into `t` even if ``t[key]`` already exists.
|
||||
AddImpl()
|
||||
addImpl()
|
||||
|
||||
proc del*[A, B](t: var TTable[A, B], key: A) =
|
||||
## deletes `key` from hash table `t`.
|
||||
var index = RawGet(t, key)
|
||||
var index = rawGet(t, key)
|
||||
if index >= 0:
|
||||
t.data[index].slot = seDeleted
|
||||
dec(t.counter)
|
||||
|
|
@ -240,7 +240,7 @@ iterator mvalues*[A, B](t: var TOrderedTable[A, B]): var B =
|
|||
forAllOrderedPairs:
|
||||
yield t.data[h].val
|
||||
|
||||
proc RawGet[A, B](t: TOrderedTable[A, B], key: A): int =
|
||||
proc rawGet[A, B](t: TOrderedTable[A, B], key: A): int =
|
||||
rawGetImpl()
|
||||
|
||||
proc `[]`*[A, B](t: TOrderedTable[A, B], key: A): B =
|
||||
|
|
@ -248,13 +248,13 @@ proc `[]`*[A, B](t: TOrderedTable[A, B], key: A): B =
|
|||
## default empty value for the type `B` is returned
|
||||
## and no exception is raised. One can check with ``hasKey`` whether the key
|
||||
## exists.
|
||||
var index = RawGet(t, key)
|
||||
var index = rawGet(t, key)
|
||||
if index >= 0: result = t.data[index].val
|
||||
|
||||
proc mget*[A, B](t: var TOrderedTable[A, B], key: A): var B =
|
||||
## retrieves the value at ``t[key]``. The value can be modified.
|
||||
## If `key` is not in `t`, the ``EInvalidKey`` exception is raised.
|
||||
var index = RawGet(t, key)
|
||||
var index = rawGet(t, key)
|
||||
if index >= 0: result = t.data[index].val
|
||||
else: raise newException(EInvalidKey, "key not found: " & $key)
|
||||
|
||||
|
|
@ -262,7 +262,7 @@ proc hasKey*[A, B](t: TOrderedTable[A, B], key: A): bool =
|
|||
## returns true iff `key` is in the table `t`.
|
||||
result = rawGet(t, key) >= 0
|
||||
|
||||
proc RawInsert[A, B](t: var TOrderedTable[A, B],
|
||||
proc rawInsert[A, B](t: var TOrderedTable[A, B],
|
||||
data: var TOrderedKeyValuePairSeq[A, B],
|
||||
key: A, val: B) =
|
||||
rawInsertImpl()
|
||||
|
|
@ -271,7 +271,7 @@ proc RawInsert[A, B](t: var TOrderedTable[A, B],
|
|||
if t.last >= 0: data[t.last].next = h
|
||||
t.last = h
|
||||
|
||||
proc Enlarge[A, B](t: var TOrderedTable[A, B]) =
|
||||
proc enlarge[A, B](t: var TOrderedTable[A, B]) =
|
||||
var n: TOrderedKeyValuePairSeq[A, B]
|
||||
newSeq(n, len(t.data) * growthFactor)
|
||||
var h = t.first
|
||||
|
|
@ -280,7 +280,7 @@ proc Enlarge[A, B](t: var TOrderedTable[A, B]) =
|
|||
while h >= 0:
|
||||
var nxt = t.data[h].next
|
||||
if t.data[h].slot == seFilled:
|
||||
RawInsert(t, n, t.data[h].key, t.data[h].val)
|
||||
rawInsert(t, n, t.data[h].key, t.data[h].val)
|
||||
h = nxt
|
||||
swap(t.data, n)
|
||||
|
||||
|
|
@ -290,7 +290,7 @@ proc `[]=`*[A, B](t: var TOrderedTable[A, B], key: A, val: B) =
|
|||
|
||||
proc add*[A, B](t: var TOrderedTable[A, B], key: A, val: B) =
|
||||
## puts a new (key, value)-pair into `t` even if ``t[key]`` already exists.
|
||||
AddImpl()
|
||||
addImpl()
|
||||
|
||||
proc initOrderedTable*[A, B](initialSize=64): TOrderedTable[A, B] =
|
||||
## creates a new ordered hash table that is empty.
|
||||
|
|
@ -398,7 +398,7 @@ iterator mvalues*[A](t: TCountTable[A]): var int =
|
|||
for h in 0..high(t.data):
|
||||
if t.data[h].val != 0: yield t.data[h].val
|
||||
|
||||
proc RawGet[A](t: TCountTable[A], key: A): int =
|
||||
proc rawGet[A](t: TCountTable[A], key: A): int =
|
||||
var h: THash = hash(key) and high(t.data) # start with real hash value
|
||||
while t.data[h].val != 0:
|
||||
if t.data[h].key == key: return h
|
||||
|
|
@ -409,13 +409,13 @@ proc `[]`*[A](t: TCountTable[A], key: A): int =
|
|||
## retrieves the value at ``t[key]``. If `key` is not in `t`,
|
||||
## 0 is returned. One can check with ``hasKey`` whether the key
|
||||
## exists.
|
||||
var index = RawGet(t, key)
|
||||
var index = rawGet(t, key)
|
||||
if index >= 0: result = t.data[index].val
|
||||
|
||||
proc mget*[A](t: var TCountTable[A], key: A): var int =
|
||||
## retrieves the value at ``t[key]``. The value can be modified.
|
||||
## If `key` is not in `t`, the ``EInvalidKey`` exception is raised.
|
||||
var index = RawGet(t, key)
|
||||
var index = rawGet(t, key)
|
||||
if index >= 0: result = t.data[index].val
|
||||
else: raise newException(EInvalidKey, "key not found: " & $key)
|
||||
|
||||
|
|
@ -423,24 +423,24 @@ proc hasKey*[A](t: TCountTable[A], key: A): bool =
|
|||
## returns true iff `key` is in the table `t`.
|
||||
result = rawGet(t, key) >= 0
|
||||
|
||||
proc RawInsert[A](t: TCountTable[A], data: var seq[tuple[key: A, val: int]],
|
||||
proc rawInsert[A](t: TCountTable[A], data: var seq[tuple[key: A, val: int]],
|
||||
key: A, val: int) =
|
||||
var h: THash = hash(key) and high(data)
|
||||
while data[h].val != 0: h = nextTry(h, high(data))
|
||||
data[h].key = key
|
||||
data[h].val = val
|
||||
|
||||
proc Enlarge[A](t: var TCountTable[A]) =
|
||||
proc enlarge[A](t: var TCountTable[A]) =
|
||||
var n: seq[tuple[key: A, val: int]]
|
||||
newSeq(n, len(t.data) * growthFactor)
|
||||
for i in countup(0, high(t.data)):
|
||||
if t.data[i].val != 0: RawInsert(t, n, t.data[i].key, t.data[i].val)
|
||||
if t.data[i].val != 0: rawInsert(t, n, t.data[i].key, t.data[i].val)
|
||||
swap(t.data, n)
|
||||
|
||||
proc `[]=`*[A](t: var TCountTable[A], key: A, val: int) =
|
||||
## puts a (key, value)-pair into `t`. `val` has to be positive.
|
||||
assert val > 0
|
||||
PutImpl()
|
||||
putImpl()
|
||||
|
||||
proc initCountTable*[A](initialSize=64): TCountTable[A] =
|
||||
## creates a new count table that is empty.
|
||||
|
|
@ -467,11 +467,11 @@ proc inc*[A](t: var TCountTable[A], key: A, val = 1) =
|
|||
if index >= 0:
|
||||
inc(t.data[index].val, val)
|
||||
else:
|
||||
if mustRehash(len(t.data), t.counter): Enlarge(t)
|
||||
RawInsert(t, t.data, key, val)
|
||||
if mustRehash(len(t.data), t.counter): enlarge(t)
|
||||
rawInsert(t, t.data, key, val)
|
||||
inc(t.counter)
|
||||
|
||||
proc Smallest*[A](t: TCountTable[A]): tuple[key: A, val: int] =
|
||||
proc smallest*[A](t: TCountTable[A]): tuple[key: A, val: int] =
|
||||
## returns the largest (key,val)-pair. Efficiency: O(n)
|
||||
assert t.len > 0
|
||||
var minIdx = 0
|
||||
|
|
@ -480,7 +480,7 @@ proc Smallest*[A](t: TCountTable[A]): tuple[key: A, val: int] =
|
|||
result.key = t.data[minIdx].key
|
||||
result.val = t.data[minIdx].val
|
||||
|
||||
proc Largest*[A](t: TCountTable[A]): tuple[key: A, val: int] =
|
||||
proc largest*[A](t: TCountTable[A]): tuple[key: A, val: int] =
|
||||
## returns the (key,val)-pair with the largest `val`. Efficiency: O(n)
|
||||
assert t.len > 0
|
||||
var maxIdx = 0
|
||||
|
|
|
|||
|
|
@ -48,11 +48,11 @@ proc getCurrentLine*(L: TBaseLexer, marker: bool = true): string
|
|||
proc getColNumber*(L: TBaseLexer, pos: int): int
|
||||
## retrieves the current column.
|
||||
|
||||
proc HandleCR*(L: var TBaseLexer, pos: int): int
|
||||
proc handleCR*(L: var TBaseLexer, pos: int): int
|
||||
## Call this if you scanned over '\c' in the buffer; it returns the the
|
||||
## position to continue the scanning from. `pos` must be the position
|
||||
## of the '\c'.
|
||||
proc HandleLF*(L: var TBaseLexer, pos: int): int
|
||||
proc handleLF*(L: var TBaseLexer, pos: int): int
|
||||
## Call this if you scanned over '\L' in the buffer; it returns the the
|
||||
## position to continue the scanning from. `pos` must be the position
|
||||
## of the '\L'.
|
||||
|
|
@ -66,7 +66,7 @@ proc close(L: var TBaseLexer) =
|
|||
dealloc(L.buf)
|
||||
close(L.input)
|
||||
|
||||
proc FillBuffer(L: var TBaseLexer) =
|
||||
proc fillBuffer(L: var TBaseLexer) =
|
||||
var
|
||||
charsRead, toCopy, s: int # all are in characters,
|
||||
# not bytes (in case this
|
||||
|
|
@ -78,7 +78,7 @@ proc FillBuffer(L: var TBaseLexer) =
|
|||
toCopy = L.BufLen - L.sentinel - 1
|
||||
assert(toCopy >= 0)
|
||||
if toCopy > 0:
|
||||
MoveMem(L.buf, addr(L.buf[L.sentinel + 1]), toCopy * chrSize)
|
||||
moveMem(L.buf, addr(L.buf[L.sentinel + 1]), toCopy * chrSize)
|
||||
# "moveMem" handles overlapping regions
|
||||
charsRead = readData(L.input, addr(L.buf[toCopy]),
|
||||
(L.sentinel + 1) * chrSize) div chrSize
|
||||
|
|
@ -103,7 +103,7 @@ proc FillBuffer(L: var TBaseLexer) =
|
|||
L.bufLen = L.BufLen * 2
|
||||
L.buf = cast[cstring](realloc(L.buf, L.bufLen * chrSize))
|
||||
assert(L.bufLen - oldBuflen == oldBufLen)
|
||||
charsRead = ReadData(L.input, addr(L.buf[oldBufLen]),
|
||||
charsRead = readData(L.input, addr(L.buf[oldBufLen]),
|
||||
oldBufLen * chrSize) div chrSize
|
||||
if charsRead < oldBufLen:
|
||||
L.buf[oldBufLen + charsRead] = EndOfFile
|
||||
|
|
@ -121,19 +121,19 @@ proc fillBaseLexer(L: var TBaseLexer, pos: int): int =
|
|||
result = 0
|
||||
L.lineStart = result
|
||||
|
||||
proc HandleCR(L: var TBaseLexer, pos: int): int =
|
||||
proc handleCR(L: var TBaseLexer, pos: int): int =
|
||||
assert(L.buf[pos] == '\c')
|
||||
inc(L.linenumber)
|
||||
result = fillBaseLexer(L, pos)
|
||||
if L.buf[result] == '\L':
|
||||
result = fillBaseLexer(L, result)
|
||||
|
||||
proc HandleLF(L: var TBaseLexer, pos: int): int =
|
||||
proc handleLF(L: var TBaseLexer, pos: int): int =
|
||||
assert(L.buf[pos] == '\L')
|
||||
inc(L.linenumber)
|
||||
result = fillBaseLexer(L, pos) #L.lastNL := result-1; // BUGFIX: was: result;
|
||||
|
||||
proc skip_UTF_8_BOM(L: var TBaseLexer) =
|
||||
proc skipUtf8Bom(L: var TBaseLexer) =
|
||||
if (L.buf[0] == '\xEF') and (L.buf[1] == '\xBB') and (L.buf[2] == '\xBF'):
|
||||
inc(L.bufpos, 3)
|
||||
inc(L.lineStart, 3)
|
||||
|
|
@ -149,7 +149,7 @@ proc open(L: var TBaseLexer, input: PStream, bufLen: int = 8192) =
|
|||
L.lineStart = 0
|
||||
L.linenumber = 1 # lines start at 1
|
||||
fillBuffer(L)
|
||||
skip_UTF_8_BOM(L)
|
||||
skipUtf8Bom(L)
|
||||
|
||||
proc getColNumber(L: TBaseLexer, pos: int): int =
|
||||
result = abs(pos - L.lineStart)
|
||||
|
|
|
|||
190
lib/pure/os.nim
190
lib/pure/os.nim
|
|
@ -93,11 +93,11 @@ when defined(Nimdoc): # only for proper documentation:
|
|||
|
||||
elif defined(macos):
|
||||
const
|
||||
curdir* = ':'
|
||||
pardir* = "::"
|
||||
dirsep* = ':'
|
||||
altsep* = dirsep
|
||||
pathsep* = ','
|
||||
CurDir* = ':'
|
||||
ParDir* = "::"
|
||||
Dirsep* = ':'
|
||||
Altsep* = dirsep
|
||||
Pathsep* = ','
|
||||
FileSystemCaseSensitive* = false
|
||||
ExeExt* = ""
|
||||
ScriptExt* = ""
|
||||
|
|
@ -123,42 +123,42 @@ elif defined(macos):
|
|||
# grandparent etc.
|
||||
elif doslike:
|
||||
const
|
||||
curdir* = '.'
|
||||
pardir* = ".."
|
||||
dirsep* = '\\' # seperator within paths
|
||||
altsep* = '/'
|
||||
pathSep* = ';' # seperator between paths
|
||||
Curdir* = '.'
|
||||
Pardir* = ".."
|
||||
Dirsep* = '\\' # seperator within paths
|
||||
Altsep* = '/'
|
||||
PathSep* = ';' # seperator between paths
|
||||
FileSystemCaseSensitive* = false
|
||||
ExeExt* = "exe"
|
||||
ScriptExt* = "bat"
|
||||
DynlibFormat* = "$1.dll"
|
||||
elif defined(PalmOS) or defined(MorphOS):
|
||||
const
|
||||
dirsep* = '/'
|
||||
altsep* = dirsep
|
||||
Dirsep* = '/'
|
||||
Altsep* = dirsep
|
||||
PathSep* = ';'
|
||||
pardir* = ".."
|
||||
Pardir* = ".."
|
||||
FileSystemCaseSensitive* = false
|
||||
ExeExt* = ""
|
||||
ScriptExt* = ""
|
||||
DynlibFormat* = "$1.prc"
|
||||
elif defined(RISCOS):
|
||||
const
|
||||
dirsep* = '.'
|
||||
altsep* = '.'
|
||||
pardir* = ".." # is this correct?
|
||||
pathSep* = ','
|
||||
Dirsep* = '.'
|
||||
Altsep* = '.'
|
||||
Pardir* = ".." # is this correct?
|
||||
PathSep* = ','
|
||||
FileSystemCaseSensitive* = true
|
||||
ExeExt* = ""
|
||||
ScriptExt* = ""
|
||||
DynlibFormat* = "lib$1.so"
|
||||
else: # UNIX-like operating system
|
||||
const
|
||||
curdir* = '.'
|
||||
pardir* = ".."
|
||||
dirsep* = '/'
|
||||
altsep* = dirsep
|
||||
pathSep* = ':'
|
||||
Curdir* = '.'
|
||||
Pardir* = ".."
|
||||
Dirsep* = '/'
|
||||
Altsep* = dirsep
|
||||
PathSep* = ':'
|
||||
FileSystemCaseSensitive* = true
|
||||
ExeExt* = ""
|
||||
ScriptExt* = ""
|
||||
|
|
@ -186,20 +186,20 @@ proc OSErrorMsg*(): string {.rtl, extern: "nos$1", deprecated.} =
|
|||
|
||||
result = ""
|
||||
when defined(Windows):
|
||||
var err = GetLastError()
|
||||
var err = getLastError()
|
||||
if err != 0'i32:
|
||||
when useWinUnicode:
|
||||
var msgbuf: widecstring
|
||||
if FormatMessageW(0x00000100 or 0x00001000 or 0x00000200,
|
||||
if formatMessageW(0x00000100 or 0x00001000 or 0x00000200,
|
||||
nil, err, 0, addr(msgbuf), 0, nil) != 0'i32:
|
||||
result = $msgbuf
|
||||
if msgbuf != nil: LocalFree(cast[pointer](msgbuf))
|
||||
if msgbuf != nil: localFree(cast[pointer](msgbuf))
|
||||
else:
|
||||
var msgbuf: cstring
|
||||
if FormatMessageA(0x00000100 or 0x00001000 or 0x00000200,
|
||||
if formatMessageA(0x00000100 or 0x00001000 or 0x00000200,
|
||||
nil, err, 0, addr(msgbuf), 0, nil) != 0'i32:
|
||||
result = $msgbuf
|
||||
if msgbuf != nil: LocalFree(msgbuf)
|
||||
if msgbuf != nil: localFree(msgbuf)
|
||||
if errno != 0'i32:
|
||||
result = $os.strerror(errno)
|
||||
|
||||
|
|
@ -238,16 +238,16 @@ proc OSErrorMsg*(errorCode: TOSErrorCode): string =
|
|||
if errorCode != TOSErrorCode(0'i32):
|
||||
when useWinUnicode:
|
||||
var msgbuf: widecstring
|
||||
if FormatMessageW(0x00000100 or 0x00001000 or 0x00000200,
|
||||
if formatMessageW(0x00000100 or 0x00001000 or 0x00000200,
|
||||
nil, errorCode.int32, 0, addr(msgbuf), 0, nil) != 0'i32:
|
||||
result = $msgbuf
|
||||
if msgbuf != nil: LocalFree(cast[pointer](msgbuf))
|
||||
if msgbuf != nil: localFree(cast[pointer](msgbuf))
|
||||
else:
|
||||
var msgbuf: cstring
|
||||
if FormatMessageA(0x00000100 or 0x00001000 or 0x00000200,
|
||||
if formatMessageA(0x00000100 or 0x00001000 or 0x00000200,
|
||||
nil, errorCode.int32, 0, addr(msgbuf), 0, nil) != 0'i32:
|
||||
result = $msgbuf
|
||||
if msgbuf != nil: LocalFree(msgbuf)
|
||||
if msgbuf != nil: localFree(msgbuf)
|
||||
else:
|
||||
if errorCode != TOSErrorCode(0'i32):
|
||||
result = $os.strerror(errorCode.int32)
|
||||
|
|
@ -287,7 +287,7 @@ proc OSLastError*(): TOSErrorCode =
|
|||
result = TOSErrorCode(errno)
|
||||
{.pop.}
|
||||
|
||||
proc UnixToNativePath*(path: string): string {.
|
||||
proc unixToNativePath*(path: string): string {.
|
||||
noSideEffect, rtl, extern: "nos$1".} =
|
||||
## Converts an UNIX-like path to a native one.
|
||||
##
|
||||
|
|
@ -340,16 +340,16 @@ when defined(windows):
|
|||
|
||||
template wrapBinary(varname, winApiProc, arg, arg2: expr) {.immediate.} =
|
||||
var varname = winApiProc(newWideCString(arg), arg2)
|
||||
proc FindFirstFile(a: string, b: var TWIN32_FIND_DATA): THandle =
|
||||
result = FindFirstFileW(newWideCString(a), b)
|
||||
template FindNextFile(a, b: expr): expr = FindNextFileW(a, b)
|
||||
proc findFirstFile(a: string, b: var TWIN32_FIND_DATA): THandle =
|
||||
result = findFirstFileW(newWideCString(a), b)
|
||||
template findNextFile(a, b: expr): expr = findNextFileW(a, b)
|
||||
template getCommandLine(): expr = getCommandLineW()
|
||||
|
||||
template getFilename(f: expr): expr =
|
||||
$cast[WideCString](addr(f.cFilename[0]))
|
||||
else:
|
||||
template FindFirstFile(a, b: expr): expr = FindFirstFileA(a, b)
|
||||
template FindNextFile(a, b: expr): expr = FindNextFileA(a, b)
|
||||
template findFirstFile(a, b: expr): expr = findFirstFileA(a, b)
|
||||
template findNextFile(a, b: expr): expr = findNextFileA(a, b)
|
||||
template getCommandLine(): expr = getCommandLineA()
|
||||
|
||||
template getFilename(f: expr): expr = $f.cFilename
|
||||
|
|
@ -364,9 +364,9 @@ proc existsFile*(filename: string): bool {.rtl, extern: "nos$1",
|
|||
## Returns true if the file exists, false otherwise.
|
||||
when defined(windows):
|
||||
when useWinUnicode:
|
||||
wrapUnary(a, GetFileAttributesW, filename)
|
||||
wrapUnary(a, getFileAttributesW, filename)
|
||||
else:
|
||||
var a = GetFileAttributesA(filename)
|
||||
var a = getFileAttributesA(filename)
|
||||
if a != -1'i32:
|
||||
result = (a and FILE_ATTRIBUTE_DIRECTORY) == 0'i32
|
||||
else:
|
||||
|
|
@ -378,9 +378,9 @@ proc existsDir*(dir: string): bool {.rtl, extern: "nos$1", tags: [FReadDir].} =
|
|||
## is returned.
|
||||
when defined(windows):
|
||||
when useWinUnicode:
|
||||
wrapUnary(a, GetFileAttributesW, dir)
|
||||
wrapUnary(a, getFileAttributesW, dir)
|
||||
else:
|
||||
var a = GetFileAttributesA(dir)
|
||||
var a = getFileAttributesA(dir)
|
||||
if a != -1'i32:
|
||||
result = (a and FILE_ATTRIBUTE_DIRECTORY) != 0'i32
|
||||
else:
|
||||
|
|
@ -395,7 +395,7 @@ proc getLastModificationTime*(file: string): TTime {.rtl, extern: "nos$1".} =
|
|||
return res.st_mtime
|
||||
else:
|
||||
var f: TWIN32_Find_Data
|
||||
var h = findfirstFile(file, f)
|
||||
var h = findFirstFile(file, f)
|
||||
if h == -1'i32: OSError(OSLastError())
|
||||
result = winTimeToUnixTime(rdFileTime(f.ftLastWriteTime))
|
||||
findclose(h)
|
||||
|
|
@ -408,7 +408,7 @@ proc getLastAccessTime*(file: string): TTime {.rtl, extern: "nos$1".} =
|
|||
return res.st_atime
|
||||
else:
|
||||
var f: TWIN32_Find_Data
|
||||
var h = findfirstFile(file, f)
|
||||
var h = findFirstFile(file, f)
|
||||
if h == -1'i32: OSError(OSLastError())
|
||||
result = winTimeToUnixTime(rdFileTime(f.ftLastAccessTime))
|
||||
findclose(h)
|
||||
|
|
@ -421,7 +421,7 @@ proc getCreationTime*(file: string): TTime {.rtl, extern: "nos$1".} =
|
|||
return res.st_ctime
|
||||
else:
|
||||
var f: TWIN32_Find_Data
|
||||
var h = findfirstFile(file, f)
|
||||
var h = findFirstFile(file, f)
|
||||
if h == -1'i32: OSError(OSLastError())
|
||||
result = winTimeToUnixTime(rdFileTime(f.ftCreationTime))
|
||||
findclose(h)
|
||||
|
|
@ -437,12 +437,12 @@ proc getCurrentDir*(): string {.rtl, extern: "nos$1", tags: [].} =
|
|||
when defined(windows):
|
||||
when useWinUnicode:
|
||||
var res = newWideCString("", bufsize)
|
||||
var L = GetCurrentDirectoryW(bufsize, res)
|
||||
var L = getCurrentDirectoryW(bufsize, res)
|
||||
if L == 0'i32: OSError(OSLastError())
|
||||
result = res$L
|
||||
else:
|
||||
result = newString(bufsize)
|
||||
var L = GetCurrentDirectoryA(bufsize, result)
|
||||
var L = getCurrentDirectoryA(bufsize, result)
|
||||
if L == 0'i32: OSError(OSLastError())
|
||||
setLen(result, L)
|
||||
else:
|
||||
|
|
@ -457,10 +457,10 @@ proc setCurrentDir*(newDir: string) {.inline, tags: [].} =
|
|||
## `newDir` cannot been set.
|
||||
when defined(Windows):
|
||||
when useWinUnicode:
|
||||
if SetCurrentDirectoryW(newWideCString(newDir)) == 0'i32:
|
||||
if setCurrentDirectoryW(newWideCString(newDir)) == 0'i32:
|
||||
OSError(OSLastError())
|
||||
else:
|
||||
if SetCurrentDirectoryA(newDir) == 0'i32: OSError(OSLastError())
|
||||
if setCurrentDirectoryA(newDir) == 0'i32: OSError(OSLastError())
|
||||
else:
|
||||
if chdir(newDir) != 0'i32: OSError(OSLastError())
|
||||
|
||||
|
|
@ -512,7 +512,7 @@ proc joinPath*(parts: varargs[string]): string {.noSideEffect,
|
|||
result = joinPath(result, parts[i])
|
||||
|
||||
proc `/` * (head, tail: string): string {.noSideEffect.} =
|
||||
## The same as ``JoinPath(head, tail)``
|
||||
## The same as ``joinPath(head, tail)``
|
||||
##
|
||||
## Here are some examples for Unix:
|
||||
##
|
||||
|
|
@ -526,7 +526,7 @@ proc `/` * (head, tail: string): string {.noSideEffect.} =
|
|||
proc splitPath*(path: string): tuple[head, tail: string] {.
|
||||
noSideEffect, rtl, extern: "nos$1".} =
|
||||
## Splits a directory into (head, tail), so that
|
||||
## ``JoinPath(head, tail) == path``.
|
||||
## ``joinPath(head, tail) == path``.
|
||||
##
|
||||
## Examples:
|
||||
##
|
||||
|
|
@ -672,14 +672,14 @@ proc expandFilename*(filename: string): string {.rtl, extern: "nos$1",
|
|||
when useWinUnicode:
|
||||
var unused: widecstring
|
||||
var res = newWideCString("", bufsize div 2)
|
||||
var L = GetFullPathNameW(newWideCString(filename), bufsize, res, unused)
|
||||
var L = getFullPathNameW(newWideCString(filename), bufsize, res, unused)
|
||||
if L <= 0'i32 or L >= bufsize:
|
||||
OSError(OSLastError())
|
||||
result = res$L
|
||||
else:
|
||||
var unused: cstring
|
||||
result = newString(bufsize)
|
||||
var L = GetFullPathNameA(filename, bufsize, result, unused)
|
||||
var L = getFullPathNameA(filename, bufsize, result, unused)
|
||||
if L <= 0'i32 or L >= bufsize: OSError(OSLastError())
|
||||
setLen(result, L)
|
||||
else:
|
||||
|
|
@ -758,29 +758,29 @@ proc sameFile*(path1, path2: string): bool {.rtl, extern: "nos$1",
|
|||
when useWinUnicode:
|
||||
var p1 = newWideCString(path1)
|
||||
var p2 = newWideCString(path2)
|
||||
template OpenHandle(path: expr): expr =
|
||||
CreateFileW(path, 0'i32, FILE_SHARE_DELETE or FILE_SHARE_READ or
|
||||
template openHandle(path: expr): expr =
|
||||
createFileW(path, 0'i32, FILE_SHARE_DELETE or FILE_SHARE_READ or
|
||||
FILE_SHARE_WRITE, nil, OPEN_EXISTING,
|
||||
FILE_FLAG_BACKUP_SEMANTICS or FILE_ATTRIBUTE_NORMAL, 0)
|
||||
|
||||
var f1 = OpenHandle(p1)
|
||||
var f2 = OpenHandle(p2)
|
||||
var f1 = openHandle(p1)
|
||||
var f2 = openHandle(p2)
|
||||
|
||||
else:
|
||||
template OpenHandle(path: expr): expr =
|
||||
CreateFileA(path, 0'i32, FILE_SHARE_DELETE or FILE_SHARE_READ or
|
||||
template openHandle(path: expr): expr =
|
||||
createFileA(path, 0'i32, FILE_SHARE_DELETE or FILE_SHARE_READ or
|
||||
FILE_SHARE_WRITE, nil, OPEN_EXISTING,
|
||||
FILE_FLAG_BACKUP_SEMANTICS or FILE_ATTRIBUTE_NORMAL, 0)
|
||||
|
||||
var f1 = OpenHandle(path1)
|
||||
var f2 = OpenHandle(path2)
|
||||
var f1 = openHandle(path1)
|
||||
var f2 = openHandle(path2)
|
||||
|
||||
var lastErr: TOSErrorCode
|
||||
if f1 != INVALID_HANDLE_VALUE and f2 != INVALID_HANDLE_VALUE:
|
||||
var fi1, fi2: TBY_HANDLE_FILE_INFORMATION
|
||||
|
||||
if GetFileInformationByHandle(f1, addr(fi1)) != 0 and
|
||||
GetFileInformationByHandle(f2, addr(fi2)) != 0:
|
||||
if getFileInformationByHandle(f1, addr(fi1)) != 0 and
|
||||
getFileInformationByHandle(f2, addr(fi2)) != 0:
|
||||
result = fi1.dwVolumeSerialNumber == fi2.dwVolumeSerialNumber and
|
||||
fi1.nFileIndexHigh == fi2.nFileIndexHigh and
|
||||
fi1.nFileIndexLow == fi2.nFileIndexLow
|
||||
|
|
@ -791,8 +791,8 @@ proc sameFile*(path1, path2: string): bool {.rtl, extern: "nos$1",
|
|||
lastErr = OSLastError()
|
||||
success = false
|
||||
|
||||
discard CloseHandle(f1)
|
||||
discard CloseHandle(f2)
|
||||
discard closeHandle(f1)
|
||||
discard closeHandle(f2)
|
||||
|
||||
if not success: OSError(lastErr)
|
||||
else:
|
||||
|
|
@ -867,9 +867,9 @@ proc getFilePermissions*(filename: string): set[TFilePermission] {.
|
|||
if (a.st_mode and S_IXOTH) != 0'i32: result.incl(fpOthersExec)
|
||||
else:
|
||||
when useWinUnicode:
|
||||
wrapUnary(res, GetFileAttributesW, filename)
|
||||
wrapUnary(res, getFileAttributesW, filename)
|
||||
else:
|
||||
var res = GetFileAttributesA(filename)
|
||||
var res = getFileAttributesA(filename)
|
||||
if res == -1'i32: OSError(OSLastError())
|
||||
if (res and FILE_ATTRIBUTE_READONLY) != 0'i32:
|
||||
result = {fpUserExec, fpUserRead, fpGroupExec, fpGroupRead,
|
||||
|
|
@ -899,18 +899,18 @@ proc setFilePermissions*(filename: string, permissions: set[TFilePermission]) {.
|
|||
if chmod(filename, p) != 0: OSError(OSLastError())
|
||||
else:
|
||||
when useWinUnicode:
|
||||
wrapUnary(res, GetFileAttributesW, filename)
|
||||
wrapUnary(res, getFileAttributesW, filename)
|
||||
else:
|
||||
var res = GetFileAttributesA(filename)
|
||||
var res = getFileAttributesA(filename)
|
||||
if res == -1'i32: OSError(OSLastError())
|
||||
if fpUserWrite in permissions:
|
||||
res = res and not FILE_ATTRIBUTE_READONLY
|
||||
else:
|
||||
res = res or FILE_ATTRIBUTE_READONLY
|
||||
when useWinUnicode:
|
||||
wrapBinary(res2, SetFileAttributesW, filename, res)
|
||||
wrapBinary(res2, setFileAttributesW, filename, res)
|
||||
else:
|
||||
var res2 = SetFileAttributesA(filename, res)
|
||||
var res2 = setFileAttributesA(filename, res)
|
||||
if res2 == - 1'i32: OSError(OSLastError())
|
||||
|
||||
proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
|
||||
|
|
@ -928,9 +928,9 @@ proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
|
|||
when useWinUnicode:
|
||||
let s = newWideCString(source)
|
||||
let d = newWideCString(dest)
|
||||
if CopyFileW(s, d, 0'i32) == 0'i32: OSError(OSLastError())
|
||||
if copyFileW(s, d, 0'i32) == 0'i32: OSError(OSLastError())
|
||||
else:
|
||||
if CopyFileA(source, dest, 0'i32) == 0'i32: OSError(OSLastError())
|
||||
if copyFileA(source, dest, 0'i32) == 0'i32: OSError(OSLastError())
|
||||
else:
|
||||
# generic version of copyFile which works for any platform:
|
||||
const bufSize = 8000 # better for memory manager
|
||||
|
|
@ -940,7 +940,7 @@ proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
|
|||
close(s)
|
||||
OSError(OSLastError())
|
||||
var buf = alloc(bufsize)
|
||||
while True:
|
||||
while true:
|
||||
var bytesread = readBuffer(s, buf, bufsize)
|
||||
if bytesread > 0:
|
||||
var byteswritten = writeBuffer(d, buf, bytesread)
|
||||
|
|
@ -968,13 +968,13 @@ when not defined(ENOENT) and not defined(Windows):
|
|||
|
||||
when defined(Windows):
|
||||
when useWinUnicode:
|
||||
template DeleteFile(file: expr): expr {.immediate.} = DeleteFileW(file)
|
||||
template SetFileAttributes(file, attrs: expr): expr {.immediate.} =
|
||||
SetFileAttributesW(file, attrs)
|
||||
template deleteFile(file: expr): expr {.immediate.} = deleteFileW(file)
|
||||
template setFileAttributes(file, attrs: expr): expr {.immediate.} =
|
||||
setFileAttributesW(file, attrs)
|
||||
else:
|
||||
template DeleteFile(file: expr): expr {.immediate.} = DeleteFileA(file)
|
||||
template SetFileAttributes(file, attrs: expr): expr {.immediate.} =
|
||||
SetFileAttributesA(file, attrs)
|
||||
template deleteFile(file: expr): expr {.immediate.} = deleteFileA(file)
|
||||
template setFileAttributes(file, attrs: expr): expr {.immediate.} =
|
||||
setFileAttributesA(file, attrs)
|
||||
|
||||
proc removeFile*(file: string) {.rtl, extern: "nos$1", tags: [FWriteDir].} =
|
||||
## Removes the `file`. If this fails, `EOS` is raised. This does not fail
|
||||
|
|
@ -985,11 +985,11 @@ proc removeFile*(file: string) {.rtl, extern: "nos$1", tags: [FWriteDir].} =
|
|||
let f = newWideCString(file)
|
||||
else:
|
||||
let f = file
|
||||
if DeleteFile(f) == 0:
|
||||
if GetLastError() == ERROR_ACCESS_DENIED:
|
||||
if SetFileAttributes(f, FILE_ATTRIBUTE_NORMAL) == 0:
|
||||
if deleteFile(f) == 0:
|
||||
if getLastError() == ERROR_ACCESS_DENIED:
|
||||
if setFileAttributes(f, FILE_ATTRIBUTE_NORMAL) == 0:
|
||||
OSError(OSLastError())
|
||||
if DeleteFile(f) == 0:
|
||||
if deleteFile(f) == 0:
|
||||
OSError(OSLastError())
|
||||
else:
|
||||
if cremove(file) != 0'i32 and errno != ENOENT:
|
||||
|
|
@ -1076,7 +1076,7 @@ else:
|
|||
when useNSGetEnviron:
|
||||
var gEnv = NSGetEnviron()[]
|
||||
var i = 0
|
||||
while True:
|
||||
while true:
|
||||
if gEnv[i] == nil: break
|
||||
add environment, $gEnv[i]
|
||||
inc(i)
|
||||
|
|
@ -1130,9 +1130,9 @@ proc putEnv*(key, val: string) {.tags: [FWriteEnv].} =
|
|||
when useWinUnicode:
|
||||
var k = newWideCString(key)
|
||||
var v = newWideCString(val)
|
||||
if SetEnvironmentVariableW(k, v) == 0'i32: OSError(OSLastError())
|
||||
if setEnvironmentVariableW(k, v) == 0'i32: OSError(OSLastError())
|
||||
else:
|
||||
if SetEnvironmentVariableA(key, val) == 0'i32: OSError(OSLastError())
|
||||
if setEnvironmentVariableA(key, val) == 0'i32: OSError(OSLastError())
|
||||
|
||||
iterator envPairs*(): tuple[key, value: TaintedString] {.tags: [FReadEnv].} =
|
||||
## Iterate over all `environments variables`:idx:. In the first component
|
||||
|
|
@ -1259,9 +1259,9 @@ iterator walkDirRec*(dir: string, filter={pcFile, pcDir}): string {.
|
|||
proc rawRemoveDir(dir: string) =
|
||||
when defined(windows):
|
||||
when useWinUnicode:
|
||||
wrapUnary(res, RemoveDirectoryW, dir)
|
||||
wrapUnary(res, removeDirectoryW, dir)
|
||||
else:
|
||||
var res = RemoveDirectoryA(dir)
|
||||
var res = removeDirectoryA(dir)
|
||||
let lastError = OSLastError()
|
||||
if res == 0'i32 and lastError.int32 != 3'i32 and
|
||||
lastError.int32 != 18'i32 and lastError.int32 != 2'i32:
|
||||
|
|
@ -1291,10 +1291,10 @@ proc rawCreateDir(dir: string) =
|
|||
OSError(OSLastError())
|
||||
else:
|
||||
when useWinUnicode:
|
||||
wrapUnary(res, CreateDirectoryW, dir)
|
||||
wrapUnary(res, createDirectoryW, dir)
|
||||
else:
|
||||
var res = CreateDirectoryA(dir)
|
||||
if res == 0'i32 and GetLastError() != 183'i32:
|
||||
var res = createDirectoryA(dir)
|
||||
if res == 0'i32 and getLastError() != 183'i32:
|
||||
OSError(OSLastError())
|
||||
|
||||
proc createDir*(dir: string) {.rtl, extern: "nos$1", tags: [FWriteDir].} =
|
||||
|
|
@ -1584,8 +1584,8 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [FReadIO].} =
|
|||
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}):
|
||||
var x = JoinPath(p, result)
|
||||
if ExistsFile(x): return x
|
||||
var x = joinPath(p, result)
|
||||
if existsFile(x): return x
|
||||
|
||||
proc getApplicationFilename*(): string {.rtl, extern: "nos$1", deprecated.} =
|
||||
## Returns the filename of the application's executable.
|
||||
|
|
@ -1636,11 +1636,11 @@ proc findExe*(exe: string): string {.tags: [FReadDir, FReadEnv].} =
|
|||
## Returns "" if the `exe` cannot be found. On DOS-like platforms, `exe`
|
||||
## is added an ``.exe`` file extension if it has no extension.
|
||||
result = addFileExt(exe, os.exeExt)
|
||||
if ExistsFile(result): return
|
||||
if existsFile(result): return
|
||||
var path = string(os.getEnv("PATH"))
|
||||
for candidate in split(path, pathSep):
|
||||
var x = candidate / result
|
||||
if ExistsFile(x): return x
|
||||
if existsFile(x): return x
|
||||
result = ""
|
||||
|
||||
proc expandTilde*(path: string): string =
|
||||
|
|
|
|||
|
|
@ -383,16 +383,16 @@ when defined(Windows) and not defined(useNimRtl):
|
|||
# O_WRONLY {.importc: "_O_WRONLY", header: "<fcntl.h>".}: int
|
||||
# O_RDONLY {.importc: "_O_RDONLY", header: "<fcntl.h>".}: int
|
||||
|
||||
proc CreatePipeHandles(Rdhandle, WrHandle: var THandle) =
|
||||
proc createPipeHandles(Rdhandle, WrHandle: var THandle) =
|
||||
var piInheritablePipe: TSecurityAttributes
|
||||
piInheritablePipe.nlength = SizeOF(TSecurityAttributes).cint
|
||||
piInheritablePipe.nlength = SizeOf(TSecurityAttributes).cint
|
||||
piInheritablePipe.lpSecurityDescriptor = nil
|
||||
piInheritablePipe.Binherithandle = 1
|
||||
if CreatePipe(Rdhandle, Wrhandle, piInheritablePipe, 1024) == 0'i32:
|
||||
if createPipe(Rdhandle, Wrhandle, piInheritablePipe, 1024) == 0'i32:
|
||||
OSError(OSLastError())
|
||||
|
||||
proc fileClose(h: THandle) {.inline.} =
|
||||
if h > 4: discard CloseHandle(h)
|
||||
if h > 4: discard closeHandle(h)
|
||||
|
||||
proc startProcess(command: string,
|
||||
workingDir: string = "",
|
||||
|
|
@ -400,8 +400,8 @@ when defined(Windows) and not defined(useNimRtl):
|
|||
env: PStringTable = nil,
|
||||
options: set[TProcessOption] = {poStdErrToStdOut}): PProcess =
|
||||
var
|
||||
SI: TStartupInfo
|
||||
ProcInfo: TProcessInformation
|
||||
si: TStartupInfo
|
||||
procInfo: TProcessInformation
|
||||
success: int
|
||||
hi, ho, he: THandle
|
||||
new(result)
|
||||
|
|
@ -511,8 +511,8 @@ when defined(Windows) and not defined(useNimRtl):
|
|||
|
||||
proc execCmd(command: string): int =
|
||||
var
|
||||
SI: TStartupInfo
|
||||
ProcInfo: TProcessInformation
|
||||
si: TStartupInfo
|
||||
procInfo: TProcessInformation
|
||||
process: THandle
|
||||
L: int32
|
||||
SI.cb = SizeOf(SI).cint
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ proc parseHex*(s: string, number: var int, start = 0): int {.
|
|||
elif s[i] == '#': inc(i)
|
||||
while true:
|
||||
case s[i]
|
||||
of '_': nil
|
||||
of '_': discard
|
||||
of '0'..'9':
|
||||
number = number shl 4 or (ord(s[i]) - ord('0'))
|
||||
foundDigit = true
|
||||
|
|
@ -74,7 +74,7 @@ proc parseOct*(s: string, number: var int, start = 0): int {.
|
|||
if s[i] == '0' and (s[i+1] == 'o' or s[i+1] == 'O'): inc(i, 2)
|
||||
while true:
|
||||
case s[i]
|
||||
of '_': nil
|
||||
of '_': discard
|
||||
of '0'..'7':
|
||||
number = number shl 3 or (ord(s[i]) - ord('0'))
|
||||
foundDigit = true
|
||||
|
|
|
|||
|
|
@ -132,17 +132,17 @@ type
|
|||
ETimeout* = object of ESynch
|
||||
|
||||
let
|
||||
InvalidSocket*: TSocket = nil ## invalid socket
|
||||
invalidSocket*: TSocket = nil ## invalid socket
|
||||
|
||||
when defined(windows):
|
||||
let
|
||||
OSInvalidSocket = winlean.INVALID_SOCKET
|
||||
osInvalidSocket = winlean.INVALID_SOCKET
|
||||
else:
|
||||
let
|
||||
OSInvalidSocket = posix.INVALID_SOCKET
|
||||
osInvalidSocket = posix.INVALID_SOCKET
|
||||
|
||||
proc newTSocket(fd: TSocketHandle, isBuff: bool): TSocket =
|
||||
if fd == OSInvalidSocket:
|
||||
if fd == osInvalidSocket:
|
||||
return nil
|
||||
new(result)
|
||||
result.fd = fd
|
||||
|
|
@ -187,14 +187,14 @@ proc htons*(x: int16): int16 =
|
|||
result = sockets.ntohs(x)
|
||||
|
||||
when defined(Posix):
|
||||
proc ToInt(domain: TDomain): cint =
|
||||
proc toInt(domain: TDomain): cint =
|
||||
case domain
|
||||
of AF_UNIX: result = posix.AF_UNIX
|
||||
of AF_INET: result = posix.AF_INET
|
||||
of AF_INET6: result = posix.AF_INET6
|
||||
else: nil
|
||||
|
||||
proc ToInt(typ: TType): cint =
|
||||
proc toInt(typ: TType): cint =
|
||||
case typ
|
||||
of SOCK_STREAM: result = posix.SOCK_STREAM
|
||||
of SOCK_DGRAM: result = posix.SOCK_DGRAM
|
||||
|
|
@ -202,7 +202,7 @@ when defined(Posix):
|
|||
of SOCK_RAW: result = posix.SOCK_RAW
|
||||
else: nil
|
||||
|
||||
proc ToInt(p: TProtocol): cint =
|
||||
proc toInt(p: TProtocol): cint =
|
||||
case p
|
||||
of IPPROTO_TCP: result = posix.IPPROTO_TCP
|
||||
of IPPROTO_UDP: result = posix.IPPROTO_UDP
|
||||
|
|
@ -216,10 +216,10 @@ else:
|
|||
proc toInt(domain: TDomain): cint =
|
||||
result = toU16(ord(domain))
|
||||
|
||||
proc ToInt(typ: TType): cint =
|
||||
proc toInt(typ: TType): cint =
|
||||
result = cint(ord(typ))
|
||||
|
||||
proc ToInt(p: TProtocol): cint =
|
||||
proc toInt(p: TProtocol): cint =
|
||||
result = cint(ord(p))
|
||||
|
||||
proc socket*(domain: TDomain = AF_INET, typ: TType = SOCK_STREAM,
|
||||
|
|
@ -333,7 +333,7 @@ when defined(ssl):
|
|||
if SSLSetFd(socket.sslHandle, socket.fd) != 1:
|
||||
SSLError()
|
||||
|
||||
proc SocketError*(socket: TSocket, err: int = -1, async = false) =
|
||||
proc socketError*(socket: TSocket, err: int = -1, async = false) =
|
||||
## Raises proper errors based on return values of ``recv`` functions.
|
||||
##
|
||||
## If ``async`` is ``True`` no error will be thrown in the case when the
|
||||
|
|
@ -471,7 +471,7 @@ template acceptAddrPlain(noClientRet, successRet: expr,
|
|||
var sock = accept(server.fd, cast[ptr TSockAddr](addr(sockAddress)),
|
||||
addr(addrLen))
|
||||
|
||||
if sock == OSInvalidSocket:
|
||||
if sock == osInvalidSocket:
|
||||
let err = OSLastError()
|
||||
when defined(windows):
|
||||
if err.int32 == WSAEINPROGRESS:
|
||||
|
|
@ -1661,7 +1661,7 @@ when defined(Windows):
|
|||
proc setBlocking(s: TSocket, blocking: bool) =
|
||||
when defined(Windows):
|
||||
var mode = clong(ord(not blocking)) # 1 for non-blocking, 0 for blocking
|
||||
if ioctlsocket(TSocketHandle(s.fd), FIONBIO, addr(mode)) == -1:
|
||||
if ioctlsocket(s.fd, FIONBIO, addr(mode)) == -1:
|
||||
OSError(OSLastError())
|
||||
else: # BSD sockets
|
||||
var x: int = fcntl(s.fd, F_GETFL, 0)
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ proc mustRehash(length, counter: int): bool =
|
|||
proc nextTry(h, maxHash: THash): THash {.inline.} =
|
||||
result = ((5 * h) + 1) and maxHash
|
||||
|
||||
proc RawGet(t: PStringTable, key: string): int =
|
||||
proc rawGet(t: PStringTable, key: string): int =
|
||||
var h: THash = myhash(t, key) and high(t.data) # start with real hash value
|
||||
while not isNil(t.data[h].key):
|
||||
if mycmp(t, t.data[h].key, key):
|
||||
|
|
@ -116,14 +116,14 @@ proc hasKey*(t: PStringTable, key: string): bool {.rtl, extern: "nst$1".} =
|
|||
## returns true iff `key` is in the table `t`.
|
||||
result = rawGet(t, key) >= 0
|
||||
|
||||
proc RawInsert(t: PStringTable, data: var TKeyValuePairSeq, key, val: string) =
|
||||
proc rawInsert(t: PStringTable, data: var TKeyValuePairSeq, key, val: string) =
|
||||
var h: THash = myhash(t, key) and high(data)
|
||||
while not isNil(data[h].key):
|
||||
h = nextTry(h, high(data))
|
||||
data[h].key = key
|
||||
data[h].val = val
|
||||
|
||||
proc Enlarge(t: PStringTable) =
|
||||
proc enlarge(t: PStringTable) =
|
||||
var n: TKeyValuePairSeq
|
||||
newSeq(n, len(t.data) * growthFactor)
|
||||
for i in countup(0, high(t.data)):
|
||||
|
|
@ -140,7 +140,7 @@ proc `[]=`*(t: PStringTable, key, val: string) {.rtl, extern: "nstPut".} =
|
|||
RawInsert(t, t.data, key, val)
|
||||
inc(t.counter)
|
||||
|
||||
proc RaiseFormatException(s: string) =
|
||||
proc raiseFormatException(s: string) =
|
||||
var e: ref EInvalidValue
|
||||
new(e)
|
||||
e.msg = "format string: key not found: " & s
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ proc cmpIgnoreStyle*(a, b: string): int {.noSideEffect,
|
|||
## | > 0 iff a > b
|
||||
var i = 0
|
||||
var j = 0
|
||||
while True:
|
||||
while true:
|
||||
while a[i] == '_': inc(i)
|
||||
while b[j] == '_': inc(j) # BUGFIX: typo
|
||||
var aa = toLower(a[i])
|
||||
|
|
@ -344,7 +344,7 @@ proc intToStr*(x: int, minchars: int = 1): string {.noSideEffect,
|
|||
if x < 0:
|
||||
result = '-' & result
|
||||
|
||||
proc ParseInt*(s: string): int {.noSideEffect, procvar,
|
||||
proc parseInt*(s: string): int {.noSideEffect, procvar,
|
||||
rtl, extern: "nsuParseInt".} =
|
||||
## Parses a decimal integer value contained in `s`. If `s` is not
|
||||
## a valid integer, `EInvalidValue` is raised.
|
||||
|
|
@ -352,7 +352,7 @@ proc ParseInt*(s: string): int {.noSideEffect, procvar,
|
|||
if L != s.len or L == 0:
|
||||
raise newException(EInvalidValue, "invalid integer: " & s)
|
||||
|
||||
proc ParseBiggestInt*(s: string): biggestInt {.noSideEffect, procvar,
|
||||
proc parseBiggestInt*(s: string): biggestInt {.noSideEffect, procvar,
|
||||
rtl, extern: "nsuParseBiggestInt".} =
|
||||
## Parses a decimal integer value contained in `s`. If `s` is not
|
||||
## a valid integer, `EInvalidValue` is raised.
|
||||
|
|
@ -360,7 +360,7 @@ proc ParseBiggestInt*(s: string): biggestInt {.noSideEffect, procvar,
|
|||
if L != s.len or L == 0:
|
||||
raise newException(EInvalidValue, "invalid integer: " & s)
|
||||
|
||||
proc ParseFloat*(s: string): float {.noSideEffect, procvar,
|
||||
proc parseFloat*(s: string): float {.noSideEffect, procvar,
|
||||
rtl, extern: "nsuParseFloat".} =
|
||||
## Parses a decimal floating point value contained in `s`. If `s` is not
|
||||
## a valid floating point number, `EInvalidValue` is raised. ``NAN``,
|
||||
|
|
@ -369,7 +369,7 @@ proc ParseFloat*(s: string): float {.noSideEffect, procvar,
|
|||
if L != s.len or L == 0:
|
||||
raise newException(EInvalidValue, "invalid float: " & s)
|
||||
|
||||
proc ParseHexInt*(s: string): int {.noSideEffect, procvar,
|
||||
proc parseHexInt*(s: string): int {.noSideEffect, procvar,
|
||||
rtl, extern: "nsuParseHexInt".} =
|
||||
## Parses a hexadecimal integer value contained in `s`. If `s` is not
|
||||
## a valid integer, `EInvalidValue` is raised. `s` can have one of the
|
||||
|
|
@ -455,7 +455,7 @@ proc align*(s: string, count: int, padding = ' '): string {.
|
|||
## assert align("1232", 6, '#') == "##1232"
|
||||
if s.len < count:
|
||||
result = newString(count)
|
||||
var spaces = count - s.len
|
||||
let spaces = count - s.len
|
||||
for i in 0..spaces-1: result[i] = padding
|
||||
for i in spaces..count-1: result[i] = s[i-spaces]
|
||||
else:
|
||||
|
|
@ -649,7 +649,7 @@ proc join*(a: openArray[string]): string {.
|
|||
result = ""
|
||||
|
||||
type
|
||||
TSkipTable = array[Char, int]
|
||||
TSkipTable = array[char, int]
|
||||
|
||||
proc preprocessSub(sub: string, a: var TSkipTable) =
|
||||
var m = len(sub)
|
||||
|
|
@ -795,7 +795,7 @@ proc delete*(s: var string, first, last: int) {.noSideEffect,
|
|||
inc(j)
|
||||
setlen(s, newLen)
|
||||
|
||||
proc ParseOctInt*(s: string): int {.noSideEffect,
|
||||
proc parseOctInt*(s: string): int {.noSideEffect,
|
||||
rtl, extern: "nsuParseOctInt".} =
|
||||
## Parses an octal integer value contained in `s`. If `s` is not
|
||||
## a valid integer, `EInvalidValue` is raised. `s` can have one of the
|
||||
|
|
@ -896,7 +896,7 @@ proc unescape*(s: string, prefix = "\"", suffix = "\""): string {.noSideEffect,
|
|||
raise newException(EInvalidValue,
|
||||
"String does not start with a prefix of: " & prefix)
|
||||
i.inc()
|
||||
while True:
|
||||
while true:
|
||||
if i == s.len-suffix.len: break
|
||||
case s[i]
|
||||
of '\\':
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ proc getGMTime*(t: TTime): TTimeInfo {.tags: [FTime], raises: [].}
|
|||
## converts the calendar time `t` to broken-down time representation,
|
||||
## expressed in Coordinated Universal Time (UTC).
|
||||
|
||||
proc TimeInfoToTime*(timeInfo: TTimeInfo): TTime {.tags: [].}
|
||||
proc timeInfoToTime*(timeInfo: TTimeInfo): TTime {.tags: [].}
|
||||
## converts a broken-down time structure to
|
||||
## calendar time representation. The function ignores the specified
|
||||
## contents of the structure members `weekday` and `yearday` and recomputes
|
||||
|
|
@ -297,7 +297,7 @@ when not defined(JS):
|
|||
when not defined(JS):
|
||||
# C wrapper:
|
||||
type
|
||||
structTM {.importc: "struct tm", final.} = object
|
||||
StructTM {.importc: "struct tm", final.} = object
|
||||
second {.importc: "tm_sec".},
|
||||
minute {.importc: "tm_min".},
|
||||
hour {.importc: "tm_hour".},
|
||||
|
|
@ -308,7 +308,7 @@ when not defined(JS):
|
|||
yearday {.importc: "tm_yday".},
|
||||
isdst {.importc: "tm_isdst".}: cint
|
||||
|
||||
PTimeInfo = ptr structTM
|
||||
PTimeInfo = ptr StructTM
|
||||
PTime = ptr TTime
|
||||
|
||||
TClock {.importc: "clock_t".} = distinct int
|
||||
|
|
@ -401,7 +401,7 @@ when not defined(JS):
|
|||
# copying is needed anyway to provide reentrancity; thus
|
||||
# the conversion is not expensive
|
||||
|
||||
proc TimeInfoToTime(timeInfo: TTimeInfo): TTime =
|
||||
proc timeInfoToTime(timeInfo: TTimeInfo): TTime =
|
||||
var cTimeInfo = timeInfo # for C++ we have to make a copy,
|
||||
# because the header of mktime is broken in my version of libc
|
||||
return mktime(timeInfoToTM(cTimeInfo))
|
||||
|
|
@ -498,7 +498,7 @@ elif defined(JS):
|
|||
result.weekday = weekDays[t.getUTCDay()]
|
||||
result.yearday = 0
|
||||
|
||||
proc TimeInfoToTime*(timeInfo: TTimeInfo): TTime =
|
||||
proc timeInfoToTime*(timeInfo: TTimeInfo): TTime =
|
||||
result = internGetTime()
|
||||
result.setSeconds(timeInfo.second)
|
||||
result.setMinutes(timeInfo.minute)
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@
|
|||
include "system/inclrtl"
|
||||
|
||||
type
|
||||
irune = int # underlying type of TRune
|
||||
TRune* = distinct irune ## type that can hold any Unicode character
|
||||
IRune = int # underlying type of TRune
|
||||
TRune* = distinct IRune ## type that can hold any Unicode character
|
||||
TRune16* = distinct int16 ## 16 bit Unicode character
|
||||
|
||||
proc `<=%`*(a, b: TRune): bool = return int(a) <=% int(b)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue