code wiki / (root) / nx_foodsci3_research_fetch.nx

nx_foodsci3_research_fetch.nx source

↩ module page · 63 lines · 3376 B

1// nx_foodsci3_research_fetch.nx -- Nishi RESEARCHER grounding the depth 2// organs that shrink the SOTA behind-axes (design of experiments, 3// micronutrients, numerical finite-difference conduction). Mirrors the 4// proven fetcher: own TLS-1.3 + Mozilla CA, idempotent have-skip, 5// ->knowledge/fetched/foodsci3_*.raw. COVERAGE: 5. expect_exit: 0 6import "nx_syscalls.nx" 7import "nx_x509_trust_store.nx" 8import "nx_trust_store_load_from_certdata.nx" 9import "nx_https_fetch_follow.nx" 10const K_MAGIC_4194304: i64 = 4194304 11const K_MAGIC_8388608: i64 = 8388608 12 13func 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 } 14func ff_putn(v: i64) -> i64 { 15 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 16 var m: i64 = v 17 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 18 let d: *u8 = sys_mmap(24) 19 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" as *u8); 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=" as *u8); ff_putn(status[0]); ff_puts(" bytes=" as *u8); ff_putn(n) 36 if n <= 0 { ff_puts(" FETCH-FAIL\n" as *u8); 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" as *u8); return 0 } 40 let fd: i64 = sys_openat_wr(opath, 0x1a4) 41 if fd < 0 { ff_puts(" SAVE-FAIL\n" as *u8); return 0 } 42 sys_write(fd, out, n) 43 sys_close(fd) 44 ff_puts(" SAVED\n" as *u8) 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("FOODSCI3: certdata load failed\n" as *u8); return 1 } 51 let store: *TrustStore = r as *TrustStore 52 ff_puts("CA roots=" as *u8); ff_putn(trust_store_count(store)); ff_puts("\n" as *u8) 53 let cap: i64 = K_MAGIC_8388608 54 let out: *u8 = sys_mmap(cap) 55 var ok: i64 = 0 56 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Factorial_experiment" as *u8, "knowledge/fetched/foodsci3_d1_factorial_experiment.raw" as *u8, store, out, cap) 57 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Yates_analysis" as *u8, "knowledge/fetched/foodsci3_d2_yates_analysis.raw" as *u8, store, out, cap) 58 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Micronutrient" as *u8, "knowledge/fetched/foodsci3_m1_micronutrient.raw" as *u8, store, out, cap) 59 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Finite_difference_method" as *u8, "knowledge/fetched/foodsci3_p1_finite_difference_method.raw" as *u8, store, out, cap) 60 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Heat_equation" as *u8, "knowledge/fetched/foodsci3_p2_heat_equation.raw" as *u8, store, out, cap) 61 ff_puts("READABLE SOURCES SAVED THIS PASS+HAVE: " as *u8); ff_putn(ok); ff_puts(" / 5\n" as *u8) 62 return 0 63}