get "libhdr" manifest $( bfeof = 0 $) let reads(v) be $( let ch = ? v%0 := 0 ch := rdch() until ch = '*N' do $( v%0 := v%0 + 1 v%(v%0) := ch ch := rdch() $) $) let contains(str, ch) = valof $( for i = 1 to str%0 do if ch = str%i then resultis true resultis false $) let readbf(file, v) = valof $( let i, ch = 1, ? let curin = input() v%0 := 0 selectinput(file) ch := rdch() until ch = endstreamch do $( if contains("+-<>.,[]", ch) then $( v%i := ch i := i + 1 $) ch := rdch() $) v%i := 0 endread() selectinput(curin) resultis i + 1 $) let bfout(ch) be wrch(ch=10 -> '*N', ch) let bfin() = valof $( let ch = rdch() resultis ch = endstreamch -> bfeof, ch $) let scan(v, i, dir) = valof $( let d = 1 until d = 0 do $( i := i + dir if v%i = 0 then $( writes("Unbalanced brackets*N") resultis 0 $) if v%i = '[' then d := d + dir if v%i = ']' then d := d - dir $) resultis i $) let run(v, m) be $( let i = 1 until v%i = 0 do $( switchon v%i into $( case '+': v%m := v%m + 1 ; endcase case '-': v%m := v%m - 1 ; endcase case '>': m := m + 1 ; endcase case '<': m := m - 1 ; endcase case '.': bfout(v%m) ; endcase case ',': v%m := bfin() ; endcase case '[': if v%m = 0 then i := scan(v, i, 1) if i = 0 then return endcase case ']': unless v%m = 0 do i := scan(v, i, -1) if i = 0 then return endcase $) i := i + 1 $) $) let start() be $( let fname = vec 63 let file = ? writes("Filename? ") reads(fname) file := findinput(fname) test file = 0 then writes("Cannot open file.*N") else $( let mvec = getvec(maxvec()) let m = readbf(file, mvec) run(mvec, m) freevec(mvec) $) $)