code wiki / (root) / nx_access_research_fetch.nx

nx_access_research_fetch.nx source

↩ module page · 83 lines · 5429 B

1// nx_access_research_fetch.nx -- the Nishi RESEARCHER's sovereign fetch for ACCESSIBILITY / ACCOMMODATION 2// (operator: "disabilities should disappear in the nishi ecosystem" -- ADHD/ADD, sleep apnea, and other 3// limiters that make average things hard). GROWS the researcher with the accessibility sub-domain, grounding 4// nx_accommodate. Mirrors nx_fin_research_fetch (own TLS-1.3, Mozilla CA, idempotent have-skip, sovereign). 5// Legs: ADHD/EXECUTIVE-FUNCTION, ACCESSIBILITY/UNIVERSAL-DESIGN, SLEEP/FATIGUE, DISABILITY-FRAMEWORKS. 6// -> knowledge/fetched/acc_*.raw. expect_exit: 0 license_tier: ORIGINAL 7import "nx_syscalls.nx" 8import "nx_x509_trust_store.nx" 9import "nx_trust_store_load_from_certdata.nx" 10import "nx_https_fetch_follow.nx" 11const K_MAGIC_4194304: i64 = 4194304 12const K_MAGIC_8388608: i64 = 8388608 13 14func ff_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 15func ff_putn(v: i64) -> i64 { 16 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 17 var m: i64 = v 18 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 19 let d: *u8 = sys_mmap(24); var k: i64 = 0 20 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 21 var j: i64 = k - 1 22 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 } 23 return 0 24} 25func have_file(path: *u8) -> i64 { 26 let fd: i64 = sys_openat_rd(path) 27 if fd < 0 { return 0 } 28 sys_close(fd) 29 return 1 30} 31func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 { 32 if have_file(opath) == 1 { ff_puts(opath); ff_puts(" [have-skip]\n"); return 1 } 33 let status: *i64 = sys_mmap(8) as *i64 34 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status) 35 ff_puts(url); ff_puts(" status="); ff_putn(status[0]); ff_puts(" bytes="); ff_putn(n) 36 if n <= 0 { ff_puts(" FETCH-FAIL\n"); return 0 } 37 var gz: i64 = 0 38 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } } 39 if gz == 1 { ff_puts(" [GZIP-skip]\n"); return 0 } 40 let fd: i64 = sys_openat_wr(opath, 0x1a4) 41 if fd < 0 { ff_puts(" SAVE-FAIL\n"); return 0 } 42 sys_write(fd, out, n) 43 sys_close(fd) 44 ff_puts(" SAVED\n") 45 return 1 46} 47 48func main() -> i64 { 49 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 50 if r <= 0 { ff_puts("ACC: certdata load failed\n"); return 1 } 51 let store: *TrustStore = r as *TrustStore 52 ff_puts("CA roots="); ff_putn(trust_store_count(store)); ff_puts("\n") 53 let cap: i64 = K_MAGIC_8388608 54 let out: *u8 = sys_mmap(cap) 55 var ok: i64 = 0 56 57 ff_puts("== ADHD / EXECUTIVE FUNCTION (one-thing-at-a-time, structure) ==\n") 58 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Attention_deficit_hyperactivity_disorder" as *u8, "knowledge/fetched/acc_adhd.raw" as *u8, store, out, cap) 59 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Executive_functions" as *u8, "knowledge/fetched/acc_execfn.raw" as *u8, store, out, cap) 60 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Executive_dysfunction" as *u8, "knowledge/fetched/acc_execdys.raw" as *u8, store, out, cap) 61 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Procrastination" as *u8, "knowledge/fetched/acc_procrastination.raw" as *u8, store, out, cap) 62 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Decision_fatigue" as *u8, "knowledge/fetched/acc_decisionfatigue.raw" as *u8, store, out, cap) 63 64 ff_puts("== ACCESSIBILITY / UNIVERSAL DESIGN ==\n") 65 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Web_Content_Accessibility_Guidelines" as *u8, "knowledge/fetched/acc_wcag.raw" as *u8, store, out, cap) 66 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Web_accessibility" as *u8, "knowledge/fetched/acc_webaccess.raw" as *u8, store, out, cap) 67 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Universal_design" as *u8, "knowledge/fetched/acc_universaldesign.raw" as *u8, store, out, cap) 68 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Assistive_technology" as *u8, "knowledge/fetched/acc_assistivetech.raw" as *u8, store, out, cap) 69 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Plain_language" as *u8, "knowledge/fetched/acc_plainlang.raw" as *u8, store, out, cap) 70 71 ff_puts("== SLEEP / FATIGUE (sleep apnea, brain fog) ==\n") 72 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Sleep_apnea" as *u8, "knowledge/fetched/acc_sleepapnea.raw" as *u8, store, out, cap) 73 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Obstructive_sleep_apnea" as *u8, "knowledge/fetched/acc_osa.raw" as *u8, store, out, cap) 74 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Fatigue" as *u8, "knowledge/fetched/acc_fatigue.raw" as *u8, store, out, cap) 75 76 ff_puts("== DISABILITY FRAMEWORKS (the model: society adapts, not the person) ==\n") 77 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Disability" as *u8, "knowledge/fetched/acc_disability.raw" as *u8, store, out, cap) 78 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Social_model_of_disability" as *u8, "knowledge/fetched/acc_socialmodel.raw" as *u8, store, out, cap) 79 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Reasonable_accommodation" as *u8, "knowledge/fetched/acc_reasonableaccom.raw" as *u8, store, out, cap) 80 81 ff_puts("ACCESSIBILITY RESEARCH SAVED THIS PASS+HAVE: "); ff_putn(ok); ff_puts(" / 16\n") 82 return 0 83}