code wiki / (root) / nx_unidoc_lib.nx

nx_unidoc_lib.nx

buildroot/runtime/nx_unidoc_lib.nx

28920 B518 linesdepth 5pulls 6 transitivereach 2 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_unidoc_lib.nx -- THE UNIFIED DOCUMENT PAGE (rung UD1 of /compare/unidoc, 2026-09-03). Operator (2026-09-03): "we want nishi browser to handle documents like webpages securely but with full interactivity so we dont have to have a file browser and a web browser etc but a unified portal." ONE page per document, whatever it was born as. A .docx, .odt, .pdf, .md, .csv or .txt becomes the SAME zero-script HTML page: the office's own document model (the H/P/T/B/I spec lines that nx_office_serve edits, versions and signs) rendered as a page, with a Content-Security-Policy that forbids every script and every foreign fetch, every byte of document text escaped BY CONSTRUCTION, and the portal's actions (original bytes, versions, annotate, sign) as plain HTML forms -- no client script anywhere, so the page is native in the Nishi browser and NishiOS first and degrades to nothing in a third-party browser. A web page is NOT a document: .html and .htm are REFUSED here by name (UD_ERR_REFUSED_HTML). The browser already serves a page as itself; wrapping one as a document would be the exact confusion this organ ends. Composition, never re-implementation: .docx and .odt go through the promoted format organs' `spec` verbs (_offc/nx_docx.elf, _offc/nx_odt.elf -- the same verbs the office import uses), .pdf through the proven text extractor _offc/nx_pdf_text.elf, all captured with nx_tool_run. Markdown, CSV and text are folded to the spec here because their grammar IS the spec's grammar. Every refusal is NAMED (ud_err_name) and the input ceiling is ANNOUNCED, never a silent truncation. license_tier: ORIGINAL

dependencies 3 imports · 2 importers

nx_syscalls.nx nx_itoa_lib.nx nx_tool_run.nx nx_unidoc_lib.nx nx_unidoc.nx nx_unidoc_gate.nx

imports: nx_syscalls.nxnx_itoa_lib.nxnx_tool_run.nx

imported by: nx_unidoc.nxnx_unidoc_gate.nx

structs

none

consts

28const UD_KIND_UNKNOWN: i64 = 0
29const UD_KIND_DOCX: i64 = 1
30const UD_KIND_ODT: i64 = 2
31const UD_KIND_PDF: i64 = 3
32const UD_KIND_MD: i64 = 4
33const UD_KIND_CSV: i64 = 5
34const UD_KIND_TXT: i64 = 6
35const UD_KIND_HTML: i64 = 7 // recognised so it can be REFUSED by name, never rendered as a document
38const UD_ERR_UNKNOWN_KIND: i64 = 0 - 1
39const UD_ERR_REFUSED_HTML: i64 = 0 - 2
40const UD_ERR_RENDERER: i64 = 0 - 3 // the format organ failed or handed back no spec
41const UD_ERR_TOO_BIG: i64 = 0 - 4 // above UD_IN_CAP: refused by name, never cut
42const UD_ERR_READ: i64 = 0 - 5 // the input could not be read
43const UD_ERR_OUT_CAP: i64 = 0 - 6 // the page would not fit the caller's buffer: refused, never truncated
46const UD_IN_CAP: i64 = 8388608 // 8 MiB of document bytes per page
47const UD_SPEC_CAP: i64 = 4194304 // the folded spec (H/P/T lines)
48const UD_CAPTURE_CAP: i64 = 4194320 // a format organ's captured stdout (spec + its BEGIN/END markers)
49const UD_PATH_CAP: i64 = 4096
50const UD_EXT_MAX: i64 = 12 // the browser's own br_doc_ext bound
51const UD_ARGV_SLOTS: i64 = 6
52const UD_PTR_BYTES: i64 = 8
53const UD_SLACK: i64 = 4096 // headroom the page emitter keeps before refusing UD_ERR_OUT_CAP
55const UD_DOCX_ELF: *u8 = "_offc/nx_docx.elf"
56const UD_ODT_ELF: *u8 = "_offc/nx_odt.elf"
57const UD_PDFTEXT_ELF: *u8 = "_offc/nx_pdf_text.elf"
58const UD_PDF_TXT_SCRATCH: *u8 = "/tmp/nx_unidoc_pdf.txt"
61const UD_NL: i64 = 10
62const UD_CR: i64 = 13
63const UD_TAB: i64 = 9
64const UD_SP: i64 = 32
65const UD_HASH: i64 = 35
66const UD_DASH: i64 = 45
67const UD_STAR: i64 = 42
68const UD_PLUS: i64 = 43
69const UD_PIPE: i64 = 124
70const UD_SLASH: i64 = 47
71const UD_COMMA: i64 = 44
72const UD_QUOTE: i64 = 34
73const UD_DOT: i64 = 46
74const UD_LT: i64 = 60
75const UD_GT: i64 = 62
76const UD_AMP: i64 = 38
77const UD_APOS: i64 = 39
78const UD_BACKTICK: i64 = 96
79const UD_H: i64 = 72
80const UD_P: i64 = 80
81const UD_T: i64 = 84
82const UD_B: i64 = 66
83const UD_I: i64 = 73
84const UD_MD_HEADING_MAX: i64 = 6

