-+-+-+-+-+-+-+-+ START OF PART 6 -+-+-+-+-+-+-+-+ X/* # D E F I N E S V */ X/* V `20 V */ X/*************************************************************************** V***/ X X/*************************************************************************** V***/ X/* V `20 V */ X/* S T R U C T U R E S , U N I O N S , T Y P E D E F S V */ X/* V `20 V */ X/*************************************************************************** V***/ X X/*************************************************************************** V***/ X/* V `20 V */ X/* E X T E R N A L D E F I N I T I O N S & D E C L A R A T I O N S V */ X/* V `20 V */ X/*************************************************************************** V***/ X X`09 char`09 *cat(), X`09`09 *str_pref_trim(), X`09`09 *str_post_trim(), X`09`09 *strmcpy(); X X`09 int`09 strins(); X X`09 void`09 strlu(); X X/*************************************************************************** V***/ X/* V `20 V */ X/* S T A T I C D E F I N I T I O N S & D E C L A R A T I O N S V */ X/* V `20 V */ X/*************************************************************************** V***/ X`0C X/*************************************************************************** V**** X**************************************************************************** V**** X X Function:`09cat X X Purpose:`09This general-purpose subroutine will concatenate null- X`09`09terminated strings into one destination string. X X Formal Parameters: X X`09Name`09`09`09Description X`09----`09`09`09----------- X`09dest`09`09`09where new string is created X`09source1,...sourcen`09input strings X X Global variables: X X`09Name`09`09`09Examine/Modify/Use/Read/Write X`09----`09`09`09----------------------------- X`09none X X Return Codes: X X`09Code`09`09`09Reason X`09----`09`09`09------ X`09retval`09`09`09pointer to destination string X`09nullptr`09`09`09null string pointer; returned when X`09`09`09`09no arguments are passed X X**************************************************************************** V**** X**************************************************************************** V***/ X Xchar *cat(va_alist) X`09`09`09`09`09/******* FORMAL PARAMETERS *******/ X`09 va_dcl`09`09`09`09/* variable-length parameter list */ X X`7B`09/*** cat ***/ X`09`09`09`09`09/******** LOCAL VARIABLES ********/ Xregister char`09 *dest,`09`09/* pointer to destination string */ X`09`09 *source;`09`09/* pointer to current source string */ X`09 char`09 *retval;`09`09/* to save pointer to destination */ Xregister int`09 count;`09`09/* number of arguments passed`09 */ X`09 va_list incrmtr;`09`09/* argument list incrementor`09 */ Xstatic`09 char`09 *nullptr = "";`09/* null string pointer`09`09 */ X X X va_start(incrmtr);`09`09`09/* begin everything....`09`09 */ X X va_count(count);`09`09`09/* get number of arguments`09 */ X X if(count == 0)`09`09`09/* were any arguments specified? */ X return(nullptr);`09`09`09/* nope, get out of here...`09 */ X X dest = va_arg(incrmtr,char*);`09/* get the destination pointer`09 */ X retval = dest;`09`09`09/* save pointer to destination`09 */ X X source = va_arg(incrmtr,char*);`09/* get the first source pointer`09 V */ X X while(--count > 0)`09`09`09/* process all of the source strings */ X `7B X while(*dest++ = *source++)`09/* cat the source to the destination */ X`09 ; X X dest--;`09`09`09`09/* back over the null character`09 */ X source = va_arg(incrmtr,char*);`09/* get the next argument`09 */ X `7D X X *dest = '\0';`09`09`09/* terminate the destination`09 */ X va_end(incrmtr);`09`09`09/* end varargs session`09`09 */ X X return(retval);`09`09`09/* return pointer to destination */ X X`7D`09/*** cat ***/ X`0C X/*************************************************************************** V**** X**************************************************************************** V**** X X Function:`09strins X X Purpose:`09Insert a character string into another at a specified X`09`09position. X X Formal Parameters: X X`09Name`09`09`09Description X`09----`09`09`09----------- X`09str`09`09`09string to be updated; should be large X`09`09`09`09enough to accomodate the new string X`09new`09`09`09string to be inserted X`09position`09`09place to insert new into str X X Global variables: X X`09Name`09`09`09Examine/Modify/Use/Read/Write X`09----`09`09`09----------------------------- X`09none X X Return Codes: X X`09Code`09`09`09Reason X`09----`09`09`09------ X`09 0`09`09`09string insert successful X`09 -1`09`09`09unable to insert string because position X`09`09`09`09points outside of str X X**************************************************************************** V**** X**************************************************************************** V***/ X Xint strins(str,new,position) X Xregister char`09 *str, X`09`09 *new; Xregister int`09 position; X X`7B`09/*** strins ***/ X`09`09`09`09`09/******** LOCAL VARIABLES ********/ Xregister int`09 i,`09`09`09/* loop and array index`09`09 */ X`09`09 j;`09`09`09/* temporary variable`09`09 */ X`09 int`09 new_len,`09`09/* length of string to insert`09 */ X`09`09 str_len;`09`09/* length of str`09`09 */ X X X str_len = strlen(str);`09`09/* get length of current str`09 */ X X if((position > str_len) `7C`7C (position < 0)) X i = -1; X else X `7B X new_len = strlen(new);`09`09/* get length of string to insert */ X i = new_len + str_len - 1;`09/* get where to start when we shift */ X *(str+i+1) = '\0'; `09`09/* terminate it first `09`09 */ X j = str_len - 1;`09`09`09/* point to last char of str`09 */ X X /* now shift everything over to make room for the new string */ X X while(j >= position) X `7B X`09 *(str+i) = *(str+j); X`09 --i; X`09 --j; X `7D X X /* now add the new string in the right slot */ X X for(i = 0,j = position; *(new+i) != '\0'; i++,j++) X *(str+j) = *(new+i); `20 X X i = 0; X `7D X X return(i); X X`7D`09/*** strins ***/ `20 X`0C X/*************************************************************************** V**** X**************************************************************************** V**** X X Function:`09strlu X X Purpose:`09Convert all lower-case characters in a string to upper-case. X X Formal Parameters: X X`09Name`09`09`09Description X`09----`09`09`09----------- X`09source`09`09`09source string to be converted X X Global variables: X X`09Name`09`09`09Examine/Modify/Use/Read/Write X`09----`09`09`09----------------------------- X`09none X X Return Codes: X X`09Code`09`09`09Reason X`09----`09`09`09------ X`09none X X**************************************************************************** V**** X**************************************************************************** V***/ X Xvoid strlu(source) X Xregister char`09 *source; X X`7B`09/*** strlu ***/ X X while(*source) X `7B X *source = _toupper(*source); X source++; X `7D X X return; X X`7D`09/*** strlu ***/ X`0C X/*************************************************************************** V**** X**************************************************************************** V**** X X Function:`09strmcpy X X Purpose:`09Copy at most m characters into the target string. The X`09`09resultant string is guaranteed to be null-terminated. X`09`09This provides an alternative to strncpy() which does not X`09`09guarantee that strings are null-terminated. X X Formal Parameters: X X`09Name`09`09`09Description X`09----`09`09`09----------- X`09dest`09`09`09where new string is written X`09source`09`09`09source for copy X`09max`09`09`09maximum number of bytes to copy X X Global variables: X X`09Name`09`09`09Examine/Modify/Use/Read/Write X`09----`09`09`09----------------------------- X`09none X X Return Codes: X X`09Code`09`09`09Reason X`09----`09`09`09------ X`09none X X**************************************************************************** V**** X**************************************************************************** V***/ X Xchar *strmcpy(dest,source,max) Xregister char`09 *dest, X`09`09 *source; Xregister int`09 max; X X`7B`09/*** strmcpy ***/ X`09`09`09`09`09/******** LOCAL VARIABLES ********/ Xregister int`09 i;`09`09`09/* loop and array index`09`09 */ X X for(i = 0;i < max && *(source+i); i++) X *(dest+i) = *(source+i); X X *(dest+i) = '\0';`09`09`09/* terminate the destination string */ X X return(dest); X X`7D`09/*** strmcpy ***/ X`0C X/*************************************************************************** V**** X**************************************************************************** V**** X X Function:`09str_pref_trim X X Purpose:`09Strip out leading whitespace from a string X X Formal Parameters: X X`09Name`09`09`09Description X`09----`09`09`09----------- X`09str`09`09`09string to be stripped X X Global variables: X X`09Name`09`09`09Examine/Modify/Use/Read/Write X`09----`09`09`09----------------------------- X`09none X X Return Codes: X X`09Code`09`09`09Reason X`09----`09`09`09------ X`09str X X**************************************************************************** V**** X**************************************************************************** V***/ X Xchar *str_pref_trim(str) X`09`09`09`09`09/******* FORMAL PARAMETERS *******/ Xregister char`09 *str;`09`09`09/* string to be trim`09`09 */ X X`7B`09/*** str_pref_trim ***/ X`09`09`09`09`09/******** LOCAL VARIABLES ********/ Xregister char`09 *ptr;`09`09`09/* temporary pointer`09`09 */ X X X ptr = str; X X while(isspace(*ptr))`09`09`09/* skip the leading whitespace first */ X ++ptr; X X while(*ptr) X *ptr++ = *str++; X X *str = '\0';`09`09`09`09/* make sure it's a string`09 */ X return(str); X X`7D`09/*** str_pref_trim ***/ X`0C X/*************************************************************************** V**** X**************************************************************************** V**** X X Function:`09str_post_trim X X Purpose:`09Strip out trailing whitespace from a string X X Formal Parameters: X X`09Name`09`09`09Description X`09----`09`09`09----------- X`09str`09`09`09string to be stripped X X Global variables: X X`09Name`09`09`09Examine/Modify/Use/Read/Write X`09----`09`09`09----------------------------- X`09none X X Return Codes: X X`09Code`09`09`09Reason X`09----`09`09`09------ X`09str X X**************************************************************************** V**** X**************************************************************************** V***/ X Xchar *str_post_trim(str) X`09`09`09`09`09/******* FORMAL PARAMETERS *******/ Xregister char`09 *str;`09`09`09/* string to be trim`09`09 */ X X`7B`09/*** str_post_trim ***/ X`09`09`09`09`09/******** LOCAL VARIABLES ********/ Xregister char`09 *ptr;`09`09`09/* temporary pointer`09`09 */ X X X ptr = &str`5Bstrlen(str) - 1`5D; X X while(isspace(*ptr))`09`09`09/* find first non-whitespace char */ X --ptr; X X *(ptr + 1) = '\0';`09`09`09/* chop off the whitespace characters */ X return(str); X X`7D`09/*** str_post_trim ***/ X $ CALL UNPACK SUBS.C;1 2015128443 $ v=f$verify(v) $ EXIT