diff options
author | bptato <nincsnevem662@gmail.com> | 2023-12-13 15:00:34 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-12-13 15:00:34 +0100 |
commit | 53bc47531543fe55997f4c6875fa03745a17e754 (patch) | |
tree | a7d3b3de2f68580a79415818bad84bf607e58c14 /src | |
parent | 4818cb28debf4601213707f6c1b9b22348b51fbc (diff) | |
download | chawan-53bc47531543fe55997f4c6875fa03745a17e754.tar.gz |
Various fixes
* Makefile: fix parallel build, add new binaries to install target * twtstr: split out libunicode-related stuff to luwrap * config: quote default gopher2html URL env var for unquote * adapter/: get rid of types/url dependency, use CURL url in all cases
Diffstat (limited to 'src')
-rw-r--r-- | src/config/config.nim | 2 | ||||
-rw-r--r-- | src/layout/engine.nim | 1 | ||||
-rw-r--r-- | src/local/container.nim | 1 | ||||
-rw-r--r-- | src/local/select.nim | 4 | ||||
-rw-r--r-- | src/types/url.nim | 1 | ||||
-rw-r--r-- | src/utils/luwrap.nim | 46 | ||||
-rw-r--r-- | src/utils/twtstr.nim | 37 |
7 files changed, 52 insertions, 40 deletions
diff --git a/src/config/config.nim b/src/config/config.nim index eec0bffd..38ab6ffb 100644 --- a/src/config/config.nim +++ b/src/config/config.nim @@ -350,7 +350,7 @@ proc readUserStylesheet(dir, file: string): string = # of several individual configuration files known as mailcap files. proc getMailcap*(config: Config): tuple[mailcap: Mailcap, errs: seq[string]] = let configDir = getConfigDir() / "chawan" #TODO store this in config? - const gopherPath0 = ChaPath("${%CHA_LIBEXEC_DIR}/gopher2html -u $MAILCAP_URL") + const gopherPath0 = ChaPath("${%CHA_LIBEXEC_DIR}/gopher2html -u \\$MAILCAP_URL") let gopherPath = gopherPath0.unquote().get const geminiPath0 = ChaPath("${%CHA_LIBEXEC_DIR}/gmi2html") let geminiPath = geminiPath0.unquote().get diff --git a/src/layout/engine.nim b/src/layout/engine.nim index 637285a6..cc80d1d8 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -8,6 +8,7 @@ import css/values import display/winattrs import layout/box import layout/layoutunit +import utils/luwrap import utils/strwidth import utils/twtstr diff --git a/src/local/container.nim b/src/local/container.nim index 09ec5a37..8a0ae37e 100644 --- a/src/local/container.nim +++ b/src/local/container.nim @@ -23,6 +23,7 @@ import types/cell import types/color import types/cookie import types/url +import utils/luwrap import utils/mimeguess import utils/strwidth import utils/twtstr diff --git a/src/local/select.nim b/src/local/select.nim index 95c89117..0be38104 100644 --- a/src/local/select.nim +++ b/src/local/select.nim @@ -1,10 +1,10 @@ -import unicode +import std/unicode import js/regex import server/buffer import types/cell +import utils/luwrap import utils/strwidth -import utils/twtstr type SubmitSelect* = proc(selected: seq[int]) diff --git a/src/types/url.nim b/src/types/url.nim index d5fbed9e..0f65e727 100644 --- a/src/types/url.nim +++ b/src/types/url.nim @@ -12,6 +12,7 @@ import js/error import js/javascript import lib/punycode import types/blob +import utils/luwrap import utils/twtstr type diff --git a/src/utils/luwrap.nim b/src/utils/luwrap.nim new file mode 100644 index 00000000..41a58701 --- /dev/null +++ b/src/utils/luwrap.nim @@ -0,0 +1,46 @@ +import std/strutils +import std/unicode + +import bindings/libunicode +import utils/charcategory + +proc passRealloc(opaque: pointer, p: pointer, size: csize_t): pointer + {.cdecl.} = + return realloc(p, size) + +proc mnormalize*(rs: var seq[Rune], form = UNICODE_NFC) = {.cast(noSideEffect).}: + if rs.len == 0: return + var outbuf: ptr uint32 + let p = cast[ptr uint32](unsafeAddr rs[0]) + let out_len = unicode_normalize(addr outbuf, p, cint(rs.len), form, nil, + passRealloc) + if out_len < 0: + raise newException(Defect, "Unicode normalization failed") + if out_len == 0: + return + rs = cast[seq[Rune]](newSeqUninitialized[uint32](out_len)) + copyMem(addr rs[0], outbuf, out_len * sizeof(uint32)) + dealloc(outbuf) + +#TODO maybe a utf8 normalization procedure? +proc mnormalize*(s: var string) = + if NonAscii notin s: + return # no need to normalize ascii + var rs = s.toRunes() + rs.mnormalize() + s = $rs + +func normalize*(rs: seq[Rune], form = UNICODE_NFC): seq[Rune] = + {.cast(noSideEffect).}: + if rs.len == 0: return + var outbuf: ptr uint32 + let p = cast[ptr uint32](unsafeAddr rs[0]) + let out_len = unicode_normalize(addr outbuf, p, cint(rs.len), form, + nil, passRealloc) + if out_len < 0: + raise newException(Defect, "Unicode normalization failed") + if out_len == 0: + return + result = cast[seq[Rune]](newSeqUninitialized[uint32](out_len)) + copyMem(addr result[0], outbuf, out_len * sizeof(uint32)) + dealloc(outbuf) diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index b235651f..da9af19a 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -7,7 +7,6 @@ import strutils import tables import unicode -import bindings/libunicode import types/opt import utils/charcategory import utils/map @@ -576,42 +575,6 @@ proc passRealloc*(opaque: pointer, p: pointer, size: csize_t): pointer {.cdecl.} = return realloc(p, size) -proc mnormalize*(rs: var seq[Rune], form = UNICODE_NFC) = {.cast(noSideEffect).}: - if rs.len == 0: return - var outbuf: ptr uint32 - let p = cast[ptr uint32](unsafeAddr rs[0]) - let out_len = unicode_normalize(addr outbuf, p, cint(rs.len), form, nil, - passRealloc) - if out_len < 0: - raise newException(Defect, "Unicode normalization failed") - if out_len == 0: - return - rs = cast[seq[Rune]](newSeqUninitialized[uint32](out_len)) - copyMem(addr rs[0], outbuf, out_len * sizeof(uint32)) - dealloc(outbuf) - -#TODO maybe a utf8 normalization procedure? -proc mnormalize*(s: var string) = - if s.isAscii(): - return # no need to normalize ascii - var rs = s.toRunes() - rs.mnormalize() - s = $rs - -func normalize*(rs: seq[Rune], form = UNICODE_NFC): seq[Rune] = {.cast(noSideEffect).}: - if rs.len == 0: return - var outbuf: ptr uint32 - let out_len = unicode_normalize(addr outbuf, - cast[ptr uint32](unsafeAddr rs[0]), - cint(rs.len), form, nil, passRealloc) - if out_len < 0: - raise newException(Defect, "Unicode normalization failed") - if out_len == 0: - return - result = cast[seq[Rune]](newSeqUninitialized[uint32](out_len)) - copyMem(addr result[0], outbuf, out_len * sizeof(uint32)) - dealloc(outbuf) - # https://www.w3.org/TR/xml/#NT-Name const NameStartCharRanges = [ (0xC0, 0xD6), |