code wiki / _hdl_build / nx_sovgit_zlibprobe.nx
nx_sovgit_zlibprobe.nx source
↩ module page · 32 lines · 1370 B
1// nx_sovgit_zlibprobe.nx -- diagnostic: inflate a zlib file (e.g. a git loose object) with the
2// sovereign decoder and print err/out/consumed vs input size. license_tier: ORIGINAL
3import "nx_sovgit_obj.nx"
4
5func zp_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
6func zp_n(v: i64) -> i64 {
7 let b: *u8 = sys_mmap(32)
8 var x: i64 = v
9 var neg: i64 = 0
10 if x < 0 { neg = 1; x = 0 - x }
11 var i: i64 = 31
12 if x == 0 { b[i] = 48 as u8; i = i - 1 }
13 while x > 0 { b[i] = (48 + x % 10) as u8; x = x / 10; i = i - 1 }
14 if neg == 1 { b[i] = 45 as u8; i = i - 1 }
15 sys_write(1, (b as i64 + i + 1) as *u8, 31 - i)
16 return 0
17}
18func main(argc: i64, argv: *i64) -> i64 {
19 if argc < 2 { zp_w("usage: zlibprobe <zlib-file>\n" as *u8); return 2 }
20 let szp: *i64 = sys_mmap(16) as *i64
21 let b: *u8 = sys_read_file(argv[1] as *u8, szp)
22 if (b as i64) == 0 { zp_w("read fail\n" as *u8); return 1 }
23 let r: *NxZlibResult = nx_zlib_inflate(b, szp[0], 1 << 23)
24 zp_w("in=" as *u8); zp_n(szp[0])
25 zp_w(" err=" as *u8); zp_n(r.error_code)
26 zp_w(" out=" as *u8); zp_n(r.output_size)
27 zp_w(" consumed=" as *u8); zp_n(r.bytes_consumed)
28 zp_w(" adler_exp=" as *u8); zp_n(r.adler_expected)
29 zp_w(" adler_got=" as *u8); zp_n(r.adler_computed)
30 zp_w("\n" as *u8)
31 return 0
32}