home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OL.LZH / PROCS.LZH / BUFFER.ICN < prev    next >
Text File  |  1991-09-05  |  1KB  |  95 lines

  1. ############################################################################
  2. #
  3. #    Name:    buffer.icn
  4. #
  5. #    Title:    Buffered I/O
  6. #
  7. #    Author:    Ralph E. Griswold
  8. #
  9. #    Date:    September 2, 1991
  10. #
  11. ############################################################################
  12. #
  13. #  These procedures provide buffered input and output:
  14. #
  15. #     Read()        read a line
  16. #     LookAhead()    look ahead at next line
  17. #     ReadAhead(n)    read ahead n lines
  18. #     PutBack(s)    put back a line
  19. #     Write(s)    write a line
  20. #     Flush()    flush output buffer
  21. #     GetBack()    get back line writen
  22. #     ClearOut()    remove contents of output buffer without writing
  23. #
  24. ############################################################################
  25.  
  26. global buffer_in, buffer_out, Eof
  27.  
  28. procedure Read()
  29.  
  30.    initial{
  31.       buffer_in := []
  32.       put(buffer_in,read()) | (Eof := 1)
  33.       }
  34.  
  35.    put(buffer_in,read()) | (Eof := 1)
  36.    return get(buffer_in)
  37.  
  38. end
  39.  
  40. procedure LookAhead()
  41.  
  42.    return buffer_in[1]
  43.  
  44. end
  45.  
  46. procedure ReadAhead(n)
  47.  
  48.    while *buffer_in < n do
  49.       put(buffer_in,read()) | {
  50.          Eof := 1
  51.          fail
  52.          }
  53.  
  54.    return
  55.  
  56. end
  57.  
  58. procedure PutBack(s)
  59.  
  60.    push(buffer_in,s)
  61.  
  62.    return
  63.  
  64. end
  65.  
  66. procedure Write(s)
  67.  
  68.    initial buffer_out := []
  69.  
  70.    push(buffer_out,s)
  71.  
  72.    return s
  73.  
  74. end
  75.  
  76. procedure Flush()
  77.  
  78.    while write(pull(buffer_out))
  79.  
  80.    return
  81.  
  82. end
  83.  
  84. procedure GetBack()
  85.  
  86.    return get(buffer_out)
  87.  
  88. end
  89.  
  90. procedure ClearOut()
  91.  
  92.    buffer_out := []
  93.  
  94. end
  95.