code wiki / _hdl_build / nx_epub_read.nx

nx_epub_read.nx

buildroot/runtime/_hdl_build/nx_epub_read.nx

15245 B349 linesdepth 6pulls 9 transitivereach 0 importersview sourcekind tooltopic epub
docsdependenciesstructsconstsfunctions

about

nx_epub_read.nx -- SOVEREIGN EPUB read (Reader-arc RUNG 2). "The agnostic Nishi read working" on EPUB, over the operator's REAL Calibre library. Composes (anti-reinvention): nx_deflate.nx (nx_deflate_inflate -- the GREEN inflate keystone), nx_html_to_text.nx (XHTML -> plain text). The ONLY new logic is a ZIP central-directory walker (name-based entry lookup; the authored _zip_extract does first-entry only) + the EPUB/OPF structure walk (container.xml -> OPF -> metadata/manifest/spine) + first-real-chapter pick. SOVEREIGN: parse path is pure Nishi organs + raw syscalls. NO python/unzip/3rd-party-xml/gcc/sh, NO calibre binaries. (Browser HTML/CSS RENDER is a later rung 2b; this rung is parse+extract only.) NO-FAKE-GREEN: the 3 inputs are REAL files on the NAS; title/author/spine/text are MEASURED from the bytes, never hardcoded. Emits the unified book model (book<N>.json + book<N>.ch1.txt), ADDITIVE. license_tier: ORIGINAL

dependencies 4 imports · 0 importers

nx_syscalls.nx nx_itoa_lib.nx nx_deflate.nx nx_html_to_text.nx nx_epub_read.nx

imports: nx_syscalls.nxnx_itoa_lib.nxnx_deflate.nxnx_html_to_text.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main er_p er_w sys_write er_slen do_book sys_mmap sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close er_p ↻ er_pn er_n nxi_fd sys_mmap ↻ ccz_cat_num sys_write ↻ sys_munmap zip_read_named sys_mmap ↻ zip_find find_eocd le16 le32 er_slen ↻ nx_deflate_inflate sys_mmap ↻ nx_bitstream_alloc sys_mmap ↻ _deflate_inflate_block nx_bitstream_read_lsb nx_bitstream_bits_remainin _bs_peek_byte nx_bitstream_byte_align nx_bitstream_read_byte_ali nx_bitstream_byte_align ↻ _deflate_build_static_litl

structs

none

consts

18const CHAP_MAGIC_262144: i64 = 262144
19const CHAP_MAGIC_1024: i64 = 1024
20const CHAP_MAGIC_2097152: i64 = 2097152
21const CHAP_MAGIC_65536: i64 = 65536
22const CHAP_MAGIC_2048: i64 = 2048
259const CHAP_CAP: i64 = 4194304

functions

25func er_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
26func er_w(fd: i64, s: *u8) -> i64 { sys_write(fd, s, er_slen(s)); return 0 }
31func er_n(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }
called by 2: er_pnwrite_book calls 1: nxi_fd
32func er_p(s: *u8) -> i64 { er_w(1, s); return 0 }
called by 2: do_bookmain calls 1: er_w
33func er_pn(v: i64) -> i64 { er_n(1, v); return 0 }
called by 2: do_bookmain calls 1: er_n
35func le16(b: *u8, o: i64) -> i64 { return (b[o] as i64) | ((b[o+1] as i64) << 8) }
called by 1: zip_find
36func le32(b: *u8, o: i64) -> i64 { return (b[o] as i64) | ((b[o+1] as i64) << 8) | ((b[o+2] as i64) << 16) | ((b[o+3] as i64) << 24) }
called by 1: zip_find
38func 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 }
39func er_catn(dst: *u8, off: i64, v: i64) -> i64 { let t: *u8=sys_mmap(28); var m: i64=v; var k: i64=0; if m==0{t[0]=48 as u8;k=1}; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var i: i64=0; while i<k{dst[off+i]=t[k-1-i];i=i+1} return off+k }
called by 1: write_book calls 1: sys_mmap
42func find_sub(hay: *u8, hl: i64, needle: *u8) -> i64
57func count_sub(hay: *u8, hl: i64, needle: *u8) -> i64
calls 1: er_slen
72func attr_val(hay: *u8, hl: i64, attr: *u8, out: *u8, outcap: i64) -> i64
called by 2: href_for_iddo_book calls 2: find_suber_slen
83func elem_text(hay: *u8, hl: i64, opentag: *u8, out: *u8, outcap: i64) -> i64
called by 1: do_book calls 1: find_sub
96func find_eocd(z: *u8, zl: i64) -> i64
called by 1: zip_find
107func zip_find(z: *u8, zl: i64, target: *u8, ob: *i64) -> i64
143func zip_read_named(z: *u8, zl: i64, target: *u8, out: *u8, outcap: i64) -> i64
166func href_for_id(opf: *u8, ol: i64, idref: *u8, out: *u8, outcap: i64) -> i64
182func join_path(opfpath: *u8, href: *u8, out: *u8) -> i64
called by 1: do_book calls 1: er_slen
196func get_spine_idrefs(opf: *u8, ol: i64, arena: *u8, offs: *i64, cap: i64) -> i64
called by 1: do_book calls 1: find_sub
221func er_wjson(fd: i64, s: *u8) -> i64
called by 1: write_book calls 1: sys_write
234func write_book(idx: i64, title: *u8, author: *u8, nspine: i64, chosen: i64, textn: i64, text: *u8) -> i64
261func do_book(epath: *u8, idx: i64) -> i64
336func main() -> i64