code wiki / _hdl_build / nx_imgsrc_probe.nx

nx_imgsrc_probe.nx source

↩ module page · 52 lines · 2144 B

1// nx_imgsrc_probe.nx -- headless diagnosis: after the SHARED br_layout, does page.bsrc_off get the 2// <img src> for image boxes? Lays out a saved HTML file and prints every box that received a src. 3// If images have their src here, the bug is downstream (GUI fetch/decode/blit); if not, br_layout's 4// positional element->box src mapping is dropping them (a shared fix). 5import "nx_syscalls.nx" 6import "nx_browser_render.nx" 7const K_MAGIC_1024: i64 = 1024 8 9func pw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 10func pn(v: i64) -> i64 { 11 if v==0 { pw("0" as *u8); return 0 } 12 var m: i64=v; if m<0 { pw("-" as *u8); m=0-m } 13 let b: *u8=sys_mmap(24); var k: i64=0 14 while m>0 { b[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } 15 var i: i64=k-1; while i>=0 { sys_write(1,((b as i64)+i) as *u8,1); i=i-1 } 16 return 0 17} 18 19func main(argc: i64, argv: *i64) -> i64 { 20 var path: *u8 = "/tmp/wb.html\x00" as *u8 21 if argc >= 2 { path = argv[1] as *u8 } 22 let lenp: *i64 = sys_mmap(8) as *i64 23 let buf: *u8 = sys_read_file(path, lenp) 24 if (buf as i64)==0 { pw("READ FAIL\n" as *u8); return 1 } 25 let hlen: i64 = lenp[0] 26 pw("html bytes=" as *u8); pn(hlen); pw("\n" as *u8) 27 let page: *Page = sys_mmap(NX_PAGE_BYTES) as *Page 28 page.raw = buf; page.raw_len = hlen; page.dark_mode = 0 29 br_layout(page, K_MAGIC_1024) 30 let cnt: i64 = page.tree.count 31 pw("tree.count=" as *u8); pn(cnt); pw("\n" as *u8) 32 var withsrc: i64 = 0 33 var shown: i64 = 0 34 var i: i64 = 0 35 while i < cnt { 36 if page.bsrc_off[i] != (0 - 1) { 37 withsrc = withsrc + 1 38 if shown < 20 { 39 pw(" box " as *u8); pn(i); pw(" src=" as *u8) 40 let so: i64 = page.bsrc_off[i] 41 let sl: i64 = page.bsrc_len[i] 42 var j: i64 = 0 43 while j < sl { if j < 100 { sys_write(1, ((page.buf as i64)+so+j) as *u8, 1) } j = j + 1 } 44 pw("\n" as *u8) 45 shown = shown + 1 46 } 47 } 48 i = i + 1 49 } 50 pw("BOXES WITH SRC=" as *u8); pn(withsrc); pw("\n" as *u8) 51 return 0 52}