Index: /trunk/psLib/src/sys/psString.c
===================================================================
--- /trunk/psLib/src/sys/psString.c	(revision 10445)
+++ /trunk/psLib/src/sys/psString.c	(revision 10446)
@@ -13,6 +13,6 @@
  *  @author David Robbins, MHPCC
  *
- *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-11-29 21:33:09 $
+ *  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-12-04 22:15:04 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -275,19 +275,21 @@
 // given the input string, search for all copies of the key, and replace with the replacement value
 // the input string may be freed if not needed
-psString psStringSubstitute(psString input,
-                            const char *replace,
-                            const char *key)
-{
+ssize_t psStringSubstitute(psString *input,
+                           const char *replace,
+                           const char *key)
+{
+    PS_ASSERT_PTR_NON_NULL(input, 0);
+
     // Empty input gives empty output
-    if (!input || strlen(input) == 0) {
-        return input;
+    if (!*input || strlen(*input) == 0) {
+        return 0;
     }
     // No key gives the same as the input
     if (!key || strlen(key) == 0) {
-        return input;
-    }
-    if (!psMemCheckString(input)) {
+        return strlen(*input);
+    }
+    if (!psMemCheckString(*input)) {
         psError(PS_ERR_BAD_PARAMETER_TYPE, true, "This function requires a psString as input.\n");
-        return NULL;
+        return 0;
     }
 
@@ -302,9 +304,9 @@
     }
 
-    char *search = input;               // Search this string
+    char *search = *input;              // Search this string
     while (true) {
         char *found = strstr(search, key); // Found occurence of the key
         if (!found) {
-            return input;
+            return strlen(*input);
         }
 
@@ -313,9 +315,9 @@
 
         // this is safe since we will subtract strlen(key) elements from input
-        psString output = psStringAlloc(strlen(input) + replaceLength + 1); // Output string
-        int numChar = found - input;    // Number of characters to copy
+        psString output = psStringAlloc(strlen(*input) + replaceLength + 1); // Output string
+        int numChar = found - *input;    // Number of characters to copy
 
         // copy the first segement into 'output'
-        strncpy(output, input, numChar);
+        strncpy(output, *input, numChar);
 
         // copy the key replacement to the start of the key
@@ -328,11 +330,11 @@
         strcpy(output + numChar, found + strlen(key));
 
-        psFree(input);
-        input = output;
+        psFree(*input);
+        *input = output;
         search = output + numChar;
     }
 
     psAbort(__func__, "Should never get here.\n");
-    return NULL;
+    return 0;
 }
 
Index: /trunk/psLib/src/sys/psString.h
===================================================================
--- /trunk/psLib/src/sys/psString.h	(revision 10445)
+++ /trunk/psLib/src/sys/psString.h	(revision 10446)
@@ -14,6 +14,6 @@
  *  @author David Robbins, MHPCC
  *
- *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-11-29 21:33:09 $
+ *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-12-04 22:15:04 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -191,8 +191,8 @@
  *  the replacement value wherever found.  The input string may be freed if not needed.
  *
- *  @return char*:      the modified input string.
- */
-psString psStringSubstitute (
-    psString input,                     ///< input string to be modified
+ *  @return ssize_t:      the length of the new string (excluding '\0')
+ */
+ssize_t psStringSubstitute (
+    psString *input,                    ///< ptr to input string to be modified
     const char *replace,                ///< replacement value
     const char *key                     ///< string to be replaced in input
Index: /trunk/psLib/test/sys/tap_psStringSubstitute.c
===================================================================
--- /trunk/psLib/test/sys/tap_psStringSubstitute.c	(revision 10445)
+++ /trunk/psLib/test/sys/tap_psStringSubstitute.c	(revision 10446)
@@ -18,5 +18,5 @@
     {
         psString input = psStringCopy(ORIGINAL);
-        input = psStringSubstitute(input, ",", NULL);
+        psStringSubstitute(&input, ",", NULL);
         ok(input && strcmp(input, ORIGINAL) == 0, "output = %s", input);
         psFree(input);
@@ -28,5 +28,5 @@
     {
         psString input = psStringCopy(ORIGINAL);
-        input = psStringSubstitute(input, "XXX", "");
+        psStringSubstitute(&input, "XXX", "");
         ok(input && strcmp(input, ORIGINAL) == 0, "output = %s", input);
         psFree(input);
@@ -38,7 +38,7 @@
     {
         psString input = psStringCopy(ORIGINAL);
-        psString output = psStringSubstitute(input, NULL, ",");
-        ok(output && strcmp(output, CORRECTED) == 0, "output = %s", output);
-        psFree(output);
+        psStringSubstitute(&input, NULL, ",");
+        ok(input && strcmp(input, CORRECTED) == 0, "output = %s", input);
+        psFree(input);
         mem();
     }
@@ -47,7 +47,7 @@
     {
         psString input = psStringCopy(ORIGINAL);
-        psString output = psStringSubstitute(input, "", ",");
-        ok(output && strcmp(output, CORRECTED) == 0, "output = %s", output);
-        psFree(output);
+        psStringSubstitute(&input, "", ",");
+        ok(input && strcmp(input, CORRECTED) == 0, "output = %s", input);
+        psFree(input);
         mem();
     }
@@ -55,6 +55,6 @@
     // Return NULL for NULL input
     {
-        psString output = psStringSubstitute(NULL, "XXX", ",");
-        ok(!output, "output = %s", output);
+        int status = psStringSubstitute(NULL, "XXX", ",");
+        ok(status == 0, "status = %d", status);
         mem();
     }
@@ -63,7 +63,7 @@
     {
         psString input = psStringCopy("");
-        psString output = psStringSubstitute(input, "XXX", ",");
-        ok(output && strcmp(output, input) == 0, "output = %s", output);
-        psFree(output);
+        psStringSubstitute(&input, "XXX", ",");
+        ok(input && strcmp(input, "") == 0, "output = %s", input);
+        psFree(input);
         mem();
     }
@@ -72,7 +72,7 @@
     {
         psString input = psStringCopy(ORIGINAL);
-        psString output = psStringSubstitute(input, "!", ",");
-        ok(output && strcmp(output, "This is! a! test case! to check.") == 0, "output = %s", output);
-        psFree(output);
+        psStringSubstitute(&input, "!", ",");
+        ok(input && strcmp(input, "This is! a! test case! to check.") == 0, "output = %s", input);
+        psFree(input);
         mem();
     }
@@ -81,9 +81,9 @@
     {
         psString input = psStringCopy(ORIGINAL);
-        psString output = psStringSubstitute(input, "; This string is too long to fit in input(35 chars)", ".");
-        ok(output && strcmp(output, "This is, a, test case, to check; "
-                            "This string is too long to fit in input(35 chars)") == 0,
-           "output = %s", output);
-        psFree(output);
+        psStringSubstitute(&input, "; This string is too long to fit in input(35 chars)", ".");
+        ok(input && strcmp(input, "This is, a, test case, to check; "
+                           "This string is too long to fit in input(35 chars)") == 0,
+           "output = %s", input);
+        psFree(input);
         mem();
     }
