nx_asset_page_lib.nx source
↩ module page · 81 lines · 3358 B
1// nx_asset_page_lib.nx -- the asset page's decisions a gate can drive in-process (2026-09-17). First resident: does this
2// manifest show a live GLB viewer canvas at all? The emitter wrote the viewer script tag on EVERY page, so an image-only
3// page (a judged photograph, a media-judge report) carried a reference to a script it never uses, and nx_page_verify
4// reads that reference BROKEN while the viewer file is absent (debt 1787785512, superseded by 1787786411: the GLB half of
5// that debt stays open, this lib only stops image-only pages from referencing a script they never needed). The predicate
6// reads the FORMAT column of tasset and tasset2 rows, never a substring: a label that says "glb" is not a canvas.
7// Consumers: nx_asset_page (the emitter), nx_asset_page_gate (planted manifests).
8// license_tier: ORIGINAL No hw writes (Rule 26).
9import "nx_syscalls.nx"
10
11const APL_TAB: i64 = 9
12const APL_NL: i64 = 10
13const APL_CR: i64 = 13
14const APL_COL_TYPE: i64 = 0
15const APL_COL_FORMAT: i64 = 2 // tasset \t <tier> \t <format> \t <href> \t <label>: the format is the third column
16const APL_SPAN_SLOTS: i64 = 2
17const APL_I64: i64 = 8
18
19// 1 when buf[a..b) equals the literal exactly (same length, same bytes)
20func apl_is(buf: *u8, a: i64, b: i64, lit: *u8) -> i64 {
21 var n: i64 = 0
22 while lit[n] != (0 as u8) { n = n + 1 }
23 if b - a != n { return 0 }
24 var i: i64 = 0
25 while i < n {
26 if buf[a + i] != lit[i] { return 0 }
27 i = i + 1
28 }
29 return 1
30}
31// the [start,end) of tab-separated column k on the line [ls,le) into span[0..1]; 1 when the line has that column
32func apl_col(buf: *u8, ls: i64, le: i64, k: i64, span: *i64) -> i64 {
33 span[0] = 0 - 1
34 span[1] = 0 - 1
35 var col: i64 = 0
36 var cs: i64 = ls
37 var i: i64 = ls
38 while i <= le {
39 var at_end: i64 = 0
40 if i == le { at_end = 1 } else { if (buf[i] as i64) == APL_TAB { at_end = 1 } }
41 if at_end == 1 {
42 if col == k {
43 span[0] = cs
44 span[1] = i
45 return 1
46 }
47 col = col + 1
48 cs = i + 1
49 }
50 i = i + 1
51 }
52 return 0
53}
54// 1 when any tasset or tasset2 row's FORMAT column is glb: the page shows a viewer canvas and needs the viewer script
55func apl_has_glb(m: *u8, mn: i64) -> i64 {
56 let span: *i64 = sys_mmap(APL_SPAN_SLOTS * APL_I64) as *i64
57 var ls: i64 = 0
58 while ls < mn {
59 var le: i64 = ls
60 var scanning: i64 = 1
61 while scanning == 1 {
62 if le >= mn { scanning = 0 } else {
63 if (m[le] as i64) == APL_NL { scanning = 0 } else { le = le + 1 }
64 }
65 }
66 // a manifest may arrive from any host: a CR before the NL is not part of the last column
67 var trim: i64 = le
68 if trim > ls { if (m[trim - 1] as i64) == APL_CR { trim = trim - 1 } }
69 if apl_col(m, ls, trim, APL_COL_TYPE, span) == 1 {
70 var is_ta: i64 = apl_is(m, span[0], span[1], "tasset" as *u8)
71 if is_ta == 0 { is_ta = apl_is(m, span[0], span[1], "tasset2" as *u8) }
72 if is_ta == 1 {
73 if apl_col(m, ls, trim, APL_COL_FORMAT, span) == 1 {
74 if apl_is(m, span[0], span[1], "glb" as *u8) == 1 { return 1 }
75 }
76 }
77 }
78 ls = le + 1
79 }
80 return 0
81}