--
--	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, V1.1, 14/06/90"
#COMMENT "(c) Copyright INMOS Limited, 1988"
#INCLUDE "hostio.inc"
#INCLUDE "streamio.inc"
#USE "hostio.lib"
--* Read lines from standard input and output them on the given key
-- stream channel.
--
-- The value ft.terminated is sent on keys.out on termination.
-- Termination of this procedure is either when an error occurs or when
-- all characters from standard input have been read, ie when end of
-- file from standard input is read. A '*c' is output to terminate a
-- text line.
--
-- @param fs from server
-- @param ts to server
-- @param keys.out for output
-- @param result spr.ok if the process was successful; otherwise >=
--   spr.operation.failed meaning that reading standard input failed -
--   see hostio.inc or iserver documentation for further details
PROC so.keystream.from.stdin (CHAN OF SP fs, ts, CHAN OF KS keys.out,
                              BYTE result)
  --{{{  history
  -- Introduced the end of file test to determine whether so.gets
  -- validly reached the end of standard input or failed.  Without
  -- this test a valid functioning of this routine would have left
  -- left spr.operation.failed in result!  New version is 1.1
  -- ( old version was 0.01, 23-Dec-88 ); 14-June-90 SRH
  --}}}

  SEQ
    result := spr.ok
    WHILE result = spr.ok
      [sp.max.readbuffer.size]BYTE buffer :
      INT len :
      SEQ
        sp.gets (fs, ts, spid.stdin, len, buffer, result)
        SEQ i = 0 FOR len
          keys.out ! INT buffer [i]
        keys.out ! INT ('*c')
    BYTE old.result : -- used to save any error value
    SEQ
      old.result := result
      so.eof( fs, ts, spid.stdin, result )
      IF
        result = spr.ok -- then end of file validly reached
          old.result := spr.ok
        TRUE -- there must have been a read error
          SKIP
      result := old.result
    keys.out ! ft.terminated
:
