CreateStreamProcs:
PUBLIC
PROC [
variety: IO.StreamVariety,
class: ATOM,
getChar: PROC [self: STREAM] RETURNS [CHAR],
getBlock: PROC [self: STREAM, block: REF TEXT, startIndex: NAT, count: NAT] RETURNS [nBytesRead: NAT],
unsafeGetBlock: UNSAFE PROC [self: STREAM, block: UnsafeBlock] RETURNS [nBytesRead: INT],
endOf: PROC [self: STREAM] RETURNS [BOOL],
charsAvail: PROC [self: STREAM, wait: BOOL] RETURNS [INT],
backup: PROC [self: STREAM, char: CHAR],
putChar: PROC [self: STREAM, char: CHAR],
putBlock: PROC [self: STREAM, block: REF READONLY TEXT, startIndex: NAT, count: NAT],
unsafePutBlock: PROC [self: STREAM, block: UnsafeBlock],
flush: PROC [self: STREAM],
reset: PROC [self: STREAM],
close: PROC [self: STREAM, abort: BOOL],
getIndex: PROC [self: STREAM] RETURNS [INT],
setIndex: PROC [self: STREAM, index: INT],
getLength: PROC [self: STREAM] RETURNS [length: INT],
setLength: PROC [self: STREAM, length: INT],
eraseChar: PROC [self: STREAM, char: CHAR]
]
RETURNS [REF StreamProcs] = {
streamProcs:
REF StreamProcs ←
NEW[StreamProcs ← [
variety: variety,
class: class,
getChar:
IF getChar #
NIL
THEN getChar
ELSE IF unsafeGetBlock # NIL THEN GetCharViaUnsafeGetBlock
ELSE DefaultGetChar,
getBlock:
IF getBlock #
NIL
THEN getBlock
ELSE IF unsafeGetBlock # NIL THEN GetBlockViaUnsafeGetBlock
ELSE GetBlockViaGetChar,
unsafeGetBlock:
IF unsafeGetBlock #
NIL
THEN unsafeGetBlock
ELSE UnsafeGetBlockViaGetChar,
endOf: IF endOf = NIL THEN DefaultEndOf ELSE endOf,
charsAvail: IF charsAvail = NIL THEN DefaultCharsAvail ELSE charsAvail,
backup: IF backup = NIL THEN DefaultBackup ELSE backup,
putChar:
IF putChar #
NIL
THEN putChar
ELSE IF unsafePutBlock # NIL THEN PutCharViaUnsafePutBlock
ELSE DefaultPutChar,
putBlock:
IF putBlock #
NIL
THEN putBlock
ELSE IF unsafePutBlock # NIL THEN PutBlockViaUnsafePutBlock
ELSE PutBlockViaPutChar,
unsafePutBlock:
IF unsafePutBlock #
NIL
THEN unsafePutBlock
ELSE UnsafePutBlockViaPutChar,
flush: IF flush = NIL THEN DefaultFlush ELSE flush,
reset: IF reset = NIL THEN DefaultReset ELSE reset,
close: IF close = NIL THEN DefaultClose ELSE close,
getIndex: IF getIndex = NIL THEN DefaultGetIndex ELSE getIndex,
setIndex: IF setIndex = NIL THEN DefaultSetIndex ELSE setIndex,
propList: NIL]];
IF getLength #
NIL
THEN
IOUtils.StoreProc[streamProcs, $GetLength, NEW[TypeOfGetLength ← getLength]];
IF setLength #
NIL
THEN
IOUtils.StoreProc[streamProcs, $SetLength, NEW[TypeOfSetLength ← setLength]];
IF eraseChar #
NIL
THEN
IOUtils.StoreProc[streamProcs, $EraseChar, NEW[TypeOfEraseChar ← eraseChar]];
RETURN[streamProcs];