code wiki / _hdl_build / nx_pptx_gate.nx
nx_pptx_gate.nx source
↩ module page · 159 lines · 8331 B
1// nx_pptx_gate.nx -- gate for PRESENTATIONS (office census OF-P1 author + OF-P2 render; the census's biggest
2// ABSENT category: "a suite without slides is not a full office suite"). Proves: spec -> valid OPC .pptx with
3// real PresentationML slide parts; per-slide read round-trip in ORDER; 0-JS deck preview via the organ AND the
4// nx_doc_view registry; XML-escape round-trip; loud-fail negatives.
5// Rows: 1 write+OPC-structure 2 read-roundtrip-ordered 3 escape-roundtrip 4 html-deck 5 registry-dispatch
6// 6 outputs-0js 7 loud-fail-missing[neg]. license_tier: ORIGINAL
7import "nx_syscalls.nx"
8
9func pg_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8) { n=n+1 } return n }
10func pg_p(s: *u8) -> i64 { sys_write(1, s, pg_slen(s)); return 0 }
11func pg_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 }
12func pg_catn(dst: *u8, off: i64, v: i64) -> i64 {
13 var o: i64=off; var m: i64=v; if m<0 { dst[o]=45 as u8; o=o+1; m=0-m }
14 let t: *u8=sys_mmap(28); var k: i64=0; if m==0 { t[0]=48 as u8; k=1 }
15 while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 }
16 var i: i64=0; while i<k { dst[o+i]=t[k-1-i]; i=i+1 } return o+k
17}
18func pg_write(path: *u8, content: *u8) -> i64 {
19 let fd: i64=sys_openat_wr(path, 0x1a4); if fd<0 { return 0-1 }
20 sys_write(fd, content, pg_slen(content)); sys_close(fd); return 0
21}
22func pg_readall(path: *u8, szout: *i64) -> *u8 {
23 let fd: i64=sys_openat_rd(path); if fd<0 { szout[0]=0-1; return 0 as *u8 }
24 let buf: *u8=sys_mmap(4194304); var got: i64=0; var n: i64=1
25 while n>0 { n=sys_read(fd,(buf as i64+got) as *u8,131072); if n>0 { got=got+n } }
26 sys_close(fd); szout[0]=got; return buf
27}
28func pg_runv(elf: *u8, args: *i64, outpath: *u8) -> i64 {
29 let pid: i64=sys_fork()
30 if pid==0 {
31 if (outpath as i64)!=0 { let ofd: i64=sys_openat_wr(outpath,0x1a4); if ofd>=0 { sys_dup3(ofd,1,0); sys_dup3(ofd,2,0) } }
32 let argv: *i64=sys_mmap(128) as *i64
33 argv[0]=elf as i64; var i: i64=0; var go: i64=1
34 while go==1 { if args[i]==0 { go=0 } else { argv[i+1]=args[i]; i=i+1 } }
35 argv[i+1]=0
36 let envp: *i64=sys_mmap(16) as *i64; envp[0]=0
37 sys_execve(elf, argv, envp); sys_exit(127)
38 }
39 let st: *i64=sys_mmap(16) as *i64; sys_wait4(pid, st, 0)
40 let sig: i64=st[0]&0x7f; if sig!=0 { return 128+sig }
41 return (st[0]>>8)&0xff
42}
43func pg_find(b: *u8, sz: i64, needle: *u8) -> i64 {
44 let n: i64=pg_slen(needle); if sz<n { return 0-1 }
45 var i: i64=0
46 while i+n<=sz { var ok: i64=1; var j: i64=0; while j<n { if b[i+j]!=needle[j] { ok=0; j=n } else { j=j+1 } } if ok==1 { return i } i=i+1 }
47 return 0-1
48}
49func pg_has(path: *u8, needle: *u8) -> i64 {
50 let szp: *i64=sys_mmap(16) as *i64; let b: *u8=pg_readall(path, szp)
51 if szp[0]<0 { return 0 }
52 if pg_find(b, szp[0], needle)>=0 { return 1 }
53 return 0
54}
55func pg_args4(a1: *u8, a2: *u8, a3: *u8, a4: *u8) -> *i64 {
56 let a: *i64=sys_mmap(64) as *i64; a[0]=a1 as i64; a[1]=a2 as i64; a[2]=a3 as i64; a[3]=a4 as i64; a[4]=0; return a
57}
58func pg_row(name: *u8, pass: i64) -> i64 {
59 pg_p("ROW " as *u8); pg_p(name); if pass==1 { pg_p(" PASS\n" as *u8) } else { pg_p(" FAIL\n" as *u8) } return pass
60}
61
62func main(argc: i64, argv: *i64) -> i64 {
63 pg_p("=== PPTX GATE: presentations (OF-P1 author + OF-P2 render) -- spec -> OPC deck -> ordered round-trip -> 0-JS preview ===\n" as *u8)
64 let px: *u8="/tmp/nx_pptx.sov.elf" as *u8
65 let pr: i64=sys_openat_rd(px)
66 if pr>=0 { sys_close(pr) } else {
67 pg_p(" instrument missing -> rebuilding\n" as *u8)
68 pg_runv("_offc/nx_sov_build_run.elf" as *u8, pg_args4("nx_pptx" as *u8, "--build-only" as *u8, 0 as *u8, 0 as *u8), "/tmp/pg_rebuild.out" as *u8)
69 }
70
71 pg_write("/tmp/pg_deck.txt" as *u8, "S Family Reunion 2026\nB Lakeside Pavilion, August 15\nB Potluck: Smith & Jones cater mains\nS Budget\nB Venue 350\nB Catering 480\nS Questions\n" as *u8)
72
73 var pass: i64=0
74 var r: i64=0
75
76 // row 1: write + OPC structure (PK header, EOCD, presentation + slide parts named in the raw STORED zip)
77 let rc1: i64=pg_runv(px, pg_args4("fromspec" as *u8, "/tmp/pg_deck.txt" as *u8, "/tmp/pg_deck.pptx" as *u8, 0 as *u8), "/tmp/pg_r1.txt" as *u8)
78 r=0
79 if rc1==0 { if pg_has("/tmp/pg_r1.txt" as *u8, "PPTX-WRITE-OK" as *u8)==1 {
80 let szp: *i64=sys_mmap(16) as *i64
81 let b: *u8=pg_readall("/tmp/pg_deck.pptx" as *u8, szp)
82 let sz: i64=szp[0]
83 if sz>4 { if (b[0] as i64)==0x50 { if (b[1] as i64)==0x4b {
84 if pg_find(b,sz,"ppt/presentation.xml" as *u8)>=0 {
85 if pg_find(b,sz,"ppt/slides/slide3.xml" as *u8)>=0 {
86 if pg_find(b,sz,"<p:sld " as *u8)>=0 { r=1 }
87 }
88 }
89 } } }
90 } }
91 pass=pass+pg_row("write-opc-structure" as *u8, r)
92
93 // row 2: read round-trip, slides in ORDER
94 let rc2: i64=pg_runv(px, pg_args4("read" as *u8, "/tmp/pg_deck.pptx" as *u8, 0 as *u8, 0 as *u8), "/tmp/pg_r2.txt" as *u8)
95 r=0
96 if rc2==0 {
97 let szp2: *i64=sys_mmap(16) as *i64
98 let b2: *u8=pg_readall("/tmp/pg_r2.txt" as *u8, szp2)
99 let p1: i64=pg_find(b2, szp2[0], "SLIDE 1: Family Reunion 2026" as *u8)
100 let p2: i64=pg_find(b2, szp2[0], "SLIDE 2: Budget" as *u8)
101 let p3: i64=pg_find(b2, szp2[0], "SLIDE 3: Questions" as *u8)
102 let p4: i64=pg_find(b2, szp2[0], "- Venue 350" as *u8)
103 if p1>=0 { if p2>p1 { if p3>p2 { if p4>p2 { if p4<p3 { if pg_find(b2, szp2[0], "PPTX-DECK-END slides=3" as *u8)>=0 { r=1 } } } } } }
104 }
105 pass=pass+pg_row("read-roundtrip-ordered" as *u8, r)
106
107 // row 3: XML escape round-trip ('&' in a bullet)
108 r=pg_has("/tmp/pg_r2.txt" as *u8, "- Potluck: Smith & Jones cater mains" as *u8)
109 pass=pass+pg_row("escape-roundtrip" as *u8, r)
110
111 // row 4: html deck preview (3 slide cards, title + bullet + slide numbers)
112 let rc4: i64=pg_runv(px, pg_args4("html" as *u8, "/tmp/pg_deck.pptx" as *u8, "/tmp/pg_deck.html" as *u8, "/sample.pptx" as *u8), "/tmp/pg_r4.txt" as *u8)
113 r=0
114 if rc4==0 { if pg_has("/tmp/pg_deck.html" as *u8, "<h2>Family Reunion 2026</h2>" as *u8)==1 {
115 if pg_has("/tmp/pg_deck.html" as *u8, "<li>Venue 350</li>" as *u8)==1 {
116 if pg_has("/tmp/pg_deck.html" as *u8, "3 slides" as *u8)==1 {
117 if pg_has("/tmp/pg_deck.html" as *u8, "Download .pptx" as *u8)==1 { r=1 }
118 }
119 }
120 } }
121 pass=pass+pg_row("html-deck" as *u8, r)
122
123 // row 5: registry dispatch routes .pptx
124 let rc5: i64=pg_runv("_offc/nx_doc_view.elf" as *u8, pg_args4("/tmp/pg_deck.pptx" as *u8, "/tmp/pg_dv.html" as *u8, "/sample.pptx" as *u8, 0 as *u8), "/tmp/pg_r5.txt" as *u8)
125 r=0
126 if rc5==0 { if pg_has("/tmp/pg_r5.txt" as *u8, "DOC-VIEW-OK ext=pptx" as *u8)==1 { if pg_has("/tmp/pg_dv.html" as *u8, "<h2>Budget</h2>" as *u8)==1 { r=1 } } }
127 pass=pass+pg_row("registry-dispatch-pptx" as *u8, r)
128
129 // row 6: outputs sovereign 0-JS
130 r=1
131 if pg_has("/tmp/pg_deck.html" as *u8, "<script" as *u8)==1 { r=0 }
132 if pg_has("/tmp/pg_dv.html" as *u8, "<script" as *u8)==1 { r=0 }
133 pass=pass+pg_row("outputs-0js" as *u8, r)
134
135 // row 7 (neg): missing spec loud-fails
136 let rc7: i64=pg_runv(px, pg_args4("fromspec" as *u8, "/tmp/pg_nope.txt" as *u8, "/tmp/pg_x.pptx" as *u8, 0 as *u8), "/tmp/pg_r7.txt" as *u8)
137 r=0
138 if rc7==1 { if pg_has("/tmp/pg_r7.txt" as *u8, "PPTX-WRITE-FAIL" as *u8)==1 { r=1 } }
139 pass=pass+pg_row("loud-fail-missing" as *u8, r)
140
141 let permil: i64=(pass*1000)/7
142 let logfd: i64=sys_openat_append("knowledge/status/vizsla_gate.log" as *u8, 0x1a4)
143 var fdi: i64=0
144 while fdi<2 {
145 var fd: i64=1; if fdi==1 { fd=logfd }
146 if fd>0 {
147 let line: *u8=sys_mmap(256); var o: i64=0
148 o=pg_cat(line,o,"PPTX-GATE epoch=" as *u8); o=pg_catn(line,o,sys_now_realtime_sec())
149 o=pg_cat(line,o," rows=7 pass=" as *u8); o=pg_catn(line,o,pass)
150 o=pg_cat(line,o," permil=" as *u8); o=pg_catn(line,o,permil)
151 if pass==7 { o=pg_cat(line,o," verdict=GREEN\n" as *u8) } else { o=pg_cat(line,o," verdict=RED\n" as *u8) }
152 sys_write(fd, line, o)
153 }
154 fdi=fdi+1
155 }
156 if logfd>0 { sys_close(logfd) }
157 if pass==7 { return 0 }
158 return 1
159}