code wiki / _hdl_build / nx_cbx_pages.nx

nx_cbx_pages.nx

buildroot/runtime/_hdl_build/nx_cbx_pages.nx

37892 B800 linesdepth 6pulls 7 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_cbx_pages.nx -- SOVEREIGN CBX page-image extraction (Reader-arc RUNG 3, FORMAT-FIX rev "cfix":2). The operator headline ask: "convert pdf into cbx type zoom" so books read easily on mobile; then "the formats are broken like for the comics" -- this rev EATS that debt. CBX = comic-archive style: ordered page IMAGES the browser renders + pinch/pan/zooms natively. KEY INSIGHT: the browser is the last-mile image renderer/zoomer (allowed). Nishi only EXTRACTS page image BYTES sovereignly, serves them. CONTAINERS (routed by MAGIC BYTES, never extension -- wild comics LIE: zip renamed .cbr, rar renamed .cbz): (A) ZIP (cbz) -- central-directory walker (proven, from nx_epub_read.nx), store+deflate. (B) RAR4 (cbr) -- sovereign block walker, STORED (method 0x30) entries extracted. Comics keep JPEG pages STORED (compressing JPEG gains ~0%), so store-only covers the real corpus; entries that ARE compressed are COUNTED and reported CBX-RAR-COMPRESSED-UNSUPPORTED -- honest, never fake pages. (C) RAR5 (cbr) -- vint block walker, method bits 7..9 == 0 (store) extracted; same honesty. (D) 7z (cb7) -- CBX-7Z-UNSUPPORTED honest skip (LZMA decode not built yet). (E) Scanned/image PDF -- /DCTDecode image XObjects = raw JPEG between stream/endstream. Anchor on /DCTDecode (NEVER bare "stream"), confirm SOI ff d8, scan to endstream. Vector/text PDF -> honest skip. FORMAT-FIX rev (the broken-comics debt this rev eats): 1. NATURAL page sort -- ascii sort put "page10" before "page2" in any non-zero-padded comic = pages OUT OF ORDER. name_cmp_nat compares digit runs numerically (case-insensitive elsewhere). 2. PER-PAGE magic gate -- __MACOSX/._foo.jpg AppleDouble junk passed the extension filter and was WRITTEN as a broken page. Now every page's BYTES must pass img_sig_ok or the entry is skipped+logged. 3. CBR support (B)(C) + magic sniffing (misnamed containers) + honest skip codes. 4. "cfix":2 schema tag in cbx.json -- the server treats a cbx.json WITHOUT the current tag as a cache MISS, so comics extracted by the OLD organ self-heal on next open (no remote rm; additive). SOVEREIGN: pure Nishi organs + raw syscalls. NO python/unzip/unrar/pdfium/mupdf/ghostscript/poppler/gcc/sh. Image DISPLAY+zoom is the browser (last-mile); the viewer JS/CSS is hand-written (no 3rd-party libs). NO-FAKE-GREEN: every written page's first bytes are a REAL image magic (JPEG/PNG/GIF/BMP/WEBP); skips are COUNTED and printed, never silent. ADDITIVE (rule 13): output dir per slug; reruns overwrite atomically. license_tier: ORIGINAL

dependencies 3 imports · 0 importers

nx_syscalls.nx nx_itoa_lib.nx nx_deflate.nx nx_cbx_pages.nx

imports: nx_syscalls.nxnx_itoa_lib.nxnx_deflate.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_pdf sys_mmap sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close er_p ↻ er_w ↻ find_sub er_slen ↻ er_cat ensure_dir ↻ sys_openat_wr find_sub_from find_sub ↻ write_page sys_mmap ↻ er_cat ↻ er_catn sys_mmap ↻ sys_openat_wr ↻ sys_write ↻ sys_close ↻ page_fname er_cat ↻ er_catn ↻ er_n nxi_fd sys_mmap ↻ ccz_cat_num sys_write ↻ sys_munmap

structs

none

consts

