Index: nasal/misc.c
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/nasal/misc.c,v
retrieving revision 1.10
diff -u -r1.10 misc.c
--- nasal/misc.c	26 Sep 2008 18:22:12 -0000	1.10
+++ nasal/misc.c	10 Nov 2008 14:01:30 -0000
@@ -5,7 +5,7 @@
 #include "nasal.h"
 #include "code.h"
 
-void naFree(void* m) { free(m); }
+void naFree(void* m) { if(0 != m) free(m); }
 void* naAlloc(int n) { return malloc(n); }
 void* naRealloc(void* b, int n) { return realloc(b, n); }
 void naBZero(void* m, int n) { memset(m, 0, n); }
Index: debug/logstream.hxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/debug/logstream.hxx,v
retrieving revision 1.16
diff -u -r1.16 logstream.hxx
--- debug/logstream.hxx	28 Jul 2008 07:52:13 -0000	1.16
+++ debug/logstream.hxx	20 Nov 2008 16:30:35 -0000
@@ -78,6 +78,8 @@
      */
     void set_log_state( sgDebugClass c, sgDebugPriority p );
 
+	bool would_log( sgDebugClass c, sgDebugPriority p ) const;
+
     /**
      * Set the global logging level.
      * @param c debug class
@@ -164,6 +166,13 @@
     logging_enabled = ((c & logClass) != 0 && p >= logPriority);
 }
 
+inline bool
+logbuf::would_log( sgDebugClass c, sgDebugPriority p ) const
+{
+    return ((c & logClass) != 0 && p >= logPriority);
+}
+
+
 inline logbuf::int_type
 logbuf::overflow( int c )
 {
@@ -240,15 +249,19 @@
      */
     void setLogLevels( sgDebugClass c, sgDebugPriority p );
 
+	bool would_log(  sgDebugClass c, sgDebugPriority p ) const {
+		return lbuf.would_log( c, p );
+	};
+
     /**
      * Output operator to capture the debug level and priority of a message.
      * @param l log level
      */
     inline std::ostream& operator<< ( const loglevel& l );
     friend logstream& sglog();
+    static logstream *initGlobalLogstream();
 protected:
     static logstream *global_logstream;
-    static void initGlobalLogstream();
 };
 
 inline std::ostream&
@@ -268,9 +281,9 @@
 inline logstream&
 sglog()
 {
-  if (logstream::global_logstream == NULL) {
-      logstream::initGlobalLogstream();
-  }
+//  if (logstream::global_logstream == NULL) {
+//      logstream::initGlobalLogstream();
+//  }
   return *logstream::global_logstream;
 }
 
@@ -284,7 +297,12 @@
 #ifdef FG_NDEBUG
 # define SG_LOG(C,P,M)
 #else
-# define SG_LOG(C,P,M) sglog() << loglevel(C,P) << M << std::endl
+//# define SG_LOG(C,P,M) sglog() << loglevel(C,P) << M << std::endl
+# define SG_LOG(C,P,M) do {                     \
+	logstream& __tmplogstreamref(sglog());                      \
+	if(__tmplogstreamref.would_log(C,P)) {                      \
+        __tmplogstreamref << loglevel(C,P) << M << std::endl; } \
+	} while(0)
 #endif
 
 #define SG_ORIGIN __FILE__ ":" SG_STRINGIZE(__LINE__)
Index: debug/logstream.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/debug/logstream.cxx,v
retrieving revision 1.7
diff -u -r1.7 logstream.cxx
--- debug/logstream.cxx	25 Jul 2008 08:34:15 -0000	1.7
+++ debug/logstream.cxx	20 Nov 2008 15:32:47 -0000
@@ -34,6 +34,19 @@
 sgDebugPriority logbuf::logPriority     = SG_INFO;
 streambuf*      logbuf::sbuf            = NULL;
 
