home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Language / Compiler / Builtins / real_Buffer.m < prev    next >
Encoding:
Text File  |  1990-08-16  |  2.0 KB  |  78 lines

  1. % @(#)real_Buffer.m    1.1  3/16/88
  2. %
  3. import _VectorOfCharObject from "Builtins"
  4. export _BufferObject to "Builtins"
  5. const _BufferObject == immutable object _BufferObject
  6.   export getSignature, create
  7.   const BufferType == type BufferType
  8.     operation write
  9.     operation addChar [Character]
  10.     operation addString [String]
  11.     operation Pad [Character, Integer]
  12.   end BufferType
  13.  
  14.   function getSignature -> [r : Signature]
  15.     r <- BufferType
  16.   end getSignature
  17.  
  18.   operation create [myfd : Integer]-> [r : BufferType]
  19.     r <- object aBuffer
  20.       export addChar, addString, write, pad
  21.       const BUFSIZE == 1024
  22.       monitor
  23.     const buf == _VectorOfCharObject.create[BUFSIZE]
  24.     var nextToFillIndex : Integer <- 0
  25.     operation write 
  26.       if nextToFillIndex > 0 then
  27.         primitive 017 [] <- [myfd, buf, nextToFillIndex]
  28.         nextToFillIndex <- 0
  29.       end if
  30.     end write
  31.     operation addChar [c : Character]
  32.       buf(nextToFillIndex) := c
  33.       nextToFillIndex <- nextToFillIndex + 1
  34.       if nextToFillIndex >= BUFSIZE or c = '\^J' then
  35.         primitive 017 [] <- [myfd, buf, nextToFillIndex]
  36.         nextToFillIndex <- 0
  37.       end if
  38.     end addChar
  39.     operation addString [s : String]
  40.       var i : Integer <- 0
  41.       var limit : Integer <- s.length
  42.       var index : Integer <- nextToFillIndex
  43.       var c : Character
  44.       loop
  45.         exit when i >= limit
  46.         c <- s(i)
  47.         buf(index) := c
  48.         index <- index + 1
  49.         i <- i + 1
  50.         if index >= BUFSIZE or c = '\^J' then
  51.           primitive 017 [] <- [myfd, buf, index]
  52.           index <- 0
  53.         end if
  54.       end loop
  55.       nextToFillIndex <- index
  56.     end addString
  57.     operation Pad [c : Character, w : Integer]
  58.       var i : Integer <- 0
  59.       var limit : Integer <- w
  60.       var index : Integer <- nextToFillIndex
  61.       loop
  62.         exit when i >= limit
  63.         buf(index) := c
  64.         index <- index + 1
  65.         i <- i + 1
  66.         if index >= BUFSIZE then
  67.           primitive 017 [] <- [myfd, buf, index]
  68.           index <- 0
  69.         end if
  70.       end loop
  71.       nextToFillIndex <- index
  72.     end Pad
  73.       end monitor
  74.     end aBuffer
  75.   end create
  76. end _BufferObject
  77.