about summary refs log tree commit diff stats
path: root/src/main.nim
Commit message (Expand)AuthorAgeFilesLines
* Use std/* imports everywherebptato2024-01-071-7/+4
* break up twtstr somewhatbptato2023-12-131-0/+1
* config: better path handling; fix array parsing bugbptato2023-12-101-1/+8
* Move clang workaround to config.nimsbptato2023-11-211-4/+0
* Add -C optionbptato2023-10-271-144/+162
* Fix crash on `cha -'bptato2023-10-181-3/+5
* move workaround from previous commitbptato2023-10-051-0/+4
* Accept bare strings in -o, fix -o with missing newlinebptato2023-09-201-1/+1
* main: set tmpdir for main processbptato2023-09-161-0/+2
* move around more modulesbptato2023-09-141-2/+2
* move some modules to local/bptato2023-09-141-1/+1
* main: remove stray eprint, update -o info textbptato2023-09-061-2/+1
* fix typobptato2023-09-061-2/+2
* main: allow grouped single-letter paramsbptato2023-09-051-59/+94
* config: fix overriding default headersbptato2023-08-261-2/+0
* Move charsets into chakasubptato2023-08-141-1/+4
* Add mailcap, mime.types & misc refactoringsbptato2023-08-131-9/+8
* Option -> Opt in config, return error in compileSearchRegexbptato2023-06-241-2/+3
* Add display/output encodingbptato2023-05-191-1/+12
* Refactor config, add charset optsbptato2023-05-161-12/+25
* Improve debugging, reduce crashesbptato2023-05-091-1/+6
* Make width table at compile-timebptato2023-01-271-1/+1
* Get rid of eprint in place of stderr.writebptato2023-01-051-2/+2
* Add visual-home, rename undocumented config valuesbptato2022-12-111-1/+1
* Add -M, -Vbptato2022-12-051-4/+14
* *_HOME should be disabled when stdin *is* a ttybptato2022-11-301-1/+1
* Disable *_HOME when stdin is a ttybptato2022-11-301-1/+1
* Load fork-server config after parsing argumentsbptato2022-11-301-1/+1
* Support WWW_HOME, HTTP_HOMEbptato2022-11-301-0/+7
* Add textareabptato2022-11-281-14/+10
* Fix some regressions, add loading progress barbptato2022-11-271-1/+3
* Avoid forking child processes from the main processbptato2022-11-241-6/+14
* Color & term improvementsbptato2022-11-211-0/+1
* Rewrite buffer/pager for multi-processingbptato2022-11-191-3/+4
* WIP pagerbptato2022-10-041-12/+19
* Tweaks/bugfixes for armbptato2022-09-141-1/+1
* More JS bindingsbptato2022-09-131-1/+7
* Add JS binding generationbptato2022-09-121-2/+2
* Update docsbptato2022-07-301-0/+2
* Implement --, handle empty argumentsbptato2022-02-191-5/+14
* Remove some unused variablesbptato2022-02-121-2/+0
* Add some command line fixes, fix related bugsbptato2022-01-251-4/+25
* Rebrand programbptato2022-01-221-1/+49
* Add client for buffer controlbptato2021-12-201-74/+2
* Fix pager mode formattingbptato2021-12-191-0/+1
* More configuration optionsbptato2021-12-191-0/+2
* Refactor selector code, optimize style tagsbptato2021-12-181-1/+1
* Profiling and more CSS compatibilitybptato2021-11-151-0/+2
* Initial implementation of CSS :hoverbptato2021-11-141-4/+0
* Rename layout.nimbptato2021-11-121-1/+1
seq[uint16], hm: seq[uint32]] var MappedMapLow: LowMap var MappedMapHigh: HighMap var DisallowedRanges: FullRangeList var Disallowed: FullSet var Ignored: FullSet var Deviation: LowMap proc loadIdnaData() = template add_map(i: uint32, str: string) = if i <= high(uint16): MappedMapLow.add((uint16(i), str)) else: MappedMapHigh.add((i, str)) template add_disallow(i, j: uint32) = if i <= high(uint16): DisallowedRanges.lm.add((uint16(i), uint16(j))) else: DisallowedRanges.hm.add((i, j)) template add_disallow(i: uint32) = if i <= high(uint16): Disallowed.lm.add(uint16(i)) else: Disallowed.hm.add(i) template add_ignore(rstart, rend: uint32) = for i in rstart..rend: if i <= high(uint16): Ignored.lm.add(uint16(i)) else: Ignored.hm.add(i) template add_ignore(i: uint32) = if i <= high(uint16): Ignored.lm.add(uint16(i)) else: Ignored.hm.add(i) template add_deviation(i: uint32, str: string) = assert i <= high(uint16) Deviation.add((uint16(i), str)) template add(firstcol: string, str: string, temp: untyped) = if firstcol.contains(".."): let fcs = firstcol.split("..") let rstart = uint32(parseHexInt(fcs[0])) let rend = uint32(parseHexInt(fcs[1])) for i in rstart..rend: temp(i, str) else: temp(uint32(parseHexInt(firstcol)), str) template add(firstcol: string, temp: untyped) = if firstcol.contains(".."): let fcs = firstcol.split("..") let rstart = uint32(parseHexInt(fcs[0])) let rend = uint32(parseHexInt(fcs[1])) temp(rstart, rend) else: temp(uint32(parseHexInt(firstcol))) var f: File if not open(f, "res/map/IdnaMappingTable.txt"): stderr.write("res/map/IdnaMappingTable.txt not found\n") quit(1) let s = f.readAll() f.close() for line in s.split('\n'): if line.len == 0 or line[0] == '#': continue var i = 0 var firstcol = "" var status = "" var thirdcol: seq[string] var fourthcol = "" while i < line.len and line[i] notin {'#', ';'}: if line[i] != ' ': firstcol &= line[i] inc i if line[i] != '#': inc i while i < line.len and line[i] notin {'#', ';'}: if line[i] != ' ': status &= line[i] inc i if line[i] != '#': inc i var nw = true while i < line.len and line[i] notin {'#', ';'}: if line[i] == ' ': nw = true else: if nw: thirdcol.add("") nw = false thirdcol[^1] &= line[i] inc i if line[i] != '#': inc i while i < line.len and line[i] notin {'#', ';'}: if line[i] != ' ': fourthcol &= line[i] inc i case status of "mapped", "disallowed_STD3_mapped": let codepoints = thirdcol var str = "" for code in codepoints: str &= Rune(parseHexInt(code)) add(firstcol, str, add_map) of "deviation": let codepoints = thirdcol var str = "" for code in codepoints: str &= Rune(parseHexInt(code)) add(firstcol, str, add_deviation) of "valid": if fourthcol == "NV8" or fourthcol == "XV8": add(firstcol, add_disallow) of "disallowed": add(firstcol, add_disallow) of "ignored": add(firstcol, add_ignore) type LineWriter = object s: Stream line: string proc write(writer: var LineWriter, s: string) = if s.len + writer.line.len > 80: writer.s.writeLine(writer.line) writer.line = "" writer.line &= s proc flush(writer: var LineWriter) = writer.s.writeLine(writer.line) writer.line = "" proc main() = loadIdnaData() var writer = LineWriter(s: newFileStream(stdout)) echo "type Z = cstring" echo "const MappedMapLow: array[" & $MappedMapLow.len & ", tuple[ucs: uint16, mapped: Z]] = [" for (ucs, s) in MappedMapLow: writer.write("(" & $ucs & "," & s.escape() & ".Z),") writer.flush() echo "]" echo "" echo "const MappedMapHigh: array[" & $MappedMapHigh.len & ", tuple[ucs: uint32, mapped: Z]] = [" for (ucs, s) in MappedMapHigh: writer.write("(" & $ucs & "," & s.escape() & ".Z),") writer.flush() echo "]" echo "" echo "const DisallowedRangesLow: array[" & $DisallowedRanges.lm.len & ", tuple[ucs, mapped: uint16]] = [" for (ucs, mapped) in DisallowedRanges.lm: writer.write("(" & $ucs & "," & $mapped & "),") writer.flush() echo "]" echo "" echo "const DisallowedRangesHigh: array[" & $DisallowedRanges.hm.len & ", tuple[ucs, mapped: uint32]] = [" for (ucs, mapped) in DisallowedRanges.hm: writer.write("(" & $ucs & "," & $mapped & "),") writer.flush() echo "]" echo "" echo "const DisallowedLow: array[" & $Disallowed.lm.len & ", uint16] = [" for ucs in Disallowed.lm: writer.write($ucs & ",") writer.flush() echo "]" echo "" echo "const DisallowedHigh: array[" & $Disallowed.hm.len & ", uint32] = [" for ucs in Disallowed.hm: writer.write($ucs & ",") writer.flush() echo "]" echo "" echo "const IgnoredLow: array[" & $Ignored.lm.len & ", uint16] = [" for ucs in Ignored.lm: writer.write($ucs & ",") writer.flush() echo "]" echo "" echo "const IgnoredHigh: array[" & $Ignored.hm.len & ", uint32] = [" for ucs in Ignored.hm: writer.write($ucs & ",") writer.flush() echo "]" echo "" echo "const Deviation: array[" & $Deviation.len & ", tuple[ucs: uint16, s: Z]] = [" for (ucs, s) in Deviation: writer.write("(" & $ucs & "," & s.escape() & ".Z),") writer.flush() echo "]" main()