code wiki / _hdl_build / nx_chapter_split.nx
nx_chapter_split.nx
buildroot/runtime/_hdl_build/nx_chapter_split.nx
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
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
| 9 | const CS_MAGIC_1252: i64 = 1252 |
| 10 | const CS_MAGIC_1024: i64 = 1024 |
| 12 | const CS_CAP: i64 = 16777216 |
functions
| 14 | func cs_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 15 | func cs_w(fd: i64, s: *u8) -> i64 { sys_write(fd, s, cs_slen(s)); return 0 } |
| 16 | func 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 } |
| 17 | func 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 |
| 18 | func 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 } |
| 19 | func cs_find_sub(hay: *u8, hl: i64, needle: *u8) -> i64 |
| 26 | func cs_wjson(fd: i64, s: *u8) -> i64 |
| 43 | func cs_utf8_put(out: *u8, o: i64, cp: i64) -> i64 called by 1: cs_decode_numeric_refs |
| 49 | func cs_decode_numeric_refs(txt: *u8, n: i64, out: *u8, outcap: i64) -> i64 |
| 80 | func cs_extract_tag(html: *u8, hl: i64, opentag: *u8, closetag: *u8, out: *u8, cap: i64) -> i64 |
| 104 | func cs_extract_heading(html: *u8, hl: i64, out: *u8, cap: i64) -> i64 |
| 112 | func cs_split_on(html: *u8, hl: i64, marker: *u8, seg_s: *i64, seg_e: *i64, maxch: i64) -> i64 |
| 134 | func chapter_split(html: *u8, htmllen: i64, dir: *u8, booktitle: *u8, jfd: i64, total_out: *i64, srctag: *u8) -> i64 called by 3: do_htmldo_kf8do_mobi calls 14: sys_mmapcs_split_onnx_html_to_textcs_decode_numeric_refsnx_charset_repair_utf8cs_cat+8 |