nx_lib_ingest_tsv.nx source
↩ module page · 54 lines · 2040 B
1// nx_lib_ingest.nx -- sovereign WRITE/INGEST path for the nishi-library catalog.
2// Ingests a TSV of works into nx_lib_store (retires the Python sources/sync).
3// line = work_hk<TAB>title<TAB>doi<TAB>published<TAB>license
4// splits work_hk off the front; the remainder is the store record. No python,
5// no shell, no 3rd-party. Built + run by the WOMB.
6// license_tier: ORIGINAL | genealogy_id: nishi_library_sovereign_ingest_2026_06_30
7import "nx_syscalls.nx"
8import "nx_lib_store.nx"
9const K_MAGIC_1024: i64 = 1024
10
11// ingest TSV from a buffer; returns the count of works put into the store.
12func nx_lib_ingest_buf(buf: *u8, n: i64) -> i64 {
13 let hkbuf: *u8 = sys_mmap(K_MAGIC_1024)
14 var count: i64 = 0
15 var ls: i64 = 0
16 var i: i64 = 0
17 while i <= n {
18 var eol: i64 = 0
19 if i == n { eol = 1 } else { if buf[i] == 10 as u8 { eol = 1 } }
20 if eol == 1 {
21 if i > ls {
22 // first TAB in [ls, i)
23 var tabpos: i64 = 0 - 1
24 var t: i64 = ls
25 while t < i {
26 if tabpos < 0 { if buf[t] == 9 as u8 { tabpos = t } }
27 t = t + 1
28 }
29 if tabpos >= 0 {
30 var k: i64 = 0
31 var j: i64 = ls
32 while j < tabpos { hkbuf[k] = buf[j]; k = k + 1; j = j + 1 }
33 hkbuf[k] = 0 as u8
34 let recptr: *u8 = ((buf as i64) + tabpos + 1) as *u8
35 let reclen: i64 = i - (tabpos + 1)
36 nx_lib_store_put_work(hkbuf, recptr, reclen)
37 count = count + 1
38 }
39 }
40 ls = i + 1
41 }
42 i = i + 1
43 }
44 return count
45}
46
47// ingest from a TSV file on disk; returns count, or -1 if unreadable.
48func nx_lib_ingest_file(path: *u8) -> i64 {
49 let lp: *i64 = sys_mmap(8) as *i64
50 lp[0] = 0
51 let buf: *u8 = sys_read_file(path, lp)
52 if (buf as i64) == 0 { return 0 - 1 }
53 return nx_lib_ingest_buf(buf, lp[0])
54}