code wiki / _hdl_build / nx_fb2_fixture.nx
nx_fb2_fixture.nx source
↩ module page · 33 lines · 2074 B
1// nx_fb2_fixture.nx -- write a tiny sovereign DRM-free FB2 (FictionBook 2.0) file so the FB2->Nishi rung can be
2// gated end-to-end (nx_fb2_book decodes -> book.json -> nx_nmz_pack @kind=book). A real .fb2 is a single XML file;
3// this one has the title-info (title + author first/last) in <description> and prose in <body><section>, including
4// a section <title> heading -- exactly the shape nx_fb2_book parses. expect_exit: 0 license_tier: ORIGINAL
5import "nx_syscalls.nx"
6
7func fx_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
8func fxw(fd: i64, s: *u8) -> i64 { sys_write(fd, s, fx_slen(s)); return 0 }
9func ensure_dir(path: *u8) -> i64 { __syscall(258, 0-100, path, 0x1ed, 0, 0, 0); return 0 }
10
11func main() -> i64 {
12 ensure_dir("knowledge/fixtures" as *u8)
13 let fd: i64 = sys_openat_wr("knowledge/fixtures/nishi_fb2_fixture.fb2" as *u8, 0x1a4)
14 if fd < 0 { fxw(1, "FB2-FIXTURE-FAIL open\n" as *u8); sys_exit(1); return 1 }
15 fxw(fd, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" as *u8)
16 fxw(fd, "<FictionBook xmlns=\"http://www.gribuser.ru/xml/fictionbook/2.0\">\n" as *u8)
17 fxw(fd, "<description><title-info>\n" as *u8)
18 fxw(fd, "<genre>sf</genre>\n" as *u8)
19 fxw(fd, "<author><first-name>Lewis</first-name><last-name>Carroll</last-name></author>\n" as *u8)
20 fxw(fd, "<book-title>Alice (Nishi FB2 Fixture)</book-title>\n" as *u8)
21 fxw(fd, "<lang>en</lang>\n" as *u8)
22 fxw(fd, "</title-info></description>\n" as *u8)
23 fxw(fd, "<body>\n" as *u8)
24 fxw(fd, "<section><title><p>Down the Rabbit-Hole</p></title>\n" as *u8)
25 fxw(fd, "<p>Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do.</p>\n" as *u8)
26 fxw(fd, "<p>Suddenly a <emphasis>White Rabbit</emphasis> with pink eyes ran close by her.</p>\n" as *u8)
27 fxw(fd, "</section>\n" as *u8)
28 fxw(fd, "</body>\n" as *u8)
29 fxw(fd, "</FictionBook>\n" as *u8)
30 sys_close(fd)
31 fxw(1, "FB2-FIXTURE-OK -> knowledge/fixtures/nishi_fb2_fixture.fb2\n" as *u8)
32 sys_exit(0); return 0
33}