diff options
Diffstat (limited to 'lib/impure')
-rwxr-xr-x | lib/impure/dialogs.nim | 12 | ||||
-rwxr-xr-x | lib/impure/graphics.nim | 29 | ||||
-rwxr-xr-x | lib/impure/osinfo_win.nim | 18 | ||||
-rwxr-xr-x | lib/impure/re.nim | 20 | ||||
-rwxr-xr-x | lib/impure/ssl.nim | 8 | ||||
-rwxr-xr-x | lib/impure/zipfiles.nim | 4 |
6 files changed, 48 insertions, 43 deletions
diff --git a/lib/impure/dialogs.nim b/lib/impure/dialogs.nim index 6956983bb..5bd7bf6f6 100755 --- a/lib/impure/dialogs.nim +++ b/lib/impure/dialogs.nim @@ -65,13 +65,13 @@ proc ChooseFileToOpen*(window: PWindow, root: string = ""): string = var opf: TOPENFILENAME buf: array [0..2047, char] - opf.lStructSize = sizeof(opf) + opf.lStructSize = sizeof(opf).int32 if root.len > 0: opf.lpstrInitialDir = root opf.lpstrFilter = "All Files\0*.*\0\0" opf.flags = OFN_FILEMUSTEXIST opf.lpstrFile = buf - opf.nMaxFile = sizeof(buf) + opf.nMaxFile = sizeof(buf).int32 var res = GetOpenFileName(addr(opf)) if res != 0: result = $buf @@ -100,13 +100,13 @@ proc ChooseFilesToOpen*(window: PWindow, root: string = ""): seq[string] = var opf: TOPENFILENAME buf: array [0..2047*4, char] - opf.lStructSize = sizeof(opf) + opf.lStructSize = sizeof(opf).int32 if root.len > 0: opf.lpstrInitialDir = root opf.lpstrFilter = "All Files\0*.*\0\0" opf.flags = OFN_FILEMUSTEXIST or OFN_ALLOWMULTISELECT or OFN_EXPLORER opf.lpstrFile = buf - opf.nMaxFile = sizeof(buf) + opf.nMaxFile = sizeof(buf).int32 var res = GetOpenFileName(addr(opf)) result = @[] if res != 0: @@ -161,13 +161,13 @@ proc ChooseFileToSave*(window: PWindow, root: string = ""): string = var opf: TOPENFILENAME buf: array [0..2047, char] - opf.lStructSize = sizeof(opf) + opf.lStructSize = sizeof(opf).int32 if root.len > 0: opf.lpstrInitialDir = root opf.lpstrFilter = "All Files\0*.*\0\0" opf.flags = OFN_OVERWRITEPROMPT opf.lpstrFile = buf - opf.nMaxFile = sizeof(buf) + opf.nMaxFile = sizeof(buf).int32 var res = GetSaveFileName(addr(opf)) if res != 0: result = $buf diff --git a/lib/impure/graphics.nim b/lib/impure/graphics.nim index 1392fd903..1d538b790 100755 --- a/lib/impure/graphics.nim +++ b/lib/impure/graphics.nim @@ -74,7 +74,7 @@ proc fontFinalizer(f: PFont) = closeFont(f.f) proc newFont*(name = "VeraMono.ttf", size = 9, color = colBlack): PFont = ## Creates a new font object. Raises ``EIO`` if the font cannot be loaded. new(result, fontFinalizer) - result.f = OpenFont(name, size) + result.f = OpenFont(name, size.cint) if result.f == nil: raise newException(EIO, "Could not open font file: " & name) result.color = toSdlColor(color) @@ -107,10 +107,10 @@ type PPixels = ptr TPixels template setPix(video, pitch, x, y, col: expr): stmt = - video[y * pitch.int + x] = int32(col) + video[y * pitch + x] = int32(col) template getPix(video, pitch, x, y: expr): expr = - colors.TColor(video[y * pitch.int + x]) + colors.TColor(video[y * pitch + x]) const ColSize = 4 @@ -118,7 +118,7 @@ const proc getPixel(sur: PSurface, x, y: Natural): colors.TColor {.inline.} = assert x <% sur.w assert y <% sur.h - result = getPix(cast[PPixels](sur.s.pixels), sur.s.pitch div ColSize.uint16, + result = getPix(cast[PPixels](sur.s.pixels), sur.s.pitch.int div ColSize, x, y) proc setPixel(sur: PSurface, x, y: Natural, col: colors.TColor) {.inline.} = @@ -126,7 +126,7 @@ proc setPixel(sur: PSurface, x, y: Natural, col: colors.TColor) {.inline.} = assert y <% sur.h var pixs = cast[PPixels](sur.s.pixels) #pixs[y * (sur.s.pitch div colSize) + x] = int(col) - setPix(pixs, sur.s.pitch div ColSize.uint16, x, y, col) + setPix(pixs, sur.s.pitch.int div ColSize, x, y, col) proc `[]`*(sur: PSurface, p: TPoint): TColor = ## get pixel at position `p`. No range checking is done! @@ -252,7 +252,7 @@ proc drawLine*(sur: PSurface, p1, p2: TPoint, color: TColor) = dy = dy * 2 dx = dx * 2 var video = cast[PPixels](sur.s.pixels) - var pitch = sur.s.pitch div ColSize + var pitch = sur.s.pitch.int div ColSize setPix(video, pitch, x0, y0, color) if dx > dy: var fraction = dy - (dx div 2) @@ -276,7 +276,7 @@ proc drawLine*(sur: PSurface, p1, p2: TPoint, color: TColor) = proc drawHorLine*(sur: PSurface, x, y, w: Natural, Color: TColor) = ## draws a horizontal line from (x,y) to (x+w-1, y). var video = cast[PPixels](sur.s.pixels) - var pitch = sur.s.pitch div ColSize + var pitch = sur.s.pitch.int div ColSize if y >= 0 and y <= sur.s.h: for i in 0 .. min(sur.s.w-x, w)-1: @@ -285,7 +285,7 @@ proc drawHorLine*(sur: PSurface, x, y, w: Natural, Color: TColor) = proc drawVerLine*(sur: PSurface, x, y, h: Natural, Color: TColor) = ## draws a vertical line from (x,y) to (x, y+h-1). var video = cast[PPixels](sur.s.pixels) - var pitch = sur.s.pitch div ColSize + var pitch = sur.s.pitch.int div ColSize if x >= 0 and x <= sur.s.w: for i in 0 .. min(sur.s.h-y, h)-1: @@ -322,7 +322,7 @@ proc fillCircle*(s: PSurface, p: TPoint, r: Natural, color: TColor) = proc drawRect*(sur: PSurface, r: TRect, color: TColor) = ## draws a rectangle. var video = cast[PPixels](sur.s.pixels) - var pitch = sur.s.pitch div ColSize + var pitch = sur.s.pitch.int div ColSize if (r.x >= 0 and r.x <= sur.s.w) and (r.y >= 0 and r.y <= sur.s.h): var minW = min(sur.s.w - r.x, r.width - 1) var minH = min(sur.s.h - r.y, r.height - 1) @@ -345,7 +345,7 @@ proc fillRect*(sur: PSurface, r: TRect, col: TColor) = proc Plot4EllipsePoints(sur: PSurface, CX, CY, X, Y: Natural, col: TColor) = var video = cast[PPixels](sur.s.pixels) - var pitch = sur.s.pitch div ColSize + var pitch = sur.s.pitch.int div ColSize if CX+X <= sur.s.w-1: if CY+Y <= sur.s.h-1: setPix(video, pitch, CX+X, CY+Y, col) if CY-Y <= sur.s.h-1: setPix(video, pitch, CX+X, CY-Y, col) @@ -409,14 +409,13 @@ proc drawEllipse*(sur: PSurface, CX, CY, XRadius, YRadius: Natural, proc plotAA(sur: PSurface, x, y: int, c: float, color: TColor) = - if (x > 0 and x < sur.s.w) and (y > 0 and - y < sur.s.h): + if (x > 0 and x < sur.s.w) and (y > 0 and y < sur.s.h): var video = cast[PPixels](sur.s.pixels) - var pitch = sur.s.pitch div ColSize + var pitch = sur.s.pitch.int div ColSize var pixColor = getPix(video, pitch, x, y) - setPix(video, pitch, x, y, + setPix(video, pitch, x, y, pixColor.intensity(1.0 - c) + color.intensity(c)) @@ -561,7 +560,7 @@ when isMainModule: else: #echo(event.kind) - SDL.UpdateRect(surf.s, int32(0), int32(0), int32(800), int32(600)) + SDL.UpdateRect(surf.s, 0, 0, 800, 600) surf.writeToBMP("test.bmp") SDL.Quit() diff --git a/lib/impure/osinfo_win.nim b/lib/impure/osinfo_win.nim index 86e437c92..46af1ddd6 100755 --- a/lib/impure/osinfo_win.nim +++ b/lib/impure/osinfo_win.nim @@ -67,7 +67,7 @@ type SuiteMask*: int ProductType*: int - TPartitionInfo* = tuple[FreeSpace, TotalSpace: filetime] + TPartitionInfo* = tuple[FreeSpace, TotalSpace: Tfiletime] const # SuiteMask - VersionInfo.SuiteMask @@ -157,7 +157,7 @@ proc GlobalMemoryStatusEx*(lpBuffer: var TMEMORYSTATUSEX){.stdcall, dynlib: "ker proc getMemoryInfo*(): TMemoryInfo = ## Retrieves memory info var statex: TMEMORYSTATUSEX - statex.dwLength = sizeof(statex) + statex.dwLength = sizeof(statex).int32 GlobalMemoryStatusEx(statex) result.MemoryLoad = statex.dwMemoryLoad @@ -180,7 +180,7 @@ proc GetModuleHandleA*(lpModuleName: cstring): int{.stdcall, proc getVersionInfo*(): TVersionInfo = ## Retrieves operating system info var osvi: TOSVERSIONINFOEX - osvi.dwOSVersionInfoSize = sizeof(osvi) + osvi.dwOSVersionInfoSize = sizeof(osvi).int32 discard GetVersionEx(osvi) result.majorVersion = osvi.dwMajorVersion result.minorVersion = osvi.dwMinorVersion @@ -367,7 +367,13 @@ proc `$`*(osvi: TVersionInfo): string = proc getFileSize*(file: string): biggestInt = var fileData: TWIN32_FIND_DATA - var hFile = FindFirstFileA(file, fileData) + + when useWinUnicode: + var aa = allocWideCString(file) + var hFile = FindFirstFileW(aa, fileData) + dealloc aa + else: + var hFile = FindFirstFileA(file, fileData) if hFile == INVALID_HANDLE_VALUE: raise newException(EIO, $GetLastError()) @@ -376,12 +382,12 @@ proc getFileSize*(file: string): biggestInt = proc GetDiskFreeSpaceEx*(lpDirectoryName: cstring, lpFreeBytesAvailableToCaller, lpTotalNumberOfBytes, - lpTotalNumberOfFreeBytes: var filetime): WINBOOL{. + lpTotalNumberOfFreeBytes: var TFiletime): WINBOOL{. stdcall, dynlib: "kernel32", importc: "GetDiskFreeSpaceExA".} proc getPartitionInfo*(partition: string): TPartitionInfo = ## Retrieves partition info, for example ``partition`` may be ``"C:\"`` - var FreeBytes, TotalBytes, TotalFreeBytes: filetime + var FreeBytes, TotalBytes, TotalFreeBytes: TFiletime var res = GetDiskFreeSpaceEx(r"C:\", FreeBytes, TotalBytes, TotalFreeBytes) return (FreeBytes, TotalBytes) diff --git a/lib/impure/re.nim b/lib/impure/re.nim index f3a6e5a44..7ef3d247a 100755 --- a/lib/impure/re.nim +++ b/lib/impure/re.nim @@ -100,7 +100,7 @@ proc findBounds*(s: string, pattern: TRegEx, matches: var openarray[string], ## is written into `matches` and ``(-1,0)`` is returned. var rawMatches: array[0..maxSubpatterns * 3 - 1, cint] - res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start, 0'i32, + res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start.cint, 0'i32, cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3) if res < 0'i32: return (-1, 0) for i in 1..int(res)-1: @@ -119,7 +119,7 @@ proc findBounds*(s: string, pattern: TRegEx, ## ``(-1,0)`` is returned. var rawMatches: array[0..maxSubpatterns * 3 - 1, cint] - res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start, 0'i32, + res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start.cint, 0'i32, cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3) if res < 0'i32: return (-1, 0) for i in 1..int(res)-1: @@ -135,7 +135,7 @@ proc findBounds*(s: string, pattern: TRegEx, ## match, ``(-1,0)`` is returned. var rawMatches: array[0..3 - 1, cint] - res = pcre.Exec(pattern.h, nil, s, len(s).cint, start, 0'i32, + res = pcre.Exec(pattern.h, nil, s, len(s).cint, start.cint, 0'i32, cast[ptr cint](addr(rawMatches)), 3) if res < 0'i32: return (int(res), 0) return (int(rawMatches[0]), int(rawMatches[1]-1)) @@ -153,25 +153,25 @@ proc match*(s: string, pattern: TRegEx, matches: var openarray[string], ## the captured substrings in the array ``matches``. If it does not ## match, nothing is written into ``matches`` and ``false`` is ## returned. - return matchOrFind(s, pattern, matches, start, + return matchOrFind(s, pattern, matches, start.cint, pcre.ANCHORED) == cint(s.len - start) proc match*(s: string, pattern: TRegEx, start = 0): bool = ## returns ``true`` if ``s[start..]`` matches the ``pattern``. - return matchOrFind(s, pattern, start, pcre.ANCHORED) == cint(s.len - start) + return matchOrFind(s, pattern, start.cint, pcre.ANCHORED) == cint(s.len-start) proc matchLen*(s: string, pattern: TRegEx, matches: var openarray[string], start = 0): int = ## the same as ``match``, but it returns the length of the match, ## if there is no match, -1 is returned. Note that a match length ## of zero can happen. - return matchOrFind(s, pattern, matches, start, pcre.ANCHORED) + return matchOrFind(s, pattern, matches, start.cint, pcre.ANCHORED) proc matchLen*(s: string, pattern: TRegEx, start = 0): int = ## the same as ``match``, but it returns the length of the match, ## if there is no match, -1 is returned. Note that a match length ## of zero can happen. - return matchOrFind(s, pattern, start, pcre.ANCHORED) + return matchOrFind(s, pattern, start.cint, pcre.ANCHORED) proc find*(s: string, pattern: TRegEx, matches: var openarray[string], start = 0): int = @@ -180,7 +180,7 @@ proc find*(s: string, pattern: TRegEx, matches: var openarray[string], ## is written into ``matches`` and -1 is returned. var rawMatches: array[0..maxSubpatterns * 3 - 1, cint] - res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start, 0'i32, + res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start.cint, 0'i32, cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3) if res < 0'i32: return res for i in 1..int(res)-1: @@ -195,7 +195,7 @@ proc find*(s: string, pattern: TRegEx, start = 0): int = ## match, -1 is returned. var rawMatches: array[0..3 - 1, cint] - res = pcre.Exec(pattern.h, nil, s, len(s).cint, start, 0'i32, + res = pcre.Exec(pattern.h, nil, s, len(s).cint, start.cint, 0'i32, cast[ptr cint](addr(rawMatches)), 3) if res < 0'i32: return res return rawMatches[0] @@ -237,7 +237,7 @@ template `=~` *(s: string, pattern: TRegEx): expr = ## echo("syntax error") ## when not definedInScope(matches): - var matches: array[0..maxSubPatterns-1, string] + var matches: array[0..re.maxSubPatterns-1, string] match(s, pattern, matches) # ------------------------- more string handling ------------------------------ diff --git a/lib/impure/ssl.nim b/lib/impure/ssl.nim index 4a101ca92..54d524c7b 100755 --- a/lib/impure/ssl.nim +++ b/lib/impure/ssl.nim @@ -10,7 +10,7 @@ ## This module provides an easy to use sockets-style ## nimrod interface to the OpenSSL library. -{.deprecate.} +{.deprecated.} import openssl, strutils, os @@ -59,10 +59,10 @@ proc recvLine*(sock: TSecureSocket, line: var TaintedString): bool = setLen(line.string, 0) while True: var c: array[0..0, char] - var n = BIO_read(sock.bio, c, c.len) + var n = BIO_read(sock.bio, c, c.len.cint) if n <= 0: return False if c[0] == '\r': - n = BIO_read(sock.bio, c, c.len) + n = BIO_read(sock.bio, c, c.len.cint) if n > 0 and c[0] == '\L': return True elif n <= 0: @@ -73,7 +73,7 @@ proc recvLine*(sock: TSecureSocket, line: var TaintedString): bool = proc send*(sock: TSecureSocket, data: string) = ## Writes `data` to the socket. - if BIO_write(sock.bio, data, data.len()) <= 0: + if BIO_write(sock.bio, data, data.len.cint) <= 0: OSError() proc close*(sock: TSecureSocket) = diff --git a/lib/impure/zipfiles.nim b/lib/impure/zipfiles.nim index 36842a51b..029d8527d 100755 --- a/lib/impure/zipfiles.nim +++ b/lib/impure/zipfiles.nim @@ -137,8 +137,8 @@ proc getStream*(z: var TZipArchive, filename: string): PZipFileStream = iterator walkFiles*(z: var TZipArchive): string = ## walks over all files in the archive `z` and returns the filename ## (including the path). - var i = 0 - var num = int(zip_get_num_files(z.w)) + var i = 0'i32 + var num = zip_get_num_files(z.w) while i < num: yield $zip_get_name(z.w, i, 0'i32) inc(i) |