#include #include "util.h" #include "var_set.h" /**AutomaticStart*************************************************************/ /*---------------------------------------------------------------------------*/ /* Static function prototypes */ /*---------------------------------------------------------------------------*/ /**AutomaticEnd***************************************************************/ /* * util_strsav -- save a copy of a string */ char * util_strsav(s) char *s; { if(s == NIL(char)) { /* added 7/95, for robustness */ return s; } else { return strcpy(ALLOC(char, strlen(s)+1), s); } } /* * util_strcat5 -- Creates a new string which is the concatenation of 5 * strings. It is the responsibility of the caller to free this string * using FREE. */ char * util_strcat5( char * str1, char * str2, char * str3, char * str4, char * str5 ) { char *str = ALLOC(char, strlen(str1) + strlen(str2) + strlen(str3) + strlen(str4) + strlen(str5) + 1); (void) strcpy(str, str1); (void) strcat(str, str2); (void) strcat(str, str3); (void) strcat(str, str4); (void) strcat(str, str5); return (str); } /* * util_strcat3 -- Creates a new string which is the concatenation of 3 * strings. It is the responsibility of the caller to free this string * using FREE. */ char * util_strcat3( char * str1, char * str2, char * str3) { char *str = ALLOC(char, strlen(str1) + strlen(str2) + strlen(str3) + 1); (void) strcpy(str, str1); (void) strcat(str, str2); (void) strcat(str, str3); return (str); } /* * util_strcat -- Creates a new string which is the concatenation of 2 * strings. It is the responsibility of the caller to free this string * using FREE. */ char * util_strcat( char * str1, char * str2) { char *str = ALLOC(char, strlen(str1) + strlen(str2) + 1); (void) strcpy(str, str1); (void) strcat(str, str2); return (str); } /* check for the first occurance of needle in haystack - return index of match, -1 if no match */ int strstrN( char *haystack, char *needle, int haystackLength ) { int needleLength = strlen( needle ); int i; for ( i = 0 ; i < haystackLength - needleLength ; i++ ) { if ( strncmp( haystack + i , needle, needleLength ) == 0 ) { return i; } } return -1; } // return 1 if strings are equal in first N places, 0 otherwise int util_strequalN( char *a, char *b, int N ) { int i; for ( i = 0 ; i < N; i++ ) { if ( a[i] != b[i] ) { return 0; } } return 1; } // return 1 if strings are equal, 0 otherwise int util_strequal( char *a, char *b ) { if ( !strcmp( a, b ) ) { return 1; } else { return 0; } } char * util_strchr_N( char *a, char searchChar, int N ) { char *foo = a; assert( N > 0 ); int i; char *tmp; for ( i = 0 ; i < N ; i++ ) { tmp = strchr( foo, searchChar ); if ( !tmp ) { return tmp; } foo = tmp+1; } return tmp; }