Index: trunk/psLib/src/sysUtils/psTrace.c
===================================================================
--- trunk/psLib/src/sysUtils/psTrace.c	(revision 1713)
+++ trunk/psLib/src/sysUtils/psTrace.c	(revision 1718)
@@ -9,6 +9,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-08 00:09:06 $
+ *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-08 05:59:41 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -27,4 +27,12 @@
  not the same thing as a node's "level", which corresponds to the
  trace level of that node.
+ 
+I think the following is the correct behavior, but not sure:
+    PS_UNKNOWN_TRACE_LEVEL: We never set the level of a component to this
+    value.  This value is only used when psTraceGetLevel is called with
+    a bad component name, or if the component root is undefined, I think.
+ 
+    PS_DEFAULT_TRACE_LEVEL: This should only be used when adding the
+    intermediate components of a long name.  Ie. the "B" in .A.B.C
  
  *****************************************************************************/
@@ -40,8 +48,5 @@
 #include "psString.h"
 #include "psError.h"
-#include "psLogMsg.h"
-
-#include "psSysUtilsErrors.h"
-#define ERRORNAME_PREFIX PS_ERRORNAME_DOMAIN ".psTrace."
+#include "psAbort.h"
 
 static p_psComponent* cRoot = NULL; // The root of the trace component
@@ -98,4 +103,6 @@
 /*****************************************************************************
 Set all trace levels to zero.
+ 
+XXX: Currently, no function calls this routine.
  *****************************************************************************/
 void p_psTraceReset(p_psComponent* currentNode)
@@ -110,7 +117,6 @@
     for (i = 0; i < currentNode->n; i++) {
         if (NULL == currentNode->subcomp[i]) {
-            psLogMsg(ERRORNAME_PREFIX "p_psTraceReset", PS_LOG_WARN,
-                     PS_ERRORTEXT_psTrace_NULL_SUBCOMPONENT,
-                     i, currentNode->name);
+            psError(__func__,
+                    "Sub-component %d of node %s in the trace tree is NULL.\n", i, currentNode->name);
         } else {
             p_psTraceReset(currentNode->subcomp[i]);
@@ -125,5 +131,5 @@
 void psTraceReset()
 {
-    psFree(cRoot);
+    componentFree(cRoot);
     cRoot = NULL;
 }
@@ -135,5 +141,5 @@
 to ANSI-C.
  *****************************************************************************/
-static bool componentAdd(const char *addNodeName, int level)
+static void componentAdd(const char *addNodeName, int level)
 {
     int i = 0;                  // Loop index variable.
@@ -146,7 +152,5 @@
     // XXX: Verify that this is the correct behavior.
     if (strcmp("", addNodeName) == 0) {
-        psErrorMsg(ERRORNAME_PREFIX "componentAdd",PS_ERR_BAD_PARAMETER_NULL,true,
-                   PS_ERRORTEXT_psTrace_ADD_NULL_COMPONENT);
-        return false;
+        psAbort(__func__, "Failed to add null component to trace tree.\n");
     }
 
@@ -154,12 +158,10 @@
     if (strcmp(".", addNodeName) == 0) {
         cRoot->level = level;
-        return true;
+        return;
     }
 
     if (addNodeName[0] != '.') {
-        psErrorMsg(ERRORNAME_PREFIX "componentAdd",PS_ERR_BAD_PARAMETER_VALUE,true,
-                   PS_ERRORTEXT_psTrace_MALFORMED_COMPONENT_NAME,
-                   addNodeName);
-        return false;
+        printf("ERROR: failed to add %s to the root component tree.\n", addNodeName);
+        exit(1);
     }
 
@@ -186,16 +188,21 @@
             currentNode->subcomp = psRealloc(currentNode->subcomp,
                                              (currentNode->n + 1) * sizeof(p_psComponent* ));
-            currentNode->n++;
+            currentNode->n = (currentNode->n) + 1;
 
             if (pname == NULL) {
-                currentNode->subcomp[currentNode->n - 1] = componentAlloc(firstComponent, level);
+                // This is the final component to add.
+                currentNode->subcomp[(currentNode->n) - 1] = componentAlloc(firstComponent, level);
             } else {
-                currentNode->subcomp[currentNode->n - 1] = componentAlloc(firstComponent, currentNode->level);
-            }
-            currentNode = currentNode->subcomp[currentNode->n - 1];
-        }
-    }
-
-    return true;
+                // We are adding an intermediate component.  The trace level
+                // is not defined.  An undefined trace level inherits the
+                // trace level of it's parent.  However, we do not set that
+                // specifically here since that would inheritance to be a
+                // static, one-time, type of behavior.
+
+                currentNode->subcomp[(currentNode->n) - 1] = componentAlloc(firstComponent, PS_DEFAULT_TRACE_LEVEL);
+            }
+            currentNode = currentNode->subcomp[(currentNode->n) - 1];
+        }
+    }
 }
 
@@ -211,6 +218,6 @@
  zero
 *****************************************************************************/
-bool psTraceSetLevel(const char *comp,   // component of interest
-                     int level)  // desired trace level
+int psTraceSetLevel(const char *comp,   // component of interest
+                    int level)  // desired trace level
 {
     // If the root component tree does not exist, then initialize it.
@@ -219,11 +226,8 @@
     }
     // Add the new component to the component tree.
-    if ( !componentAdd(comp, level) ) {
-        psErrorMsg(ERRORNAME_PREFIX "psTraceSetLevel", PS_ERR_UNKNOWN, false,
-                   PS_ERRORTEXT_psTrace_FAILED_TO_ADD_COMPONENT,level,comp);
-        return false;
-    }
+    componentAdd(comp, level);
+
     // return 0 on success.
