Index: /trunk/psLib/src/sys/psTrace.c
===================================================================
--- /trunk/psLib/src/sys/psTrace.c	(revision 3780)
+++ /trunk/psLib/src/sys/psTrace.c	(revision 3781)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-04-07 20:27:41 $
+ *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-04-28 23:46:29 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -252,4 +252,8 @@
     if (cRoot == NULL) {
         initTrace();
+    }
+
+    if (traceFP == NULL) {
+        traceFP = stdout;
     }
 
@@ -425,23 +429,15 @@
     psS32 i = 0;
 
+    if (traceFP == NULL) {
+        traceFP = stderr;
+    }
+
     if (comp->name[0] == '\0') {
         return;
     } else {
         if (comp->level == PS_DEFAULT_TRACE_LEVEL) {
-            if (traceFP == NULL) {
-                printf("%*s%-*s %d\n", depth, "", 20 - depth, comp->name,
-                       defLevel);
-            } else {
-                fprintf(traceFP,"%*s%-*s %d\n", depth, "", 20 - depth, comp->name,
-                        defLevel);
-            }
+            fprintf(traceFP,"%*s%-*s %d\n", depth, "", 20 - depth, comp->name, defLevel);
         } else {
-            if (traceFP == NULL) {
-                printf("%*s%-*s %d\n", depth, "", 20 - depth, comp->name,
-                       comp->level);
-            } else {
-                fprintf(traceFP, "%*s%-*s %d\n", depth, "", 20 - depth, comp->name,
-                        comp->level);
-            }
+            fprintf(traceFP, "%*s%-*s %d\n", depth, "", 20 - depth, comp->name, comp->level);
         }
     }
@@ -498,4 +494,8 @@
     psS32 i = 0;
 
+    if (traceFP == NULL) {
+        traceFP = stderr;
+    }
+
     if (NULL == comp) {
         psError(PS_ERR_BAD_PARAMETER_NULL, true,
@@ -514,26 +514,43 @@
         fmt = va_arg(ap, char *);
 
-        if (traceFP != NULL) {
-            // We indent each message one space for each level of the message.
-            for (i = 0; i < level; i++) {
-                fprintf(traceFP, " ");
-            }
-            vfprintf(traceFP, fmt, ap);
-        } else {
-            // We indent each message one space for each level of the message.
-            for (i = 0; i < level; i++) {
-                putchar(' ');
-            }
-            vprintf(fmt, ap);
-        }
+        // We indent each message one space for each level of the message.
+        for (i = 0; i < level; i++) {
+            fprintf(traceFP, " ");
+        }
+        vfprintf(traceFP, fmt, ap);
         va_end(ap);
     }
-    // NOTE: should we free *fmt as well? Read the man page.
-}
-
+}
+
+// XXX EAM : I've added code to close the old traceFP (safely)
 void psTraceSetDestination(FILE * fp)
 {
+
+    bool special;
+
+    // XXX EAM perhaps return an error?
+    if (fp == NULL) {
+        return;
+    }
+
+    // cannot close traceFP if one of the special FILE ptrs
+    special  = (traceFP == NULL);
+    special |= (traceFP == stdin);
+    special |= (traceFP == stdout);
+    special |= (traceFP == stderr);
+
+    if (!special) {
+        fclose (traceFP);
+    }
     traceFP = fp;
 }
 
+FILE *psTraceGetDestination()
+{
+    if (traceFP == NULL) {
+        traceFP = stderr;
+    }
+    return traceFP;
+}
+
 #endif
Index: /trunk/psLib/src/sys/psTrace.h
===================================================================
--- /trunk/psLib/src/sys/psTrace.h	(revision 3780)
+++ /trunk/psLib/src/sys/psTrace.h	(revision 3781)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-02-17 19:26:24 $
+ *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-04-28 23:46:29 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -29,31 +29,32 @@
 //#define PS_NO_TRACE 1   ///< to turn off all tracing
 
