Index: /trunk/psLib/src/sys/psTrace.c
===================================================================
--- /trunk/psLib/src/sys/psTrace.c	(revision 8440)
+++ /trunk/psLib/src/sys/psTrace.c	(revision 8441)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.69 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-08-18 02:24:13 $
+ *  @version $Revision: 1.70 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-08-21 22:11:39 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -38,12 +38,4 @@
  *****************************************************************************/
 
-
-// NOTE: We want to avoid using the psString functions, or any function that calls the PS memory management,
-// since there seems to be a problem with memory fragmentation.  Since psTrace can get called a LOT, it
-// manifests this problem.  To get around this, we will use variable length char arrays, instead of the
-// psString functions.  This can be revised once the PS memory management system is fixed.
-#define USE_PS_MEMORY 0
-
-
 #ifndef PS_NO_TRACE
 
@@ -61,4 +53,6 @@
 #include "psLogMsg.h"
 
+#define MAX_HOSTNAME_LENGTH 256
+#define MAX_HEADER_LENGTH 256
 
 
@@ -414,21 +408,9 @@
     // If the component name has no leading dot, then supply it.
     if (name[0] != '.') {
-        #if USE_PS_MEMORY
-        psString compName = (char *) psAlloc(10 + strlen(name));
-        strcpy(compName, ".");
-        compName = strcat(compName, name);
-        #else
-
         char compName[strlen(name) + 2];
         compName[0] = '.';
         strcpy(&compName[1], name);
-        #endif
 
         traceLevel = doGetTraceLevel(compName);
-        #if USE_PS_MEMORY
-
-        psFree(compName);
-        #endif
-
     } else {
         // Search the component root tree, determine the trace level.
@@ -520,46 +502,41 @@
               va_list ap)
 {
-    // char *fmt = NULL;
-    //    va_list ap;
-    static psS32 first = 1;       // Flag for calling gethostname()
-    static char hostname[256 + 1];
-    char clevel = 0;            // letter-name for level
-    psS32 i = 0;
-    char head[256 + 2]; // the added two are for the ending | and \0
-    char *head_ptr = head;      // where we've got to in head
-    psS32 maxLength = 256;
-    time_t clock = time(NULL);  // The current time.
-    struct tm *utc = gmtime(&clock);    // The current gm time.
+    PS_ASSERT_PTR_NON_NULL(comp, );
+    PS_ASSERT_PTR_NON_NULL(format, );
 
     // XXX EAM : fd < 1 does not print messages
-    if (traceFD < 1)
+    if (traceFD < 1) {
         return;
-
-    if (NULL == comp) {
-        psError(PS_ERR_BAD_PARAMETER_NULL, true,
-                _("Function %s called on a NULL trace level tree."),
-                __func__);
-        return;
-    }
-
+    }
+
+    static bool first = true;           // First time we've been called?
+    static char hostname[MAX_HOSTNAME_LENGTH + 1]; // Host name
     if (first) {
-        first = 0;
+        first = false;
         gethostname(hostname, 256);
     }
 
-    if (level == PS_LOG_ABORT) {
+    char clevel = 0;                    // letter-name for level
+    switch (level) {
+    case PS_LOG_ABORT:
         clevel = 'A';
-    } else if (level == PS_LOG_ERROR) {
+        break;
+    case PS_LOG_ERROR:
         clevel = 'E';
-    } else if (level == PS_LOG_WARN) {
+        break;
+    case PS_LOG_WARN:
         clevel = 'W';
-    } else if (level == PS_LOG_INFO) {
+        break;
+    case PS_LOG_INFO:
         clevel = 'I';
-    } else if (level >= 4) {
-        clevel = level + '0';
-    } else {
-        psTrace("psLib.sys", 2, "Invalid logMsg level: %d (%s)\n", level, format);
-        level = (level < 0) ? 0 : 9;
-        clevel = level + '0';
+        break;
+    default:
+        if (level >= 4) {
+            clevel = level + '0';
+        } else {
+            psTrace("psLib.sys", 2, "Invalid logMsg level: %d (%s)\n", level, format);
+            level = (level < 0) ? 0 : 9;
+            clevel = level + '0';
+        }
     }
 
@@ -567,8 +544,12 @@
     // of it's associatedcomponent.
     if (level <= psTraceGetLevel(comp)) {
-        //        va_start(ap, format);
+        int maxLength = MAX_HEADER_LENGTH; // Maximum length of header string
+        char head[maxLength + 2];       // the added two are for the ending | and \0
+        char *head_ptr = head;          // where we've got to in head
 
         // Create the various log fields...
         if (traceTime) {
+            time_t clock = time(NULL);  // The current time.
+            struct tm *utc = gmtime(&clock);    // The current gm time.
             maxLength -= snprintf(head_ptr, maxLength, "%4d:%02d:%02d %02d:%02d:%02dZ",
                                   utc->tm_year + 1900, utc->tm_mon + 1, utc->tm_mday,
@@ -607,16 +588,11 @@
         *head_ptr = '\0';
 
-        write (traceFD, head, strlen(head));
+        write(traceFD, head, strlen(head));
 
         if (traceMsg) {
             char line[1024];
 
-            // The following functions get the variable list of parameters with
-            // which this function was called, and print them to the standard
-            // output.
-            // fmt = va_arg(ap, char *);
-
             // We indent each message one space for each level of the message.
-            for (i = 0; i < level; i++) {
+            for (int i = 0; i < level; i++) {
                 write (traceFD, " ", 1);
             }
@@ -630,7 +606,6 @@
         }
 
-
-    }
-
+        // XXX: what is fd-appropriate equivalent of fflush?
+    }
 }
 
@@ -665,14 +640,6 @@
 
     // XXX file & lineo are currently unused
-    va_list ap;
-    va_start(ap, format);
-    //    format = va_arg(ap, char *);
-
-    #if USE_PS_MEMORY
-
-    psString fullFacil = NULL;
-    psStringAppend(&fullFacil, "%s.%s", facil, func);
-    #else
-
+
+    // Append the function name to the facility
     size_t facilLength = strlen(facil); // Length of facility name
     size_t funcLength = strlen(func);   // Length of function name
@@ -681,15 +648,9 @@
     fullFacil[facilLength] = '.';
     strcpy(&fullFacil[facilLength + 1], func);
-    #endif
-
+
+    va_list ap;
+    va_start(ap, format);
     psTraceV(fullFacil, level, format, ap);
-    #if USE_PS_MEMORY
-
-    psFree(fullFacil);
-    #endif
-
     va_end(ap);
-    // fflush(traceFP);
-    // XXX EAM : what is fd-appropriate equivalent?
 }
 