+namespace {
+	struct ignore_me {
+		ignore_me() {
+			static bool initialized = false;
+			if (initialized)
+				return;
+			initialized = true;
+			logstream::initGlobalLogstream();
+		}
+	};
+	static ignore_me im;
+}
+
 logbuf::logbuf()
 {
 //     if ( sbuf == NULL )
@@ -92,10 +105,12 @@
     logbuf::set_log_level( c, p );
 }
 
-void
+logstream *
 logstream::initGlobalLogstream()
 {
     // Force initialization of cerr.
     static std::ios_base::Init initializer;
-    global_logstream = new logstream(std::cerr);
+	if( 0 == global_logstream )
+		global_logstream = new logstream(std::cerr);
+	return global_logstream;
 }
Index: misc/strutils.hxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/misc/strutils.hxx,v
retrieving revision 1.4
diff -u -r1.4 strutils.hxx
--- misc/strutils.hxx	28 Jul 2008 07:52:14 -0000	1.4
+++ misc/strutils.hxx	24 Nov 2008 17:12:50 -0000
@@ -84,6 +84,10 @@
 	       const char* sep = 0,
 	       int maxsplit = 0 );
 
+	int
+	split_aptdat( const string& str, const char* sep, int maxsplit, std::vector<std::string>& res );
+
+
     } // end namespace strutils
 } // end namespace simgear
 
Index: misc/strutils.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/misc/strutils.cxx,v
retrieving revision 1.4
diff -u -r1.4 strutils.cxx
--- misc/strutils.cxx	13 Apr 2008 21:11:44 -0000	1.4
+++ misc/strutils.cxx	24 Nov 2008 17:13:29 -0000
@@ -117,6 +117,89 @@
 	}
 
 	/**
+	* Avoid new/delete/cpconstructor clusterfsck
+	*/
+	int
+		split_whitespace_aptdat( const string& str, int maxsplit, vector<string>& res )
+	{
+		string::size_type len = str.length();
+		string::size_type i = 0;
+		string::size_type j;
+		int countsplit = 0;
+		const char * p = str.c_str();
+
+		while (i < len)
+		{
+			while (i < len && isspace((unsigned char)p[i]))
+			{
+				++i;
+			}
+
+			j = i;
+
+			while (i < len && !isspace((unsigned char)p[i]))
+			{
+				++i;
+			}
+
+			if (j < i)
+			{
+				res[countsplit].assign(str, j, i-j);
+				++countsplit;
+				while (i < len && isspace((unsigned char)p[i]))
+				{
+					++i;
+				}
+
+				if (maxsplit && (countsplit >= maxsplit) && i < len)
+				{
+					res[countsplit].assign( str, i, len-i);
+					i = len;
+				}
+			}
+		}
+		return countsplit;
+	}
+
+	/**
+	 * Avoid new/delete/cpconstructor clusterfsck
+	 */
+	int
+	split_aptdat( const string& str, const char* sep, int maxsplit, vector<string>& res )
+	{
+		if (sep == 0) {
+			return split_whitespace_aptdat( str, maxsplit, res );
+		}
+	    int n = std::strlen( sep );
+	    if (n == 0)
+			return 0;
+
+		const char* s = str.c_str();
+	    string::size_type len = str.length();
+	    string::size_type i = 0;
+	    string::size_type j = 0;
+	    int splitcount = 0;
+		
+	    while (i+n <= len)
+	    {
+			if (s[i] == sep[0] && (n == 1 || std::memcmp(s+i, sep, n) == 0))
+			{
+			    res[splitcount].assign(str, j, i-j );
+				i = j = i + n;
+			    ++splitcount;
+			    if (maxsplit && (splitcount >= maxsplit))
+				break;
+			}
+			else
+			{
+				++i;
+			}
+	    }
+		return splitcount;
+	}
+
+
+	/**
 	 * The lstrip(), rstrip() and strip() functions are implemented
 	 * in do_strip() which uses an additional parameter to indicate what
 	 * type of strip should occur.
