1 /***********************************************************************/ 2 /* Open Visualization Data Explorer */ 3 /* (C) Copyright IBM Corp. 1989,1999 */ 4 /* ALL RIGHTS RESERVED */ 5 /* This code licensed under the */ 6 /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */ 7 /***********************************************************************/ 8 9 #include <dxconfig.h> 10 #include "../base/defines.h" 11 12 #ifndef _DXStrings_h 13 #define _DXStrings_h 14 15 #include <string.h> 16 17 #ifdef DXD_NEEDS_CTYPE_H 18 #include <ctype.h> //SMH to get isalpha prototype 19 #endif 20 21 #if defined(DXD_NON_UNIX_DIR_SEPARATOR) || defined(DXD_OS_NON_UNIX) 22 #define UNIX2DOSPATH(a) (Unix2DosPath(a)) 23 #define DOS2UNIXPATH(a) (Dos2UnixPath(a)) 24 #else 25 #define UNIX2DOSPATH(a) 26 #define DOS2UNIXPATH(a) 27 #endif 28 29 30 #ifdef NEEDS_STRRSTR 31 // 32 // Find the last occurence of s2 in s1. 33 // Returns a pointer to last occurence or NULL. 34 // 35 const char *strrstr(const char *s1, const char *s2); 36 #endif 37 38 // 39 // Compares two strings and returns TRUE if they are equal, FALSE otherwise. 40 // 41 #define EqualString(first, second) \ 42 (!STRCMP((first), (second))) 43 44 45 // 46 // Compares two substrings; returns TRUE if first n characters are equal, 47 // FALSE otherwise. 48 // 49 #define EqualSubstring(first, second, n) \ 50 (!STRNCMP((first), (second), (n))) 51 52 #ifdef NON_ANSI_SPRINTF 53 int _sprintf(char *s, const char* format, ...); 54 # define SPRINTF _sprintf 55 #else 56 # define SPRINTF sprintf 57 #endif 58 59 #define STRLEN(a) ((a != NULL) ? strlen(a) : 0) 60 61 # define STRCMP(a,b) ((a) ? ((b) ? strcmp(a,b) \ 62 : strcmp(a,"")) \ 63 : ((b) ? strcmp("",b) \ 64 : 0)) 65 66 # define STRNCMP(a,b,n) ((a) ? ((b) ? strncmp(a,b,n) \ 67 : strncmp(a,"",n)) \ 68 : ((b) ? strncmp("",b,n) \ 69 : 0)) 70 71 72 #ifdef NEEDS_STRERROR 73 extern 74 char *strerror(int errnum); 75 #endif 76 77 // 78 // Duplicates a given string. 79 // 80 extern 81 char* DuplicateString(const char* string); 82 83 // 84 // Returns TRUE if the entire string consists of blanks/tabs; FALSE, otherwise. 85 // 86 extern 87 boolean IsBlankString(const char* string); 88 89 extern 90 char* GetDirname(const char*); 91 92 extern 93 char* GetFileBaseName(const char* path, const char* extension); 94 95 extern 96 char* GetFullFilePath(const char*); 97 98 extern 99 char* FilterDottedPath(const char*); 100 101 // 102 // Find the first string in s that is delimited by the 'begin' and 'end' 103 // characters. 104 // Return NULL if none found otherwise a string that contains the begin and 105 // end characters. 106 // If buf is NULL a new strings is allocated and must be deleted by the caller. 107 // if buf is not NULL it must be large enough to hold the resulting string and 108 // on success contains the delimited string. 109 // If nest_chars is given as a string of nesting characters (i.e. '"'), then 110 // if the end delimiter is found within the nesting characters then don't 111 // accept it as a terminating delimiter. This is useful for finding 112 // '"{a} {b}"' within '{"{a} {b}"}'. 113 // 114 char *FindDelimitedString(const char *s, char begin, char end, 115 char *buf=NULL, const char *nest_chars = NULL); 116 117 // 118 // Convert all escaped characters (i.e. \n, \t, \r, \f, \b and \123) 119 // into a new string with the real characters. 120 // The returned string must be freed by the caller. 121 // 122 char *DeEscapeString(const char *str); 123 124 // 125 // Given a pathname or a filename, construct a unique filename in the given 126 // directory (filename implies directory of given file). If NULL is given, 127 // then construct a unique filename in the current director. 128 // The returned string must be freed by the caller. 129 // If a unique filename could not be created, NULL is returned. 130 // 131 char *UniqueFilename(const char *filename); 132 133 // 134 // Strip all the white space characters out of the given string. 135 // If the string contains all white space, then a zero-length string 136 // is returned. If the given string is NULL, NULL is returned. 137 // The returned string must be deleted by the caller. 138 // 139 char* StripWhiteSpace(const char* string); 140 void Dos2UnixPath(char *path); 141 void Unix2DosPath(char* path); 142 boolean unRename(const char *SrcFile, const char *DestFile); 143 144 #endif /* _DXStrings.h */ 145