--
--	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 hostio

#COMMENT "Host i/o library, V1.00, 10/03/89"
#COMMENT "(c) Copyright INMOS Limited 1989"
#INCLUDE "hostio.inc"
#USE "splib.lib"

--* Read a line from the keyboard without echoing it.
--
-- The line to be read is considered terminated by a carriage return,
-- ie ASCII ^M, which has value #0D = 13.  This carriage return is not
-- included in the line, and nor is a newline ( ASCII ^J, #0A = 10 ) if
-- present in the input. If an error occurs whilst reading the line
-- this routine terminates immediately.
--
-- @param fs from server
-- @param ts to server
-- @param len the number of bytes in the parameter line that form the
--   line that was read
-- @param line if result = spr.ok, the line that was read is in the
--   first len bytes, the remaining bytes being undefined or if the
--   supplied byte array was not large enough for the read line, the
--   read line is truncated to fit; otherwise undefined
-- @param result spr.ok if the line was successfully read; otherwise >=
--   spr.operation.failed - see hostio.inc or iserver documentation for
--   further details
PROC so.read.line (CHAN OF SP fs, ts, INT len, []BYTE line, BYTE result)
  --{{{  declarations
  BOOL running :
  BYTE key :

  VAL delete    IS 127(BYTE) :
  VAL backspace IS   8(BYTE) :
  --}}}

  SEQ
    len := 0
    running := TRUE
    WHILE running
      SEQ
        sp.getkey (fs, ts, key, result)
        IF
          result = spr.ok
            --{{{  add to line, and check for '*c' or '*n'
            IF
              --{{{  return or newline key - finished
              (key = '*c') OR (key = '*n')
                running := FALSE
              --}}}
              --{{{  delete key
              (key = delete) OR (key = backspace)
                IF
                  len > 0
                    len := len - 1
                  TRUE
                    SKIP
              --}}}
              --{{{  it fits on the line, add it
              len < (SIZE line)
                SEQ
                  line [len] := key
                  len := len + 1
              --}}}
              --{{{  otherwise skip
              TRUE
                SKIP
              --}}}
            --}}}  add to line, and check for '*c'
          TRUE
            running := FALSE
:
