code wiki / _hdl_build / nx_game_catalog.nx

nx_game_catalog.nx source

↩ module page · 87 lines · 4902 B

1import "nx_gate_gn.nx" 2import "nx_gate_base.nx" 3// nx_game_catalog.nx -- NISHI GAME RESEARCH, rung 1: PER-GAME catalog. The genre registry (nx_game_ingest) 4// only counts links; THIS parses the banked catalog (knowledge/store/bobeff_games.md) into a per-game registry 5// knowledge/store/nx_game_catalog.reg = TSV `genre<TAB>name<TAB>repo_url` -- i.e. the 441 actual GIT REPOS to 6// review. Foundation for "review their gits / what does what / how to S-class exceed". Reads the banked raw 7// (run nx_game_ingest first to bank it). 100% sovereign (own parse, nx_cc->nxasm). license_tier: ORIGINAL 8import "nx_syscalls.nx" 9 10func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 11" as *u8); return ok } 12 13func match_at(buf: *u8, n: i64, i: i64, pat: *u8) -> i64 { 14 var j: i64 = 0 15 while pat[j] != (0 as u8) { if i + j >= n { return 0 } if buf[i + j] != pat[j] { return 0 } j = j + 1 } 16 return 1 17} 18// find pat within [start,end); return its index or -1 19func find_in(buf: *u8, n: i64, start: i64, end: i64, pat: *u8) -> i64 { 20 var i: i64 = start 21 while i < end { if match_at(buf, n, i, pat) == 1 { return i } i = i + 1 } 22 return 0 - 1 23} 24 25func main() -> i64 { 26 let lenp: *i64 = sys_mmap(8) as *i64 27 let buf: *u8 = sys_read_file("knowledge/store/bobeff_games.md" as *u8, lenp) 28 if (buf as i64) == 0 { gw("CATALOG: banked catalog missing -- run nx_game_ingest first\n"); return 1 } 29 let n: i64 = lenp[0] 30 let fd: i64 = sys_openat_wr("knowledge/store/nx_game_catalog.reg" as *u8, 0x1a4) 31 if fd < 0 { gw("CATALOG: registry open failed\n"); return 2 } 32 33 var i: i64 = 0 34 var cg0: i64 = 0; var cg1: i64 = 0; var have_g: i64 = 0 // current genre slice 35 var count: i64 = 0; var shown: i64 = 0 36 gw("== PER-GAME CATALOG (sample) ==\n") 37 while i < n { 38 var ls: i64 = 0 39 if i == 0 { ls = 1 } else { if buf[i-1] == 10 as u8 { ls = 1 } } 40 if ls == 1 { 41 if match_at(buf, n, i, "## " as *u8) == 1 { 42 let t0: i64 = i + 3; var t1: i64 = t0 43 while t1 < n { if buf[t1] == 10 as u8 { break } t1 = t1 + 1 } 44 if match_at(buf, n, t0, "Table of contents" as *u8) == 0 { 45 cg0 = t0; cg1 = t1; have_g = 1 46 if match_at(buf, n, t0, "Other lists" as *u8) == 1 { have_g = 0 } // meta-lists, not games 47 } 48 } else { if match_at(buf, n, i, "- **" as *u8) == 1 { if have_g == 1 { 49 var le: i64 = i 50 while le < n { if buf[le] == 10 as u8 { break } le = le + 1 } 51 // name: "[Name]" or "Name**" 52 let p: i64 = i + 4; var n0: i64 = p; var n1: i64 = p 53 if buf[p] == 91 as u8 { n0 = p + 1; n1 = n0; while n1 < le { if buf[n1] == 93 as u8 { break } n1 = n1 + 1 } } 54 else { n0 = p; n1 = n0; while n1 < le { if buf[n1] == 42 as u8 { break } n1 = n1 + 1 } } 55 // repo url from [[source]](URL) 56 var u0: i64 = 0 - 1; var u1: i64 = 0 - 1 57 let su: i64 = find_in(buf, n, i, le, "[[source]](" as *u8) 58 if su >= 0 { u0 = su + 11; u1 = u0; while u1 < le { if buf[u1] == 41 as u8 { break } u1 = u1 + 1 } } 59 else { 60 // fallback: a game whose homepage IS its git repo (no separate [[source]]) 61 let hp: i64 = find_in(buf, n, n1, le, "](http" as *u8) 62 if hp >= 0 { 63 let h0: i64 = hp + 2; var h1: i64 = h0; while h1 < le { if buf[h1] == 41 as u8 { break } h1 = h1 + 1 } 64 var isgit: i64 = 0 65 if find_in(buf, n, h0, h1, "github" as *u8) >= 0 { isgit = 1 } 66 if find_in(buf, n, h0, h1, "gitlab" as *u8) >= 0 { isgit = 1 } 67 if find_in(buf, n, h0, h1, "codeberg" as *u8) >= 0 { isgit = 1 } 68 if isgit == 1 { u0 = h0; u1 = h1 } 69 } 70 } 71 if u0 >= 0 { 72 sys_write(fd, ((buf as i64) + cg0) as *u8, cg1 - cg0); sys_write(fd, "\t" as *u8, 1) 73 sys_write(fd, ((buf as i64) + n0) as *u8, n1 - n0); sys_write(fd, "\t" as *u8, 1) 74 sys_write(fd, ((buf as i64) + u0) as *u8, u1 - u0); sys_write(fd, "\n" as *u8, 1) 75 count = count + 1 76 if shown < 5 { gw(" "); sys_write(1, ((buf as i64) + n0) as *u8, n1 - n0); gw(" -> "); sys_write(1, ((buf as i64) + u0) as *u8, u1 - u0); gw("\n"); shown = shown + 1 } 77 } 78 } } } 79 } 80 i = i + 1 81 } 82 sys_close(fd) 83 gw("CATALOG: parsed "); gn(count); gw(" games with repo URLs -> knowledge/store/nx_game_catalog.reg\n") 84 if count >= 140 { gw("CATALOG-OK\n"); return 0 } 85 gw("CATALOG: too few games parsed (format drift?)\n") 86 return 3 87}