diff dmutil.cpp @ 47:9909014498f0

Add helper functions dmError() and dmMsg() and use them.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Dec 2019 23:52:45 +0200
parents 03b86b9c2f29
children
line wrap: on
line diff
--- a/dmutil.cpp	Thu Dec 05 22:45:21 2019 +0200
+++ b/dmutil.cpp	Thu Dec 05 23:52:45 2019 +0200
@@ -10,6 +10,38 @@
 #include <fstream>
 
 
+void dmMsg_V(const char *fmt, va_list ap)
+{
+    fprintf(stdout, "INFO: ");
+    vfprintf(stdout, fmt, ap);
+}
+
+
+void dmMsg(const char *fmt, ...)
+{
+    va_list ap;
+    va_start(ap, fmt);
+    dmMsg_V(fmt, ap);
+    va_end(ap);
+}
+
+
+void dmError_V(const char *fmt, va_list ap)
+{
+    fprintf(stdout, "ERROR: ");
+    vfprintf(stdout, fmt, ap);
+}
+
+
+void dmError(const char *fmt, ...)
+{
+    va_list ap;
+    va_start(ap, fmt);
+    dmError_V(fmt, ap);
+    va_end(ap);
+}
+
+
 std::string dmStrLTrim(const std::string& str, const std::string& delim)
 {
     return str.substr(str.find_first_not_of(delim));
@@ -91,7 +123,7 @@
 
     if (!in.is_open())
     {
-        printf("ERROR: Unable to open file '%s'.\n",
+        dmError("Unable to open file '%s'.\n",
             filename.c_str());
         return false;
     }
@@ -100,7 +132,7 @@
 
     if (in.tellg() > maxSize)
     {
-        printf("ERROR: File '%s' is too large.\n",
+        dmError("File '%s' is too large.\n",
             filename.c_str());
         return false;
     }