--
--	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.1 22/03/90"
#COMMENT "(c) Copyright INMOS Limited 1988"
PROC INTTOSTRING (INT len, []BYTE string, VAL INT n)

  --{{{  history
  -- Beta-2 (27feb87)
  -- V1.0, 1-Jul-88
  -- Added V to OPTIONs; V1.1, 22-Mar-90 SRH
  --}}}

  INT R, W:
  BYTE b:
  BOOL Neg:
  SEQ
    IF
      n < 0
        SEQ
          W := 0 MINUS n
          Neg := TRUE
          len := 0
      n > 0
        SEQ
          W := n
          Neg := FALSE
          len := 0
      TRUE
        SEQ
          W := n
          Neg := FALSE
          len := 1
          string[0] := '0'
    WHILE W <> 0
      SEQ
        W, R := LONGDIV (0, W, 10)
        string[len] := (BYTE (R + (INT '0')))
        len := len + 1
    IF
      Neg
        SEQ
          string[len] := '-'
          len := len + 1
      TRUE
        SKIP
    W := 0
    R := (len - 1)
    WHILE (W < R)
      SEQ
        b := string[W]
        string[W] := string[R]
        string[R] := b
        W := W + 1
        R := R - 1
:
