code wiki / _hdl_build / nx_profile_region_extract_t239.nx

nx_profile_region_extract_t239.nx source

↩ module page · 36 lines · 1897 B

1// Select an explicit source profile part without changing measurements or coordinate frame. 2// Preserves source comments, V/N contract and Q rows affecting selected part. 3// This is selection, not anatomical validation or conversion between specimen cohorts. 4import "nx_syscalls.nx" 5import "nx_profile_contract.nx" 6func pe_int(b:*u8,p:*i64,e:i64)->i64{ 7 while p[0]<e{if b[p[0]]>(32 as u8){break}p[0]=p[0]+1} 8 var n:i64=0;var seen:i64=0 9 while p[0]<e{let c:i64=b[p[0]] as i64;if c<48{break}if c>57{break} 10 if n>922337203685477580{return 0-1}if n==922337203685477580{if c>55{return 0-1}} 11 n=n*10+c-48;seen=1;p[0]=p[0]+1} 12 if seen==0{return 0-1}return n 13} 14func main(argc:i64,argv:*i64)->i64{ 15 if argc!=4{return 2}let size:*i64=sys_mmap(16) as *i64 16 let b:*u8=sys_read_file(argv[1] as *u8,size);if (b as i64)==0{return 3} 17 let info:*i64=sys_mmap(40) as *i64;let status:i64=profile_contract_scan(b,size[0],info);if status<0{return 4} 18 let p:*i64=sys_mmap(8) as *i64;let arg:*u8=argv[3] as *u8;var al:i64=0;while arg[al]!=(0 as u8){al=al+1} 19 p[0]=0;let part:i64=pe_int(arg,p,al);if part<0{return 2}if p[0]!=al{return 2} 20 let out:*u8=sys_mmap(size[0]+1);var used:i64=0;var rows:i64=0;var i:i64=0 21 while i<size[0]{ 22 var e:i64=i;while e<size[0]{if b[e]==(10 as u8){break}e=e+1} 23 var j:i64=i;while j<e{if b[j]>(32 as u8){break}j=j+1} 24 var keep:i64=1 25 if j<e{ 26 if b[j]==(83 as u8){p[0]=j+1;let id:i64=pe_int(b,p,e);if id<0{return 4}keep=0;if id==part{keep=1;rows=rows+1}} 27 if b[j]==(81 as u8){p[0]=j+1;pe_int(b,p,e);let a:i64=pe_int(b,p,e);let c:i64=pe_int(b,p,e);keep=0;if a==part{keep=1}if c==part{keep=1}} 28 } 29 if keep==1{var k:i64=i;while k<e{out[used]=b[k];used=used+1;k=k+1}out[used]=10 as u8;used=used+1} 30 i=e+1 31 } 32 if rows==0{return 5} 33 let fd:i64=sys_openat_wr(argv[2] as *u8,420);if fd<0{return 6} 34 let wrote:i64=sys_write(fd,out,used);sys_close(fd);if wrote!=used{return 6} 35 return 0 36}