code wiki / _hdl_build / nx_kf8_book.nx
nx_kf8_book.nx
buildroot/runtime/_hdl_build/nx_kf8_book.nx
about
nx_kf8_book.nx -- SOVEREIGN KF8 / AZW3 (the newer Kindle format) -> Nishi format. KF8 lives in the SAME PDB
container as MOBI6; a dual file has a MOBI6 part (record 0) + a KF8 part whose start record is named by EXTH 121
("KF8 boundary"); a pure-KF8 file has mobiType==8 at record 0. The KF8 part has its OWN PalmDOC/MOBI header +
its own text records, compressed exactly like MOBI6 (PalmDOC or HUFF/CDIC) -- so this REUSES the validated
nx_palmdoc + nx_huffcdic codecs and only adds the boundary glue. nx_mobi_book (validated) is left untouched.
LEGAL LINE: detects encryptionType and DECLINES DRM (exit 2), never circumvents.
Rung 1: decompress the KF8 text flows + nx_html_to_text -> readable book.json (the text is all there). Rung 2 =
SKEL/FRAG/FDST reassembly for exact structure, + unify the decode glue with nx_mobi_book (DRY). expect_exit: 0
Usage: nx_kf8_book <mobi/azw3-path> <slug>. license_tier: ORIGINAL
dependencies 8 imports · 0 importers
imports: nx_syscalls.nxnx_itoa_lib.nxnx_palmdoc.nxnx_huffcdic.nxnx_html_to_text.nxnx_mobi_cover.nxnx_chapter_split.nxnx_charset.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 18 | const K_MAGIC_1252: i64 = 1252 |
| 19 | const K_MAGIC_1024: i64 = 1024 |
| 20 | const K_MAGIC_8192: i64 = 8192 |
| 21 | const K_MAGIC_262144: i64 = 262144 |
| 22 | const K_MAGIC_17480: i64 = 17480 |
| 95 | const KCAP: i64 = 16777216 |
functions
| 24 | func kf_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 25 | func kf_w(fd: i64, s: *u8) -> i64 { sys_write(fd, s, kf_slen(s)); return 0 } |
| 30 | func kf_n(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 } |
| 31 | func kf_p(s: *u8) -> i64 { kf_w(1, s); return 0 } |
| 32 | func kf_pn(v: i64) -> i64 { kf_n(1, v); return 0 } |
| 33 | func ensure_dir(path: *u8) -> i64 { __syscall(258, 0-100, path, 0x1ed, 0, 0, 0); return 0 } called by 1: do_kf8 |
| 34 | func be16(b: *u8, o: i64) -> i64 { return ((b[o] as i64)<<8)|(b[o+1] as i64) } called by 1: do_kf8 |
| 35 | func be32(b: *u8, o: i64) -> i64 { return ((b[o] as i64)<<24)|((b[o+1] as i64)<<16)|((b[o+2] as i64)<<8)|(b[o+3] as i64) } called by 1: do_kf8 |
| 36 | func find_sub(hay: *u8, hl: i64, needle: *u8) -> i64 |
| 42 | func er_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){dst[off+i]=s[i];i=i+1} return off+i } called by 1: do_kf8 |
| 44 | func er_wjson(fd: i64, s: *u8) -> i64 |
| 54 | func utf8_put(out: *u8, o: i64, cp: i64) -> i64 called by 1: decode_numeric_refs |
| 60 | func decode_numeric_refs(txt: *u8, n: i64, out: *u8, outcap: i64) -> i64 |
| 89 | func exth_copy(z: *u8, p: i64, rlen: i64, out: *u8, cap: i64) -> i64 called by 1: do_kf8 |
| 97 | func do_kf8(path: *u8, slug: *u8) -> i64 |
| 249 | func main(argc: i64, argv: *i64) -> i64 |