code wiki / (root) / nx_app_seed.nx

nx_app_seed.nx source

↩ module page · 71 lines · 4257 B

1// nx_app_seed.nx -- seed the sovereign app registry (nx_app_store / seg_store) with 2// the current Nishi web apps, then list them back to prove put+list round-trips. 3// Idempotent: re-running adds additive versions; __apps__ stays deduped. expect_exit 0. 4import "nx_syscalls.nx" 5import "nx_app_store.nx" 6const K_MAGIC_4096: i64 = 4096 7const K_MAGIC_65536: i64 = 65536 8 9func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 10func wn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; 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{b[i]=t[k-1-i];i=i+1}; sys_write(1,b,k); return 0 } 11func cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){ dst[off+i]=s[i]; i=i+1 } return off+i } 12 13// record = path<TAB>title<TAB>blurb<TAB>category<TAB>marker 14func mkrec(rec: *u8, path: *u8, title: *u8, blurb: *u8, cate: *u8, marker: *u8) -> i64 { 15 var o: i64 = cat(rec, 0, path); rec[o]=9 as u8; o=o+1 16 o = cat(rec, o, title); rec[o]=9 as u8; o=o+1 17 o = cat(rec, o, blurb); rec[o]=9 as u8; o=o+1 18 o = cat(rec, o, cate); rec[o]=9 as u8; o=o+1 19 o = cat(rec, o, marker) 20 return o 21} 22func seed1(name: *u8, path: *u8, title: *u8, blurb: *u8, cate: *u8, marker: *u8) -> i64 { 23 let rec: *u8 = sys_mmap(K_MAGIC_4096) 24 let l: i64 = mkrec(rec, path, title, blurb, cate, marker) 25 let rc: i64 = nx_app_store_put(name, rec, l) 26 if rc == 0 { w(" put " as *u8) } else { w(" FAIL " as *u8) } 27 w(name); w("\n" as *u8) 28 return rc 29} 30 31func main() -> i64 { 32 w("=== seeding app registry into sovereign seg_store (knowledge/appstore-) ===\n" as *u8) 33 seed1("cad" as *u8, "/cad/" as *u8, "Nishi CAD" as *u8, "Sovereign parametric solid modeling, sculpt, CSG &amp; fillets &rarr; printable STL." as *u8, "make" as *u8, "Nishi CAD" as *u8) 34 seed1("hub" as *u8, "/hub/" as *u8, "Hub" as *u8, "The family hub &mdash; every app in one place." as *u8, "make" as *u8, "Nishi Family" as *u8) 35 seed1("wiki" as *u8, "/wiki/" as *u8, "Wiki" as *u8, "The knowledge base &mdash; cited, fresh, evidence-first." as *u8, "make" as *u8, "html" as *u8) 36 seed1("games" as *u8, "/games/" as *u8, "Games" as *u8, "Family games built on the Nishi engine." as *u8, "play" as *u8, "html" as *u8) 37 seed1("econsim" as *u8, "/econsim/" as *u8, "EconSim" as *u8, "A Capitalism-Lab economic strategy game." as *u8, "play" as *u8, "EconSim" as *u8) 38 seed1("tictactoe" as *u8, "/tictactoe/" as *u8, "Tic-Tac-Toe" as *u8, "Minimax, bits-up." as *u8, "play" as *u8, "html" as *u8) 39 seed1("video" as *u8, "/video" as *u8, "Family Video" as *u8, "Sovereign video room &mdash; our own codec + transport." as *u8, "home" as *u8, "html" as *u8) 40 seed1("iot" as *u8, "/iot.html" as *u8, "Home control" as *u8, "IoT lighting &amp; devices, never-brick by design." as *u8, "home" as *u8, "html" as *u8) 41 42 w("=== read-back from the store (__apps__ index -> ss_get each) ===\n" as *u8) 43 let idx: *u8 = sys_mmap(K_MAGIC_65536) 44 let n: i64 = nx_app_store_index(idx) 45 let po: *i64 = sys_mmap(16) as *i64 46 let lo: *i64 = sys_mmap(16) as *i64 47 let nm: *u8 = sys_mmap(256) 48 var ls: i64 = 0 49 var i: i64 = 0 50 var cnt: i64 = 0 51 while i <= n { 52 var eol: i64 = 0 53 if i == n { eol = 1 } else { if idx[i] == 10 as u8 { eol = 1 } } 54 if eol == 1 { 55 if i > ls { 56 var c: i64 = 0 57 while c < i - ls { nm[c] = idx[ls + c]; c = c + 1 } 58 nm[i - ls] = 0 as u8 59 w(" " as *u8); w(nm); w(" = " as *u8) 60 if nx_app_store_get(nm, po, lo) >= 0 { sys_write(1, po[0] as *u8, lo[0]) } else { w("(missing)" as *u8) } 61 w("\n" as *u8) 62 cnt = cnt + 1 63 } 64 ls = i + 1 65 } 66 i = i + 1 67 } 68 w("APP-STORE count=" as *u8); wn(cnt); w("\n" as *u8) 69 if cnt == 8 { w("APP-STORE-OK 8 apps in the sovereign registry\n" as *u8); sys_exit(0); return 0 } 70 w("APP-STORE-FAIL expected 8\n" as *u8); sys_exit(1); return 1 71}