code wiki / _hdl_build / nx_dupname_worklist.nx
nx_dupname_worklist.nx source
↩ module page · 74 lines · 4173 B
1// nx_dupname_worklist.nx -- turns the 22 shadow collisions into a PRIORITIZED, actionable rename worklist:
2// for EVERY collision, how many files reference that organ name (fewer = easier/safer to rename). Composes
3// nx_janitor_dupname (the collision set) + a single sovereign tree walk (the caller count) -- ONE walk that
4// checks every .nx against ALL collision names at once (not N walks), reusing the nx_organ_callers reference
5// test. READ-ONLY (never-brick). The caller count INCLUDES the organ's own 2 copies, so external callers ~=
6// count - 2; the RANKING (which collisions are cheapest to resolve) is what matters. license_tier: ORIGINAL
7import "nx_janitor_dupname.nx" // jdn_scan, jdn_is_shadowed
8import "nx_organ_callers.nx" // oc_referenced, oc_read, oc_getdents, oc_isdir, oc_join, oc_ends, oc_eq, oc_slen
9import "nx_syscalls.nx"
10const K_MAGIC_16384: i64 = 16384
11const K_MAGIC_65536: i64 = 65536
12const K_MAGIC_4194304: i64 = 4194304
13
14// ONE walk of `root`: for each .nx, for each of the ncoll collision names, if referenced, counts[k]++.
15func wl_walk(root: *u8, fnames: *u8, colloff: *i64, ncoll: i64, counts: *i64) -> i64 {
16 let qbuf: *u8=sys_mmap(768*K_MAGIC_16384)
17 let gbuf: *u8=sys_mmap(K_MAGIC_65536)
18 let stbuf: *u8=sys_mmap(256)
19 let fbuf: *u8=sys_mmap(K_MAGIC_4194304)
20 let child: *u8=sys_mmap(768)
21 var qh: i64=0; var qt: i64=0
22 var ri: i64=0; while root[ri]!=(0 as u8){ qbuf[ri]=root[ri]; ri=ri+1 } qbuf[ri]=0 as u8; qt=1
23 while qh<qt {
24 let dir: *u8=((qbuf as i64)+qh*768) as *u8; qh=qh+1
25 let fd: i64=sys_openat_rd(dir)
26 if fd<0 { } else {
27 var nread: i64=oc_getdents(fd, gbuf, K_MAGIC_65536)
28 while nread>0 {
29 var off: i64=0
30 while off<nread {
31 let reclen: i64=(gbuf[off+16] as i64)|((gbuf[off+17] as i64)<<8)
32 if reclen<=0 { off=nread } else {
33 let name: *u8=((gbuf as i64)+off+19) as *u8
34 var skip: i64=0
35 if oc_eq(name, "." as *u8)==1 { skip=1 }
36 if oc_eq(name, ".." as *u8)==1 { skip=1 }
37 if skip==0 {
38 oc_join(child, dir, name)
39 let isd: i64=oc_isdir(child, stbuf)
40 if isd==1 {
41 var vend: i64=0
42 if oc_eq(name, "node_modules" as *u8)==1 { vend=1 }
43 if oc_eq(name, ".git" as *u8)==1 { vend=1 }
44 if oc_eq(name, ".alelane" as *u8)==1 { vend=1 }
45 if vend==0 { if qt<K_MAGIC_16384 { let dst: *u8=((qbuf as i64)+qt*768) as *u8; var c: i64=0; while child[c]!=(0 as u8){ dst[c]=child[c]; c=c+1 } dst[c]=0 as u8; qt=qt+1 } }
46 } else { if isd==0 {
47 let pl: i64=oc_slen(child)
48 if oc_ends(child, pl, ".nx" as *u8)==1 {
49 let fn: i64=oc_read(child, fbuf, K_MAGIC_4194304)
50 if fn>0 {
51 var k: i64=0
52 while k<ncoll { if oc_referenced(fbuf, fn, (fnames as i64 + colloff[k]) as *u8)==1 { counts[k]=counts[k]+1 } k=k+1 }
53 }
54 }
55 } }
56 }
57 off=off+reclen
58 }
59 }
60 nread=oc_getdents(fd, gbuf, K_MAGIC_65536)
61 }
62 sys_close(fd)
63 }
64 }
65 sys_munmap(qbuf, 768*K_MAGIC_16384); sys_munmap(gbuf, K_MAGIC_65536); sys_munmap(fbuf, K_MAGIC_4194304)
66 return 0
67}
68
69// collect the collision basenames (the shadowed runtime entries) into colloff[]; returns ncoll.
70func wl_collisions(fnames: *u8, fnoff: *i64, hc: i64, NF: i64, colloff: *i64, maxc: i64) -> i64 {
71 var n: i64=0; var i: i64=hc
72 while i<NF { if jdn_is_shadowed(fnames, fnoff, i, hc)==1 { if n<maxc { colloff[n]=fnoff[i]; n=n+1 } } i=i+1 }
73 return n
74}