comparison 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
comparison
equal deleted inserted replaced
46:0c75c5f5c6b6 47:9909014498f0
6 // 6 //
7 // See file "COPYING" for license information. 7 // See file "COPYING" for license information.
8 // 8 //
9 #include "dmutil.h" 9 #include "dmutil.h"
10 #include <fstream> 10 #include <fstream>
11
12
13 void dmMsg_V(const char *fmt, va_list ap)
14 {
15 fprintf(stdout, "INFO: ");
16 vfprintf(stdout, fmt, ap);
17 }
18
19
20 void dmMsg(const char *fmt, ...)
21 {
22 va_list ap;
23 va_start(ap, fmt);
24 dmMsg_V(fmt, ap);
25 va_end(ap);
26 }
27
28
29 void dmError_V(const char *fmt, va_list ap)
30 {
31 fprintf(stdout, "ERROR: ");
32 vfprintf(stdout, fmt, ap);
33 }
34
35
36 void dmError(const char *fmt, ...)
37 {
38 va_list ap;
39 va_start(ap, fmt);
40 dmError_V(fmt, ap);
41 va_end(ap);
42 }
11 43
12 44
13 std::string dmStrLTrim(const std::string& str, const std::string& delim) 45 std::string dmStrLTrim(const std::string& str, const std::string& delim)
14 { 46 {
15 return str.substr(str.find_first_not_of(delim)); 47 return str.substr(str.find_first_not_of(delim));
89 { 121 {
90 std::ifstream in(filename.c_str(), std::fstream::in); 122 std::ifstream in(filename.c_str(), std::fstream::in);
91 123
92 if (!in.is_open()) 124 if (!in.is_open())
93 { 125 {
94 printf("ERROR: Unable to open file '%s'.\n", 126 dmError("Unable to open file '%s'.\n",
95 filename.c_str()); 127 filename.c_str());
96 return false; 128 return false;
97 } 129 }
98 130
99 in.seekg(0, std::ios::end); 131 in.seekg(0, std::ios::end);
100 132
101 if (in.tellg() > maxSize) 133 if (in.tellg() > maxSize)
102 { 134 {
103 printf("ERROR: File '%s' is too large.\n", 135 dmError("File '%s' is too large.\n",
104 filename.c_str()); 136 filename.c_str());
105 return false; 137 return false;
106 } 138 }
107 139
108 buf.reserve(in.tellg()); 140 buf.reserve(in.tellg());