From 41c41ca859e093f8029bc5c6e9df996df8998530 Mon Sep 17 00:00:00 2001 From: dos-reis Date: Wed, 1 Oct 2008 09:50:16 +0000 Subject: * algebra/files.spad.pamphlet (IOMode): New domain. * algebra/net.spad.pamphlet (InputBinaryFile): Likewise. (OutputBinaryFile): Likewise. * interp/sys-utility.boot (openBinaryFile): New. (readByteFromFile): Likewise. (writeByteToFile): Likewise. (closeFile): Likewise. --- src/interp/sys-utility.boot | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/interp') diff --git a/src/interp/sys-utility.boot b/src/interp/sys-utility.boot index 82fb11e2..57fc9a9b 100644 --- a/src/interp/sys-utility.boot +++ b/src/interp/sys-utility.boot @@ -220,3 +220,35 @@ PRINT_-AND_-EVAL_-DEFUN(name,body) == PRINT_-DEFUN(name,body) + +--% File IO +$InputIOMode == KEYWORD::INPUT +$OutputIOMode == KEYWORD::OUTPUT +$BothWaysIOMode == KEYWORD::IO + +++ return a binary stream open for `file' in mode `mode'; nil +++ if something wnet wrong. +openBinaryFile(file,mode) == + mode = $InputIOMode => + OPEN(file,KEYWORD::DIRECTION,mode, + KEYWORD::IF_-DOES_-NOT_-EXIST,nil, + KEYWORD::ELEMENT_-TYPE,"%Byte") + OPEN(file,KEYWORD::DIRECTION,mode, + KEYWORD::IF_-EXISTS,KEYWORD::SUPERSEDE, + KEYWORD::ELEMENT_-TYPE,"%Byte") + +++ Attemp to read a byte from input file `ifile'. If not end of +++ file, return the read byte; otherwise -1. +readByteFromFile: %Thing -> %Short +readByteFromFile ifile == + byte := READ_-BYTE(ifile,false) => byte + -1 + +++ Write byte `b' to output binary file `ofile'. +writeByteToFile: (%Thing,%Byte) -> %Short +writeByteToFile(ofile,b) == + WRITE_-BYTE(b,ofile) + +closeFile file == + CLOSE file + nil -- cgit v1.2.3