functions

86func ud_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
87func ud_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; var o: i64 = off; while s[i] != (0 as u8) { dst[o] = s[i]; o = o + 1; i = i + 1 } return o }
88func ud_catn(dst: *u8, off: i64, v: i64) -> i64 { return nxi_buf(dst, off, v) }
called by 1: ud_page calls 1: nxi_buf
89func ud_lower(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c }
called by 1: ud_ext
90func ud_streq(a: *u8, b: *u8) -> i64
97func ud_find(hay: *u8, n: i64, needle: *u8) -> i64
called by 2: ug_hasud_spec_from_fork calls 1: ud_slen
110func ud_count(hay: *u8, n: i64, needle: *u8) -> i64
called by 1: main calls 1: ud_slen
127func ud_esc_n(out: *u8, off: i64, src: *u8, a: i64, b: i64) -> i64
called by 2: ud_escud_spec_to_html calls 1: ud_cat
141func ud_esc(out: *u8, off: i64, s: *u8) -> i64 { return ud_esc_n(out, off, s, 0, ud_slen(s)) }
called by 2: mainud_page calls 2: ud_esc_nud_slen
144func ud_ext(path: *u8, ext: *u8) -> i64
called by 1: ud_kind_of_path calls 2: ud_slenud_lower
168func ud_kind_of_ext(ext: *u8) -> i64
called by 1: ud_kind_of_path calls 1: ud_streq
181func ud_kind_of_path(path: *u8) -> i64
187func ud_kind_label(kind: i64) -> *u8
called by 1: ud_page
197func ud_kind_name(kind: i64) -> *u8
called by 1: main
207func ud_err_name(code: i64) -> *u8
called by 2: mainmain
217func ud_check_size(n: i64) -> i64 { if n > UD_IN_CAP { return UD_ERR_TOO_BIG } return 0 }
called by 2: mainud_render_path
221func ud_spec_line(out: *u8, o0: i64, cap: i64, tag: i64, src: *u8, a: i64, b: i64, in_tbl: i64) -> i64
238func ud_spec_from_text(src: *u8, n: i64, out: *u8, cap: i64) -> i64
260func ud_spec_from_md(src: *u8, n: i64, out: *u8, cap: i64) -> i64
called by 1: ud_spec_of calls 1: ud_spec_line
305func ud_spec_from_csv(src: *u8, n: i64, out: *u8, cap: i64) -> i64
called by 1: ud_spec_of
334func ud_spec_from_fork(elf: *u8, path: *u8, out: *u8, cap: i64) -> i64
362func ud_spec_from_pdf(path: *u8, out: *u8, cap: i64) -> i64
396func ud_spec_of(kind: i64, path: *u8, bytes: *u8, n: i64, out: *u8, cap: i64) -> i64
408func ud_spec_to_html(out: *u8, off: i64, spec: *u8, sl: i64) -> i64
called by 1: ud_page calls 2: ud_catud_esc_n
442func ud_css(out: *u8, off: i64) -> i64
called by 1: ud_page calls 1: ud_cat
457func ud_page(out: *u8, cap: i64, title: *u8, kind: i64, nbytes: i64, spec: *u8, sl: i64, dlurl: *u8, base: *u8, sha: *u8) -> i64
486func ud_title_of(path: *u8, out: *u8) -> i64
called by 1: ud_render_path calls 1: ud_slen
499func ud_render_path(path: *u8, dlurl: *u8, base: *u8, out: *u8, cap: i64, kind_out: *i64) -> i64