code wiki / _hdl_build / nx_chapter_split.nx

nx_chapter_split.nx

buildroot/runtime/_hdl_build/nx_chapter_split.nx

11561 B201 linesdepth 4pulls 5 transitivereach 5 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_chapter_split.nx -- SHARED chapter-splitting for the Kindle decoders (nx_mobi_book + nx_kf8_book). Splits the decoded HTML on <mbp:pagebreak> into real chapters -> writes chap<i>.txt + extracts per-chapter <h1> titles, and writes the chapters[]/toc[] JSON straight to the open book.json fd. The zero-JS reader already renders chapters[]/toc[] (the EPUB path), so a multi-chapter book.json = a real navigable TOC for free. No pagebreak -> 1 chapter titled with the book title (back-compat). license_tier: ORIGINAL

dependencies 3 imports · 5 importers

nx_syscalls.nx nx_html_to_text.nx nx_charset.nx nx_chapter_split.nx nx_book_titles_gate.nx nx_fb2_book.nx nx_html_book.nx nx_kf8_book.nx nx_mobi_book.nx

imports: nx_syscalls.nxnx_html_to_text.nxnx_charset.nx

imported by: nx_book_titles_gate.nxnx_fb2_book.nxnx_html_book.nxnx_kf8_book.nxnx_mobi_book.nx

structs

none

consts

9const CS_MAGIC_1252: i64 = 1252
10const CS_MAGIC_1024: i64 = 1024
12const CS_CAP: i64 = 16777216

functions

14func cs_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
15func cs_w(fd: i64, s: *u8) -> i64 { sys_write(fd, s, cs_slen(s)); return 0 }
called by 1: chapter_split calls 2: sys_writecs_slen
16func cs_wn(fd: i64, v: i64) -> i64 { let b: *u8=sys_mmap(24); var m: i64=v; if m<0{m=0-m;sys_write(fd,"-" as *u8,1)}; let t: *u8=sys_mmap(24); 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{b[i]=t[k-1-i];i=i+1}; sys_write(fd,b,k); return 0 }
called by 1: chapter_split calls 2: sys_mmapsys_write
17func cs_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){d[o+i]=s[i];i=i+1} return o+i }
called by 1: chapter_split
18func cs_catn(d: *u8, o0: i64, v: i64) -> i64 { var o: i64=o0; let t: *u8=sys_mmap(24); 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{d[o+i]=t[k-1-i];i=i+1} return o+k }
called by 2: chapter_splitdo_fb2 calls 1: sys_mmap
19func cs_find_sub(hay: *u8, hl: i64, needle: *u8) -> i64
called by 2: cs_extract_tagcs_split_on calls 1: cs_slen
26func cs_wjson(fd: i64, s: *u8) -> i64
43func cs_utf8_put(out: *u8, o: i64, cp: i64) -> i64
49func cs_decode_numeric_refs(txt: *u8, n: i64, out: *u8, outcap: i64) -> i64
called by 1: chapter_split calls 1: cs_utf8_put
80func cs_extract_tag(html: *u8, hl: i64, opentag: *u8, closetag: *u8, out: *u8, cap: i64) -> i64
104func cs_extract_heading(html: *u8, hl: i64, out: *u8, cap: i64) -> i64
112func cs_split_on(html: *u8, hl: i64, marker: *u8, seg_s: *i64, seg_e: *i64, maxch: i64) -> i64
134func chapter_split(html: *u8, htmllen: i64, dir: *u8, booktitle: *u8, jfd: i64, total_out: *i64, srctag: *u8) -> i64