35const PAGE_MAGIC_1024: i64 = 1024
36const PAGE_MAGIC_1048576: i64 = 1048576
266const PAGE_CAP: i64 = 67108864 // 64 MiB per page buffer (largest cbz page << this)
305const ECAP: i64 = 4096 // max archive entries enumerated

functions

39func er_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
40func er_w(fd: i64, s: *u8) -> i64 { sys_write(fd, s, er_slen(s)); return 0 }
45func er_n(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }
called by 3: er_pnemit_pagesdo_pdf calls 1: nxi_fd
46func er_p(s: *u8) -> i64 { er_w(1, s); return 0 }
called by 4: emit_pagesdo_pdfdo_cbzmain calls 1: er_w
47func er_pn(v: i64) -> i64 { er_n(1, v); return 0 }
called by 4: emit_pagesdo_pdfdo_cbzmain calls 1: er_n
49func le16(b: *u8, o: i64) -> i64 { return (b[o] as i64) | ((b[o+1] as i64) << 8) }
called by 2: zip_enumrar4_enum
50func 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 2: zip_enumrar4_enum
52func 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 }
53func 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: write_pagepage_fname calls 1: sys_mmap
56func find_sub(hay: *u8, hl: i64, needle: *u8) -> i64
71func find_sub_from(hay: *u8, hl: i64, needle: *u8, from: i64) -> i64
called by 1: do_pdf calls 1: find_sub
79func find_eocd(z: *u8, zl: i64) -> i64
called by 1: zip_enum
91func zip_enum(z: *u8, zl: i64, arena: *u8, acap: i64, noffs: *i64, meths: *i64, comps: *i64, doffs: *i64, ecap: i64) -> i64
called by 1: do_cbz calls 3: find_eocdle16le32
128func name_cmp(a: *u8, b: *u8) -> i64
called by 1: is_image_name
143func lc(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c }
146func nat_digits(s: *u8, o: i64) -> i64
called by 1: name_cmp_nat
160func name_cmp_nat(a: *u8, b: *u8) -> i64
called by 1: emit_pages calls 2: nat_digitslc
213func is_image_name(name: *u8) -> i64
237func is_junk_name(name: *u8) -> i64
called by 1: emit_pages calls 2: er_slenfind_sub
249func ext_of(name: *u8, out: *u8) -> i64
called by 1: emit_pages calls 3: er_slener_catlc
264func ensure_dir(path: *u8) -> i64 { __syscall(258, 0-100, path, 0x1ed, 0, 0, 0); return 0 }
269func write_page(dir: *u8, idx: i64, ext: *u8, bytes: *u8, n: i64) -> i64
285func page_fname(out: *u8, idx: i64, ext: *u8) -> i64
called by 2: emit_pagesdo_pdf calls 2: er_cater_catn
296func img_sig_ok(b: *u8, n: i64) -> i64
called by 1: emit_pages
313func emit_pages(z: *u8, slug: *u8, fmt: *u8, arena: *u8, noffs: *i64, meths: *i64, comps: *i64, doffs: *i64, nent: i64, cover_only: i64) -> i64
466func rar4_enum(z: *u8, zl: i64, arena: *u8, acap: i64, noffs: *i64, meths: *i64, comps: *i64, doffs: *i64, ecap: i64, skipc: *i64) -> i64
called by 1: do_cbz calls 2: le16le32
527func r5v(z: *u8, pos: *i64, zl: i64) -> i64
called by 1: rar5_enum
550func rar5_enum(z: *u8, zl: i64, arena: *u8, acap: i64, noffs: *i64, meths: *i64, comps: *i64, doffs: *i64, ecap: i64, skipc: *i64) -> i64
called by 1: do_cbz calls 2: sys_mmapr5v
609func do_pdf(path: *u8, slug: *u8) -> i64
694func do_cbz(path: *u8, slug: *u8, cover_only: i64) -> i64
758func main(argc: i64, argv: *i64) -> i64