omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / apps / interplane-forge / server / chromegen.om
| 1 | om2 |
| 2 | note server/chromegen.om: makes the forge's copy of the interplane.io site chrome from the site's own |
| 3 | note source, at every build (run.sh units runs it), so a site change never needs a hand copy. |
| 4 | note stdin: content/_layout.html, a 0 byte, public/style.css, a 0 byte, the site commit (40 hex). |
| 5 | note stdout: one Omega unit (texts tchrsite, tchrhead, tchrfoot, tchrcss) that server/pages.om writes: |
| 6 | note tchrhead <header class="site-head"> .. </header> of the layout, release build: {{#flag}} and |
| 7 | note {{/flag}} marks dropped (the optional data is present on interplane.io), every |
| 8 | note site-relative href or src made absolute (https://interplane.io/...), and the one link |
| 9 | note to https://interplane.io/explore marked aria-current="true" (Forge is the section); |
| 10 | note translate="no" attributes left out: forged adds its hints when it sends a page |
| 11 | note (server/tr.om, class brand and others), so a page in fob holds none and its size is exact |
| 12 | note tchrfoot the footer lines after <footer class="site-foot"><div class="shell"> up to the first |
| 13 | note <p class="foot-fine"> line (the forge writes its own fine print), the same way |
| 14 | note tchrcss the site's :root line, then between the marks of server/tests/sitechrome.sh every |
| 15 | note style.css rule line that styles the header or footer (the rule below, the same one |
| 16 | note sitechrome.sh checks) inside its @-block, in the site's order |
| 17 | note Chrome rule: a line that starts with a base selector (*, html, body, a, a:hover, a:active, |
| 18 | note a:focus-visible,summary:focus-visible, code,pre,.mono) and "{", or names one of the classes |
| 19 | note site-head head-row brand site-foot foot-<a-z> si-line skip shell (not followed by a-z or -), or |
| 20 | note .button, .button.dark or .button.small before ":" or "{"; left out: nav.short, main p:where, |
| 21 | note .invite .button, .actions .button, .hop-stage (page rules), a one-line @media print rule, and |
| 22 | note @-blocks naming |
| 23 | note prefers-reduced-motion. |
| 24 | note Refusals (stderr names the reason, stdout is empty): exit 2 input shape, 3 header or footer |
| 25 | note not found, 4 a {{ mark other than {{#..}} or {{/..}} in them, 5 no single Forge link, 6 no :root |
| 26 | note first line, 7 a control byte other than a line feed, 8 fewer than 30 chrome lines, 9 output. |
| 27 | note The input and output buffers are 16 MiB each (the largest pool omc allows); the site files are |
| 28 | note about 40 KB. A larger input is refused with exit 2, never cut. |
| 29 | global cgi uchar 16777216 |
| 30 | global cgn ulong 1 |
| 31 | global cgo uchar 16777216 |
| 32 | global cgl ulong 1 |
| 33 | note the three parts of the input: layout [0, cgp 1), style [cgp 2, cgp 3), sha [cgp 4, cgn) |
| 34 | global cgp ulong 5 |
| 35 | note the current @-block: its line (start, end) and whether it was written yet |
| 36 | global cgb ulong 3 |
| 37 | global cgcur ulong 1 |
| 38 | text thd "<header class=\"site-head\">" |
| 39 | text the "</header>" |
| 40 | text tfo "<footer class=\"site-foot\"><div class=\"shell\">" |
| 41 | text tff "<p class=\"foot-fine\">" |
| 42 | text thref "href=\"/" |
| 43 | text tsrc "src=\"/" |
| 44 | text tsite "https://interplane.io" |
| 45 | text tforge "<a href=\"https://interplane.io/explore\"" |
| 46 | text tcur " aria-current=\"true\"" |
| 47 | text thint " translate=\"no\"" |
| 48 | text troot ":root{" |
| 49 | text tm1 "/* site chrome: copied from interplane.io public/style.css */\n" |
| 50 | text tm2 "/* end site chrome */\n" |
| 51 | text tqe "\"\n" |
| 52 | text tn1 "note server/chrome.om: GENERATED by server/chromegen.om at build (run.sh units) from interplane.io\n" |
| 53 | text tn2 "note content/_layout.html and public/style.css at the site commit in tchrsite. Not in git; do not edit.\n" |
| 54 | text ts1 "text tchrsite \"" |
| 55 | text ts2 "text tchrhead \"" |
| 56 | text ts3 "text tchrfoot \"" |
| 57 | text ts4 "text tchrcss \"" |
| 58 | text tbs1 "*{" |
| 59 | text tbs2 "html{" |
| 60 | text tbs3 "body{" |
| 61 | text tbs4 "a{" |
| 62 | text tbs5 "a:hover{" |
| 63 | text tbs6 "a:active{" |
| 64 | text tbs7 "a:focus-visible,summary:focus-visible{" |
| 65 | text tbs8 "code,pre,.mono{" |
| 66 | text tcl1 "site-head" |
| 67 | text tcl2 "head-row" |
| 68 | text tcl3 "brand" |
| 69 | text tcl4 "site-foot" |
| 70 | text tcl5 "si-line" |
| 71 | text tcl6 "skip" |
| 72 | text tcl7 "shell" |
| 73 | text tcl8 "foot-" |
| 74 | text tbtn "button" |
| 75 | text tdark ".dark" |
| 76 | text tsmall ".small" |
| 77 | text tsk1 "nav.short" |
| 78 | text tsk2 "main p:where" |
| 79 | text tsk3 ".invite .button" |
| 80 | text tsk4 ".actions .button" |
| 81 | text tsk5 ".hop-stage " |
| 82 | text tsk6 "@media print" |
| 83 | text tskin "prefers-reduced-motion" |
| 84 | text te2 "chromegen: input is not layout, NUL, style, NUL, commit (or larger than 16 MiB)\n" |
| 85 | text te3 "chromegen: the layout has no <header class=\"site-head\"> .. </header>, or no footer line <footer class=\"site-foot\"><div class=\"shell\"> followed by a <p class=\"foot-fine\"> line\n" |
| 86 | text te4 "chromegen: the site header or footer holds a {{ mark other than {{#name}} or {{/name}}; teach server/chromegen.om what the release build does with it\n" |
| 87 | text te5 "chromegen: the site header does not hold exactly one <a href=\"https://interplane.io/explore\"> (the Forge entry)\n" |
| 88 | text te6 "chromegen: the first line of public/style.css is not the :root token line\n" |
| 89 | text te7 "chromegen: a control byte other than a line feed in the copied header, footer or stylesheet lines\n" |
| 90 | text te8 "chromegen: fewer than 30 chrome rule lines found in public/style.css; the rule above no longer fits the site\n" |
| 91 | text te9 "chromegen: the output did not fit or could not be written\n" |
| 92 | fn cgdie code ulong t view uchar * to void |
| 93 | w = write 2 t 0 len t |
| 94 | exit int code |
| 95 | end |
| 96 | fn cgc c uchar to void |
| 97 | n = get cgl 0 |
| 98 | if ge n len cgo |
| 99 | cgdie 9 te9 |
| 100 | end |
| 101 | put cgo n c |
| 102 | put cgl 0 add n 1 |
| 103 | end |
| 104 | fn cgt t view uchar * to void |
| 105 | for i ulong len t bound 4096 |
| 106 | cgc get t i |
| 107 | end |
| 108 | end |
| 109 | note cge: one byte of an Omega text literal |
| 110 | fn cge c uchar to void |
| 111 | if eq c 10 |
| 112 | cgc 92 |
| 113 | cgc 110 |
| 114 | ret |
| 115 | end |
| 116 | if eq c 9 |
| 117 | cgc 92 |
| 118 | cgc 116 |
| 119 | ret |
| 120 | end |
| 121 | if lt c 32 |
| 122 | cgdie 7 te7 |
| 123 | end |
| 124 | if eq c 127 |
| 125 | cgdie 7 te7 |
| 126 | end |
| 127 | if or eq c 34 eq c 92 |
| 128 | cgc 92 |
| 129 | end |
| 130 | cgc c |
| 131 | end |
| 132 | note cgat: cgi[p, e) starts with t |
| 133 | fn cgat p ulong e ulong t view uchar * to bool |
| 134 | if gt add p len t e |
| 135 | ret false |
| 136 | end |
| 137 | for i ulong len t bound 4096 |
| 138 | if ne get cgi add p i get t i |
| 139 | ret false |
| 140 | end |
| 141 | end |
| 142 | ret true |
| 143 | end |
| 144 | note cgfind: the first p in [a, e) where t starts, or e |
| 145 | fn cgfind a ulong e ulong t view uchar * to ulong |
| 146 | p = a |
| 147 | while lt p e bound 16777216 |
| 148 | if cgat p e t |
| 149 | ret p |
| 150 | end |
| 151 | p = add p 1 |
| 152 | end |
| 153 | ret e |
| 154 | end |
| 155 | fn cglow c uchar to bool |
| 156 | ret and ge c 97 le c 122 |
| 157 | end |
| 158 | fn cgname c uchar to bool |
| 159 | ret or cglow c eq c 45 |
| 160 | end |
| 161 | note ---- the layout parts |
| 162 | note cgmark: at cgi[p] a {{ mark; returns its end (after the }}) for {{#name}} or {{/name}}, refuses others |
| 163 | fn cgmark p ulong e ulong to ulong |
| 164 | q = add p 2 |
| 165 | if ge q e |
| 166 | cgdie 4 te4 |
| 167 | end |
| 168 | c = get cgi q |
| 169 | if and ne c 35 ne c 47 |
| 170 | cgdie 4 te4 |
| 171 | end |
| 172 | q = add q 1 |
| 173 | s = q |
| 174 | while lt q e bound 16777216 |
| 175 | c = get cgi q |
| 176 | if not or cglow c eq c 95 |
| 177 | break |
| 178 | end |
| 179 | q = add q 1 |
| 180 | end |
| 181 | if or eq q s gt add q 2 e |
| 182 | cgdie 4 te4 |
| 183 | end |
| 184 | if or ne get cgi q 125 ne get cgi add q 1 125 |
| 185 | cgdie 4 te4 |
| 186 | end |
| 187 | ret add q 2 |
| 188 | end |
| 189 | note cgpart: cgi[a, e) as the release build writes it, escaped into the output; returns the count of |
| 190 | note Forge links it marked current (when cur) |
| 191 | fn cgpart a ulong e ulong cur bool to ulong |
| 192 | n = ulong 0 |
| 193 | p = a |
| 194 | while lt p e bound 16777216 |
| 195 | if and eq get cgi p 123 lt add p 1 e |
| 196 | if eq get cgi add p 1 123 |
| 197 | p = cgmark p e |
| 198 | continue |
| 199 | end |
| 200 | end |
| 201 | if cgat p e thint |
| 202 | p = add p len thint |
| 203 | continue |
| 204 | end |
| 205 | if and cur cgat p e tforge |
| 206 | for i ulong len tforge |
| 207 | cge get tforge i |
| 208 | end |
| 209 | for i ulong len tcur |
| 210 | cge get tcur i |
| 211 | end |
| 212 | p = add p len tforge |
| 213 | n = add n 1 |
| 214 | continue |
| 215 | end |
| 216 | k = ulong 0 |
| 217 | if cgat p e thref |
| 218 | k = len thref |
| 219 | end |
| 220 | if cgat p e tsrc |
| 221 | k = len tsrc |
| 222 | end |
| 223 | if gt k 0 |
| 224 | r = sub add p k 1 |
| 225 | if or ge add r 1 e ne get cgi add r 1 47 |
| 226 | for i ulong sub k 1 |
| 227 | cge get cgi add p i |
| 228 | end |
| 229 | for i ulong len tsite |
| 230 | cge get tsite i |
| 231 | end |
| 232 | p = r |
| 233 | continue |
| 234 | end |
| 235 | end |
| 236 | cge get cgi p |
| 237 | p = add p 1 |
| 238 | end |
| 239 | ret n |
| 240 | end |
| 241 | note ---- the stylesheet |
| 242 | note cglst: [s, e) is a line of the stylesheet; true when it is a block line "@..{" with no "}" |
| 243 | fn cgopen s ulong e ulong to bool |
| 244 | if or ge s e ne get cgi s 64 |
| 245 | ret false |
| 246 | end |
| 247 | if ne get cgi sub e 1 123 |
| 248 | ret false |
| 249 | end |
| 250 | for i ulong sub e s bound 16777216 |
| 251 | if eq get cgi add s i 125 |
| 252 | ret false |
| 253 | end |
| 254 | end |
| 255 | ret true |
| 256 | end |
| 257 | fn cgclose s ulong e ulong to bool |
| 258 | if ge s e |
| 259 | ret false |
| 260 | end |
| 261 | for i ulong sub e s bound 16777216 |
| 262 | if ne get cgi add s i 125 |
| 263 | ret false |
| 264 | end |
| 265 | end |
| 266 | ret true |
| 267 | end |
| 268 | note cgcls: at p a class name t followed by a byte that is not a-z or -, or the line end |
| 269 | fn cgcls p ulong e ulong t view uchar * to bool |
| 270 | if not cgat p e t |
| 271 | ret false |
| 272 | end |
| 273 | q = add p len t |
| 274 | if ge q e |
| 275 | ret true |
| 276 | end |
| 277 | ret not cgname get cgi q |
| 278 | end |
| 279 | fn cgfoot p ulong e ulong to bool |
| 280 | if not cgat p e tcl8 |
| 281 | ret false |
| 282 | end |
| 283 | q = add p len tcl8 |
| 284 | s = q |
| 285 | while lt q e bound 16777216 |
| 286 | if not cglow get cgi q |
| 287 | break |
| 288 | end |
| 289 | q = add q 1 |
| 290 | end |
| 291 | if eq q s |
| 292 | ret false |
| 293 | end |
| 294 | if ge q e |
| 295 | ret true |
| 296 | end |
| 297 | ret ne get cgi q 45 |
| 298 | end |
| 299 | fn cgbtn p ulong e ulong to bool |
| 300 | if not cgat p e tbtn |
| 301 | ret false |
| 302 | end |
| 303 | q = add p len tbtn |
| 304 | if cgat q e tdark |
| 305 | q = add q len tdark |
| 306 | else |
| 307 | if cgat q e tsmall |
| 308 | q = add q len tsmall |
| 309 | end |
| 310 | end |
| 311 | if ge q e |
| 312 | ret false |
| 313 | end |
| 314 | c = get cgi q |
| 315 | if or eq c 58 eq c 123 |
| 316 | ret true |
| 317 | end |
| 318 | q = add p len tbtn |
| 319 | if ge q e |
| 320 | ret false |
| 321 | end |
| 322 | c = get cgi q |
| 323 | ret or eq c 58 eq c 123 |
| 324 | end |
| 325 | fn cgbase s ulong e ulong to bool |
| 326 | if or cgat s e tbs1 or cgat s e tbs2 cgat s e tbs3 |
| 327 | ret true |
| 328 | end |
| 329 | if or cgat s e tbs4 or cgat s e tbs5 cgat s e tbs6 |
| 330 | ret true |
| 331 | end |
| 332 | ret or cgat s e tbs7 cgat s e tbs8 |
| 333 | end |
| 334 | note cgsel: the rule line [s, e) styles the header or footer (the chrome rule in the notes above) |
| 335 | fn cgsel s ulong e ulong to bool |
| 336 | if lt cgfind s e tsk1 e |
| 337 | ret false |
| 338 | end |
| 339 | if or cgat s e tsk2 or cgat s e tsk3 or cgat s e tsk4 cgat s e tsk5 |
| 340 | ret false |
| 341 | end |
| 342 | if cgat s e tsk6 |
| 343 | ret false |
| 344 | end |
| 345 | if cgbase s e |
| 346 | ret true |
| 347 | end |
| 348 | p = s |
| 349 | while lt p e bound 16777216 |
| 350 | if eq get cgi p 46 |
| 351 | q = add p 1 |
| 352 | if or cgcls q e tcl1 or cgcls q e tcl2 or cgcls q e tcl3 cgcls q e tcl4 |
| 353 | ret true |
| 354 | end |
| 355 | if or cgcls q e tcl5 or cgcls q e tcl6 or cgcls q e tcl7 cgfoot q e |
| 356 | ret true |
| 357 | end |
| 358 | if cgbtn q e |
| 359 | ret true |
| 360 | end |
| 361 | end |
| 362 | p = add p 1 |
| 363 | end |
| 364 | ret false |
| 365 | end |
| 366 | fn cgline s ulong e ulong to void |
| 367 | for i ulong sub e s bound 16777216 |
| 368 | cge get cgi add s i |
| 369 | end |
| 370 | cge 10 |
| 371 | end |
| 372 | note cgcss: the :root line, the marks and the chrome rule lines; returns the count of rule lines |
| 373 | fn cgcss a ulong e ulong to ulong |
| 374 | x = a |
| 375 | while lt x e bound 16777216 |
| 376 | if eq get cgi x 10 |
| 377 | break |
| 378 | end |
| 379 | x = add x 1 |
| 380 | end |
| 381 | if not cgat a x troot |
| 382 | cgdie 6 te6 |
| 383 | end |
| 384 | cgline a x |
| 385 | for i ulong len tm1 |
| 386 | cge get tm1 i |
| 387 | end |
| 388 | put cgcur 0 0 |
| 389 | put cgb 2 0 |
| 390 | n = ulong 0 |
| 391 | s = add x 1 |
| 392 | while lt s e bound 16777216 |
| 393 | l = s |
| 394 | while lt l e bound 16777216 |
| 395 | if eq get cgi l 10 |
| 396 | break |
| 397 | end |
| 398 | l = add l 1 |
| 399 | end |
| 400 | if cgopen s l |
| 401 | put cgb 0 s |
| 402 | put cgb 1 l |
| 403 | put cgb 2 0 |
| 404 | put cgcur 0 1 |
| 405 | else |
| 406 | if cgclose s l |
| 407 | if and eq get cgcur 0 1 eq get cgb 2 1 |
| 408 | cgline s l |
| 409 | end |
| 410 | put cgcur 0 0 |
| 411 | put cgb 2 0 |
| 412 | else |
| 413 | if cgsel s l |
| 414 | sk = false |
| 415 | if eq get cgcur 0 1 |
| 416 | sk = lt cgfind get cgb 0 get cgb 1 tskin get cgb 1 |
| 417 | end |
| 418 | if not sk |
| 419 | if and eq get cgcur 0 1 eq get cgb 2 0 |
| 420 | cgline get cgb 0 get cgb 1 |
| 421 | put cgb 2 1 |
| 422 | end |
| 423 | cgline s l |
| 424 | n = add n 1 |
| 425 | end |
| 426 | end |
| 427 | end |
| 428 | end |
| 429 | s = add l 1 |
| 430 | end |
| 431 | for i ulong len tm2 |
| 432 | cge get tm2 i |
| 433 | end |
| 434 | ret n |
| 435 | end |
| 436 | fn main to int |
| 437 | cgreadin |
| 438 | cgsplit |
| 439 | cgsha |
| 440 | cghead |
| 441 | cgfootp |
| 442 | cgt ts4 |
| 443 | m = cgcss add get cgp 1 1 get cgp 2 |
| 444 | cgt tqe |
| 445 | if lt m 30 |
| 446 | cgdie 8 te8 |
| 447 | end |
| 448 | w = write 1 cgo 0 get cgl 0 |
| 449 | if ne w long get cgl 0 |
| 450 | cgdie 9 te9 |
| 451 | end |
| 452 | ret 0 |
| 453 | end |
| 454 | fn cgreadin to void |
| 455 | n = ulong 0 |
| 456 | while lt n len cgi bound 16777216 |
| 457 | r = read 0 cgi n sub len cgi n |
| 458 | if lt r 0 |
| 459 | if eq r -4 |
| 460 | continue |
| 461 | end |
| 462 | cgdie 2 te2 |
| 463 | end |
| 464 | if eq r 0 |
| 465 | break |
| 466 | end |
| 467 | n = add n ulong r |
| 468 | end |
| 469 | if ge n len cgi |
| 470 | cgdie 2 te2 |
| 471 | end |
| 472 | put cgn 0 n |
| 473 | end |
| 474 | note cgsplit: the two 0 bytes into cgp 1 and cgp 2 |
| 475 | fn cgsplit to void |
| 476 | n = get cgn 0 |
| 477 | k = ulong 0 |
| 478 | for i ulong n bound 16777216 |
| 479 | if eq get cgi i 0 |
| 480 | if ge k 2 |
| 481 | cgdie 2 te2 |
| 482 | end |
| 483 | put cgp add k 1 i |
| 484 | k = add k 1 |
| 485 | end |
| 486 | end |
| 487 | if ne k 2 |
| 488 | cgdie 2 te2 |
| 489 | end |
| 490 | end |
| 491 | fn cgisx c uchar to bool |
| 492 | if and ge c 48 le c 57 |
| 493 | ret true |
| 494 | end |
| 495 | ret and ge c 97 le c 102 |
| 496 | end |
| 497 | note cgsha: the third part is 40 lowercase hex (a trailing line feed allowed); writes tchrsite and the notes |
| 498 | fn cgsha to void |
| 499 | ha = add get cgp 2 1 |
| 500 | he = get cgn 0 |
| 501 | while gt he ha bound 16777216 |
| 502 | if ne get cgi sub he 1 10 |
| 503 | break |
| 504 | end |
| 505 | he = sub he 1 |
| 506 | end |
| 507 | if ne sub he ha 40 |
| 508 | cgdie 2 te2 |
| 509 | end |
| 510 | for i ulong 40 |
| 511 | if not cgisx get cgi add ha i |
| 512 | cgdie 2 te2 |
| 513 | end |
| 514 | end |
| 515 | cgt tn1 |
| 516 | cgt tn2 |
| 517 | cgt ts1 |
| 518 | for i ulong 40 |
| 519 | cgc get cgi add ha i |
| 520 | end |
| 521 | cgt tqe |
| 522 | end |
| 523 | note cghead: from the header's opening tag to the end of </header> |
| 524 | fn cghead to void |
| 525 | lz = get cgp 1 |
| 526 | h0 = cgfind 0 lz thd |
| 527 | h1 = cgfind h0 lz the |
| 528 | if or ge h0 lz ge h1 lz |
| 529 | cgdie 3 te3 |
| 530 | end |
| 531 | cgt ts2 |
| 532 | m = cgpart h0 add h1 len the true |
| 533 | cge 10 |
| 534 | cgt tqe |
| 535 | if ne m 1 |
| 536 | cgdie 5 te5 |
| 537 | end |
| 538 | end |
| 539 | note cgfootp: the lines after the footer opening line, before the first fine-print line |
| 540 | fn cgfootp to void |
| 541 | lz = get cgp 1 |
| 542 | f0 = cgfind 0 lz tfo |
| 543 | if ge f0 lz |
| 544 | cgdie 3 te3 |
| 545 | end |
| 546 | f1 = cgfind f0 lz tff |
| 547 | fa = add f0 len tfo |
| 548 | if or ge f1 lz ge fa lz |
| 549 | cgdie 3 te3 |
| 550 | end |
| 551 | if ne get cgi fa 10 |
| 552 | cgdie 3 te3 |
| 553 | end |
| 554 | fa = add fa 1 |
| 555 | if or le f1 fa ne get cgi sub f1 1 10 |
| 556 | cgdie 3 te3 |
| 557 | end |
| 558 | cgt ts3 |
| 559 | m = cgpart fa f1 false |
| 560 | cgt tqe |
| 561 | end |