Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-11 - 43,50544/convrt.bli
There is 1 other file named convrt.bli in the archive. Click here to see a list.
!<BLF/remark:9>
!<BLF/lowercase_user>
!<BLF/uppercase_key>
MODULE convrt (								!
		IDENT = '01'
		) =
BEGIN

!++
! Facility:
!
!	BLISS Utilities
!
! Abstract:
!
!	This module contains conversion routines, e.g. from binary
!	integer to ASCII decimal strings. It is primarily designed for
!	use by the BLISS Language Formatter, "PRETTY".
!
! Environment:
!
!	Transportable.
!
!--

!<BLF/page>
!
! Table of contents:
!--

FORWARD ROUTINE
    cvt$put_dec;

!
! Include files:
!	(None)
!--

!
! Macros:
!--

!
! Equated symbols:
!--

LITERAL
    true = 1 EQL 1,
    false = 1 NEQ 1;

!
! Own storage:
!--

!
! External references:
!	(None)
!--

GLOBAL ROUTINE cvt$put_dec (num, nd, cp) = 				!

!++
! Functional description:
!
!	This routine converts an input value to ASCII decimal format.
!
! Formal parameters:
!
!	cp	= character pointer to the space in which the ASCII
!		number is to be stored.
!	nd	= the number of digit positions expected (including
!	num	= the value to be converted
!		leading spaces.) If the number is too large to be
!		represented in nd digits, additional space will be
!		taken so that the full value of the input will always
!		be output.
!
! Implicit inputs:
!
!	None
!
! Implicit outputs:
!
!	None.
!
! Routine value:
!
!	The character pointer to the next available position.
!
! Side effects:
!
!	If the number is too large to fit the specified number of digits,
!	more space will be used than requested. The user should
!	check the actual space used (value of output character pointer.)
!
!--

    BEGIN

    LITERAL
	last = 36;							! Max size of ASCII string

    OWN
	digits : INITIAL (CH$PTR (UPLIT('0123456789'))),
	string : VECTOR [CH$ALLOCATION (last)],
	len,
	value,								! local version of t
	tp;								!
!<BLF/page>
    value = ABS (.num);
    CH$FILL (%C' ', .nd, .cp);					! Prepare output string to receive digits.
    tp = CH$PTR (string, last);

    DO
	BEGIN
	tp = CH$PLUS (.tp, -1);
	CH$WCHAR (CH$RCHAR (CH$PLUS (.digits, .value MOD 10)), .tp);
	value = .value/10;
	END
    UNTIL .value EQL 0;

    IF .num LSS 0 THEN (tp = CH$PLUS (.tp, -1); CH$WCHAR (%C'-', .tp); );

    len = CH$DIFF (CH$PTR (string, last), .tp);
    RETURN CH$MOVE (.len, .tp, CH$PLUS (.cp, MAX (0, .nd - .len)));
    END;								! End of 'cvt$put_dec'
%TITLE 'Last page of CONVRT.BLI'
END									! End of module 'convrt'

ELUDOM