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

#OPTION "E V" -- no compiler libraries, no vector space
#COMMENT "Type conversion library V1.2 22/11/90"
#COMMENT "(c) Copyright INMOS Limited 1988"
#USE "ioconv.lib"
--{{{  history
-- V1.0, 1-Jul-88
-- Added V to OPTIONs; V1.1, 22-Mar-90 SRH
-- Bug fix of STRINGTOINT16 report number TS/822; Error now correctly set,
-- and n contains low order bits when string overflows INT32 range; V1.2,
-- 22-Nov-90 SRH
--}}}
--{{{  STRINGTOINT16 TA
--* Convert to an INT16 the value represented by string.
--
-- A plus ( + ) or a minus ( - ) sign is allowed in the first position
-- of string. An illegal character is any non-numeric character, other
-- than + or - in the first position.
--
-- @param Error TRUE if the value of string overflows the INT16 range;
--   TRUE if there are any illegal characters in string; FALSE
--   otherwise
-- @param n if the value that string represents does not overflow the
--   INT16 range then n is the INT16 that string represents, with the
--   convention that n is zero if string is empty; otherwise n will be
--   the value of the portion of string up to any illegal character,
--   where n is zero if an illegal character is in the first position
--   of string, or if the INT16 range overflows n will contain the low
--   order bits of the binary representation of string
-- @param string the characters that are to be converted to an INT16
PROC STRINGTOINT16 (BOOL Error, INT16 n, VAL []BYTE string)
  --{{{  more information
  --           This routine assumes that it is written to be compiled
  --           for a 32-bit processor.
  --}}}

  #IF TARGET.BITS.PER.WORD = 32
  INT m :
  SEQ
    STRINGTOINT (Error, m, string)
    [ 2 ]INT16 m.prime RETYPES m :
    n := m.prime[ 0 ]  -- n assigned low order bits of m
    IF
      Error
        SKIP
      ( m < (INT (MOSTNEG INT16)) ) OR ( m > (INT (MOSTPOS INT16)) )
        Error := TRUE
      TRUE
        SKIP
  #ELSE
  CAUSEERROR ()
  #ENDIF
:
--}}}
--{{{  INT16TOSTRING TA
PROC INT16TOSTRING (INT len, []BYTE string, VAL INT16 n)
  INTTOSTRING (len, string, INT n)
:
--}}}