-#if defined(PS_NO_TRACE)
-#        define psTrace(facil, level, ...) (void)0
-/* do nothing */
-#        define p_psTrace(facil, level, ...)  (void)0
-/* do nothing */
-#        define psTraceSetLevel(facil,level) 0
-#        define psTraceGetLevel(facil) 0
-#        define psTraceReset() (void)0     /* do nothing */
-#        define psTraceFree() (void)0      /* do nothing */
-#        define psTracePrintLevels() (void)0
-/* do nothing */
-#        define psTraceSetDestination(fp) (void)0
-/* do nothing */
-#    else
+// XXX EAM : the old 'empty' values of (void) 0 are dangerous
+# if defined(PS_NO_TRACE)
+    #   define psTrace(facil, level, ...)   /* do nothing */
+    #   define p_psTrace(facil, level, ...) /* do nothing */
+    #   define psTraceSetLevel(facil,level) /* do nothing */
+    #   define psTraceGetLevel(facil)       /* do nothing */
+    #   define psTraceReset()               /* do nothing */
+    #   define psTraceFree()                /* do nothing */
+    #   define psTracePrintLevels()         /* do nothing */
+    #   define psTraceSetDestination(fp)    /* do nothing */
+    #   define psTraceSetDestination()      /* do nothing */
+    #   define PS_TRACE_ON 0
 
-    /** Basic structure for the component tree.  A component is a string of the
-        form aaa.bbb.ccc, and may itself contain further subcomponents.  The
-        Component structure doesn't in fact contain it's full name, but only the
-        last part. */
-    typedef struct p_psComponent
-    {
-        const char *name;           // last part of name of component
-        psS32 level;                  // trace level for this component
-        bool p_psSpecified;
-        psS32 n;                      // number of subcomponents
-        struct p_psComponent* *subcomp;     // next level of subcomponents
-    }
+    # else /* PS_NO_TRACE */
+        #   define PS_TRACE_ON 1
+
+        /** Basic structure for the component tree.  A component is a string of the
+            form aaa.bbb.ccc, and may itself contain further subcomponents.  The
+            Component structure doesn't in fact contain it's full name, but only the
+            last part. */
+        typedef struct p_psComponent
+        {
+            const char *name;   // last part of name of component
+            psS32 level;   // trace level for this component
+            bool p_psSpecified;
+            psS32 n;    // number of subcomponents
+            struct p_psComponent* *subcomp;     // next level of subcomponents
+        }
 p_psComponent;
 
@@ -72,7 +73,7 @@
 #ifndef SWIG
 #define psTrace(facil, level, ...) p_psTrace(facil, level, __VA_ARGS__)
-#endif
+#endif /* SWIG */
 
-#endif
+#endif /* DOXYGEN */
 
 /// Set trace level
@@ -82,5 +83,5 @@
 
 /// Get the trace level
-psS32 psTraceGetLevel(const char *facil)     ///< facilty of interest
+psS32 psTraceGetLevel(const char *facil) ///< facilty of interest
 ;
 
@@ -94,7 +95,11 @@
 void psTraceSetDestination(FILE * fp);
 
+/// Get the current destination for trace messages.
+FILE *psTraceGetDestination(void);
+
 /* \} */// End of SystemGroup Functions
 
-#endif
+#endif /* PS_NO_TRACE */
 
-#endif
+#endif /* PS_TRACE_H */
+
Index: /trunk/psLib/src/sysUtils/psTrace.c
===================================================================
--- /trunk/psLib/src/sysUtils/psTrace.c	(revision 3780)
+++ /trunk/psLib/src/sysUtils/psTrace.c	(revision 3781)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-04-07 20:27:41 $
+ *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-04-28 23:46:29 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -252,4 +252,8 @@
     if (cRoot == NULL) {
         initTrace();
+    }
+
+    if (traceFP == NULL) {
+        traceFP = stdout;
     }
 
@@ -425,23 +429,15 @@
     psS32 i = 0;
 
