home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
OL.LZH
/
PROCS.LZH
/
BUFFER.ICN
< prev
next >
Wrap
Text File
|
1991-09-05
|
1KB
|
95 lines
############################################################################
#
# Name: buffer.icn
#
# Title: Buffered I/O
#
# Author: Ralph E. Griswold
#
# Date: September 2, 1991
#
############################################################################
#
# These procedures provide buffered input and output:
#
# Read() read a line
# LookAhead() look ahead at next line
# ReadAhead(n) read ahead n lines
# PutBack(s) put back a line
# Write(s) write a line
# Flush() flush output buffer
# GetBack() get back line writen
# ClearOut() remove contents of output buffer without writing
#
############################################################################
global buffer_in, buffer_out, Eof
procedure Read()
initial{
buffer_in := []
put(buffer_in,read()) | (Eof := 1)
}
put(buffer_in,read()) | (Eof := 1)
return get(buffer_in)
end
procedure LookAhead()
return buffer_in[1]
end
procedure ReadAhead(n)
while *buffer_in < n do
put(buffer_in,read()) | {
Eof := 1
fail
}
return
end
procedure PutBack(s)
push(buffer_in,s)
return
end
procedure Write(s)
initial buffer_out := []
push(buffer_out,s)
return s
end
procedure Flush()
while write(pull(buffer_out))
return
end
procedure GetBack()
return get(buffer_out)
end
procedure ClearOut()
buffer_out := []
end