Changeset 11711 for trunk/psLib/src/sys/psString.c
- Timestamp:
- Feb 8, 2007, 12:27:30 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psString.c (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psString.c
r11686 r11711 13 13 * @author David Robbins, MHPCC 14 14 * 15 * @version $Revision: 1.5 1$ $Name: not supported by cvs2svn $16 * @date $Date: 2007-02-0 7 23:52:54$15 * @version $Revision: 1.52 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2007-02-08 22:27:30 $ 17 17 * 18 18 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 33 33 #include "psMemory.h" 34 34 35 36 35 static void stringFree(psString string) 37 36 { 38 // There is non dynamic allocated item 39 } 40 41 psString psStringAlloc(long nChar) 37 // this function is only nessicary so psMemCheckString has a function 38 // pointer address to test against 39 } 40 41 42 psString p_psStringAlloc(const char *file, 43 unsigned int lineno, 44 const char *func, 45 long nChar) 42 46 { 43 47 if (nChar < 1) { 44 48 return NULL; 45 49 } 46 psString string = psAlloc(nChar + 1); 50 51 psString string = p_psAlloc(file, lineno, func, nChar + 1); 47 52 psMemSetDeallocator(string, (psFreeFunc)stringFree); 53 48 54 return string; 49 55 } 50 56 57 51 58 bool psMemCheckString(psPtr ptr) 52 59 { 53 60 PS_ASSERT_PTR(ptr, false); 54 return ( psMemGetDeallocator(ptr) == (psFreeFunc)stringFree ); 55 } 56 57 psString psStringCopy(const char *string) 61 return (psMemGetDeallocator(ptr) == (psFreeFunc)stringFree); 62 } 63 64 65 psString p_psStringCopy(const char *file, 66 unsigned int lineno, 67 const char *func, 68 const char *string) 58 69 { 59 70 // Pass through NULL values! … … 61 72 return NULL; 62 73 } 63 psString output = psStringAlloc(strlen(string) + 1); // Output string 74 75 // Output string 76 psString output = p_psStringAlloc(file, lineno, func, strlen(string) + 1); 77 64 78 // Copy input string to memory just allocated 65 79 return strcpy(output, string); 66 80 } 67 81 68 psString psStringNCopy(const char *string, 69 unsigned int nChar) 82 83 psString p_psStringNCopy(const char *file, 84 unsigned int lineno, 85 const char *func, 86 const char *string, 87 unsigned int nChar) 70 88 { 71 89 PS_ASSERT_PTR_NON_NULL(string, NULL); … … 86 104 87 105 // Copy input string to memory allocated up to nChar characters 88 psString output = p sStringAlloc((size_t) nChar + 1);106 psString output = p_psStringAlloc(file, lineno, func, (size_t) nChar + 1); 89 107 output = strncpy(output, string, (size_t) nChar); 90 108 … … 96 114 } 97 115 98 ssize_t psStringAppend(char **dest, 99 const char *format, 100 ...) 116 117 ssize_t p_psStringAppend(const char *file, 118 unsigned int lineno, 119 const char *func, 120 char **dest, 121 const char *format, 122 ...) 101 123 { 102 124 PS_ASSERT_PTR_NON_NULL(dest, 0); … … 105 127 va_list ap; 106 128 va_start(ap, format); 107 ssize_t length = p sStringAppendV(dest, format, ap);129 ssize_t length = p_psStringAppendV(file, lineno, func, dest, format, ap); 108 130 va_end(ap); 109 131 … … 111 133 } 112 134 113 ssize_t psStringAppendV(char **dest, 114 const char *format, 115 va_list ap) 135 ssize_t p_psStringAppendV(const char *file, 136 unsigned int lineno, 137 const char *func, 138 char **dest, 139 const char *format, 140 va_list ap) 116 141 { 117 142 PS_ASSERT_PTR_NON_NULL(dest, 0); … … 144 169 // realloc string to string + tail + \0 145 170 if (*dest) { 146 *dest = p sRealloc(*dest, oldLength + tailLength + 1);171 *dest = p_psRealloc(file, lineno, func, *dest, oldLength + tailLength + 1); 147 172 } else { 148 *dest = p sStringAlloc(oldLength + tailLength + 1);173 *dest = p_psStringAlloc(file, lineno, func, oldLength + tailLength + 1); 149 174 } 150 175 … … 160 185 } 161 186 162 ssize_t psStringPrepend(char **dest, 163 const char *format, 164 ...) 187 188 ssize_t p_psStringPrepend(const char *file, 189 unsigned int lineno, 190 const char *func, 191 char **dest, 192 const char *format, 193 ...) 165 194 { 166 195 PS_ASSERT_PTR_NON_NULL(dest, 0); … … 169 198 va_list ap; 170 199 va_start(ap, format); 171 ssize_t length = p sStringPrependV(dest, format, ap);200 ssize_t length = p_psStringPrependV(file, lineno, func, dest, format, ap); 172 201 va_end(ap); 173 202 … … 175 204 } 176 205 177 ssize_t psStringPrependV(char **dest, 178 const char *format, 179 va_list ap) 206 207 ssize_t p_psStringPrependV(const char *file, 208 unsigned int lineno, 209 const char *func, 210 char **dest, 211 const char *format, 212 va_list ap) 180 213 { 181 214 PS_ASSERT_PTR_NON_NULL(dest, 0); … … 188 221 if (!*dest) { 189 222 // makes the string backup and concatination pointless 190 *dest = p sStringCopy("");223 *dest = p_psStringCopy(file, lineno, func, ""); 191 224 length = 0; 192 225 } else { … … 210 243 211 244 // backup original string 212 oldDest = p sStringCopy(*dest);245 oldDest = p_psStringCopy(file, lineno, func, *dest); 213 246 214 247 // new string length (sans \0) … … 216 249 217 250 // realloc string to head + string + \0 218 *dest = p sRealloc(*dest, length + 1);251 *dest = p_psRealloc(file, lineno, func, *dest, length + 1); 219 252 220 253 // copy the new head to the beginning of string … … 234 267 } 235 268 269 236 270 // split the string by the given splitters 237 271 // NULL input string returns empty (not NULL) list … … 276 310 return values; 277 311 } 312 278 313 279 314 // given the input string, search for all copies of the key, and replace with the replacement value … … 343 378 } 344 379 380 345 381 psArray *psStringSplitArray(const char *string, const char *splitters, bool multi) 346 382 { … … 352 388 } 353 389 390 354 391 #ifndef whitespace 355 392 #define whitespace(c) (((c) == ' ') || ((c) == '\t')) … … 376 413 return i; 377 414 } 415 416 378 417 /* 379 418 * Used by PS_FILE_LINE
Note:
See TracChangeset
for help on using the changeset viewer.
