[SOLVED] CS import io

$25

File Name: CS_import_io.zip
File Size: 113.04 KB

5/5 - (1 vote)

import io

manifest
{ iosb_ichar = 0;
iosb_ochar = 1;
iosb_close = 2;
iosb_unit = 3;
iosb_buffer = 4;
iosb_pos = 5;
iosb_size = 6;
sizeof_iosb = 7 }

let readch_tty(iosb) be
{ resultis inch() }

let writech_tty(iosb, c) be
{ outch(c) }

let close_tty(iosb) be
{ }

let tty = table readch_tty, writech_tty, close_tty, 0, 0, 0, 0;

let tapes = table 1, 0, 0, 0, 0, 0, 0, 0, 0;

let find_free_tape_unit() be
{ for i = 1 to 8 do
if tapes ! i = 0 then
{ tapes ! i := 1;
resultis i }
out(All tape drives are in use
);
finish }

let close_writetape(iosb) be
{ let r;
if iosb ! iosb_pos /= 0 then
{ let r = devctl(DC_TAPE_WRITE,
iosb ! iosb_unit,
iosb ! iosb_buffer,
iosb ! iosb_pos);
if r < 0 then{ out(“code %d from tape write
“, r);finish } }r := devctl(DC_TAPE_UNLOAD, iosb ! iosb_unit);if r < 0 then{ out(“code %d from tape unload
“, r);finish }tapes ! (iosb ! iosb_unit) := 0;freevec(iosb ! iosb_buffer);freevec(iosb) }let close_readtape(iosb) be{ let r = devctl(DC_TAPE_UNLOAD, iosb ! iosb_unit);if r < 0 then{ out(“code %d from tape unload
“, r);finish }tapes ! (iosb ! iosb_unit) := 0;freevec(iosb ! iosb_buffer);freevec(iosb) }let writechar_tape(iosb, ch) be{ if iosb ! iosb_pos = iosb ! iosb_size then{ let r = devctl(DC_TAPE_WRITE, iosb ! iosb_unit,iosb ! iosb_buffer, iosb ! iosb_size);if r < 0 then{ out(“code %d from tape write
“, r);finish }iosb ! iosb_pos := 0 }byte (iosb ! iosb_pos) of (iosb ! iosb_buffer) := ch;iosb ! iosb_pos +:= 1 }let readchar_tape(iosb) be{ let c;if iosb ! iosb_pos >= iosb ! iosb_size then
{ let r = devctl(DC_TAPE_READ,
iosb ! iosb_unit,
iosb ! iosb_buffer);
if r < 0 then{ out(“code %d from tape read
“, r);finish }iosb ! iosb_pos := 0;iosb ! iosb_size := r }if iosb ! iosb_pos = iosb ! iosb_size then{ iosb ! iosb_size := -1;resultis -1; }c := byte (iosb ! iosb_pos) of (iosb ! iosb_buffer);iosb ! iosb_pos +:= 1;resultis c }let illegal_writech(iosb, ch) be{ out(“Write performed on read-only file
“);finish }let illegal_readch(iosb) be{ out(“Read performed on write-only file
“);finish }let at_eof(iosb) be{ resultis iosb ! iosb_size = -1 }let tape_open_w(fname) be{ let t = find_free_tape_unit();let r = devctl(DC_TAPE_LOAD, t, fname, ‘W’);if r < 0 then{ out(“code %d from tape load
“, r);finish }r := newvec(sizeof_iosb);r ! iosb_ichar := illegal_readch;r ! iosb_ochar := writechar_tape;r ! iosb_close := close_writetape;r ! iosb_unit := t;r ! iosb_buffer := newvec(128);r ! iosb_pos := 0;r ! iosb_size := 512;resultis r; }let tape_open_r(fname) be{ let t = find_free_tape_unit();let r = devctl(DC_TAPE_LOAD, t, fname, ‘R’);if r < 0 then{ out(“code %d from tape load
“, r);finish }r := newvec(sizeof_iosb);r ! iosb_ichar := readchar_tape;r ! iosb_ochar := illegal_writech;r ! iosb_close := close_readtape;r ! iosb_unit := t;r ! iosb_buffer := newvec(128);r ! iosb_pos := 0;r ! iosb_size := 512;resultis r; }let writech(iosb, ch) be{ (iosb ! iosb_ochar)(iosb, ch) }let readch(iosb) be{ resultis (iosb ! iosb_ichar)(iosb) }let close(iosb) be{ (iosb ! iosb_close)(iosb) }let writestr(iosb, s) be{ let i = 0;while true do{ let c = byte i of s;if c = 0 then break;writech(iosb, c);i +:= 1 } }let writeno(iosb, n) be{ if n < 0 then{ writech(iosb, ‘-‘);n := -n }if n > 9 then
writeno(iosb, n / 10);
writech(iosb, 0 + n rem 10) }

let readno(iosb) be
{ let n = 0, c = readch(iosb), s = 1;
while c < ‘ ‘ doc:=readch(iosb);if c = ‘-‘ then{ s := -1;c := readch(iosb) }while c >= 0 / c <= ‘9’ do{ n := n * 10 + c – ‘0’; c := readch(iosb) }resultis n * s }let start() be{ let fi, fo, min, max;init(!0x101, !0x100 – !0x101);writestr(tty, “The program is creating table.txt
“);fi := tape_open_r(“limits.txt”);fo := tape_open_w(“table.txt”);min := readno(fi);max := readno(fi);for cent = min to max do{ let fahr = cent * 9 / 5 + 32;writeno(fo, cent);writestr(fo, ” centigrade is “);writeno(fo, fahr);writestr(fo, ” fahrenheit
“) }close(fi);close(fo) }

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS import io
$25