code wiki / (root) / nx_foodsci2_research_fetch.nx

nx_foodsci2_research_fetch.nx source

↩ module page · 82 lines · 4815 B

1// nx_foodsci2_research_fetch.nx -- the Nishi RESEARCHER grounding the FINAL 2// five food-science-suite disciplines (rheology/texture, shelf-life, 3// emulsion, unit-operations, quality control) in real sources -- "research 4// not bro science". Mirrors the proven nx_foodsci_research_fetch pattern: 5// own TLS-1.3 + Mozilla CA, idempotent have-skip, ->knowledge/fetched/ 6// foodsci2_*.raw. COVERAGE: 12 sources. 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) 20 var k: i64 = 0 21 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 22 var j: i64 = k - 1 23 while j >= 0 { sys_write(1, (d as i64 + j) as *u8, 1); j = j - 1 } 24 return 0 25} 26func have_file(path: *u8) -> i64 { 27 let fd: i64 = sys_openat_rd(path) 28 if fd < 0 { return 0 } 29 sys_close(fd) 30 return 1 31} 32func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 { 33 if have_file(opath) == 1 { ff_puts(opath); ff_puts(" [have-skip]\n" as *u8); return 1 } 34 let status: *i64 = sys_mmap(8) as *i64 35 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status) 36 ff_puts(url); ff_puts(" status=" as *u8); ff_putn(status[0]); ff_puts(" bytes=" as *u8); ff_putn(n) 37 if n <= 0 { ff_puts(" FETCH-FAIL\n" as *u8); return 0 } 38 var gz: i64 = 0 39 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } } 40 if gz == 1 { ff_puts(" [GZIP-skip]\n" as *u8); return 0 } 41 let fd: i64 = sys_openat_wr(opath, 0x1a4) 42 if fd < 0 { ff_puts(" SAVE-FAIL\n" as *u8); return 0 } 43 sys_write(fd, out, n) 44 sys_close(fd) 45 ff_puts(" SAVED\n" as *u8) 46 return 1 47} 48 49func main() -> i64 { 50 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 51 if r <= 0 { ff_puts("FOODSCI2: certdata load failed\n" as *u8); return 1 } 52 let store: *TrustStore = r as *TrustStore 53 ff_puts("CA roots=" as *u8); ff_putn(trust_store_count(store)); ff_puts("\n" as *u8) 54 let cap: i64 = K_MAGIC_8388608 55 let out: *u8 = sys_mmap(cap) 56 var ok: i64 = 0 57 58 ff_puts("== RHEOLOGY & TEXTURE ==\n" as *u8) 59 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Rheology" as *u8, "knowledge/fetched/foodsci2_r1_rheology.raw" as *u8, store, out, cap) 60 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Power-law_fluid" as *u8, "knowledge/fetched/foodsci2_r2_power_law_fluid.raw" as *u8, store, out, cap) 61 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Herschel%E2%80%93Bulkley_fluid" as *u8, "knowledge/fetched/foodsci2_r3_herschel_bulkley.raw" as *u8, store, out, cap) 62 63 ff_puts("== SHELF-LIFE ==\n" as *u8) 64 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Shelf_life" as *u8, "knowledge/fetched/foodsci2_s1_shelf_life.raw" as *u8, store, out, cap) 65 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Q10_(temperature_coefficient)" as *u8, "knowledge/fetched/foodsci2_s2_q10.raw" as *u8, store, out, cap) 66 67 ff_puts("== EMULSION / COLLOID ==\n" as *u8) 68 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Emulsion" as *u8, "knowledge/fetched/foodsci2_e1_emulsion.raw" as *u8, store, out, cap) 69 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Hydrophilic-lipophilic_balance" as *u8, "knowledge/fetched/foodsci2_e2_hlb.raw" as *u8, store, out, cap) 70 71 ff_puts("== UNIT OPERATIONS ==\n" as *u8) 72 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Unit_operation" as *u8, "knowledge/fetched/foodsci2_u1_unit_operation.raw" as *u8, store, out, cap) 73 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Mass_balance" as *u8, "knowledge/fetched/foodsci2_u2_mass_balance.raw" as *u8, store, out, cap) 74 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Freezing-point_depression" as *u8, "knowledge/fetched/foodsci2_u3_freezing_point_depression.raw" as *u8, store, out, cap) 75 76 ff_puts("== QUALITY CONTROL ==\n" as *u8) 77 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Statistical_process_control" as *u8, "knowledge/fetched/foodsci2_q1_spc.raw" as *u8, store, out, cap) 78 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Process_capability_index" as *u8, "knowledge/fetched/foodsci2_q2_process_capability.raw" as *u8, store, out, cap) 79 80 ff_puts("READABLE SOURCES SAVED THIS PASS+HAVE: " as *u8); ff_putn(ok); ff_puts(" / 12\n" as *u8) 81 return 0 82}