--
--	Inmos Libraries
--	Copyright (C) 1988, 1989, 1990, 1991, 1993  Inmos Limited
--
--	This library is free software; you can redistribute it and/or
--	modify it under the terms of the GNU Lesser General Public
--	License as published by the Free Software Foundation; either
--	version 2 of the License, or (at your option) any later version.
--
--	This library is distributed in the hope that it will be useful,
--	but WITHOUT ANY WARRANTY; without even the implied warranty of
--	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
--	Lesser General Public License for more details.
--
--	You should have received a copy of the GNU Lesser General Public
--	License along with this library; if not, write to the Free Software
--	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
--

--** @module streamio

#OPTION "E"  -- no compliler libs
#COMMENT "Stream i/o library, V0.02 12/04/89"
#COMMENT "(c) Copyright INMOS Limited, 1988, 1989"
#INCLUDE "streamio.inc"
--{{{  history
-- V0.01
-- V0.02, 12-Apr-89
--}}}
--{{{  ks.read.char
--* Obtain the value of the next word length quantity from the given
-- keystream channel.
--
-- @param source for input
-- @param char the value of the word obtained
PROC ks.read.char (CHAN OF KS source, INT char)
  source ? char
:
--}}}
--{{{  ks.read.line
--* Read a line of text from the given keystream channel.
--
-- Although characters ( ie BYTE's ) are inserted into line, it is word
-- length quantities that are read from source. The line of text is
-- deemed to be terminated by INT '*c' or any negative value. The word
-- that terminated the line is not included in line. Any word read with
-- a value greater than 255 ( the maximum that a byte can hold ) is
-- ignored. Any '*n' read is ignored. If the array line is filled
-- before a valid termination character is encountered, then all
-- further words are ignored.
--
-- @param source for input
-- @param len the number of characters that have been put into line
-- @param line the line that was read is [ line FROM 0 FOR len ]
-- @param char the word that terminated the line
PROC ks.read.line (CHAN OF KS source, INT len, []BYTE line, INT char)
  VAL cr IS INT '*c' :
  INT pos, ch, max :
  SEQ
    max := (SIZE line) - 1
    pos := 0
    source ? ch
    WHILE (ch >= 0) AND (ch <> cr)
      SEQ
        IF
          ch = (INT '*n')
            SKIP
          (ch > 255) OR (pos >= max)
            SKIP
          TRUE
            SEQ
              line[pos] := BYTE ch
              pos := pos + 1
        source ? ch
    len := pos
    char := ch  -- terminating character ( as an INT )
:
--}}}
