diff options
author | Araq <rumpf_a@web.de> | 2019-07-10 19:17:06 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2019-07-10 19:17:06 +0200 |
commit | 87a2ced1baec059922a567e2000c0fe16cc1db52 (patch) | |
tree | 7f29bfe00f2b0b26dce69593e0cfe47d47b177e2 /lib | |
parent | 73cc029fec8ff52ace34cc94ccee0ff89e975862 (diff) | |
download | Nim-87a2ced1baec059922a567e2000c0fe16cc1db52.tar.gz |
there is only one style -- my style
Diffstat (limited to 'lib')
-rw-r--r-- | lib/packages/docutils/rstgen.nim | 32 | ||||
-rw-r--r-- | lib/posix/termios.nim | 6 | ||||
-rw-r--r-- | lib/pure/ioselects/ioselectors_epoll.nim | 22 | ||||
-rw-r--r-- | lib/pure/nativesockets.nim | 12 | ||||
-rw-r--r-- | lib/pure/net.nim | 5 | ||||
-rw-r--r-- | lib/pure/terminal.nim | 32 | ||||
-rw-r--r-- | lib/pure/times.nim | 8 | ||||
-rw-r--r-- | lib/std/sha1.nim | 116 |
8 files changed, 126 insertions, 107 deletions
diff --git a/lib/packages/docutils/rstgen.nim b/lib/packages/docutils/rstgen.nim index 85b40af4a..c5cee9c90 100644 --- a/lib/packages/docutils/rstgen.nim +++ b/lib/packages/docutils/rstgen.nim @@ -591,33 +591,33 @@ proc readIndexDir(dir: string): var fileEntries: seq[IndexEntry] title: IndexEntry - F = 0 + f = 0 newSeq(fileEntries, 500) setLen(fileEntries, 0) for line in lines(path): let s = line.find('\t') if s < 0: continue - setLen(fileEntries, F+1) - fileEntries[F].keyword = line.substr(0, s-1) - fileEntries[F].link = line.substr(s+1) + setLen(fileEntries, f+1) + fileEntries[f].keyword = line.substr(0, s-1) + fileEntries[f].link = line.substr(s+1) # See if we detect a title, a link without a `#foobar` trailing part. - if title.keyword.len == 0 and fileEntries[F].link.isDocumentationTitle: - title.keyword = fileEntries[F].keyword - title.link = fileEntries[F].link + if title.keyword.len == 0 and fileEntries[f].link.isDocumentationTitle: + title.keyword = fileEntries[f].keyword + title.link = fileEntries[f].link - if fileEntries[F].link.find('\t') > 0: - let extraCols = fileEntries[F].link.split('\t') - fileEntries[F].link = extraCols[0] + if fileEntries[f].link.find('\t') > 0: + let extraCols = fileEntries[f].link.split('\t') + fileEntries[f].link = extraCols[0] assert extraCols.len == 3 - fileEntries[F].linkTitle = extraCols[1].unquoteIndexColumn - fileEntries[F].linkDesc = extraCols[2].unquoteIndexColumn + fileEntries[f].linkTitle = extraCols[1].unquoteIndexColumn + fileEntries[f].linkDesc = extraCols[2].unquoteIndexColumn else: - fileEntries[F].linkTitle = "" - fileEntries[F].linkDesc = "" - inc F + fileEntries[f].linkTitle = "" + fileEntries[f].linkDesc = "" + inc f # Depending on type add this to the list of symbols or table of APIs. if title.keyword.len == 0: - for i in 0 ..< F: + for i in 0 ..< f: # Don't add to symbols TOC entries (they start with a whitespace). let toc = fileEntries[i].linkTitle if toc.len > 0 and toc[0] == ' ': diff --git a/lib/posix/termios.nim b/lib/posix/termios.nim index 34bb47f93..6a7ffb33e 100644 --- a/lib/posix/termios.nim +++ b/lib/posix/termios.nim @@ -241,8 +241,14 @@ proc tcFlow*(fd: cint; action: cint): cint {.importc: "tcflow", # Window size ioctl. Should work on on any Unix that xterm has been ported to. var TIOCGWINSZ*{.importc, header: "<sys/ioctl.h>".}: culong +when defined(nimHasStyleChecks): + {.push styleChecks: off.} + type IOctl_WinSize* = object ws_row*, ws_col*, ws_xpixel*, ws_ypixel*: cushort +when defined(nimHasStyleChecks): + {.pop.} + proc ioctl*(fd: cint, request: culong, reply: ptr IOctl_WinSize): int {. importc: "ioctl", header: "<stdio.h>", varargs.} diff --git a/lib/pure/ioselects/ioselectors_epoll.nim b/lib/pure/ioselects/ioselectors_epoll.nim index 9389a6591..7c6f15164 100644 --- a/lib/pure/ioselects/ioselectors_epoll.nim +++ b/lib/pure/ioselects/ioselectors_epoll.nim @@ -267,8 +267,8 @@ proc unregister*[T](s: Selector[T], ev: SelectEvent) = proc registerTimer*[T](s: Selector[T], timeout: int, oneshot: bool, data: T): int {.discardable.} = var - new_ts: Itimerspec - old_ts: Itimerspec + newTs: Itimerspec + oldTs: Itimerspec let fdi = timerfd_create(CLOCK_MONOTONIC, 0).int if fdi == -1: raiseIOSelectorsError(osLastError()) @@ -282,19 +282,19 @@ proc registerTimer*[T](s: Selector[T], timeout: int, oneshot: bool, epv.data.u64 = fdi.uint if oneshot: - new_ts.it_interval.tv_sec = posix.Time(0) - new_ts.it_interval.tv_nsec = 0 - new_ts.it_value.tv_sec = posix.Time(timeout div 1_000) - new_ts.it_value.tv_nsec = (timeout %% 1_000) * 1_000_000 + newTs.it_interval.tv_sec = posix.Time(0) + newTs.it_interval.tv_nsec = 0 + newTs.it_value.tv_sec = posix.Time(timeout div 1_000) + newTs.it_value.tv_nsec = (timeout %% 1_000) * 1_000_000 incl(events, Event.Oneshot) epv.events = epv.events or EPOLLONESHOT else: - new_ts.it_interval.tv_sec = posix.Time(timeout div 1000) - new_ts.it_interval.tv_nsec = (timeout %% 1_000) * 1_000_000 - new_ts.it_value.tv_sec = new_ts.it_interval.tv_sec - new_ts.it_value.tv_nsec = new_ts.it_interval.tv_nsec + newTs.it_interval.tv_sec = posix.Time(timeout div 1000) + newTs.it_interval.tv_nsec = (timeout %% 1_000) * 1_000_000 + newTs.it_value.tv_sec = newTs.it_interval.tv_sec + newTs.it_value.tv_nsec = newTs.it_interval.tv_nsec - if timerfd_settime(fdi.cint, cint(0), new_ts, old_ts) != 0: + if timerfd_settime(fdi.cint, cint(0), newTs, oldTs) != 0: raiseIOSelectorsError(osLastError()) if epoll_ctl(s.epollFD, EPOLL_CTL_ADD, fdi.cint, addr epv) != 0: raiseIOSelectorsError(osLastError()) diff --git a/lib/pure/nativesockets.nim b/lib/pure/nativesockets.nim index 2ca4f557e..1ede469c7 100644 --- a/lib/pure/nativesockets.nim +++ b/lib/pure/nativesockets.nim @@ -253,8 +253,8 @@ proc getAddrInfo*(address: string, port: Port, domain: Domain = AF_INET, when not defined(freebsd) and not defined(openbsd) and not defined(netbsd) and not defined(android) and not defined(haiku): if domain == AF_INET6: hints.ai_flags = AI_V4MAPPED - let socket_port = if sockType == SOCK_RAW: "" else: $port - var gaiResult = getaddrinfo(address, socket_port, addr(hints), result) + let socketPort = if sockType == SOCK_RAW: "" else: $port + var gaiResult = getaddrinfo(address, socketPort, addr(hints), result) if gaiResult != 0'i32: when useWinVersion: raiseOSError(osLastError()) @@ -357,8 +357,8 @@ proc getHostByAddr*(ip: string): Hostent {.tags: [ReadIOEffect].} = result.addrList = @[] var i = 0 while not isNil(s.h_addr_list[i]): - var inaddr_ptr = cast[ptr InAddr](s.h_addr_list[i]) - result.addrList.add($inet_ntoa(inaddr_ptr[])) + var inaddrPtr = cast[ptr InAddr](s.h_addr_list[i]) + result.addrList.add($inet_ntoa(inaddrPtr[])) inc(i) else: result.addrList = cstringArrayToSeq(s.h_addr_list) @@ -386,8 +386,8 @@ proc getHostByName*(name: string): Hostent {.tags: [ReadIOEffect].} = result.addrList = @[] var i = 0 while not isNil(s.h_addr_list[i]): - var inaddr_ptr = cast[ptr InAddr](s.h_addr_list[i]) - result.addrList.add($inet_ntoa(inaddr_ptr[])) + var inaddrPtr = cast[ptr InAddr](s.h_addr_list[i]) + result.addrList.add($inet_ntoa(inaddrPtr[])) inc(i) else: result.addrList = cstringArrayToSeq(s.h_addr_list) diff --git a/lib/pure/net.nim b/lib/pure/net.nim index 1cb141669..8ae40a799 100644 --- a/lib/pure/net.nim +++ b/lib/pure/net.nim @@ -148,6 +148,9 @@ type Peek, SafeDisconn ## Ensures disconnection exceptions (ECONNRESET, EPIPE etc) are not thrown. +when defined(nimHasStyleChecks): + {.push styleChecks: off.} + type IpAddressFamily* {.pure.} = enum ## Describes the type of an IP address IPv6, ## IPv6 address @@ -161,6 +164,8 @@ type of IpAddressFamily.IPv4: address_v4*: array[0..3, uint8] ## Contains the IP address in bytes in ## case of IPv4 +when defined(nimHasStyleChecks): + {.pop.} proc socketError*(socket: Socket, err: int = -1, async = false, lastError = (-1).OSErrorCode): void {.gcsafe.} diff --git a/lib/pure/terminal.nim b/lib/pure/terminal.nim index 1bc5aa11a..eb65b6f57 100644 --- a/lib/pure/terminal.nim +++ b/lib/pure/terminal.nim @@ -71,14 +71,14 @@ when defined(windows): type SHORT = int16 COORD = object - X: SHORT - Y: SHORT + x: SHORT + y: SHORT SMALL_RECT = object - Left: SHORT - Top: SHORT - Right: SHORT - Bottom: SHORT + left: SHORT + top: SHORT + right: SHORT + bottom: SHORT CONSOLE_SCREEN_BUFFER_INFO = object dwSize: COORD @@ -114,14 +114,14 @@ when defined(windows): var csbi: CONSOLE_SCREEN_BUFFER_INFO for h in handles: if getConsoleScreenBufferInfo(h, addr csbi) != 0: - return int(csbi.srWindow.Right - csbi.srWindow.Left + 1) + return int(csbi.srWindow.right - csbi.srWindow.left + 1) return 0 proc terminalHeightIoctl*(handles: openArray[Handle]): int = var csbi: CONSOLE_SCREEN_BUFFER_INFO for h in handles: if getConsoleScreenBufferInfo(h, addr csbi) != 0: - return int(csbi.srWindow.Bottom - csbi.srWindow.Top + 1) + return int(csbi.srWindow.bottom - csbi.srWindow.top + 1) return 0 proc terminalWidth*(): int = @@ -168,12 +168,12 @@ when defined(windows): var c: CONSOLE_SCREEN_BUFFER_INFO if getConsoleScreenBufferInfo(h, addr(c)) == 0: raiseOSError(osLastError()) - return (int(c.dwCursorPosition.X), int(c.dwCursorPosition.Y)) + return (int(c.dwCursorPosition.x), int(c.dwCursorPosition.y)) proc setCursorPos(h: Handle, x, y: int) = var c: COORD - c.X = int16(x) - c.Y = int16(y) + c.x = int16(x) + c.y = int16(y) if setConsoleCursorPosition(h, c) == 0: raiseOSError(osLastError()) @@ -319,7 +319,7 @@ proc setCursorXPos*(f: File, x: int) = if getConsoleScreenBufferInfo(h, addr(scrbuf)) == 0: raiseOSError(osLastError()) var origin = scrbuf.dwCursorPosition - origin.X = int16(x) + origin.x = int16(x) if setConsoleCursorPosition(h, origin) == 0: raiseOSError(osLastError()) else: @@ -336,7 +336,7 @@ when defined(windows): if getConsoleScreenBufferInfo(h, addr(scrbuf)) == 0: raiseOSError(osLastError()) var origin = scrbuf.dwCursorPosition - origin.Y = int16(y) + origin.y = int16(y) if setConsoleCursorPosition(h, origin) == 0: raiseOSError(osLastError()) else: @@ -422,10 +422,10 @@ proc eraseLine*(f: File) = if getConsoleScreenBufferInfo(h, addr(scrbuf)) == 0: raiseOSError(osLastError()) var origin = scrbuf.dwCursorPosition - origin.X = 0'i16 + origin.x = 0'i16 if setConsoleCursorPosition(h, origin) == 0: raiseOSError(osLastError()) - var wt: DWORD = scrbuf.dwSize.X - origin.X + var wt: DWORD = scrbuf.dwSize.x - origin.x if fillConsoleOutputCharacter(h, ' ', wt, origin, addr(numwrote)) == 0: raiseOSError(osLastError()) @@ -446,7 +446,7 @@ proc eraseScreen*(f: File) = if getConsoleScreenBufferInfo(h, addr(scrbuf)) == 0: raiseOSError(osLastError()) - let numChars = int32(scrbuf.dwSize.X)*int32(scrbuf.dwSize.Y) + let numChars = int32(scrbuf.dwSize.x)*int32(scrbuf.dwSize.y) if fillConsoleOutputCharacter(h, ' ', numChars, origin, addr(numwrote)) == 0: diff --git a/lib/pure/times.nim b/lib/pure/times.nim index b7ef4ba9c..7550a8dea 100644 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -283,12 +283,20 @@ type dSat = "Saturday" dSun = "Sunday" +when defined(nimHasStyleChecks): + {.push styleChecks: off.} + +type DateTimeLocale* = object MMM*: array[mJan..mDec, string] MMMM*: array[mJan..mDec, string] ddd*: array[dMon..dSun, string] dddd*: array[dMon..dSun, string] +when defined(nimHasStyleChecks): + {.pop.} + +type MonthdayRange* = range[1..31] HourRange* = range[0..23] MinuteRange* = range[0..59] diff --git a/lib/std/sha1.nim b/lib/std/sha1.nim index d99715583..0099d5f6d 100644 --- a/lib/std/sha1.nim +++ b/lib/std/sha1.nim @@ -65,85 +65,85 @@ template ror2 (val: uint32): uint32 = (val shr 2) or (val shl 30) template ror31(val: uint32): uint32 = (val shr 31) or (val shl 1) proc transform(ctx: var Sha1State) = - var W: array[80, uint32] - var A, B, C, D, E: uint32 + var w: array[80, uint32] + var a, b, c, d, e: uint32 var t = 0 - A = ctx.state[0] - B = ctx.state[1] - C = ctx.state[2] - D = ctx.state[3] - E = ctx.state[4] + a = ctx.state[0] + b = ctx.state[1] + c = ctx.state[2] + d = ctx.state[3] + e = ctx.state[4] - template SHA_F1(A, B, C, D, E, t: untyped) = - bigEndian32(addr W[t], addr ctx.buf[t * 4]) - E += ror27(A) + W[t] + (D xor (B and (C xor D))) + 0x5A827999'u32 - B = ror2(B) + template shaF1(a, b, c, d, e, t: untyped) = + bigEndian32(addr w[t], addr ctx.buf[t * 4]) + e += ror27(a) + w[t] + (d xor (b and (c xor d))) + 0x5A827999'u32 + b = ror2(b) while t < 15: - SHA_F1(A, B, C, D, E, t + 0) - SHA_F1(E, A, B, C, D, t + 1) - SHA_F1(D, E, A, B, C, t + 2) - SHA_F1(C, D, E, A, B, t + 3) - SHA_F1(B, C, D, E, A, t + 4) + shaF1(a, b, c, d, e, t + 0) + shaF1(e, a, b, c, d, t + 1) + shaF1(d, e, a, b, c, t + 2) + shaF1(c, d, e, a, b, t + 3) + shaF1(b, c, d, e, a, t + 4) t += 5 - SHA_F1(A, B, C, D, E, t + 0) # 16th one, t == 15 + shaF1(a, b, c, d, e, t + 0) # 16th one, t == 15 - template SHA_F11(A, B, C, D, E, t: untyped) = - W[t] = ror31(W[t-3] xor W[t-8] xor W[t-14] xor W[t-16]) - E += ror27(A) + W[t] + (D xor (B and (C xor D))) + 0x5A827999'u32 - B = ror2(B) + template shaF11(a, b, c, d, e, t: untyped) = + w[t] = ror31(w[t-3] xor w[t-8] xor w[t-14] xor w[t-16]) + e += ror27(a) + w[t] + (d xor (b and (c xor d))) + 0x5A827999'u32 + b = ror2(b) - SHA_F11(E, A, B, C, D, t + 1) - SHA_F11(D, E, A, B, C, t + 2) - SHA_F11(C, D, E, A, B, t + 3) - SHA_F11(B, C, D, E, A, t + 4) + shaF11(e, a, b, c, d, t + 1) + shaF11(d, e, a, b, c, t + 2) + shaF11(c, d, e, a, b, t + 3) + shaF11(b, c, d, e, a, t + 4) - template SHA_F2(A, B, C, D, E, t: untyped) = - W[t] = ror31(W[t-3] xor W[t-8] xor W[t-14] xor W[t-16]) - E += ror27(A) + W[t] + (B xor C xor D) + 0x6ED9EBA1'u32 - B = ror2(B) + template shaF2(a, b, c, d, e, t: untyped) = + w[t] = ror31(w[t-3] xor w[t-8] xor w[t-14] xor w[t-16]) + e += ror27(a) + w[t] + (b xor c xor d) + 0x6ED9EBA1'u32 + b = ror2(b) t = 20 while t < 40: - SHA_F2(A, B, C, D, E, t + 0) - SHA_F2(E, A, B, C, D, t + 1) - SHA_F2(D, E, A, B, C, t + 2) - SHA_F2(C, D, E, A, B, t + 3) - SHA_F2(B, C, D, E, A, t + 4) + shaF2(a, b, c, d, e, t + 0) + shaF2(e, a, b, c, d, t + 1) + shaF2(d, e, a, b, c, t + 2) + shaF2(c, d, e, a, b, t + 3) + shaF2(b, c, d, e, a, t + 4) t += 5 - template SHA_F3(A, B, C, D, E, t: untyped) = - W[t] = ror31(W[t-3] xor W[t-8] xor W[t-14] xor W[t-16]) - E += ror27(A) + W[t] + ((B and C) or (D and (B or C))) + 0x8F1BBCDC'u32 - B = ror2(B) + template shaF3(a, b, c, d, e, t: untyped) = + w[t] = ror31(w[t-3] xor w[t-8] xor w[t-14] xor w[t-16]) + e += ror27(a) + w[t] + ((b and c) or (d and (b or c))) + 0x8F1BBCDC'u32 + b = ror2(b) while t < 60: - SHA_F3(A, B, C, D, E, t + 0) - SHA_F3(E, A, B, C, D, t + 1) - SHA_F3(D, E, A, B, C, t + 2) - SHA_F3(C, D, E, A, B, t + 3) - SHA_F3(B, C, D, E, A, t + 4) + shaF3(a, b, c, d, e, t + 0) + shaF3(e, a, b, c, d, t + 1) + shaF3(d, e, a, b, c, t + 2) + shaF3(c, d, e, a, b, t + 3) + shaF3(b, c, d, e, a, t + 4) t += 5 - template SHA_F4(A, B, C, D, E, t: untyped) = - W[t] = ror31(W[t-3] xor W[t-8] xor W[t-14] xor W[t-16]) - E += ror27(A) + W[t] + (B xor C xor D) + 0xCA62C1D6'u32 - B = ror2(B) + template shaF4(a, b, c, d, e, t: untyped) = + w[t] = ror31(w[t-3] xor w[t-8] xor w[t-14] xor w[t-16]) + e += ror27(a) + w[t] + (b xor c xor d) + 0xCA62C1D6'u32 + b = ror2(b) while t < 80: - SHA_F4(A, B, C, D, E, t + 0) - SHA_F4(E, A, B, C, D, t + 1) - SHA_F4(D, E, A, B, C, t + 2) - SHA_F4(C, D, E, A, B, t + 3) - SHA_F4(B, C, D, E, A, t + 4) + shaF4(a, b, c, d, e, t + 0) + shaF4(e, a, b, c, d, t + 1) + shaF4(d, e, a, b, c, t + 2) + shaF4(c, d, e, a, b, t + 3) + shaF4(b, c, d, e, a, t + 4) t += 5 - ctx.state[0] += A - ctx.state[1] += B - ctx.state[2] += C - ctx.state[3] += D - ctx.state[4] += E + ctx.state[0] += a + ctx.state[1] += b + ctx.state[2] += c + ctx.state[3] += d + ctx.state[4] += e proc update*(ctx: var Sha1State, data: openArray[char]) = var i = ctx.count mod 64 @@ -178,7 +178,7 @@ proc update*(ctx: var Sha1State, data: openArray[char]) = proc finalize*(ctx: var Sha1State): Sha1Digest = var cnt = uint64(ctx.count * 8) - # A 1 bit + # a 1 bit update(ctx, "\x80") # Add padding until we reach a complexive size of 64 - 8 bytes while (ctx.count mod 64) != (64 - 8): |