code wiki / _hdl_build / nx_epub_read.nx
nx_epub_read.nx
buildroot/runtime/_hdl_build/nx_epub_read.nx
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
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
structs
| none |
consts
| 18 | const CHAP_MAGIC_262144: i64 = 262144 |
| 19 | const CHAP_MAGIC_1024: i64 = 1024 |
| 20 | const CHAP_MAGIC_2097152: i64 = 2097152 |
| 21 | const CHAP_MAGIC_65536: i64 = 65536 |
| 22 | const CHAP_MAGIC_2048: i64 = 2048 |
| 259 | const CHAP_CAP: i64 = 4194304 |
functions
| 25 | func er_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 26 | func er_w(fd: i64, s: *u8) -> i64 { sys_write(fd, s, er_slen(s)); return 0 } |
| 31 | func er_n(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 } |
| 32 | func er_p(s: *u8) -> i64 { er_w(1, s); return 0 } |
| 33 | func er_pn(v: i64) -> i64 { er_n(1, v); return 0 } |
| 35 | func le16(b: *u8, o: i64) -> i64 { return (b[o] as i64) | ((b[o+1] as i64) << 8) } called by 1: zip_find |
| 36 | func 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 |
| 38 | 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 } |
| 39 | func 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 } |
| 42 | func find_sub(hay: *u8, hl: i64, needle: *u8) -> i64 |
| 57 | func count_sub(hay: *u8, hl: i64, needle: *u8) -> i64 calls 1: er_slen |
| 72 | func attr_val(hay: *u8, hl: i64, attr: *u8, out: *u8, outcap: i64) -> i64 |
| 83 | func elem_text(hay: *u8, hl: i64, opentag: *u8, out: *u8, outcap: i64) -> i64 |
| 96 | func find_eocd(z: *u8, zl: i64) -> i64 called by 1: zip_find |
| 107 | func zip_find(z: *u8, zl: i64, target: *u8, ob: *i64) -> i64 |
| 143 | func zip_read_named(z: *u8, zl: i64, target: *u8, out: *u8, outcap: i64) -> i64 |
| 166 | func href_for_id(opf: *u8, ol: i64, idref: *u8, out: *u8, outcap: i64) -> i64 |
| 182 | func join_path(opfpath: *u8, href: *u8, out: *u8) -> i64 |
| 196 | func get_spine_idrefs(opf: *u8, ol: i64, arena: *u8, offs: *i64, cap: i64) -> i64 |
| 221 | func er_wjson(fd: i64, s: *u8) -> i64 |
| 234 | func write_book(idx: i64, title: *u8, author: *u8, nspine: i64, chosen: i64, textn: i64, text: *u8) -> i64 |
| 261 | func do_book(epath: *u8, idx: i64) -> i64 |
| 336 | func main() -> i64 |