9 ** This module defines some useful routines for maniputing strings.
12 #include <string.h> /* strlen() strncpy() */
13 #include <sys/types.h> /* size_t */
22 ** Replaces the characters in #string# with their lower- or upper-case
23 ** equivalents. #toWhatCase# specifies whether the result to be ENTIRELY
24 ** UPPER, entirely lower, iNITIAL lOWER, or Initial Upper.
26 typedef enum {ALL_LOWER, ALL_UPPER, INITIAL_LOWER, INITIAL_UPPER} CaseTypes;
29 CaseTypes toWhatCase);
33 ** Returns 1 or 0 depending on whether or not the first #len# characters of
34 ** #string# matches #pattern#, which may contain wildcard characters (*).
37 strnmatch(const char *string,
40 #define strmatch(string,pattern) strnmatch(string, pattern, strlen(string))
44 ** Copies a "token" -- a series of characters deliminated by one of the chars
45 ** in #delim# -- from #source# to the #len#-long string #dest#. Terminates
46 ** #dest# with a null character. Returns the position within #source# of the
47 ** character after the token in #end#. Skips any leading delimiters in
48 ** #source#. Returns 0 if the end of source is reached without finding any
49 ** non-delimiter characters, 1 otherwise.
57 #define GETTOK(dest,source,delim,end) strntok(dest,source,sizeof(dest),delim,end)
58 #define GETWORD(dest,source,end) GETTOK(dest,source," \t\n",end)
62 * Define strnlen in case there is no such a function in the library
63 * (sometimes there is not the definition in the include so we define it
67 strnlen(const char *s, size_t maxlen);
70 ** Calls strncpy() passing #dest#, #src#, and #len#, then places a terminating
71 ** character in the last (len - 1) byte of #dest#.
73 #define zstrncpy(dest,src,len) \
74 do {strncpy(dest, src, len); dest[len - 1] = '\0'; if (1) break;} while (0)
75 #define SAFESTRCPY(dest,src) zstrncpy(dest, src, sizeof(dest))
79 ** Catenates the #count#-long set of source strings into #dest#. Copies at
80 ** most #len# characters, including the null terminator.