code wiki / _hdl_build / _reader_open_authored.nx

_reader_open_authored.nx

buildroot/runtime/_hdl_build/_reader_open_authored.nx

2581 B19 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic reader
docsdependenciesstructsconstsfunctions

about

AUTHORED BY THE NISHI BUILDER (reader-open template) -- e-reader open-document happy path, bits-up

dependencies 1 imports · 0 importers

_inflate_lib_authored.nx _reader_open_authored.nx

imports: _inflate_lib_authored.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_read_file sys_openat_rd sys_lseek sys_mmap sys_read sys_close reader_open pdf_extract psub inflate sys_mmap ↻ ibr ihb sys_mmap ↻ icodes ihd ibr ↻ ibr ↻ ihd ↻ pdf_text word_wrap psub ↻

structs

none

consts

none

functions

3func psub(buf: *u8, n: i64, from: i64, needle: *u8, nl: i64) -> i64 { var i: i64=from; while i+nl<=n { var ok: i64=1; var j: i64=0; while j<nl { if buf[i+j]!=needle[j] { ok=0; j=nl } else { j=j+1 } } if ok==1 { return i } i=i+1 } return 0-1 }
called by 2: pdf_extractmain
4func pdf_extract(pdf: *u8, pl: i64, out: *u8) -> i64 { let s: i64=psub(pdf,pl,0,"stream" as *u8,6); if s<0 { return 0-1 } var ds: i64=s+6; if pdf[ds]==0x0d as u8 { ds=ds+1 } if pdf[ds]==0x0a as u8 { ds=ds+1 } let e: i64=psub(pdf,pl,ds,"endstream" as *u8,9); if e<0 { return 0-1 } var de: i64=e; if de>ds { if pdf[de-1]==0x0a as u8 { de=de-1 } } if de>ds { if pdf[de-1]==0x0d as u8 { de=de-1 } } return inflate(((pdf as i64)+ds+2) as *u8, de-ds-2, out) }
called by 1: reader_open calls 2: psubinflate
5func pdf_text(s: *u8, sl: i64, out: *u8) -> i64 { var op: i64=0; var i: i64=0; while i<sl { if s[i]==0x28 as u8 { i=i+1; var instr: i64=1; while instr==1 { if i>=sl { instr=0 } else { if s[i]==0x5c as u8 { i=i+1; if i<sl { out[op]=s[i]; op=op+1; i=i+1 } } else { if s[i]==0x29 as u8 { instr=0; i=i+1 } else { out[op]=s[i]; op=op+1; i=i+1 } } } } } else { i=i+1 } } return op }
called by 1: reader_open
6func word_wrap(s: *u8, n: i64, width: i64, out: *u8) -> i64 { var op: i64=0; var ll: i64=0; var i: i64=0; while i<n { while i<n { if s[i]==0x20 as u8 { i=i+1 } else { break } } if i<n { let ws: i64=i; while i<n { if s[i]!=0x20 as u8 { i=i+1 } else { break } } let wl: i64=i-ws; if ll==0 { var k: i64=0; while k<wl { out[op]=s[ws+k]; op=op+1; k=k+1 } ll=wl } else { if ll+1+wl<=width { out[op]=0x20 as u8; op=op+1; var k2: i64=0; while k2<wl { out[op]=s[ws+k2]; op=op+1; k2=k2+1 } ll=ll+1+wl } else { out[op]=0x0a as u8; op=op+1; var k3: i64=0; while k3<wl { out[op]=s[ws+k3]; op=op+1; k3=k3+1 } ll=wl } } } } return op }
called by 1: reader_open
7func reader_open(pdf: *u8, pl: i64, width: i64, out: *u8) -> i64 { let t1: *u8=sys_mmap(65536); let sn: i64=pdf_extract(pdf,pl,t1); if sn<0 { return 0-1 } let t2: *u8=sys_mmap(65536); let tn: i64=pdf_text(t1,sn,t2); return word_wrap(t2,tn,width,out) }
called by 1: main calls 3: pdf_extractpdf_textword_wrap
8func main() -> i64