code wiki / _hdl_build / nx_kf8_book.nx

nx_kf8_book.nx

buildroot/runtime/_hdl_build/nx_kf8_book.nx

15225 B256 linesdepth 5pulls 10 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_itoa_lib.nx nx_palmdoc.nx nx_huffcdic.nx nx_html_to_text.nx nx_mobi_cover.nx nx_chapter_split.nx nx_charset.nx nx_kf8_book.nx

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

main do_kf8 sys_mmap sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close kf_p kf_w sys_write kf_slen be16 be32 find_sub kf_slen ↻ exth_copy kf_pn kf_n nxi_fd sys_mmap ↻ ccz_cat_num sys_write ↻ sys_munmap sys_exit huff_load hc_be32 cdic_load hc_be32 ↻ hc_be16 palmdoc_decompress hc_unpack sys_mmap ↻ hc_be64 hc_unpack ↻ nx_html_to_text nx_html_to_text_x h2t_state_new sys_mmap ↻

structs

none

consts

18const K_MAGIC_1252: i64 = 1252
19const K_MAGIC_1024: i64 = 1024
20const K_MAGIC_8192: i64 = 8192
21const K_MAGIC_262144: i64 = 262144
22const K_MAGIC_17480: i64 = 17480
95const KCAP: i64 = 16777216

functions

24func kf_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 3: kf_wfind_subdo_kf8
25func kf_w(fd: i64, s: *u8) -> i64 { sys_write(fd, s, kf_slen(s)); return 0 }
called by 2: kf_pdo_kf8 calls 2: sys_writekf_slen
30func kf_n(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }
called by 1: kf_pn calls 1: nxi_fd
31func kf_p(s: *u8) -> i64 { kf_w(1, s); return 0 }
called by 2: do_kf8main calls 1: kf_w
32func kf_pn(v: i64) -> i64 { kf_n(1, v); return 0 }
called by 1: do_kf8 calls 1: kf_n
33func ensure_dir(path: *u8) -> i64 { __syscall(258, 0-100, path, 0x1ed, 0, 0, 0); return 0 }
called by 1: do_kf8
34func be16(b: *u8, o: i64) -> i64 { return ((b[o] as i64)<<8)|(b[o+1] as i64) }
called by 1: do_kf8
35func 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
36func find_sub(hay: *u8, hl: i64, needle: *u8) -> i64
called by 1: do_kf8 calls 1: kf_slen
42func 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
44func er_wjson(fd: i64, s: *u8) -> i64
54func utf8_put(out: *u8, o: i64, cp: i64) -> i64
called by 1: decode_numeric_refs
60func decode_numeric_refs(txt: *u8, n: i64, out: *u8, outcap: i64) -> i64
called by 1: do_kf8 calls 1: utf8_put
89func exth_copy(z: *u8, p: i64, rlen: i64, out: *u8, cap: i64) -> i64
called by 1: do_kf8
97func do_kf8(path: *u8, slug: *u8) -> i64
249func main(argc: i64, argv: *i64) -> i64