import "io" let buffer = vec(128); let pos = 0, size = 0; // size = no of bytes in buffer let ateof = 0; // not at end of file yet let refill() be { let r = devctl(DC_TAPE_READ, 1, buffer); if r < 0 then { out("error %d from tape_read\n", r); finish } pos := 0; size := r; if size = 0 then ateof := true } let fgetc() be { let result; if pos >= size then refill(); if ateof then resultis -1; result := byte pos of buffer; pos +:= 1; resultis result } let fgetno() be { let sofar = 0; let c = fgetc(); while c <= ' ' do { if c = -1 then resultis -1; c := fgetc() } while true do { if c = -1 then resultis sofar; test c >= '0' /\ c <= '9' then sofar := sofar * 10 + c - '0' else resultis sofar; c := fgetc() } } let fopen(name) be { let r = devctl(DC_TAPE_LOAD, 1, name, 'R'); if r < 0 then { out("error %d for load\n", r); finish } } let fclose() be { devctl(DC_TAPE_UNLOAD, 1) } let start() be { fopen("numbers.txt"); while true do { let c = fgetno(); if c = -1 then break; out("the number was %d\n", c) } fclose(); }