main.cpp

changeset 13
3955ff2a7d72
parent 4
758302636564
child 18
a6732098fed8
--- a/main.cpp	Sat Mar 16 00:35:36 2013 +0200
+++ b/main.cpp	Sat Mar 16 01:32:47 2013 +0200
@@ -50,4 +50,81 @@
 		getCoordinateRep (x).chars(),
 		getCoordinateRep (y).chars(),
 		getCoordinateRep (z).chars());
+}
+
+// =============================================================================
+// void logVA (logtype_e, const char*, va_list) [static]
+//
+// Common code for the two logfs
+// =============================================================================
+static void logVA (logtype_e eType, const char* fmt, va_list va) {
+	str zText;
+	char* sBuffer;
+	
+	// Log it to standard output
+	vprintf (fmt, va);
+	
+	sBuffer = vdynformat (fmt, va, 128);
+	zText = sBuffer;
+	delete[] sBuffer;
+	
+	
+	// Replace some things out with HTML entities
+	zText.replace ("<", "&lt;");
+	zText.replace (">", "&gt;");
+	zText.replace ("\n", "<br />");
+	
+	str zHTML;
+	
+	switch (eType) {
+	case LOG_Normal:
+		zHTML = zText;
+		break;
+	
+	case LOG_Error:
+		zHTML.format ("<span style=\"color: #F8F8F8; background-color: #800\"><b>[ERROR]</b> %s</span>",
+			zText.chars());
+		break;
+	
+	case LOG_Info:
+		zHTML.format ("<span style=\"color: #04F\"><b>[INFO]</b> %s</span>",
+			zText.chars());
+		break;
+	
+	case LOG_Success:
+		zHTML.format ("<span style=\"color: #6A0\"><b>[SUCCESS]</b> %s</span>",
+			zText.chars());
+		break;
+	
+	case LOG_Warning:
+		zHTML.format ("<span style=\"color: #C50\"><b>[WARNING]</b> %s</span>",
+			zText.chars());
+		break;
+	}
+	
+	g_qWindow->zMessageLogHTML += zHTML;
+	g_qWindow->qMessageLog->setHtml (g_qWindow->zMessageLogHTML);
+}
+
+
+// =============================================================================
+// logf (const char*, ...)
+// logf (logtype_e eType, const char*, ...)
+//
+// Outputs a message into the message log
+// =============================================================================
+void logf (const char* fmt, ...) {
+	va_list va;
+	
+	va_start (va, fmt);
+	logVA (LOG_Normal, fmt, va);
+	va_end (va);
+}
+
+void logf (logtype_e eType, const char* fmt, ...) {
+	va_list va;
+	
+	va_start (va, fmt);
+	logVA (eType, fmt, va);
+	va_end (va);
 }
\ No newline at end of file

mercurial