30 vector<LDOpenFile*> g_loadedFiles; |
31 vector<LDOpenFile*> g_loadedFiles; |
31 LDOpenFile* g_curfile = null; |
32 LDOpenFile* g_curfile = null; |
32 ForgeWindow* g_win = null; |
33 ForgeWindow* g_win = null; |
33 bbox g_BBox; |
34 bbox g_BBox; |
34 const QApplication* g_app = null; |
35 const QApplication* g_app = null; |
|
36 QFile g_file_stdout, g_file_stderr; |
35 |
37 |
36 const vertex g_origin (0.0f, 0.0f, 0.0f); |
38 const vertex g_origin (0.0f, 0.0f, 0.0f); |
37 const matrix g_identity ({1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}); |
39 const matrix g_identity ({1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}); |
|
40 |
|
41 void doPrint (QFile& f, initlist<StringFormatArg> args) { |
|
42 str msg = DoFormat (args); |
|
43 f.write (msg.toUtf8 (), msg.length ()); |
|
44 f.flush (); |
|
45 } |
|
46 |
|
47 void doPrint (FILE* fp, initlist<StringFormatArg> args) { |
|
48 if (fp == stdout) |
|
49 doPrint (g_file_stdout, args); |
|
50 else if (fp == stderr) |
|
51 doPrint (g_file_stderr, args); |
|
52 |
|
53 fatal ("unknown FILE* argument"); |
|
54 } |
38 |
55 |
39 // ============================================================================= |
56 // ============================================================================= |
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
41 // ============================================================================= |
58 // ============================================================================= |
42 int main (int argc, char* argv[]) { |
59 int main (int argc, char* argv[]) { |
|
60 g_file_stdout.open (stdout, QIODevice::WriteOnly); |
|
61 g_file_stderr.open (stderr, QIODevice::WriteOnly); |
|
62 |
43 const QApplication app (argc, argv); |
63 const QApplication app (argc, argv); |
44 g_app = &app; |
64 g_app = &app; |
45 g_curfile = NULL; |
65 g_curfile = NULL; |
46 |
66 |
47 // Load or create the configuration |
67 // Load or create the configuration |
92 va_end (va); |
112 va_end (va); |
93 } |
113 } |
94 |
114 |
95 str versionString () { |
115 str versionString () { |
96 #if VERSION_PATCH == 0 |
116 #if VERSION_PATCH == 0 |
97 return fmt ("%d.%d", VERSION_MAJOR, VERSION_MINOR); |
117 return fmt ("%1.%2", VERSION_MAJOR, VERSION_MINOR); |
98 #else |
118 #else |
99 return fmt ("%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); |
119 return fmt ("%1.%2.%3", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); |
100 #endif // VERSION_PATCH |
120 #endif // VERSION_PATCH |
101 } |
121 } |
102 |
122 |
103 const char* versionMoniker () { |
123 const char* versionMoniker () { |
104 #if BUILD_ID == BUILD_INTERNAL |
124 #if BUILD_ID == BUILD_INTERNAL |
132 box.setDefaultButton (btn); |
152 box.setDefaultButton (btn); |
133 box.exec (); |
153 box.exec (); |
134 } |
154 } |
135 |
155 |
136 void assertionFailure (const char* file, const ulong line, const char* funcname, const char* expr) { |
156 void assertionFailure (const char* file, const ulong line, const char* funcname, const char* expr) { |
137 str errmsg = fmt ("File %s\nLine: %lu:\nFunction %s:\n\nAssertion `%s' failed", |
157 str errmsg = fmt ("File: %1\nLine: %2:\nFunction %3:\n\nAssertion `%4' failed", |
138 file, line, funcname, expr); |
158 file, line, funcname, expr); |
139 |
159 |
140 #if BUILD_ID == BUILD_INTERNAL |
160 #if BUILD_ID == BUILD_INTERNAL |
141 errmsg += ", aborting."; |
161 errmsg += ", aborting."; |
142 #else |
162 #else |
143 errmsg += "."; |
163 errmsg += "."; |
144 #endif |
164 #endif |
145 |
165 |
146 printf ("%s\n", errmsg.chars ()); |
166 printf ("%s\n", qchars (errmsg)); |
147 |
167 |
148 #if BUILD_ID == BUILD_INTERNAL |
168 #if BUILD_ID == BUILD_INTERNAL |
149 if (g_win) |
169 if (g_win) |
150 g_win->deleteLater (); |
170 g_win->deleteLater (); |
151 |
171 |
153 abort (); |
173 abort (); |
154 #endif |
174 #endif |
155 } |
175 } |
156 |
176 |
157 void fatalError (const char* file, const ulong line, const char* funcname, str msg) { |
177 void fatalError (const char* file, const ulong line, const char* funcname, str msg) { |
158 str errmsg = fmt ("Aborting over a call to fatal():\nFile: %s\nLine: %lu\nFunction: %s\n\n%s", |
178 str errmsg = fmt ("Aborting over a call to fatal():\nFile: %1\nLine: %2\nFunction: %3\n\n%4", |
159 file, line, funcname, msg.chars ()); |
179 file, line, funcname, msg); |
160 |
180 |
161 printf ("%s\n", errmsg.chars ()); |
181 printf ("%s\n", qchars (errmsg)); |
162 |
182 |
163 if (g_win) |
183 if (g_win) |
164 g_win->deleteLater (); |
184 g_win->deleteLater (); |
165 |
185 |
166 bombBox (errmsg); |
186 bombBox (errmsg); |