$include(subsys.inc) /***************************************************************************** * * MODULE NAME: strng (note: module name should always be the same as * the source file name without the extension) * * DESCRIPTION: This module contains string manipulation utilities. * iRMX defines a string as a length byte followed * by up to 255 characters. The routines in this module * allow these strings to be easily built by combining * strings and non-strings together. All iRMX system * calls that deal with names require these names to be * in the form of strings. * ******************************************************************************/ strng: DO; $include(:rmx:inc/error.lit) $include(:rmx:inc/common.lit) $subtitle('min$word') /**************************************************************************** * * PROC NAME: min$word * * DESCRIPTION: returns the minimum of two input values * * CALL: min$value = min$word(val1,val2); * * INPUTS: val1 a WORD containing the first value * val2 a WORD containing the second value * * RETURNS: min$value a WORD containing the minimum of val1,val2 * ****************************************************************************/ min$word: PROCEDURE(val1,val2) WORD REENTRANT PUBLIC; DECLARE val1 WORD, val2 WORD; IF val1 < val2 THEN RETURN val1; RETURN val2; END min$word; $subtitle('concatenate$to$string') /**************************************************************************** * * PROC NAME: concatenate$to$string * * DESCRIPTION: Concatenate the contents of the source buffer to the end * of the destination string. If there is not enough room * for the entire source buffer, concatenate as much as * possible. * * CALL: CALL concatenate$to$string(destination$p,destination$max, * source$p,source$length, * status$ptr ); * * INPUTS: destination$max a WORD containing the size of the * destination buffer * source$p a pointer to the source buffer * source$length a WORD containing the length of the * source buffer * * OUTPUTS: destination$p a pointer to the destination buffer * for the concatenated string * status$ptr a pointer to a WORD that will * receive the exception word * ****************************************************************************/ concatenate$to$string: PROCEDURE(destination$p,destination$max, source$p,source$length,status$ptr) PUBLIC REENTRANT; DECLARE destination$p POINTER, destination$max WORD, source$p POINTER, source$length WORD, status$ptr POINTER, destination BASED destination$p STRING, status BASED status$ptr WORD, d$length WORD; $EJECT IF destination$p = NULL$POINTER THEN DO; status = E$STRING$BUFFER; RETURN; END; ELSE IF destination$max < 1 THEN DO; status = E$STRING$BUFFER; RETURN; END; status = E$OK; IF source$p <> NULL$POINTER THEN DO; destination$max = min$word((double(string$max)+1),destination$max); IF DOUBLE(destination.length) >= destination$max THEN status = E$STRING$BUFFER; ELSE IF source$length > 0 THEN DO; d$length = DOUBLE(destination.length) + source$length; IF d$length >= destination$max THEN DO; IF d$length > STRING$MAX THEN status = E$STRING; ELSE status = E$STRING$BUFFER; source$length = destination$max-destination.length-1; END; CALL movb(source$p,@destination.char(destination.length), source$length); destination.length = destination.length + source$length; END; END; END concatenate$to$string; $subtitle('concatenate$string') /**************************************************************************** * * PROC NAME: concatenate$string * * DESCRIPTION: Concatenate the contents of the source string to the end * of the destination string. If there is not enough room * for the entire source buffer, concatenate as much as * possible. * * CALL: CALL concatenate$to$string(destination$p,destination$max, * source$p,status$ptr ); * * INPUTS: destination$max a WORD containing the size of the * destination buffer * source$p a pointer to the source string * * OUTPUTS: destination$p A POINTER TO THE DESTINATION BUFFER * FOR THE CONCATENATED STRING * status$ptr A POINTER TO A WORD THAT WILL * RECEIVE THE EXCEPTION WORD * ****************************************************************************/ concatenate$string: PROCEDURE(destination$p,destination$max, source$p,status$ptr) PUBLIC REENTRANT; DECLARE destination$p POINTER, destination$max WORD, source$p POINTER, status$ptr POINTER, source BASED source$p STRING, status BASED status$ptr WORD; IF destination$p = NULL$POINTER THEN DO; status = E$STRING$BUFFER; RETURN; END; ELSE IF destination$max < 1 THEN DO; status = E$STRING$BUFFER; RETURN; END; status = E$OK; IF source$p <> NULL$POINTER THEN CALL concatenate$to$string(destination$p,destination$max, @source.char, source.length, status$ptr); END concatenate$string; $SUBTITLE('move$string') /**************************************************************************** * * PROC NAME: move$string * * DESCRIPTION: Moves the contents of the source string to the start * of the destination string. * * CALL: CALL move$string(destination$p,destination$max, * source$p,status$ptr ); * * INPUTS: destination$max a WORD containing the size of the * destination buffer * source$p a pointer to the source string * * OUTPUTS: destination$p a pointer to the destination string * status$ptr a pointer to a WORD that will * receive the exception word * ****************************************************************************/ move$string: PROCEDURE(destination$p,destination$max, source$p,status$ptr) PUBLIC REENTRANT; DECLARE destination$p POINTER, destination$max WORD, source$p POINTER, status$ptr POINTER, source BASED source$p STRING, status BASED status$ptr WORD, destination BASED destination$p STRING; IF destination$p = NULL$POINTER THEN DO; status = E$STRING$BUFFER; RETURN; END; ELSE IF destination$max < 1 THEN DO; status = E$STRING$BUFFER; RETURN; END; destination.length = 0; IF source$p <> NULL$POINTER THEN CALL concatenate$to$string(destination$p,destination$max, @source.char,source.length,status$ptr); END move$string; END strng;