+    if (traceFP == NULL) {
+        traceFP = stderr;
+    }
+
     if (comp->name[0] == '\0') {
         return;
     } else {
         if (comp->level == PS_DEFAULT_TRACE_LEVEL) {
-            if (traceFP == NULL) {
-                printf("%*s%-*s %d\n", depth, "", 20 - depth, comp->name,
-                       defLevel);
-            } else {
-                fprintf(traceFP,"%*s%-*s %d\n", depth, "", 20 - depth, comp->name,
-                        defLevel);
-            }
+            fprintf(traceFP,"%*s%-*s %d\n", depth, "", 20 - depth, comp->name, defLevel);
         } else {
-            if (traceFP == NULL) {
-                printf("%*s%-*s %d\n", depth, "", 20 - depth, comp->name,
-                       comp->level);
-            } else {
-                fprintf(traceFP, "%*s%-*s %d\n", depth, "", 20 - depth, comp->name,
-                        comp->level);
-            }
+            fprintf(traceFP, "%*s%-*s %d\n", depth, "", 20 - depth, comp->name, comp->level);
         }
     }
@@ -498,4 +494,8 @@
     psS32 i = 0;
 
+    if (traceFP == NULL) {
+        traceFP = stderr;
+    }
+
     if (NULL == comp) {
         psError(PS_ERR_BAD_PARAMETER_NULL, true,
@@ -514,26 +514,43 @@
         fmt = va_arg(ap, char *);
 
-        if (traceFP != NULL) {
-            // We indent each message one space for each level of the message.
-            for (i = 0; i < level; i++) {
-                fprintf(traceFP, " ");
-            }
-            vfprintf(traceFP, fmt, ap);
-        } else {
-            // We indent each message one space for each level of the message.
-            for (i = 0; i < level; i++) {
-                putchar(' ');
-            }
-            vprintf(fmt, ap);
-        }
+        // We indent each message one space for each level of the message.
+        for (i = 0; i < level; i++) {
+            fprintf(traceFP, " ");
+        }
+        vfprintf(traceFP, fmt, ap);
         va_end(ap);
     }
-    // NOTE: should we free *fmt as well? Read the man page.
-}
-
+}
+
+// XXX EAM : I've added code to close the old traceFP (safely)
 void psTraceSetDestination(FILE * fp)
 {
+
+    bool special;
+
+    // XXX EAM perhaps return an error?
+    if (fp == NULL) {
+        return;
+    }
+
+    // cannot close traceFP if one of the special FILE ptrs
+    special  = (traceFP == NULL);
+    special |= (traceFP == stdin);
+    special |= (traceFP == stdout);
+    special |= (traceFP == stderr);
+
+    if (!special) {
+        fclose (traceFP);
+    }
     traceFP = fp;
 }
 
+FILE *psTraceGetDestination()
+{
+    if (traceFP == NULL) {
+        traceFP = stderr;
+    }
+    return traceFP;
+}
+
 #endif
Index: /trunk/psLib/src/sysUtils/psTrace.h
===================================================================
--- /trunk/psLib/src/sysUtils/psTrace.h	(revision 3780)
+++ /trunk/psLib/src/sysUtils/psTrace.h	(revision 3781)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-02-17 19:26:24 $
+ *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-04-28 23:46:29 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -29,31 +29,32 @@
 //#define PS_NO_TRACE 1   ///< to turn off all tracing
 
-#if defined(PS_NO_TRACE)
-#        define psTrace(facil, level, ...) (void)0
-/* do nothing */
-#        define p_psTrace(facil, level, ...)  (void)0
-/* do nothing */
-#        define psTraceSetLevel(facil,level) 0
-#        define psTraceGetLevel(facil) 0
-#        define psTraceReset() (void)0     /* do nothing */
-#        define psTraceFree() (void)0      /* do nothing */
-#        define psTracePrintLevels() (void)0
-/* do nothing */
-#        define psTraceSetDestination(fp) (void)0
-/* do nothing */
-#    else
+// XXX EAM : the old 'empty' values of (void) 0 are dangerous
+# if defined(PS_NO_TRACE)
+    #   define psTrace(facil, level, ...)   /* do nothing */
+    #   define p_psTrace(facil, level, ...) /* do nothing */
+    #   define psTraceSetLevel(facil,level) /* do nothing */
+    #   define psTraceGetLevel(facil)       /* do nothing */
+    #   define psTraceReset()               /* do nothing */
+    #   define psTraceFree()                /* do nothing */
+    #   define psTracePrintLevels()         /* do nothing */
+    #   define psTraceSetDestination(fp)    /* do nothing */
+    #   define psTraceSetDestination()      /* do nothing */
+    #   define PS_TRACE_ON 0
 
