code wiki / (root) / nx_refintake.nx

nx_refintake.nx source

↩ module page · 450 lines · 22713 B

1// nx_refintake.nx -- CLI over nx_refintake_lib (aesthetictwin AT22, 2026-09-16): reference intake as a workflow of verbs, 2// each one a step that can run alone or inside `all`, so the same organ is a primitive, a workflow and an agent's tool. 3// nx_refintake pages <slug> mirror every page source whose mirror is absent (journaled PAGE-OK / PAGE-FAILED) 4// nx_refintake discover <slug> apply every knowledge/refintake.hosts pattern whose prefix matches a page source; 5// rewrite knowledge/refintake/<slug>.sources (one url per line, deduped) 6// nx_refintake mirror <slug> mirror every declared image source and every discovered url not yet journaled; every 7// mirrored body is classified by its magic bytes (JPEG/PNG/GIF/WEBP are OK, an HTML stub or 8// anything else is journaled NOT-IMAGE-<class>, never counted as a picture) 9// nx_refintake verify <slug> re-classify every journaled OK mirror; names each row whose bytes are no longer a picture 10// nx_refintake videos <slug> KVS player pages (kind video): page, player video_url + license_code, the function/0/ hash 11// permutation undone, the clip mirrored and classified by its ftyp magic (AT24) 12// nx_refintake all <slug> pages, discover, mirror, verify, videos in that order (the one-call workflow) 13// nx_refintake check the conf: subjects, sources per kind, tags on declared axes (a group label is refused by name) 14// exit: 0 ok | 2 usage | 3 conf unreadable | 4 subject undeclared or refused | 5 tag refused | 6 a leg reported failures 15// license_tier: ORIGINAL No hw writes (Rule 26). 16import "nx_syscalls.nx" 17import "nx_refintake_lib.nx" 18 19const RC_EXIT_USAGE: i64 = 2 20const RC_EXIT_CONF: i64 = 3 21const RC_EXIT_SUBJECT: i64 = 4 22const RC_EXIT_TAG: i64 = 5 23const RC_EXIT_LEG: i64 = 6 24const RC_ARGC_SLUG: i64 = 3 25const RC_C_N: i64 = 8 26const RC_C_TRIED: i64 = 0 27const RC_C_OK: i64 = 1 28const RC_C_FAILED: i64 = 2 29const RC_C_PRESENT: i64 = 3 30const RC_C_NOTIMAGE: i64 = 4 31const RC_C_ALREADY: i64 = 5 32const RC_C_PATTERNS: i64 = 6 33const RC_C_UNKNOWNHOST: i64 = 7 34const RC_V_ROWS: i64 = 0 35const RC_V_IMAGES: i64 = 1 36const RC_V_HTML: i64 = 2 37const RC_V_OTHER: i64 = 3 38const RC_V_UNREADABLE: i64 = 4 39 40func rc_usage() -> i64 { 41 ri_puts("usage: nx_refintake pages|discover|mirror|verify|videos|all <slug> | check\n" as *u8) 42 return RC_EXIT_USAGE 43} 44func rc_zero(c: *i64, n: i64) -> i64 { var i: i64 = 0; while i < n { c[i] = 0; i = i + 1 } return 0 } 45func rc_fetched_path(mirror: *u8, out: *u8) -> i64 { 46 var o: i64 = ri_cat(out, 0, RI_FETCHED) 47 o = ri_cat(out, o, mirror) 48 return o 49} 50// a mirror is present when its file opens and carries at least the magic window 51func rc_present(mirror: *u8) -> i64 { 52 let path: *u8 = sys_mmap(RI_PATHB) 53 rc_fetched_path(mirror, path) 54 if ri_image_class(path) == RI_IMG_UNREADABLE { return 0 } 55 return 1 56} 57// is <url> already journaled for this subject? (the url sits between pipes, so a prefix cannot match) 58func rc_journaled(jrnl: *u8, jn: i64, url: *u8) -> i64 { 59 if jn <= 0 { return 0 } 60 let needle: *u8 = sys_mmap(RI_ROWB) 61 var o: i64 = 0 62 needle[o] = RI_PIPE as u8; o = o + 1 63 o = ri_cat(needle, o, url) 64 needle[o] = RI_PIPE as u8; o = o + 1 65 needle[o] = 0 as u8 66 return ri_contains(jrnl, jn, needle) 67} 68func rc_load_journal(slug: *u8, lenp: *i64) -> *u8 { 69 let path: *u8 = sys_mmap(RI_PATHB) 70 ri_journal_path(slug, path) 71 return ri_load(path, lenp) 72} 73 74// PAGES: mirror every page source whose mirror is absent 75func rc_pages(conf: *u8, n: i64, slug: *u8, lic: *u8, c: *i64) -> i64 { 76 let kind: *u8 = sys_mmap(RI_PATHB) 77 let url: *u8 = sys_mmap(RI_ROWB) 78 let mirror: *u8 = sys_mmap(RI_PATHB) 79 let date: *u8 = sys_mmap(RI_PATHB) 80 let sha: *u8 = sys_mmap(RI_PATHB) 81 let bytesp: *i64 = sys_mmap(RI_I64) as *i64 82 var idx: i64 = 0 83 while ri_source_at(conf, n, slug, idx, kind, url, mirror, date) == 1 { 84 if ri_streq(kind, "page" as *u8) == 1 { 85 if rc_present(mirror) == 1 { c[RC_C_PRESENT] = c[RC_C_PRESENT] + 1 } else { 86 c[RC_C_TRIED] = c[RC_C_TRIED] + 1 87 let rc: i64 = ri_mirror_one(url, mirror, sha, bytesp) 88 if rc == RI_OK { 89 c[RC_C_OK] = c[RC_C_OK] + 1 90 ri_journal(slug, url, mirror, sha, bytesp[0], lic, "PAGE-OK" as *u8) 91 } else { 92 c[RC_C_FAILED] = c[RC_C_FAILED] + 1 93 ri_journal(slug, url, mirror, "-" as *u8, 0, lic, "PAGE-FAILED" as *u8) 94 ri_puts("PAGE-FAILED url=" as *u8); ri_puts(url); ri_puts("\n" as *u8) 95 } 96 } 97 } 98 idx = idx + 1 99 } 100 ri_puts("REFINTAKE pages slug=" as *u8); ri_puts(slug) 101 ri_puts(" present=" as *u8); ri_putn(c[RC_C_PRESENT]) 102 ri_puts(" tried=" as *u8); ri_putn(c[RC_C_TRIED]) 103 ri_puts(" ok=" as *u8); ri_putn(c[RC_C_OK]) 104 ri_puts(" failed=" as *u8); ri_putn(c[RC_C_FAILED]) 105 ri_puts("\n" as *u8) 106 return c[RC_C_FAILED] 107} 108 109// DISCOVER: every host pattern whose prefix matches each mirrored page source; the .sources file is rewritten whole 110func rc_discover(conf: *u8, n: i64, slug: *u8, hosts: *u8, hn: i64, c: *i64, urlsp: *i64) -> i64 { 111 let kind: *u8 = sys_mmap(RI_PATHB) 112 let url: *u8 = sys_mmap(RI_ROWB) 113 let mirror: *u8 = sys_mmap(RI_PATHB) 114 let date: *u8 = sys_mmap(RI_PATHB) 115 let path: *u8 = sys_mmap(RI_PATHB) 116 let lenp: *i64 = sys_mmap(RI_I64) as *i64 117 // the output cannot exceed the pages it is cut from: size it from their bytes (no guessed cap) 118 var total: i64 = RI_ROWB 119 var idx: i64 = 0 120 while ri_source_at(conf, n, slug, idx, kind, url, mirror, date) == 1 { 121 if ri_streq(kind, "page" as *u8) == 1 { 122 rc_fetched_path(mirror, path) 123 let fd: i64 = sys_openat_rd(path) 124 if fd >= 0 { let sz: i64 = sys_lseek(fd, 0, 2); sys_close(fd); if sz > 0 { total = total + sz } } 125 } 126 idx = idx + 1 127 } 128 let out: *u8 = sys_mmap(total) 129 let outlen: *i64 = sys_mmap(RI_I64) as *i64 130 outlen[0] = 0 131 let needle: *u8 = sys_mmap(RI_PATHB) 132 let term: *u8 = sys_mmap(RI_PATHB) 133 let base: *u8 = sys_mmap(RI_PATHB) 134 let skipp: *i64 = sys_mmap(RI_I64) as *i64 135 var pages_read: i64 = 0 136 var pages_absent: i64 = 0 137 var found: i64 = 0 138 idx = 0 139 while ri_source_at(conf, n, slug, idx, kind, url, mirror, date) == 1 { 140 if ri_streq(kind, "page" as *u8) == 1 { 141 rc_fetched_path(mirror, path) 142 let page: *u8 = ri_load(path, lenp) 143 if lenp[0] <= 0 { pages_absent = pages_absent + 1 } else { 144 pages_read = pages_read + 1 145 var hidx: i64 = 0 146 while ri_host_at(hosts, hn, url, hidx, needle, skipp, term, base) == 1 { 147 let got: i64 = ri_discover_pat(page, lenp[0], needle, skipp[0], term, base, out, total, outlen) 148 found = found + got 149 c[RC_C_PATTERNS] = c[RC_C_PATTERNS] + 1 150 hidx = hidx + 1 151 } 152 if hidx == 0 { 153 c[RC_C_UNKNOWNHOST] = c[RC_C_UNKNOWNHOST] + 1 154 ri_puts("DISCOVER-UNKNOWN-HOST url=" as *u8); ri_puts(url); ri_puts(" (add a host| row to knowledge/refintake.hosts)\n" as *u8) 155 } 156 } 157 } 158 idx = idx + 1 159 } 160 let spath: *u8 = sys_mmap(RI_PATHB) 161 sys_mkdir(RI_DIR, RI_MODE755) 162 ri_sources_path(slug, spath) 163 let fd: i64 = sys_openat_wr(spath, RI_MODE644) 164 var wrote: i64 = 0 - 1 165 if fd >= 0 { wrote = sys_write(fd, out, outlen[0]); sys_close(fd) } 166 urlsp[0] = found 167 ri_puts("REFINTAKE discover slug=" as *u8); ri_puts(slug) 168 ri_puts(" pages_read=" as *u8); ri_putn(pages_read) 169 ri_puts(" pages_absent=" as *u8); ri_putn(pages_absent) 170 ri_puts(" patterns_applied=" as *u8); ri_putn(c[RC_C_PATTERNS]) 171 ri_puts(" pages_unknown_host=" as *u8); ri_putn(c[RC_C_UNKNOWNHOST]) 172 ri_puts(" urls=" as *u8); ri_putn(found) 173 ri_puts(" sources=" as *u8); ri_puts(spath) 174 ri_puts(" bytes=" as *u8); ri_putn(wrote) 175 ri_puts("\n" as *u8) 176 if wrote < 0 { return 1 } 177 return 0 178} 179 180// mirror one url to <mirror>; the body is classified by magic before it is journaled 181func rc_mirror_url(slug: *u8, url: *u8, mirror: *u8, lic: *u8, c: *i64) -> i64 { 182 let sha: *u8 = sys_mmap(RI_PATHB) 183 let bytesp: *i64 = sys_mmap(RI_I64) as *i64 184 let path: *u8 = sys_mmap(RI_PATHB) 185 let status: *u8 = sys_mmap(RI_PATHB) 186 c[RC_C_TRIED] = c[RC_C_TRIED] + 1 187 let rc: i64 = ri_mirror_one(url, mirror, sha, bytesp) 188 if rc != RI_OK { 189 c[RC_C_FAILED] = c[RC_C_FAILED] + 1 190 ri_journal(slug, url, mirror, "-" as *u8, 0, lic, "FAILED" as *u8) 191 ri_puts("MIRROR-FAILED url=" as *u8); ri_puts(url); ri_puts("\n" as *u8) 192 return 1 193 } 194 rc_fetched_path(mirror, path) 195 let cls: i64 = ri_image_class(path) 196 if ri_is_image(cls) == 1 { 197 c[RC_C_OK] = c[RC_C_OK] + 1 198 ri_journal(slug, url, mirror, sha, bytesp[0], lic, "OK" as *u8) 199 return 0 200 } 201 c[RC_C_NOTIMAGE] = c[RC_C_NOTIMAGE] + 1 202 var o: i64 = ri_cat(status, 0, "NOT-IMAGE-" as *u8) 203 o = ri_cat(status, o, ri_class_word(cls)) 204 ri_journal(slug, url, mirror, sha, bytesp[0], lic, status) 205 ri_puts("MIRROR-NOT-IMAGE url=" as *u8); ri_puts(url); ri_puts(" class=" as *u8); ri_puts(ri_class_word(cls)); ri_puts(" bytes=" as *u8); ri_putn(bytesp[0]); ri_puts("\n" as *u8) 206 return 0 207} 208 209// MIRROR: declared image sources first (their own mirror names), then every discovered url; the journal is the dedupe 210func rc_mirror(conf: *u8, n: i64, slug: *u8, lic: *u8, c: *i64) -> i64 { 211 let kind: *u8 = sys_mmap(RI_PATHB) 212 let url: *u8 = sys_mmap(RI_ROWB) 213 let mirror: *u8 = sys_mmap(RI_PATHB) 214 let date: *u8 = sys_mmap(RI_PATHB) 215 let jlen: *i64 = sys_mmap(RI_I64) as *i64 216 var jrnl: *u8 = rc_load_journal(slug, jlen) 217 var idx: i64 = 0 218 while ri_source_at(conf, n, slug, idx, kind, url, mirror, date) == 1 { 219 if ri_streq(kind, "image" as *u8) == 1 { 220 if rc_journaled(jrnl, jlen[0], url) == 1 { c[RC_C_ALREADY] = c[RC_C_ALREADY] + 1 } 221 else { rc_mirror_url(slug, url, mirror, lic, c) } 222 } 223 idx = idx + 1 224 } 225 jrnl = rc_load_journal(slug, jlen) 226 let spath: *u8 = sys_mmap(RI_PATHB) 227 ri_sources_path(slug, spath) 228 let slen: *i64 = sys_mmap(RI_I64) as *i64 229 let src: *u8 = ri_load(spath, slen) 230 var i: i64 = 0 231 var k: i64 = 0 232 while i < slen[0] { 233 let e: i64 = ri_line_end(src, slen[0], i) 234 if e > i { 235 var q: i64 = 0 236 while i + q < e { if q < RI_ROWB - 1 { url[q] = src[i + q] } q = q + 1 } 237 url[q] = 0 as u8 238 if rc_journaled(jrnl, jlen[0], url) == 1 { c[RC_C_ALREADY] = c[RC_C_ALREADY] + 1 } 239 else { 240 ri_mirror_name(slug, k, url, mirror) 241 rc_mirror_url(slug, url, mirror, lic, c) 242 jrnl = rc_load_journal(slug, jlen) 243 } 244 k = k + 1 245 } 246 i = e + 1 247 } 248 ri_puts("REFINTAKE mirror slug=" as *u8); ri_puts(slug) 249 ri_puts(" tried=" as *u8); ri_putn(c[RC_C_TRIED]) 250 ri_puts(" ok=" as *u8); ri_putn(c[RC_C_OK]) 251 ri_puts(" notimage=" as *u8); ri_putn(c[RC_C_NOTIMAGE]) 252 ri_puts(" failed=" as *u8); ri_putn(c[RC_C_FAILED]) 253 ri_puts(" already=" as *u8); ri_putn(c[RC_C_ALREADY]) 254 ri_puts(" (ok+notimage+failed=tried; a body that is not JPEG/PNG/GIF/WEBP by magic is never counted as a picture)\n" as *u8) 255 return c[RC_C_FAILED] 256} 257 258// VERIFY: every journaled OK row is re-classified from its bytes; offenders are named 259func rc_verify(slug: *u8, v: *i64) -> i64 { 260 let jlen: *i64 = sys_mmap(RI_I64) as *i64 261 let jrnl: *u8 = rc_load_journal(slug, jlen) 262 let status: *u8 = sys_mmap(RI_PATHB) 263 let path: *u8 = sys_mmap(RI_PATHB) 264 var i: i64 = 0 265 while i < jlen[0] { 266 let e: i64 = ri_line_end(jrnl, jlen[0], i) 267 if ri_starts(jrnl, jlen[0], i, "mirror|" as *u8) == 1 { 268 ri_field(jrnl, i, e, RI_J_STATUS, status, RI_PATHB) 269 if ri_streq(status, "OK" as *u8) == 1 { 270 v[RC_V_ROWS] = v[RC_V_ROWS] + 1 271 ri_field(jrnl, i, e, RI_J_PATH, path, RI_PATHB) 272 let cls: i64 = ri_image_class(path) 273 if ri_is_image(cls) == 1 { v[RC_V_IMAGES] = v[RC_V_IMAGES] + 1 } else { 274 if cls == RI_IMG_HTML { v[RC_V_HTML] = v[RC_V_HTML] + 1 } 275 else { if cls == RI_IMG_UNREADABLE { v[RC_V_UNREADABLE] = v[RC_V_UNREADABLE] + 1 } else { v[RC_V_OTHER] = v[RC_V_OTHER] + 1 } } 276 ri_puts("VERIFY-NOT-IMAGE path=" as *u8); ri_puts(path); ri_puts(" class=" as *u8); ri_puts(ri_class_word(cls)); ri_puts("\n" as *u8) 277 } 278 } 279 } 280 i = e + 1 281 } 282 ri_puts("REFINTAKE verify slug=" as *u8); ri_puts(slug) 283 ri_puts(" ok_rows=" as *u8); ri_putn(v[RC_V_ROWS]) 284 ri_puts(" images=" as *u8); ri_putn(v[RC_V_IMAGES]) 285 ri_puts(" html_stubs=" as *u8); ri_putn(v[RC_V_HTML]) 286 ri_puts(" other=" as *u8); ri_putn(v[RC_V_OTHER]) 287 ri_puts(" unreadable=" as *u8); ri_putn(v[RC_V_UNREADABLE]) 288 ri_puts(" (images+html_stubs+other+unreadable=ok_rows)\n" as *u8) 289 return v[RC_V_HTML] + v[RC_V_OTHER] + v[RC_V_UNREADABLE] 290} 291 292// VIDEOS: KVS player pages (thothub, reached through the clean-serve lane): mirror the page, extract the player's video_url 293// and license_code, undo the function/0/ hash permutation, mirror the media and classify it by magic (ftyp) before journaling 294func rc_videos(conf: *u8, n: i64, slug: *u8, lic: *u8, c: *i64) -> i64 { 295 let kind: *u8 = sys_mmap(RI_PATHB) 296 let url: *u8 = sys_mmap(RI_ROWB) 297 let mirror: *u8 = sys_mmap(RI_PATHB) 298 let date: *u8 = sys_mmap(RI_PATHB) 299 let pagename: *u8 = sys_mmap(RI_PATHB) 300 let medianame: *u8 = sys_mmap(RI_PATHB) 301 let path: *u8 = sys_mmap(RI_PATHB) 302 let vurl: *u8 = sys_mmap(RI_ROWB) 303 let code: *u8 = sys_mmap(RI_PATHB) 304 let media: *u8 = sys_mmap(RI_ROWB) 305 let sha: *u8 = sys_mmap(RI_PATHB) 306 let status: *u8 = sys_mmap(RI_PATHB) 307 let bytesp: *i64 = sys_mmap(RI_I64) as *i64 308 let lenp: *i64 = sys_mmap(RI_I64) as *i64 309 let jlen: *i64 = sys_mmap(RI_I64) as *i64 310 var jrnl: *u8 = rc_load_journal(slug, jlen) 311 var idx: i64 = 0 312 while ri_source_at(conf, n, slug, idx, kind, url, mirror, date) == 1 { 313 if ri_streq(kind, "video" as *u8) == 1 { 314 var o: i64 = ri_cat(pagename, 0, mirror) 315 o = ri_cat(pagename, o, ".html" as *u8) 316 o = ri_cat(medianame, 0, mirror) 317 o = ri_cat(medianame, o, ".mp4" as *u8) 318 if rc_present(pagename) == 0 { 319 let prc: i64 = ri_mirror_one(url, pagename, sha, bytesp) 320 if prc == RI_OK { ri_journal(slug, url, pagename, sha, bytesp[0], lic, "PAGE-OK" as *u8) } 321 else { ri_journal(slug, url, pagename, "-" as *u8, 0, lic, "PAGE-FAILED" as *u8) } 322 } 323 rc_fetched_path(pagename, path) 324 let page: *u8 = ri_load(path, lenp) 325 if lenp[0] <= 0 { 326 c[RC_C_FAILED] = c[RC_C_FAILED] + 1 327 ri_puts("VIDEO-PAGE-ABSENT url=" as *u8); ri_puts(url); ri_puts("\n" as *u8) 328 } else { 329 if ri_kvs_extract(page, lenp[0], vurl, code) == 0 { 330 c[RC_C_FAILED] = c[RC_C_FAILED] + 1 331 ri_journal(slug, url, pagename, "-" as *u8, 0, lic, "VIDEO-NO-PLAYER" as *u8) 332 ri_puts("VIDEO-NO-PLAYER url=" as *u8); ri_puts(url); ri_puts(" (no video_url and license_code pair on the page: a player that is not KVS needs its own pattern)\n" as *u8) 333 } else { 334 let rrc: i64 = ri_kvs_real_url(vurl, code, media) 335 if rrc < 0 { 336 c[RC_C_FAILED] = c[RC_C_FAILED] + 1 337 ri_journal(slug, url, pagename, "-" as *u8, 0, lic, "VIDEO-URL-REFUSED" as *u8) 338 ri_puts("VIDEO-URL-REFUSED url=" as *u8); ri_puts(url); ri_puts(" rc=" as *u8); ri_putn(rrc); ri_puts("\n" as *u8) 339 } else { 340 if rc_journaled(jrnl, jlen[0], media) == 1 { c[RC_C_ALREADY] = c[RC_C_ALREADY] + 1 } else { 341 c[RC_C_TRIED] = c[RC_C_TRIED] + 1 342 let mrc: i64 = ri_mirror_one(media, medianame, sha, bytesp) 343 if mrc != RI_OK { 344 c[RC_C_FAILED] = c[RC_C_FAILED] + 1 345 ri_journal(slug, media, medianame, "-" as *u8, 0, lic, "FAILED" as *u8) 346 ri_puts("VIDEO-FAILED media=" as *u8); ri_puts(media); ri_puts("\n" as *u8) 347 } else { 348 rc_fetched_path(medianame, path) 349 let cls: i64 = ri_image_class(path) 350 if ri_is_video(cls) == 1 { 351 c[RC_C_OK] = c[RC_C_OK] + 1 352 ri_journal(slug, media, medianame, sha, bytesp[0], lic, "VIDEO-OK" as *u8) 353 ri_puts("VIDEO-OK media=" as *u8); ri_puts(media); ri_puts(" bytes=" as *u8); ri_putn(bytesp[0]); ri_puts("\n" as *u8) 354 } else { 355 c[RC_C_NOTIMAGE] = c[RC_C_NOTIMAGE] + 1 356 var so: i64 = ri_cat(status, 0, "NOT-VIDEO-" as *u8) 357 so = ri_cat(status, so, ri_class_word(cls)) 358 ri_journal(slug, media, medianame, sha, bytesp[0], lic, status) 359 ri_puts("VIDEO-NOT-VIDEO media=" as *u8); ri_puts(media); ri_puts(" class=" as *u8); ri_puts(ri_class_word(cls)); ri_puts(" bytes=" as *u8); ri_putn(bytesp[0]); ri_puts("\n" as *u8) 360 } 361 } 362 jrnl = rc_load_journal(slug, jlen) 363 } 364 } 365 } 366 } 367 } 368 idx = idx + 1 369 } 370 ri_puts("REFINTAKE videos slug=" as *u8); ri_puts(slug) 371 ri_puts(" tried=" as *u8); ri_putn(c[RC_C_TRIED]) 372 ri_puts(" ok=" as *u8); ri_putn(c[RC_C_OK]) 373 ri_puts(" notvideo=" as *u8); ri_putn(c[RC_C_NOTIMAGE]) 374 ri_puts(" failed=" as *u8); ri_putn(c[RC_C_FAILED]) 375 ri_puts(" already=" as *u8); ri_putn(c[RC_C_ALREADY]) 376 ri_puts(" (a body without the ftyp magic is never counted as a clip)\n" as *u8) 377 return c[RC_C_FAILED] 378} 379 380func rc_check(conf: *u8, n: i64) -> i64 { 381 let bad: *u8 = sys_mmap(RI_PATHB) 382 let badc: i64 = ri_tags_check(conf, n, bad) 383 var subjects: i64 = 0 384 var sources: i64 = 0 385 var tags: i64 = 0 386 var i: i64 = 0 387 while i < n { 388 let e: i64 = ri_line_end(conf, n, i) 389 if ri_starts(conf, n, i, "subject|" as *u8) == 1 { subjects = subjects + 1 } 390 if ri_starts(conf, n, i, "source|" as *u8) == 1 { sources = sources + 1 } 391 if ri_starts(conf, n, i, "tag|" as *u8) == 1 { tags = tags + 1 } 392 i = e + 1 393 } 394 ri_puts("REFINTAKE check conf=" as *u8); ri_puts(RI_CONF) 395 ri_puts(" subjects=" as *u8); ri_putn(subjects) 396 ri_puts(" sources=" as *u8); ri_putn(sources) 397 ri_puts(" tags=" as *u8); ri_putn(tags) 398 ri_puts(" tags_refused=" as *u8); ri_putn(badc) 399 if badc > 0 { ri_puts(" first_refused_axis=" as *u8); ri_puts(bad); ri_puts(" (not a declared morphology axis; the intake carries no group label of any person)\n" as *u8); return RC_EXIT_TAG } 400 ri_puts(" verdict=OK\n" as *u8) 401 return 0 402} 403 404func main(argc: i64, argv: *i64) -> i64 { 405 if argc < 2 { return rc_usage() } 406 let verb: *u8 = argv[1] as *u8 407 let lenp: *i64 = sys_mmap(RI_I64) as *i64 408 let conf: *u8 = ri_load(RI_CONF, lenp) 409 let n: i64 = lenp[0] 410 if n <= 0 { ri_puts("REFINTAKE conf unreadable: " as *u8); ri_puts(RI_CONF); ri_puts("\n" as *u8); return RC_EXIT_CONF } 411 if ri_streq(verb, "check" as *u8) == 1 { return rc_check(conf, n) } 412 if argc < RC_ARGC_SLUG { return rc_usage() } 413 let slug: *u8 = argv[2] as *u8 414 let allowed: i64 = ri_mirror_allowed(conf, n, slug) 415 if allowed == RI_E_NOSUBJECT { ri_puts("REFINTAKE subject undeclared: " as *u8); ri_puts(slug); ri_puts("\n" as *u8); return RC_EXIT_SUBJECT } 416 if allowed == RI_E_REFUSED { ri_puts("REFINTAKE subject REFUSED by its licence row: " as *u8); ri_puts(slug); ri_puts("\n" as *u8); return RC_EXIT_SUBJECT } 417 let lic: *u8 = sys_mmap(RI_PATHB) 418 ri_subject_licence(conf, n, slug, lic) 419 let bad: *u8 = sys_mmap(RI_PATHB) 420 if ri_tags_check(conf, n, bad) > 0 { ri_puts("REFINTAKE tag refused: axis " as *u8); ri_puts(bad); ri_puts(" is not a declared morphology axis\n" as *u8); return RC_EXIT_TAG } 421 let c: *i64 = sys_mmap(RC_C_N * RI_I64) as *i64 422 let v: *i64 = sys_mmap(RC_C_N * RI_I64) as *i64 423 let urlsp: *i64 = sys_mmap(RI_I64) as *i64 424 rc_zero(c, RC_C_N) 425 rc_zero(v, RC_C_N) 426 let hlen: *i64 = sys_mmap(RI_I64) as *i64 427 let hosts: *u8 = ri_load(RI_HOSTS, hlen) 428 var failed: i64 = 0 429 if ri_streq(verb, "pages" as *u8) == 1 { failed = rc_pages(conf, n, slug, lic, c) } 430 else { if ri_streq(verb, "discover" as *u8) == 1 { 431 if hlen[0] <= 0 { ri_puts("REFINTAKE hosts unreadable: " as *u8); ri_puts(RI_HOSTS); ri_puts("\n" as *u8); return RC_EXIT_CONF } 432 failed = rc_discover(conf, n, slug, hosts, hlen[0], c, urlsp) 433 } else { if ri_streq(verb, "mirror" as *u8) == 1 { failed = rc_mirror(conf, n, slug, lic, c) } 434 else { if ri_streq(verb, "verify" as *u8) == 1 { failed = rc_verify(slug, v) } 435 else { if ri_streq(verb, "videos" as *u8) == 1 { failed = rc_videos(conf, n, slug, lic, c) } 436 else { if ri_streq(verb, "all" as *u8) == 1 { 437 if hlen[0] <= 0 { ri_puts("REFINTAKE hosts unreadable: " as *u8); ri_puts(RI_HOSTS); ri_puts("\n" as *u8); return RC_EXIT_CONF } 438 failed = rc_pages(conf, n, slug, lic, c) 439 rc_zero(c, RC_C_N) 440 failed = failed + rc_discover(conf, n, slug, hosts, hlen[0], c, urlsp) 441 rc_zero(c, RC_C_N) 442 failed = failed + rc_mirror(conf, n, slug, lic, c) 443 failed = failed + rc_verify(slug, v) 444 rc_zero(c, RC_C_N) 445 failed = failed + rc_videos(conf, n, slug, lic, c) 446 ri_puts("REFINTAKE all slug=" as *u8); ri_puts(slug); ri_puts(" legs=5 failures=" as *u8); ri_putn(failed); ri_puts("\n" as *u8) 447 } else { return rc_usage() } } } } } } 448 if failed > 0 { return RC_EXIT_LEG } 449 return 0 450}