code wiki / _hdl_build / _pngchunk_corpus_drive.nx

_pngchunk_corpus_drive.nx source

↩ module page · 34 lines · 2117 B

1// _pngchunk_corpus_drive.nx -- GATE HARNESS (not organ logic): drives the ORGAN-authored 2// _pe_pngchunk walker over the REAL corpus sample and prints what it found, so the gate can 3// diff against the independently-measured oracle (tEXt off=33, seed off=66, IEND last). 4// This file only READS a PNG and CALLS the authored functions -- it authors NO parser logic. 5// Reading raw PNG bytes is the sovereign ingest itself (NOT an Elder-service dependency). 6import "_pe_pngchunk.nx" 7import "nx_syscalls.nx" 8func _w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } 9func _wn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m; sys_write(fd,"-" as *u8,1)}; let t: *u8=sys_mmap(28); 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{bb[i]=t[k-1-i];i=i+1}; sys_write(fd,bb,k); return 0 } 10func main(argc: i64, argv: *i64) -> i64 { 11 if argc < 2 { _w(1, "usage: drive <png>\n" as *u8); sys_exit(2); return 2 } 12 let path: *u8 = argv[1] as *u8 13 let lenp: *i64 = sys_mmap(16) as *i64 14 let raw: *u8 = sys_read_file(path, lenp) 15 if raw as i64 == 0 { _w(1, "READ-FAIL\n" as *u8); sys_exit(1); return 1 } 16 let total: i64 = lenp[0] 17 // PNG signature is 8 bytes; the chunk stream begins at offset 8 18 let base: i64 = raw as i64 19 let chunks: *u8 = (base + 8) as *u8 20 let n: i64 = total - 8 21 // type codes as BE i64 (4 ASCII bytes): tEXt = 0x74455874, IEND = 0x49454E44, iTXt = 0x69545874 22 let cnt: i64 = _pe_pngchunk_count(chunks, n) 23 let off_text: i64 = _pe_pngchunk_find(chunks, n, 0x74455874) 24 let off_itxt: i64 = _pe_pngchunk_find(chunks, n, 0x69545874) 25 let off_iend: i64 = _pe_pngchunk_find(chunks, n, 0x49454E44) 26 _w(1, "PNGWALK file_bytes=" as *u8); _wn(1, total) 27 _w(1, " chunk_count=" as *u8); _wn(1, cnt) 28 _w(1, " first_tEXt_body_off=" as *u8); _wn(1, off_text) 29 _w(1, " first_iTXt_body_off=" as *u8); _wn(1, off_itxt) 30 _w(1, " IEND_body_off=" as *u8); _wn(1, off_iend) 31 _w(1, "\n" as *u8) 32 sys_exit(0) 33 return 0 34}