code wiki / _hdl_build / nx_epub_book.nx

nx_epub_book.nx

buildroot/runtime/_hdl_build/nx_epub_book.nx

42771 B869 linesdepth 6pulls 11 transitivereach 0 importersview sourcekind tooltopic epub
docsdependenciesstructsconstsfunctions

about

nx_epub_book.nx -- SOVEREIGN FULL-BOOK EPUB extraction (Reader-arc RUNG 2b, deliverable 1). Builds on nx_epub_read.nx (RUNG 2, GREEN over real Calibre epubs). Same sovereign parse path: ZIP central-directory walker + nx_deflate inflate + container.xml -> OPF -> spine + nx_html_to_text. NEW logic only (everything else reused verbatim): (a) walk ALL spine items in reading order (not the first-real-chapter pick), (b) decode_numeric_refs: a sovereign post-pass that rewrites &#DDDD; / &#xHHHH; numeric character references to UTF-8 bytes (nx_html_to_text leaves these RAW -- the rung-2 output showed literal &#x2019; / &#x201c; / &#x2014;; fixed here so curly quotes / em-dashes render natively), (c) TOC/nav skip: flag the nav/TOC doc so the reader opens at real prose, but STILL include it in chapters[] in reading order (operator requirement: skip-as-opening only, include all), (d) emit knowledge/staging/media/reader/<slug>/book.json {title,author,format,nchapters, chapters:[{idx,title,file,chars,is_nav}]} + one chap<K>.txt per chapter. ADDITIVE (rule 13). SOVEREIGN: pure Nishi organs + raw syscalls. NO python/unzip/3rd-party-xml/gcc/sh, NO calibre binaries. NO-FAKE-GREEN: a REAL Calibre epub; title/author/spine/text MEASURED from bytes; after decode, NO chapter may contain "&#" (has_raw_entities asserted 0). license_tier: ORIGINAL

dependencies 6 imports · 0 importers

nx_syscalls.nx nx_itoa_lib.nx nx_deflate.nx nx_html_to_text.nx nx_epub_nav.nx nx_charset.nx nx_epub_book.nx

imports: nx_syscalls.nxnx_itoa_lib.nxnx_deflate.nxnx_html_to_text.nxnx_epub_nav.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 er_p er_w sys_write er_slen ensure_dir do_full_book sys_mmap sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close er_p ↻ 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 sys_mmap ↻ nx_huffman_build _deflate_build_static_dist sys_mmap ↻ nx_huffman_build ↻ _deflate_decode_huffman_bl

structs

none

consts

24const CHAP_MAGIC_1252: i64 = 1252
25const CHAP_MAGIC_1200: i64 = 1200
26const CHAP_MAGIC_1024: i64 = 1024
27const CHAP_MAGIC_262144: i64 = 262144
28const CHAP_MAGIC_2097152: i64 = 2097152
29const CHAP_MAGIC_8192: i64 = 8192
30const CHAP_MAGIC_65536: i64 = 65536
31const CHAP_MAGIC_16384: i64 = 16384
32const CHAP_MAGIC_2048: i64 = 2048
33const CHAP_MAGIC_32768: i64 = 32768
34const CHAP_MAGIC_5381: i64 = 5381
35const CHAP_MAGIC_2000: i64 = 2000
409const CHAP_CAP: i64 = 4194304

functions

38func er_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
39func er_w(fd: i64, s: *u8) -> i64 { sys_write(fd, s, er_slen(s)); return 0 }
called by 2: er_pdo_full_book calls 2: sys_writeer_slen
44func er_n(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }
called by 2: er_pndo_full_book calls 1: nxi_fd
45func er_p(s: *u8) -> i64 { er_w(1, s); return 0 }
called by 2: do_full_bookmain calls 1: er_w
46func er_pn(v: i64) -> i64 { er_n(1, v); return 0 }
called by 1: do_full_book calls 1: er_n
48func le16(b: *u8, o: i64) -> i64 { return (b[o] as i64) | ((b[o+1] as i64) << 8) }
called by 1: zip_find
49func 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
51func 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 }
52func 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 2: chap_titledo_full_book calls 1: sys_mmap
55func find_sub(hay: *u8, hl: i64, needle: *u8) -> i64
70func count_sub(hay: *u8, hl: i64, needle: *u8) -> i64
called by 1: is_nav_doc calls 1: er_slen
85func attr_val(hay: *u8, hl: i64, attr: *u8, out: *u8, outcap: i64) -> i64
96func elem_text(hay: *u8, hl: i64, opentag: *u8, out: *u8, outcap: i64) -> i64
called by 1: do_full_book calls 1: find_sub
108func find_eocd(z: *u8, zl: i64) -> i64
called by 1: zip_find
118func zip_find(z: *u8, zl: i64, target: *u8, ob: *i64) -> i64
153func zip_read_named(z: *u8, zl: i64, target: *u8, out: *u8, outcap: i64) -> i64
175func href_for_id(opf: *u8, ol: i64, idref: *u8, out: *u8, outcap: i64) -> i64
190func join_path(opfpath: *u8, href: *u8, out: *u8) -> i64
called by 1: do_full_book calls 1: er_slen
204func get_spine_idrefs(opf: *u8, ol: i64, arena: *u8, offs: *i64, cap: i64) -> i64
called by 1: do_full_book calls 1: find_sub
231func er_wjson(fd: i64, s: *u8) -> i64
251func utf8_put(out: *u8, o: i64, cp: i64) -> i64
called by 1: decode_numeric_refs
275func decode_numeric_refs(txt: *u8, n: i64, out: *u8, outcap: i64) -> i64
called by 1: do_full_book calls 1: utf8_put
337func is_nav_doc(raw: *u8, rawn: i64, text: *u8, textn: i64) -> i64
called by 1: do_full_book calls 2: find_subcount_sub
350func first_line(txt: *u8, n: i64, out: *u8, outcap: i64) -> i64
called by 1: chap_title
367func eb_heading_inner(raw: *u8, rawn: i64, open: *u8, close: *u8, out: *u8, cap: i64) -> i64
called by 1: chap_title calls 1: find_sub
389func chap_title(raw: *u8, rawn: i64, dtxt: *u8, dn: i64, k: i64, out: *u8, outcap: i64) -> i64
412func ensure_dir(path: *u8) -> i64 { __syscall(258, 0-100, path, 0x1ed, 0, 0, 0); return 0 }
called by 2: do_full_bookmain
416func elem_owner_href(opf: *u8, ol: i64, marker: *u8, out: *u8, outcap: i64) -> i64
called by 1: do_full_book calls 2: find_subattr_val
426func base_after_slash(src: *u8, out: *u8, outcap: i64) -> i64
436func strip_frag(s: *u8) -> i64
441func str_eq0(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8){ if a[i]!=b[i]{return 0} i=i+1 } if b[i]!=(0 as u8){return 0} return 1 }
called by 1: do_full_book
447func img_markerize(raw: *u8, n: i64, out: *u8, cap: i64) -> i64
485func tag_is(raw: *u8, n: i64, i: i64, tag: *u8) -> i64
called by 1: fn_markerize
506func fn_markerize(raw: *u8, n: i64, out: *u8, cap: i64, fnctx: *i64) -> i64
560func do_full_book(epath: *u8, slug: *u8) -> i64
860func main(argc: i64, argv: *i64) -> i64