-    /** Basic structure for the component tree.  A component is a string of the
-        form aaa.bbb.ccc, and may itself contain further subcomponents.  The
-        Component structure doesn't in fact contain it's full name, but only the
-        last part. */
-    typedef struct p_psComponent
-    {
-        const char *name;           // last part of name of component
-        psS32 level;                  // trace level for this component
-        bool p_psSpecified;
-        psS32 n;                      // number of subcomponents
-        struct p_psComponent* *subcomp;     // next level of subcomponents
-    }
+    # else /* PS_NO_TRACE */
+        #   define PS_TRACE_ON 1
+
+        /** Basic structure for the component tree.  A component is a string of the
+            form aaa.bbb.ccc, and may itself contain further subcomponents.  The
+            Component structure doesn't in fact contain it's full name, but only the
+            last part. */
+        typedef struct p_psComponent
+        {
+            const char *name;   // last part of name of component
+            psS32 level;   // trace level for this component
+            bool p_psSpecified;
+            psS32 n;    // number of subcomponents
+            struct p_psComponent* *subcomp;     // next level of subcomponents
+        }
 p_psComponent;
 
@@ -72,7 +73,7 @@
 #ifndef SWIG
 #define psTrace(facil, level, ...) p_psTrace(facil, level, __VA_ARGS__)
-#endif
+#endif /* SWIG */
 
-#endif
+#endif /* DOXYGEN */
 
 /// Set trace level
@@ -82,5 +83,5 @@
 
 /// Get the trace level
-psS32 psTraceGetLevel(const char *facil)     ///< facilty of interest
+psS32 psTraceGetLevel(const char *facil) ///< facilty of interest
 ;
 
@@ -94,7 +95,11 @@
 void psTraceSetDestination(FILE * fp);
 
+/// Get the current destination for trace messages.
+FILE *psTraceGetDestination(void);
+
 /* \} */// End of SystemGroup Functions
 
-#endif
+#endif /* PS_NO_TRACE */
 
-#endif
+#endif /* PS_TRACE_H */
+
Index: /trunk/psLib/test/runTest
===================================================================
--- /trunk/psLib/test/runTest	(revision 3780)
+++ /trunk/psLib/test/runTest	(revision 3781)
@@ -26,5 +26,5 @@
 #
 #  $Revison:  $  $Name: not supported by cvs2svn $
-#  $Date: 2005-04-26 19:53:30 $
+#  $Date: 2005-04-28 23:46:29 $
 #
 #  Copyright 2004 Maui High Performance Computering Center, University of Hawaii
@@ -354,5 +354,5 @@
 
         # Perform difference on the STD stream files
-        $diffstdout = `diff $streamFile $tempFile`;
+        $diffstdout = `diff -b -y --suppress-common-lines $streamFile $tempFile`;
 
         # Check the return value of the difference
Index: /trunk/psLib/test/sysUtils/verified/tst_psTrace.stderr
===================================================================
--- /trunk/psLib/test/sysUtils/verified/tst_psTrace.stderr	(revision 3780)
+++ /trunk/psLib/test/sysUtils/verified/tst_psTrace.stderr	(revision 3781)
@@ -64,4 +64,7 @@
      (1) This message should be displayed (beefface)
      (2) This message should be displayed (beefface)
+     (0) This message should be displayed (beefface)
+     (1) This message should be displayed (beefface)
+     (2) This message should be displayed (beefface)
 
 ---> TESTPOINT PASSED (psTrace{psTrace()} | tst_psTrace.c)
Index: /trunk/psLib/test/sysUtils/verified/tst_psTrace.stdout
===================================================================
--- /trunk/psLib/test/sysUtils/verified/tst_psTrace.stdout	(revision 3780)
+++ /trunk/psLib/test/sysUtils/verified/tst_psTrace.stdout	(revision 3781)
@@ -1,5 +1,2 @@
-     (0) This message should be displayed (beefface)
-     (1) This message should be displayed (beefface)
-     (2) This message should be displayed (beefface)
      (0) This message should be displayed (beefface)
      (1) This message should be displayed (beefface)
