diff TL1/test/t4.tl1 @ 175:c83545730d6c

openm
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 14 Apr 2019 17:17:34 +0900
parents
children 6ef317714ae8
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TL1/test/t4.tl1	Sun Apr 14 17:17:34 2019 +0900
@@ -0,0 +1,43 @@
+% ** TEST PROGRAM **
+func search
+%--- main ---
+var dict,buf
+array tend[2]
+begin
+  dict := openm($2,0)
+  write(dict:ascii(0))
+  write(dict:ascii(30),ascii(-'P'),"ROC")
+  write(dict:ascii(31),ascii(-'F'),"UNC")
+  write(dict:ascii(33),ascii(-'V'),"AR")
+  postion(dict,tend)
+  buf := openm($2,0)
+  write(buf:"FUNC",ascii(0))
+  write(0:search(buf),crlf)
+  seek(buf,0)
+  write(buf:"NONAME",ascii(0))
+  write(0:search(buf),crlf)
+end
+
+search(buf)
+var val,k,c
+array bend
+begin
+  val := seek(dict,tend)
+  position(buf,bend)
+  while val#0 do [
+     c:=seekr(buf,-1)
+     k:=seekr(dict,-1)
+     if k.lt.0 then [
+       if c=-k then
+          return val    % found
+       val := seekr(dict,-1)
+     ] else if c#k then [
+       seek(buf,bend)
+       repeat
+          k:=seekr(dict,-1)
+       until k.lt.0
+       val := seekr(dict,-1)
+     ]
+  ]
+  return val % not found
+end