home *** CD-ROM | disk | FTP | other *** search
- ############################################################################
- #
- # File: buffer.icn
- #
- # Subject: Procedures for buffered input and output
- #
- # Author: Ralph E. Griswold
- #
- # Date: August 10, 1992
- #
- ###########################################################################
- #
- # 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 := []
- }
-
- if *buffer_in = 0 then
- 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
-