$include(subsys.inc) /***************************************************************************** * * MODULE NAME: condec (note: module name should always be the same as * the source file name without the extension) * * DESCRIPTION: This module contains a decimal conversion procedure. * *****************************************************************************/ condec: DO; $include(:rmx:inc/error.lit) $include(:rmx:inc/common.lit) $include(strng.ext) $subtitle('construct$integer') /**************************************************************************** * * PROC NAME: construct$integer * * DESCRIPTION: a procedure to convert a WORD into a decimal string * * CALL: CALL construct$integer(buff$ptr,number); * * INPUTS: number a WORD to be converted to decimal * * OUTPUTS: buff$ptr a pointer to a string to which the converted * number will be appended * ****************************************************************************/ construct$integer: PROCEDURE(buff$ptr,number) REENTRANT; DECLARE buff$ptr POINTER, number WORD, buff BASED buff$ptr STRING, num10 WORD; num10 = number / 10; IF num10 <> 0 THEN CALL construct$integer(buff$ptr,num10); buff.char(buff.length) = (number MOD 10) + '0'; buff.length = buff.length + 1; END construct$integer; $subtitle('convert$decimal') /**************************************************************************** * * PROC NAME: convert$decimal * * DESCRIPTION: Converts a 16 bit binary number to a decimal string * and right justifies it in a fixed width field. The * field will be blank padded. If the field width is zero * no padding will be done. * * * CALL: CALL convert$decimal(buff$ptr,buff$max,number,length, * status$ptr); * * * INPUTS: buff$max a WORD containing the size of the buffer * number a WORD to be converted to decimal * length a byte containing the width of the field * that the output should be right justified in * * * OUTPUTS: buff$ptr a pointer to a string to which the converted * number will be appended * status$ptr a pointer to a WORD that will receive the * exception word * ****************************************************************************/ convert$decimal: PROCEDURE(buff$ptr,buff$max,number,length,status$ptr) REENTRANT PUBLIC; DECLARE buff$ptr POINTER, buff$max WORD, number WORD, length BYTE, i BYTE, status$ptr POINTER, buff BASED buff$ptr STRING, status BASED status$ptr WORD; DECLARE local$buff STRUCTURE( length BYTE, char(5) BYTE); local$buff.length = 0; CALL construct$integer(@local$buff,number); IF (length > 0) AND (local$buff.length <= length) THEN DO i = 1 TO (length - local$buff.length); CALL concatenate$string(buff$ptr,buff$max,@(1,' '),status$ptr); IF status <> E$OK THEN RETURN; END; CALL concatenate$string(buff$ptr,buff$max,@local$buff,status$ptr); END convert$decimal; END condec;