92 } |
92 } |
93 |
93 |
94 // ============================================================================= |
94 // ============================================================================= |
95 // ----------------------------------------------------------------------------- |
95 // ----------------------------------------------------------------------------- |
96 void doPrint (FILE* fp, initlist<StringFormatArg> args) |
96 void doPrint (FILE* fp, initlist<StringFormatArg> args) |
97 { if (fp == stdout) |
97 { str msg = DoFormat (args); |
98 doPrint (g_file_stdout, args); |
98 fwrite (msg.toStdString().c_str(), 1, msg.length(), fp); |
99 |
99 fflush (fp); |
100 elif (fp == stderr) |
|
101 doPrint (g_file_stderr, args); |
|
102 else |
|
103 fatal ("unknown FILE* argument"); |
|
104 } |
100 } |
105 |
101 |
106 // ============================================================================= |
102 // ============================================================================= |
107 // ----------------------------------------------------------------------------- |
103 // ----------------------------------------------------------------------------- |
108 str versionString() |
104 QString versionString() |
109 { if (g_versionString.length() == 0) |
105 { if (g_versionString.length() == 0) |
110 { |
106 { |
111 #if VERSION_PATCH == 0 |
107 #if VERSION_PATCH == 0 |
112 g_versionString = fmt ("%1.%2", VERSION_MAJOR, VERSION_MINOR); |
108 g_versionString = fmt ("%1.%2", VERSION_MAJOR, VERSION_MINOR); |
113 #else |
109 #else |
135 #endif // BUILD_ID |
131 #endif // BUILD_ID |
136 } |
132 } |
137 |
133 |
138 // ============================================================================= |
134 // ============================================================================= |
139 // ----------------------------------------------------------------------------- |
135 // ----------------------------------------------------------------------------- |
140 str fullVersionString() |
136 QString fullVersionString() |
141 { return fmt ("v%1 %2", versionString(), versionMoniker()); |
137 { return fmt ("v%1 %2", versionString(), versionMoniker()); |
142 } |
|
143 |
|
144 // ============================================================================= |
|
145 // ----------------------------------------------------------------------------- |
|
146 static void bombBox (str msg) |
|
147 { msg.replace ("\n", "<br />"); |
|
148 |
|
149 QMessageBox box (null); |
|
150 const QMessageBox::StandardButton btn = QMessageBox::Close; |
|
151 box.setWindowTitle ("Fatal Error"); |
|
152 box.setIconPixmap (getIcon ("bomb")); |
|
153 box.setWindowIcon (getIcon ("ldforge")); |
|
154 box.setText (msg); |
|
155 box.addButton (btn); |
|
156 box.button (btn)->setText ("Damn it"); |
|
157 box.setDefaultButton (btn); |
|
158 box.exec(); |
|
159 } |
138 } |
160 |
139 |
161 // ============================================================================= |
140 // ============================================================================= |
162 // ----------------------------------------------------------------------------- |
141 // ----------------------------------------------------------------------------- |
163 void assertionFailure (const char* file, const ulong line, const char* funcname, const char* expr) |
142 void assertionFailure (const char* file, const ulong line, const char* funcname, const char* expr) |
164 { str errmsg = fmt ("File: %1\nLine: %2:\nFunction %3:\n\nAssertion `%4' failed", |
143 { str errmsg = fmt ("File: %1\nLine: %2:\nFunction %3:\n\nAssertion `%4' failed", |
165 file, line, funcname, expr); |
144 file, line, funcname, expr); |
166 |
145 |
167 #if BUILD_ID == BUILD_INTERNAL |
146 #ifndef RELEASE |
168 errmsg += ", aborting."; |
147 errmsg += ", aborting."; |
169 #else |
148 #else |
170 errmsg += "."; |
149 errmsg += "."; |
171 #endif |
150 #endif |
172 |
151 |
173 printf ("%s\n", errmsg.toStdString().c_str()); |
152 printf ("%s\n", errmsg.toStdString().c_str()); |
174 |
153 |
175 #if BUILD_ID == BUILD_INTERNAL |
154 #ifndef RELEASE |
176 |
|
177 if (g_win) |
155 if (g_win) |
178 g_win->deleteLater(); |
156 g_win->deleteLater(); |
179 |
157 |
180 bombBox (errmsg); |
158 errmsg.replace ("\n", "<br />"); |
|
159 |
|
160 QMessageBox box (null); |
|
161 const QMessageBox::StandardButton btn = QMessageBox::Close; |
|
162 box.setWindowTitle ("Fatal Error"); |
|
163 box.setIconPixmap (getIcon ("bomb")); |
|
164 box.setWindowIcon (getIcon ("ldforge")); |
|
165 box.setText (errmsg); |
|
166 box.addButton (btn); |
|
167 box.button (btn)->setText ("Damn it"); |
|
168 box.setDefaultButton (btn); |
|
169 box.exec(); |
181 abort(); |
170 abort(); |
182 #endif |
171 #endif |
183 } |
172 } |
184 |
|
185 // ============================================================================= |
|
186 // ----------------------------------------------------------------------------- |
|
187 void fatalError (const char* file, const ulong line, const char* funcname, str msg) |
|
188 { str errmsg = fmt ("Aborting over a call to fatal():\nFile: %1\nLine: %2\nFunction: %3\n\n%4", |
|
189 file, line, funcname, msg); |
|
190 |
|
191 print ("%1\n", errmsg); |
|
192 |
|
193 if (g_win) |
|
194 g_win->deleteLater(); |
|
195 |
|
196 bombBox (errmsg); |
|
197 abort(); |
|
198 } |
|