Trailing-Edge
-
PDP-10 Archives
-
DEC_CMS-20_V1.0_SRC
-
cms/sources/ascdec.bli
There are no other files named ascdec.bli in the archive.
MODULE ASCDEC (
IDENT = '1',
%IF
%BLISS(BLISS32)
%THEN
LANGUAGE(BLISS32),
ADDRESSING_MODE(EXTERNAL=LONG_RELATIVE,
NONEXTERNAL=LONG_RELATIVE)
%ELSE
LANGUAGE(BLISS36)
%FI
) =
BEGIN
!
! COPYRIGHT (c) 1982, BY
! DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
!
! THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED
! ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE
! INCLUSION OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE OR ANY OTHER
! COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
! OTHER PERSON. NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY
! TRANSFERRED.
!
! THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE
! AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT
! CORPORATION.
!
! DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS
! SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.
!
!++
! FACILITY: CMS Library Processor
!
! ABSTRACT:
!
! Convert a numeric ASCII string to decimal.
!
! ENVIRONMENT: VAX/VMS, DS-20
!
! AUTHOR: D. Knight , CREATION DATE: 27-Nov-78
!
!--
!
! TABLE OF CONTENTS
!
FORWARD ROUTINE
ASCDEC, !Convert ASCII to DECIMAL
ASCHEX; !Convert ASCII to HEX
!
! INCLUDE FILES:
!
%if %bliss(bliss32) %then
library 'sys$library:starlet';
%else
require 'jsys:';
%fi
LIBRARY 'XPORT:';
REQUIRE 'SCONFG:';
REQUIRE 'BLISSX:';
REQUIRE 'COMUSR:';
!
! MACROS:
!
!
! EQUATED SYMBOLS:
!
!
! OWN STORAGE:
!
!
! EXTERNAL REFERENCES:
!
EXTERNAL ROUTINE
BUG;
GLOBAL ROUTINE ASCDEC (STG_PTR,STG_LEN) =
!++
! FUNCTIONAL DESCRIPTION:
!
! Convert ASCII to decimal
!
! FORMAL PARAMETERS:
!
! STG_PTR - address of character pointer to numeric string
! STG_LEN - length of string to convert (always quit on first
! non-digit if it is seen before the count is exhausted)
!
! IMPLICIT INPUTS:
!
! NONE.
!
! IMPLICIT OUTPUTS:
!
! STG_PTR has been advanced over the numeric field.
!
! ROUTINE VALUE:
! COMPLETION CODES:
!
! -1 - no number seen
! <>-1 - value found.
!
! SIDE EFFECTS:
!
! NONE.
!
!--
BEGIN
LOCAL
CHARS_SEEN,
NUM_SO_FAR;
!quit if no number exists
IF
NOT (CH$RCHAR(..STG_PTR) GEQ %C'0' AND
CH$RCHAR(..STG_PTR) LEQ %C'9')
THEN
RETURN -1;
NUM_SO_FAR=0;
CHARS_SEEN=0;
!Collect the number
REPEAT
BEGIN
LOCAL
CHAR;
!Pick up a digit
CHAR=CH$RCHAR(..STG_PTR);
!Quit when a non-digit is seen or there is no more text
IF
(IF
.STG_LEN NEQ 0
THEN
.CHARS_SEEN EQL .STG_LEN
ELSE
FALSE) OR
NOT (.CHAR GEQ %C'0' AND
.CHAR LEQ %C'9')
THEN
RETURN .NUM_SO_FAR;
!Watch out for possible numeric overflow failure
IF
.CHARS_SEEN GEQ MAX_NUM_SIZE OR
.NUM_SO_FAR*10+.CHAR-%C'0' LSS .NUM_SO_FAR
THEN
BUG(LIT('ASCII to DECIMAL conversion failure'));
NUM_SO_FAR=.NUM_SO_FAR*10 + .CHAR-%C'0';
CHARS_SEEN=.CHARS_SEEN+1;
.STG_PTR=CH$PLUS(..STG_PTR,1)
END
END; !End of ASCDEC
GLOBAL ROUTINE ASCHEX (STG_PTR,STG_LEN) =
!++
! FUNCTIONAL DESCRIPTION:
!
! Convert ASCII to hex
!
! FORMAL PARAMETERS:
!
! STG_PTR - character pointer to numeric string
! STG_LEN - length of string to convert (if zero, quit on first
! non-digit)
!
! IMPLICIT INPUTS:
!
! NONE.
!
! IMPLICIT OUTPUTS:
!
! NONE.
!
! ROUTINE VALUE:
! COMPLETION CODES:
!
! -1 - no number seen
! <>-1 - value found.
!
! SIDE EFFECTS:
!
! NONE.
!
!--
BEGIN
LOCAL
CHARS_SEEN,
NUM_SO_FAR;
IF
NOT ((CH$RCHAR(..STG_PTR) GEQ %C'0' AND
CH$RCHAR(..STG_PTR) LEQ %C'9') OR
(CH$RCHAR(..STG_PTR) GEQ %C'A' AND
CH$RCHAR(..STG_PTR) LEQ %C'F'))
THEN
RETURN -1;
NUM_SO_FAR=0;
CHARS_SEEN=0;
!Collect the number
REPEAT
BEGIN
LOCAL
CHAR;
!Pick up a digit
CHAR=CH$RCHAR(..STG_PTR);
!Quit when a non-digit is seen or there is no more text
IF
(IF
.STG_LEN NEQ 0
THEN
.CHARS_SEEN EQL .STG_LEN
ELSE
FALSE) OR
NOT ((.CHAR GEQ %C'0' AND
.CHAR LEQ %C'9') OR
(.CHAR GEQ %C'A' AND
.CHAR LEQ %C'F'))
THEN
RETURN .NUM_SO_FAR;
!Watch out for possible failure
IF
.CHARS_SEEN GEQ MAX_NUM_SIZE
THEN
BUG(LIT('ASCII to HEX conversion failure'));
! We could check here to make sure the number is not now negative -
! but since we use this routine for CRC's we don't
! Convert the character
! If it's a digit we must subtract the character 0 ; if it's
! a letter (A thru F) we must subtract a hexadecimal 37.
IF .CHAR GEQ %C'0' AND .CHAR LEQ %C'9'
THEN
NUM_SO_FAR=.NUM_SO_FAR*16 + .CHAR-%C'0'
ELSE
NUM_SO_FAR=.NUM_SO_FAR*16 + .CHAR-%x'37' ;
CHARS_SEEN=.CHARS_SEEN+1;
.STG_PTR=CH$PLUS(..STG_PTR,1)
END
END; !End of ASCDEC
END !End of Module ASCDEC
ELUDOM