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