more tests green

This commit is contained in:
Araq 2014-08-31 17:23:35 +02:00
commit d7d059a686
16 changed files with 79 additions and 79 deletions

View file

@ -1799,11 +1799,11 @@ proc inet_pton*(a1: cint, a2: cstring, a3: pointer): cint {.
importc, header: "<arpa/inet.h>".}
var
in6addr_any* {.importc, header: "<netinet/in.h>".}: TIn6_addr
in6addr_loopback* {.importc, header: "<netinet/in.h>".}: TIn6_addr
in6addr_any* {.importc, header: "<netinet/in.h>".}: TIn6Addr
in6addr_loopback* {.importc, header: "<netinet/in.h>".}: TIn6Addr
proc IN6ADDR_ANY_INIT* (): TIn6_addr {.importc, header: "<netinet/in.h>".}
proc IN6ADDR_LOOPBACK_INIT* (): TIn6_addr {.importc, header: "<netinet/in.h>".}
proc IN6ADDR_ANY_INIT* (): TIn6Addr {.importc, header: "<netinet/in.h>".}
proc IN6ADDR_LOOPBACK_INIT* (): TIn6Addr {.importc, header: "<netinet/in.h>".}
# dirent.h
proc closedir*(a1: ptr TDIR): cint {.importc, header: "<dirent.h>".}
@ -2518,40 +2518,40 @@ proc if_indextoname*(a1: cint, a2: cstring): cstring {.
proc if_nameindex*(): ptr Tif_nameindex {.importc, header: "<net/if.h>".}
proc if_freenameindex*(a1: ptr Tif_nameindex) {.importc, header: "<net/if.h>".}
proc IN6_IS_ADDR_UNSPECIFIED* (a1: ptr TIn6_addr): cint {.
proc IN6_IS_ADDR_UNSPECIFIED* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".}
## Unspecified address.
proc IN6_IS_ADDR_LOOPBACK* (a1: ptr TIn6_addr): cint {.
proc IN6_IS_ADDR_LOOPBACK* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".}
## Loopback address.
proc IN6_IS_ADDR_MULTICAST* (a1: ptr TIn6_addr): cint {.
proc IN6_IS_ADDR_MULTICAST* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".}
## Multicast address.
proc IN6_IS_ADDR_LINKLOCAL* (a1: ptr TIn6_addr): cint {.
proc IN6_IS_ADDR_LINKLOCAL* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".}
## Unicast link-local address.
proc IN6_IS_ADDR_SITELOCAL* (a1: ptr TIn6_addr): cint {.
proc IN6_IS_ADDR_SITELOCAL* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".}
## Unicast site-local address.
proc IN6_IS_ADDR_V4MAPPED* (a1: ptr TIn6_addr): cint {.
proc IN6_IS_ADDR_V4MAPPED* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".}
## IPv4 mapped address.
proc IN6_IS_ADDR_V4COMPAT* (a1: ptr TIn6_addr): cint {.
proc IN6_IS_ADDR_V4COMPAT* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".}
## IPv4-compatible address.
proc IN6_IS_ADDR_MC_NODELOCAL* (a1: ptr TIn6_addr): cint {.
proc IN6_IS_ADDR_MC_NODELOCAL* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".}
## Multicast node-local address.
proc IN6_IS_ADDR_MC_LINKLOCAL* (a1: ptr TIn6_addr): cint {.
proc IN6_IS_ADDR_MC_LINKLOCAL* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".}
## Multicast link-local address.
proc IN6_IS_ADDR_MC_SITELOCAL* (a1: ptr TIn6_addr): cint {.
proc IN6_IS_ADDR_MC_SITELOCAL* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".}
## Multicast site-local address.
proc IN6_IS_ADDR_MC_ORGLOCAL* (a1: ptr TIn6_addr): cint {.
proc IN6_IS_ADDR_MC_ORGLOCAL* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".}
## Multicast organization-local address.
proc IN6_IS_ADDR_MC_GLOBAL* (a1: ptr TIn6_addr): cint {.
proc IN6_IS_ADDR_MC_GLOBAL* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".}
## Multicast global address.

View file

@ -262,7 +262,7 @@ else:
else:
const iconvDll = "(libc.so.6|libiconv.so)"
when defined(macosx) and defined(powerpc32):
when defined(macosx) and defined(powerpc):
const prefix = "lib"
else:
const prefix = ""
@ -281,14 +281,14 @@ else:
var errno {.importc, header: "<errno.h>".}: cint
proc iconvOpen(tocode, fromcode: cstring): PConverter {.
proc iconvOpen(tocode, fromcode: cstring): EncodingConverter {.
importc: prefix & "iconv_open", cdecl, dynlib: iconvDll.}
proc iconvClose(c: PConverter) {.
proc iconvClose(c: EncodingConverter) {.
importc: prefix & "iconv_close", cdecl, dynlib: iconvDll.}
proc iconv(c: PConverter, inbuf: var cstring, inbytesLeft: var int,
proc iconv(c: EncodingConverter, inbuf: var cstring, inbytesLeft: var int,
outbuf: var cstring, outbytesLeft: var int): int {.
importc: prefix & "iconv", cdecl, dynlib: iconvDll.}
proc iconv(c: PConverter, inbuf: pointer, inbytesLeft: pointer,
proc iconv(c: EncodingConverter, inbuf: pointer, inbytesLeft: pointer,
outbuf: var cstring, outbytesLeft: var int): int {.
importc: prefix & "iconv", cdecl, dynlib: iconvDll.}
@ -305,7 +305,7 @@ proc open*(destEncoding = "UTF-8", srcEncoding = "CP1252"): EncodingConverter =
when not defined(windows):
result = iconvOpen(destEncoding, srcEncoding)
if result == nil:
raise newException(EInvalidEncoding,
raise newException(EncodingError,
"cannot create encoding converter from " &
srcEncoding & " to " & destEncoding)
else:
@ -401,7 +401,7 @@ when defined(windows):
assert(false) # cannot happen
else:
proc convert*(c: PConverter, s: string): string =
proc convert*(c: EncodingConverter, s: string): string =
result = newString(s.len)
var inLen = len(s)
var outLen = len(result)
@ -414,7 +414,7 @@ else:
var lerr = errno
if lerr == EILSEQ or lerr == EINVAL:
# unknown char, skip
Dst[0] = Src[0]
dst[0] = src[0]
src = cast[cstring](cast[int](src) + 1)
dst = cast[cstring](cast[int](dst) + 1)
dec(inLen)
@ -426,19 +426,19 @@ else:
dst = cast[cstring](cast[int](cstring(result)) + offset)
outLen = len(result) - offset
else:
osError(lerr.TOSErrorCode)
raiseOSError(lerr.OSErrorCode)
# iconv has a buffer that needs flushing, specially if the last char is
# not '\0'
discard iconv(c, nil, nil, dst, outlen)
discard iconv(c, nil, nil, dst, outLen)
if iconvres == cint(-1) and errno == E2BIG:
var offset = cast[int](dst) - cast[int](cstring(result))
setLen(result, len(result)+inLen*2+5)
# 5 is minimally one utf-8 char
dst = cast[cstring](cast[int](cstring(result)) + offset)
outLen = len(result) - offset
discard iconv(c, nil, nil, dst, outlen)
discard iconv(c, nil, nil, dst, outLen)
# trim output buffer
setLen(result, len(result) - outlen)
setLen(result, len(result) - outLen)
proc convert*(s: string, destEncoding = "UTF-8",
srcEncoding = "CP1252"): string =

View file

@ -19,7 +19,7 @@ type
{.deprecated: [EInvalidXml: XmlError].}
proc raiseInvalidXml(errors: seq[string]) =
var e: ref EInvalidXml
var e: ref XmlError
new(e)
e.msg = errors[0]
e.errors = errors
@ -125,14 +125,14 @@ proc parseXml*(s: Stream): XmlNode =
## errors are turned into an ``EInvalidXML`` exception.
var errors: seq[string] = @[]
result = parseXml(s, "unknown_html_doc", errors)
if errors.len > 0: raiseInvalidXMl(errors)
if errors.len > 0: raiseInvalidXml(errors)
proc loadXml*(path: string, errors: var seq[string]): XmlNode =
## Loads and parses XML from file specified by ``path``, and returns
## a ``PXmlNode``. Every occured parsing error is added to the `errors`
## sequence.
var s = newFileStream(path, fmRead)
if s == nil: raise newException(EIO, "Unable to read file: " & path)
if s == nil: raise newException(IOError, "Unable to read file: " & path)
result = parseXml(s, path, errors)
proc loadXml*(path: string): XmlNode =
@ -141,7 +141,7 @@ proc loadXml*(path: string): XmlNode =
## exception.
var errors: seq[string] = @[]
result = loadXml(path, errors)
if errors.len > 0: raiseInvalidXMl(errors)
if errors.len > 0: raiseInvalidXml(errors)
when isMainModule:
import os