code wiki / _hdl_build / nx_loose_format_census.nx

nx_loose_format_census.nx source

↩ module page · 99 lines · 5427 B

1// nx_loose_format_census.nx -- COORDINATED sweep driver for E-DOCTRINE's consistency sweep: a sovereign 2// scanner that enumerates every organ still touching a loose DATA format (.tsv/.conf string-literal paths), 3// so the "~106" becomes a real, measured, trackable worklist any workstream can pull from. getdents64 over 4// the organ dirs + a bounded read per .nx + substring flag; the flagged list -> knowledge/status/ 5// loose_format_census.log. (.log excluded on purpose -- gate output is fine; the target is DATA in loose 6// files.) Pairs with nx_sprawl_ratchet (the guard): census = what's LEFT, ratchet = no NEW regressions. 7// license_tier: ORIGINAL 8import "nx_syscalls.nx" 9const K_MAGIC_65536: i64 = 65536 10const K_MAGIC_262144: i64 = 262144 11const K_MAGIC_4096: i64 = 4096 12 13func lc_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 } 14func lc_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 } 15 16func lc_has(buf: *u8, n: i64, pat: *u8, plen: i64) -> i64 { 17 var i: i64=0 18 while i + plen <= n { 19 var j: i64=0; var m: i64=1 20 while j < plen { if buf[i+j]!=pat[j] { m=0; j=plen } else { j=j+1 } } 21 if m==1 { return 1 } 22 i=i+1 23 } 24 return 0 25} 26func lc_ends(name: *u8, nlen: i64, suf: *u8, slen: i64) -> i64 { 27 if slen > nlen { return 0 } 28 var i: i64=0 29 while i < slen { if name[nlen-slen+i]!=suf[i] { return 0 } i=i+1 } 30 return 1 31} 32func lc_cat(dst: *u8, o: i64, s: *u8) -> i64 { var oo:i64=o; var i:i64=0; while s[i]!=(0 as u8){dst[oo]=s[i];oo=oo+1;i=i+1} return oo } 33 34func lc_scan(dirpath: *u8, logfd: i64, cnt: *i64, rbuf: *u8, fullbuf: *u8, dbuf: *u8) -> i64 { 35 let fd: i64 = __syscall(257, 0 - 100, dirpath as i64, 0x10000, 0, 0, 0) 36 if fd < 0 { return 0 } 37 var go: i64 = 1 38 while go == 1 { 39 let nr: i64 = __syscall(217, fd, dbuf as i64, K_MAGIC_65536, 0, 0, 0) 40 if nr <= 0 { go = 0 } else { 41 var pos: i64 = 0 42 while pos < nr { 43 let reclen: i64 = (dbuf[pos+16] as i64) | ((dbuf[pos+17] as i64) << 8) 44 let name: *u8 = ((dbuf as i64)+pos+19) as *u8 45 var nlen: i64=0; while name[nlen]!=(0 as u8){nlen=nlen+1} 46 if lc_ends(name, nlen, ".nx\x00" as *u8, 3) == 1 { 47 cnt[2] = cnt[2] + 1 48 var fo: i64 = lc_cat(fullbuf, 0, dirpath); fullbuf[fo]=(47 as u8); fo=fo+1 49 fo = lc_cat(fullbuf, fo, name); fullbuf[fo]=0 as u8 50 let rfd: i64 = sys_openat_rd(fullbuf) 51 if rfd >= 0 { 52 let rn: i64 = sys_read(rfd, rbuf, K_MAGIC_262144) 53 sys_close(rfd) 54 let hastsv: i64 = lc_has(rbuf, rn, ".tsv\"\x00" as *u8, 5) 55 let hasconf: i64 = lc_has(rbuf, rn, ".conf\"\x00" as *u8, 6) 56 if hastsv == 1 { cnt[0]=cnt[0]+1 } 57 if hasconf == 1 { cnt[1]=cnt[1]+1 } 58 // REAL sweep target = touches a loose DATA format AND reads-a-file AND is not a 59 // test/gate/census organ (those reference loose paths in fixtures, not as the SSOT). 60 var istest: i64 = 0 61 if lc_ends(name, nlen, "_gate.nx\x00" as *u8, 8) == 1 { istest = 1 } 62 if lc_ends(name, nlen, "_test.nx\x00" as *u8, 8) == 1 { istest = 1 } 63 if lc_ends(name, nlen, "_census.nx\x00" as *u8, 10) == 1 { istest = 1 } 64 var reads: i64 = 0 65 if lc_has(rbuf, rn, "sys_read_file\x00" as *u8, 13) == 1 { reads = 1 } 66 if lc_has(rbuf, rn, "sys_openat_rd\x00" as *u8, 13) == 1 { reads = 1 } 67 var real: i64 = 0 68 if hastsv == 1 { real = 1 } 69 if hasconf == 1 { real = 1 } 70 if istest == 1 { real = 0 } 71 if reads == 0 { real = 0 } 72 if real == 1 { cnt[3] = cnt[3] + 1; lc_w(logfd, fullbuf); lc_w(logfd, "\n\x00" as *u8) } 73 } 74 } 75 pos = pos + reclen 76 } 77 } 78 } 79 sys_close(fd) 80 return 0 81} 82 83func main() -> i64 { 84 let cnt: *i64 = sys_mmap(8*4) as *i64 85 cnt[0]=0; cnt[1]=0; cnt[2]=0; cnt[3]=0 86 let rbuf: *u8 = sys_mmap(K_MAGIC_262144) 87 let fullbuf: *u8 = sys_mmap(K_MAGIC_4096) 88 let dbuf: *u8 = sys_mmap(K_MAGIC_65536) 89 let logfd: i64 = sys_openat_wr("knowledge/status/loose_format_census.log\x00" as *u8, 420) 90 lc_scan("runtime/_hdl_build\x00" as *u8, logfd, cnt, rbuf, fullbuf, dbuf) 91 lc_scan("runtime\x00" as *u8, logfd, cnt, rbuf, fullbuf, dbuf) 92 if logfd >= 0 { sys_close(logfd) } 93 lc_w(1, "nx_loose_format_census: .nx organs scanned=\x00" as *u8); lc_wn(1, cnt[2]) 94 lc_w(1, " touch .tsv=\x00" as *u8); lc_wn(1, cnt[0]) 95 lc_w(1, " touch .conf=\x00" as *u8); lc_wn(1, cnt[1]) 96 lc_w(1, " ==> REAL sweep targets (touch loose data + read-a-file + non-test)=\x00" as *u8); lc_wn(1, cnt[3]) 97 lc_w(1, " (worklist -> knowledge/status/loose_format_census.log)\n\x00" as *u8) 98 return 0 99}