-    return true;
+    return 0;
 }
 
@@ -249,4 +253,5 @@
     p_psComponent* currentNode = cRoot;
     int i = 0;
+    int defaultLevel = 0;
 
     if (NULL == currentNode) {
@@ -262,4 +267,5 @@
     }
 
+    defaultLevel = cRoot->level;
     strcpy(name, aname);
     pname = &name[1];
@@ -268,22 +274,31 @@
         for (i = 0; i < currentNode->n; i++) {
             if (NULL == currentNode->subcomp[i]) {
-                psLogMsg(ERRORNAME_PREFIX "p_psTraceReset", PS_LOG_WARN,
-                         PS_ERRORTEXT_psTrace_NULL_SUBCOMPONENT,
-                         i, currentNode->name);
+                psError(__func__,
+                        "Sub-component %d of node %s in trace tree is NULL.\n", i, currentNode->name);
             }
 
             if (strcmp(currentNode->subcomp[i]->name, firstComponent) == 0) {
                 currentNode = currentNode->subcomp[i];
+                // For level inheritance purpose, we save the level of this
+                // component if it is not DEFAULT.
+                if (currentNode->level != PS_DEFAULT_TRACE_LEVEL) {
+                    defaultLevel = currentNode->level;
+                }
+                // Determine if thisis the last component:
                 if (pname == NULL) {
-                    return (currentNode->level);
+                    if (currentNode->level != PS_DEFAULT_TRACE_LEVEL) {
+                        return (currentNode->level);
+                    } else {
+                        return(PS_DEFAULT_TRACE_LEVEL);
+                    }
                 }
             }
         }
     }
-    return (PS_UNKNOWN_TRACE_LEVEL);
-}
-
-/*****************************************************************************
-    psGetTraceLevel()
+    return(defaultLevel);
+}
+
+/*****************************************************************************
+    psTraceLevelGet()
  Return a trace level of "name" in the root component tree.  If the
  exact string of components in "name" does not exist in the root
@@ -303,4 +318,37 @@
     // Search the component root tree, determine the trace level.
     return (doGetTraceLevel(name));
+}
+
+/*****************************************************************************
+    doPrintTraceLevelsOld()
+ This function recursively searches the component tree supplied by the
+ parameter "comp" and prints the name and level of each component.
+    Inputs:
+ comp: a node in the component tree.
+ level: the level of that node
+    Outputs:
+ none
+    Returns:
+ null
+ *****************************************************************************/
+static void doPrintTraceLevelsOld(const p_psComponent* comp, int depth)
+{
+    int i = 0;
+
+    if (comp->name[0] == '\0') {
+        printf("%*s%-*s %d\n", depth, "", 20 - depth,
+               "(root)", (comp->level == PS_DEFAULT_TRACE_LEVEL) ? 0 : comp->level);
+    } else {
+        if (comp->level == PS_DEFAULT_TRACE_LEVEL) {
+            printf("%*s%-*s %s\n", depth, "", 20 - depth, comp->name, ".");
+        } else {
+            printf("%*s%-*s %d\n", depth, "", 20 - depth, comp->name,
+                   comp->level);
+        }
+    }
+
+    for (i = 0; i < comp->n; i++) {
+        doPrintTraceLevelsOld(comp->subcomp[i], depth + 1);
+    }
 }
 
@@ -317,23 +365,31 @@
  null
  *****************************************************************************/
-static void doPrintTraceLevels(const p_psComponent* comp, int depth)
+static void doPrintTraceLevels(const p_psComponent* comp,
+                               int depth,
+                               int defLevel)
 {
     int i = 0;
 
     if (comp->name[0] == '\0') {
-        printf("%*s%-*s %d\n", depth, "", 20 - depth,
-               "(root)", (comp->level == PS_UNKNOWN_TRACE_LEVEL) ? 0 : comp->level);
+        psAbort(__func__, "component name is NULL\n");
     } else {
-        if (comp->level == PS_UNKNOWN_TRACE_LEVEL) {
-            printf("%*s%-*s %s\n", depth, "", 20 - depth, comp->name, ".");
+        if (comp->level == PS_DEFAULT_TRACE_LEVEL) {
+            printf("%*s%-*s %d\n", depth, "", 20 - depth, comp->name,
+                   defLevel);
         } else {
-            printf("%*s%-*s %d\n", depth, "", 20 - depth, comp->name, comp->level);
+            printf("%*s%-*s %d\n", depth, "", 20 - depth, comp->name,
+                   comp->level);
         }
     }
 
     for (i = 0; i < comp->n; i++) {
-        doPrintTraceLevels(comp->subcomp[i], depth + 1);
-    }
-}
+        if (comp->level == PS_DEFAULT_TRACE_LEVEL) {
+            doPrintTraceLevels(comp->subcomp[i], depth + 1, defLevel);
+        } else {
+            doPrintTraceLevels(comp->subcomp[i], depth + 1, comp->level);
+        }
+    }
+}
+
 
 /*****************************************************************************
@@ -353,5 +409,5 @@
     }
 
-    doPrintTraceLevels(cRoot, 0);
+    doPrintTraceLevels(cRoot, 0, PS_DEFAULT_TRACE_LEVEL);
 }
 
@@ -379,8 +435,5 @@
 
     if (NULL == comp) {
-        psErrorMsg(ERRORNAME_PREFIX "psTrace", PS_ERR_BAD_PARAMETER_NULL, true,
-                   PS_ERRORTEXT_psTrace_NULL_TRACETREE,
-                   __func__);
-        return;
+        psError(__func__, "p_psTrace() called on a NULL trace level tree\n");
     }
     // Only display this message if it's trace level is less than the level
