code wiki / _hdl_build / _structure_text_authored.nx

_structure_text_authored.nx source

↩ module page · 22 lines · 1135 B

1// AUTHORED BY THE NISHI BUILDER (structure-text template) -- tag-strip + paragraph structure tree, bits-up 2import "nx_syscalls.nx" 3func structure_text(s: *u8, n: i64, out: *u8, marks: *i64, omc: *i64) -> i64 { 4 var op: i64=0; var mc: i64=0; var i: i64=0 5 while i<n { 6 if s[i]==0x3c as u8 { 7 if i+3<n { if s[i+1]==0x2f as u8 { if s[i+2]==0x70 as u8 { if s[i+3]==0x3e as u8 { marks[mc]=op; mc=mc+1 } } } } 8 var done: i64=0; while done==0 { if i>=n { done=1 } else { let c: i64=s[i] as i64; i=i+1; if c==0x3e { done=1 } } } 9 } else { out[op]=s[i]; op=op+1; i=i+1 } 10 } 11 omc[0]=mc; return op 12} 13func main() -> i64 { 14 let s: *u8="<p>Hello</p><p>World</p>" as *u8 15 let out: *u8=sys_mmap(64); let marks: *i64=sys_mmap(8*8) as *i64; let omc: *i64=sys_mmap(8) as *i64 16 let op: i64=structure_text(s, 24, out, marks, omc) 17 let exp: *u8="HelloWorld" as *u8 18 var ok: i64=1; if op!=10 { ok=0 } if omc[0]!=2 { ok=0 } if marks[0]!=5 { ok=0 } if marks[1]!=10 { ok=0 } 19 var i: i64=0; while i<10 { if out[i]!=exp[i] { ok=0 } i=i+1 } 20 if ok==1 { sys_exit(0) } sys_exit(1) 21 return 1 22}