author | kergoth <kergoth> | 2002-11-01 00:10:42 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-11-01 00:10:42 (UTC) |
commit | 5042e3cf0d3514552769e441f5aad590c8eaf967 (patch) (unidiff) | |
tree | 4a5ea45f3519d981a172ab5275bf38c6fa778dec /qmake/tools/qglobal.cpp | |
parent | 108c1c753e74e989cc13923086996791428c9af4 (diff) | |
download | opie-5042e3cf0d3514552769e441f5aad590c8eaf967.zip opie-5042e3cf0d3514552769e441f5aad590c8eaf967.tar.gz opie-5042e3cf0d3514552769e441f5aad590c8eaf967.tar.bz2 |
Adding qmake in preperation for new build system
-rw-r--r-- | qmake/tools/qglobal.cpp | 835 |
1 files changed, 835 insertions, 0 deletions
diff --git a/qmake/tools/qglobal.cpp b/qmake/tools/qglobal.cpp new file mode 100644 index 0000000..47cd6bd --- a/dev/null +++ b/qmake/tools/qglobal.cpp | |||
@@ -0,0 +1,835 @@ | |||
1 | /**************************************************************************** | ||
2 | ** $Id$ | ||
3 | ** | ||
4 | ** Global functions | ||
5 | ** | ||
6 | ** Created : 920604 | ||
7 | ** | ||
8 | ** Copyright (C) 1992-2002 Trolltech AS. All rights reserved. | ||
9 | ** | ||
10 | ** This file is part of the tools module of the Qt GUI Toolkit. | ||
11 | ** | ||
12 | ** This file may be distributed under the terms of the Q Public License | ||
13 | ** as defined by Trolltech AS of Norway and appearing in the file | ||
14 | ** LICENSE.QPL included in the packaging of this file. | ||
15 | ** | ||
16 | ** This file may be distributed and/or modified under the terms of the | ||
17 | ** GNU General Public License version 2 as published by the Free Software | ||
18 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
19 | ** packaging of this file. | ||
20 | ** | ||
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | ||
22 | ** licenses may use this file in accordance with the Qt Commercial License | ||
23 | ** Agreement provided with the Software. | ||
24 | ** | ||
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
27 | ** | ||
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
29 | ** information about Qt Commercial License Agreements. | ||
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | ||
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
32 | ** | ||
33 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
34 | ** not clear to you. | ||
35 | ** | ||
36 | **********************************************************************/ | ||
37 | |||
38 | #include "qplatformdefs.h" | ||
39 | |||
40 | #include "qasciidict.h" | ||
41 | #include <limits.h> | ||
42 | #include <stdio.h> | ||
43 | #include <limits.h> | ||
44 | #include <stdarg.h> | ||
45 | #include <stdlib.h> | ||
46 | |||
47 | |||
48 | /*! | ||
49 | \relates QApplication | ||
50 | |||
51 | Returns the Qt version number as a string, for example, "2.3.0" or | ||
52 | "3.0.5". | ||
53 | |||
54 | The \c QT_VERSION define has the numeric value in the form: | ||
55 | 0xmmiibb (m = major, i = minor, b = bugfix). For example, Qt | ||
56 | 3.0.5's \c QT_VERSION is 0x030005. | ||
57 | */ | ||
58 | |||
59 | const char *qVersion() | ||
60 | { | ||
61 | return QT_VERSION_STR; | ||
62 | } | ||
63 | |||
64 | |||
65 | /***************************************************************************** | ||
66 | System detection routines | ||
67 | *****************************************************************************/ | ||
68 | |||
69 | static bool si_alreadyDone = FALSE; | ||
70 | static int si_wordSize; | ||
71 | static bool si_bigEndian; | ||
72 | |||
73 | /*! | ||
74 | \relates QApplication | ||
75 | |||
76 | Obtains information about the system. | ||
77 | |||
78 | The system's word size in bits (typically 32) is returned in \a | ||
79 | *wordSize. The \a *bigEndian is set to TRUE if this is a big-endian | ||
80 | machine, or to FALSE if this is a little-endian machine. | ||
81 | |||
82 | In debug mode, this function calls qFatal() with a message if the | ||
83 | computer is truly weird (i.e. different endianness for 16 bit and | ||
84 | 32 bit integers); in release mode it returns FALSE. | ||
85 | */ | ||
86 | |||
87 | bool qSysInfo( int *wordSize, bool *bigEndian ) | ||
88 | { | ||
89 | #if defined(QT_CHECK_NULL) | ||
90 | Q_ASSERT( wordSize != 0 ); | ||
91 | Q_ASSERT( bigEndian != 0 ); | ||
92 | #endif | ||
93 | |||
94 | if ( si_alreadyDone ) { // run it only once | ||
95 | *wordSize = si_wordSize; | ||
96 | *bigEndian = si_bigEndian; | ||
97 | return TRUE; | ||
98 | } | ||
99 | |||
100 | si_wordSize = 0; | ||
101 | Q_ULONG n = (Q_ULONG)(~0); | ||
102 | while ( n ) { // detect word size | ||
103 | si_wordSize++; | ||
104 | n /= 2; | ||
105 | } | ||
106 | *wordSize = si_wordSize; | ||
107 | |||
108 | if ( *wordSize != 64 && | ||
109 | *wordSize != 32 && | ||
110 | *wordSize != 16 ) { // word size: 16, 32 or 64 | ||
111 | #if defined(QT_CHECK_RANGE) | ||
112 | qFatal( "qSysInfo: Unsupported system word size %d", *wordSize ); | ||
113 | #endif | ||
114 | return FALSE; | ||
115 | } | ||
116 | if ( sizeof(Q_INT8) != 1 || sizeof(Q_INT16) != 2 || sizeof(Q_INT32) != 4 || | ||
117 | sizeof(Q_ULONG)*8 != si_wordSize || sizeof(float) != 4 || sizeof(double) != 8 ) { | ||
118 | #if defined(QT_CHECK_RANGE) | ||
119 | qFatal( "qSysInfo: Unsupported system data type size" ); | ||
120 | #endif | ||
121 | return FALSE; | ||
122 | } | ||
123 | |||
124 | bool be16, be32; // determine byte ordering | ||
125 | short ns = 0x1234; | ||
126 | int nl = 0x12345678; | ||
127 | |||
128 | unsigned char *p = (unsigned char *)(&ns);// 16-bit integer | ||
129 | be16 = *p == 0x12; | ||
130 | |||
131 | p = (unsigned char *)(&nl); // 32-bit integer | ||
132 | if ( p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78 ) | ||
133 | be32 = TRUE; | ||
134 | else | ||
135 | if ( p[0] == 0x78 && p[1] == 0x56 && p[2] == 0x34 && p[3] == 0x12 ) | ||
136 | be32 = FALSE; | ||
137 | else | ||
138 | be32 = !be16; | ||
139 | |||
140 | if ( be16 != be32 ) { // strange machine! | ||
141 | #if defined(QT_CHECK_RANGE) | ||
142 | qFatal( "qSysInfo: Inconsistent system byte order" ); | ||
143 | #endif | ||
144 | return FALSE; | ||
145 | } | ||
146 | |||
147 | *bigEndian = si_bigEndian = be32; | ||
148 | si_alreadyDone = TRUE; | ||
149 | return TRUE; | ||
150 | } | ||
151 | |||
152 | #if defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN) | ||
153 | bool qt_winunicode; | ||
154 | |||
155 | #include "qt_windows.h" | ||
156 | |||
157 | int qWinVersion() | ||
158 | { | ||
159 | #ifndef VER_PLATFORM_WIN32s | ||
160 | #define VER_PLATFORM_WIN32s 0 | ||
161 | #endif | ||
162 | #ifndef VER_PLATFORM_WIN32_WINDOWS | ||
163 | #define VER_PLATFORM_WIN32_WINDOWS 1 | ||
164 | #endif | ||
165 | #ifndef VER_PLATFORM_WIN32_NT | ||
166 | #define VER_PLATFORM_WIN32_NT 2 | ||
167 | #endif | ||
168 | |||
169 | static int winver = Qt::WV_NT; | ||
170 | static int t=0; | ||
171 | if ( !t ) { | ||
172 | t=1; | ||
173 | #ifdef Q_OS_TEMP | ||
174 | OSVERSIONINFOW osver; | ||
175 | osver.dwOSVersionInfoSize = sizeof(osver); | ||
176 | GetVersionEx( &osver ); | ||
177 | #else | ||
178 | OSVERSIONINFOA osver; | ||
179 | osver.dwOSVersionInfoSize = sizeof(osver); | ||
180 | GetVersionExA( &osver ); | ||
181 | #endif | ||
182 | switch ( osver.dwPlatformId ) { | ||
183 | case VER_PLATFORM_WIN32s: | ||
184 | winver = Qt::WV_32s; | ||
185 | break; | ||
186 | case VER_PLATFORM_WIN32_WINDOWS: | ||
187 | // We treat Windows Me (minor 90) the same as Windows 98 | ||
188 | if ( ( osver.dwMinorVersion == 10 ) || ( osver.dwMinorVersion == 90 ) ) | ||
189 | winver = Qt::WV_98; | ||
190 | else | ||
191 | winver = Qt::WV_95; | ||
192 | break; | ||
193 | default: // VER_PLATFORM_WIN32_NT | ||
194 | if ( osver.dwMajorVersion < 5 ) { | ||
195 | winver = Qt::WV_NT; | ||
196 | } else if ( osver.dwMinorVersion == 0 ) { | ||
197 | winver = Qt::WV_2000; | ||
198 | } else { | ||
199 | winver = Qt::WV_XP; | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | |||
204 | #if defined(UNICODE) | ||
205 | if ( winver & Qt::WV_NT_based ) | ||
206 | qt_winunicode = TRUE; | ||
207 | else | ||
208 | #endif | ||
209 | qt_winunicode = FALSE; | ||
210 | |||
211 | return winver; | ||
212 | } | ||
213 | |||
214 | Qt::WindowsVersion qt_winver = (Qt::WindowsVersion)qWinVersion(); | ||
215 | #endif | ||
216 | |||
217 | |||
218 | /***************************************************************************** | ||
219 | Debug output routines | ||
220 | *****************************************************************************/ | ||
221 | |||
222 | /*! | ||
223 | \fn void qDebug( const char *msg, ... ) | ||
224 | |||
225 | \relates QApplication | ||
226 | |||
227 | Prints a debug message \a msg, or calls the message handler (if it | ||
228 | has been installed). | ||
229 | |||
230 | This function takes a format string and a list of arguments, | ||
231 | similar to the C printf() function. | ||
232 | |||
233 | Example: | ||
234 | \code | ||
235 | qDebug( "my window handle = %x", myWidget->id() ); | ||
236 | \endcode | ||
237 | |||
238 | Under X11, the text is printed to stderr. Under Windows, the text | ||
239 | is sent to the debugger. | ||
240 | |||
241 | \warning The internal buffer is limited to 8196 bytes (including | ||
242 | the '\0'-terminator). | ||
243 | |||
244 | \warning Passing (const char *)0 as argument to qDebug might lead | ||
245 | to crashes on certain platforms due to the platforms printf implementation. | ||
246 | |||
247 | \sa qWarning(), qFatal(), qInstallMsgHandler(), | ||
248 | \link debug.html Debugging\endlink | ||
249 | */ | ||
250 | |||
251 | /*! | ||
252 | \fn void qWarning( const char *msg, ... ) | ||
253 | |||
254 | \relates QApplication | ||
255 | |||
256 | Prints a warning message \a msg, or calls the message handler (if | ||
257 | it has been installed). | ||
258 | |||
259 | This function takes a format string and a list of arguments, | ||
260 | similar to the C printf() function. | ||
261 | |||
262 | Example: | ||
263 | \code | ||
264 | void f( int c ) | ||
265 | { | ||
266 | if ( c > 200 ) | ||
267 | qWarning( "f: bad argument, c == %d", c ); | ||
268 | } | ||
269 | \endcode | ||
270 | |||
271 | Under X11, the text is printed to stderr. Under Windows, the text | ||
272 | is sent to the debugger. | ||
273 | |||
274 | \warning The internal buffer is limited to 8196 bytes (including | ||
275 | the '\0'-terminator). | ||
276 | |||
277 | \warning Passing (const char *)0 as argument to qWarning might lead | ||
278 | to crashes on certain platforms due to the platforms printf implementation. | ||
279 | |||
280 | \sa qDebug(), qFatal(), qInstallMsgHandler(), | ||
281 | \link debug.html Debugging\endlink | ||
282 | */ | ||
283 | |||
284 | /*! | ||
285 | \fn void qFatal( const char *msg, ... ) | ||
286 | |||
287 | \relates QApplication | ||
288 | |||
289 | Prints a fatal error message \a msg and exits, or calls the | ||
290 | message handler (if it has been installed). | ||
291 | |||
292 | This function takes a format string and a list of arguments, | ||
293 | similar to the C printf() function. | ||
294 | |||
295 | Example: | ||
296 | \code | ||
297 | int divide( int a, int b ) | ||
298 | { | ||
299 | if ( b == 0 ) // program error | ||
300 | qFatal( "divide: cannot divide by zero" ); | ||
301 | return a/b; | ||
302 | } | ||
303 | \endcode | ||
304 | |||
305 | Under X11, the text is printed to stderr. Under Windows, the text | ||
306 | is sent to the debugger. | ||
307 | |||
308 | \warning The internal buffer is limited to 8196 bytes (including | ||
309 | the '\0'-terminator). | ||
310 | |||
311 | \warning Passing (const char *)0 as argument to qFatal might lead | ||
312 | to crashes on certain platforms due to the platforms printf implementation. | ||
313 | |||
314 | \sa qDebug(), qWarning(), qInstallMsgHandler(), | ||
315 | \link debug.html Debugging\endlink | ||
316 | */ | ||
317 | |||
318 | |||
319 | static QtMsgHandler handler = 0; // pointer to debug handler | ||
320 | static const int QT_BUFFER_LENGTH = 8196;// internal buffer length | ||
321 | |||
322 | |||
323 | #ifdef Q_OS_MAC | ||
324 | const unsigned char * p_str(const char * c, int len=-1) | ||
325 | { | ||
326 | const int maxlen = 255; | ||
327 | if(len == -1) | ||
328 | len = qstrlen(c); | ||
329 | if(len > maxlen) { | ||
330 | qWarning( "p_str len must never exceed %d", maxlen ); | ||
331 | len = maxlen; | ||
332 | } | ||
333 | unsigned char *ret = (unsigned char*)malloc(len+2); | ||
334 | *ret=len; | ||
335 | memcpy(((char *)ret)+1,c,len); | ||
336 | *(ret+len+1) = '\0'; | ||
337 | return ret; | ||
338 | } | ||
339 | |||
340 | const unsigned char * p_str(const QString &s) | ||
341 | { | ||
342 | return p_str(s, s.length()); | ||
343 | } | ||
344 | |||
345 | QCString p2qstring(const unsigned char *c) { | ||
346 | char *arr = (char *)malloc(c[0] + 1); | ||
347 | memcpy(arr, c+1, c[0]); | ||
348 | arr[c[0]] = '\0'; | ||
349 | QCString ret = arr; | ||
350 | delete arr; | ||
351 | return ret; | ||
352 | } | ||
353 | #endif | ||
354 | |||
355 | |||
356 | #ifdef Q_CC_MWERKS | ||
357 | |||
358 | #include "qt_mac.h" | ||
359 | |||
360 | extern bool qt_is_gui_used; | ||
361 | static void mac_default_handler( const char *msg ) | ||
362 | { | ||
363 | if ( qt_is_gui_used ) { | ||
364 | const char *p = p_str(msg); | ||
365 | DebugStr(p); | ||
366 | free(p); | ||
367 | } else { | ||
368 | fprintf( stderr, msg ); | ||
369 | } | ||
370 | } | ||
371 | |||
372 | #endif | ||
373 | |||
374 | |||
375 | void qDebug( const char *msg, ... ) | ||
376 | { | ||
377 | char buf[QT_BUFFER_LENGTH]; | ||
378 | va_list ap; | ||
379 | va_start( ap, msg ); // use variable arg list | ||
380 | if ( handler ) { | ||
381 | #if defined(QT_VSNPRINTF) | ||
382 | QT_VSNPRINTF( buf, QT_BUFFER_LENGTH, msg, ap ); | ||
383 | #else | ||
384 | vsprintf( buf, msg, ap ); | ||
385 | #endif | ||
386 | va_end( ap ); | ||
387 | (*handler)( QtDebugMsg, buf ); | ||
388 | } else { | ||
389 | #if defined(Q_CC_MWERKS) | ||
390 | vsprintf( buf, msg, ap ); // ### is there no vsnprintf()? | ||
391 | va_end( ap ); | ||
392 | mac_default_handler(buf); | ||
393 | #else | ||
394 | vfprintf( stderr, msg, ap ); | ||
395 | va_end( ap ); | ||
396 | fprintf( stderr, "\n" ); // add newline | ||
397 | #endif | ||
398 | } | ||
399 | } | ||
400 | |||
401 | // copied... this looks really bad. | ||
402 | void debug( const char *msg, ... ) | ||
403 | { | ||
404 | char buf[QT_BUFFER_LENGTH]; | ||
405 | va_list ap; | ||
406 | va_start( ap, msg ); // use variable arg list | ||
407 | if ( handler ) { | ||
408 | #if defined(QT_VSNPRINTF) | ||
409 | QT_VSNPRINTF( buf, QT_BUFFER_LENGTH, msg, ap ); | ||
410 | #else | ||
411 | vsprintf( buf, msg, ap ); | ||
412 | #endif | ||
413 | va_end( ap ); | ||
414 | (*handler)( QtDebugMsg, buf ); | ||
415 | } else { | ||
416 | #ifdef Q_CC_MWERKS | ||
417 | vsprintf( buf, msg, ap ); // ### is there no vsnprintf()? | ||
418 | va_end( ap ); | ||
419 | mac_default_handler(buf); | ||
420 | #else | ||
421 | vfprintf( stderr, msg, ap ); | ||
422 | va_end( ap ); | ||
423 | fprintf( stderr, "\n" ); // add newline | ||
424 | #endif | ||
425 | } | ||
426 | } | ||
427 | |||
428 | void qWarning( const char *msg, ... ) | ||
429 | { | ||
430 | char buf[QT_BUFFER_LENGTH]; | ||
431 | va_list ap; | ||
432 | va_start( ap, msg ); // use variable arg list | ||
433 | if ( handler ) { | ||
434 | #if defined(QT_VSNPRINTF) | ||
435 | QT_VSNPRINTF( buf, QT_BUFFER_LENGTH, msg, ap ); | ||
436 | #else | ||
437 | vsprintf( buf, msg, ap ); | ||
438 | #endif | ||
439 | va_end( ap ); | ||
440 | (*handler)( QtWarningMsg, buf ); | ||
441 | } else { | ||
442 | #ifdef Q_CC_MWERKS | ||
443 | vsprintf( buf, msg, ap ); // ### is there no vsnprintf()? | ||
444 | va_end( ap ); | ||
445 | mac_default_handler(buf); | ||
446 | #else | ||
447 | vfprintf( stderr, msg, ap ); | ||
448 | va_end( ap ); | ||
449 | fprintf( stderr, "\n" ); // add newline | ||
450 | #endif | ||
451 | } | ||
452 | } | ||
453 | |||
454 | |||
455 | // again, copied | ||
456 | void warning( const char *msg, ... ) | ||
457 | { | ||
458 | char buf[QT_BUFFER_LENGTH]; | ||
459 | va_list ap; | ||
460 | va_start( ap, msg ); // use variable arg list | ||
461 | if ( handler ) { | ||
462 | #if defined(QT_VSNPRINTF) | ||
463 | QT_VSNPRINTF( buf, QT_BUFFER_LENGTH, msg, ap ); | ||
464 | #else | ||
465 | vsprintf( buf, msg, ap ); | ||
466 | #endif | ||
467 | va_end( ap ); | ||
468 | (*handler)( QtWarningMsg, buf ); | ||
469 | } else { | ||
470 | #ifdef Q_CC_MWERKS | ||
471 | vsprintf( buf, msg, ap ); // ### is there no vsnprintf()? | ||
472 | va_end( ap ); | ||
473 | mac_default_handler(buf); | ||
474 | #else | ||
475 | vfprintf( stderr, msg, ap ); | ||
476 | va_end( ap ); | ||
477 | fprintf( stderr, "\n" ); // add newline | ||
478 | #endif | ||
479 | } | ||
480 | } | ||
481 | |||
482 | void qFatal( const char *msg, ... ) | ||
483 | { | ||
484 | char buf[QT_BUFFER_LENGTH]; | ||
485 | va_list ap; | ||
486 | va_start( ap, msg ); // use variable arg list | ||
487 | if ( handler ) { | ||
488 | #if defined(QT_VSNPRINTF) | ||
489 | QT_VSNPRINTF( buf, QT_BUFFER_LENGTH, msg, ap ); | ||
490 | #else | ||
491 | vsprintf( buf, msg, ap ); | ||
492 | #endif | ||
493 | va_end( ap ); | ||
494 | (*handler)( QtFatalMsg, buf ); | ||
495 | } else { | ||
496 | #ifdef Q_CC_MWERKS | ||
497 | vsprintf( buf, msg, ap ); // ### is there no vsnprintf()? | ||
498 | va_end( ap ); | ||
499 | mac_default_handler(buf); | ||
500 | #else | ||
501 | vfprintf( stderr, msg, ap ); | ||
502 | va_end( ap ); | ||
503 | fprintf( stderr, "\n" ); // add newline | ||
504 | #endif | ||
505 | #if defined(Q_OS_UNIX) && defined(QT_DEBUG) | ||
506 | abort(); // trap; generates core dump | ||
507 | #else | ||
508 | exit( 1 ); // goodbye cruel world | ||
509 | #endif | ||
510 | } | ||
511 | } | ||
512 | |||
513 | // yet again, copied | ||
514 | void fatal( const char *msg, ... ) | ||
515 | { | ||
516 | char buf[QT_BUFFER_LENGTH]; | ||
517 | va_list ap; | ||
518 | va_start( ap, msg ); // use variable arg list | ||
519 | if ( handler ) { | ||
520 | #if defined(QT_VSNPRINTF) | ||
521 | QT_VSNPRINTF( buf, QT_BUFFER_LENGTH, msg, ap ); | ||
522 | #else | ||
523 | vsprintf( buf, msg, ap ); | ||
524 | #endif | ||
525 | va_end( ap ); | ||
526 | (*handler)( QtFatalMsg, buf ); | ||
527 | } else { | ||
528 | #ifdef Q_CC_MWERKS | ||
529 | vsprintf( buf, msg, ap ); // ### is there no vsnprintf()? | ||
530 | va_end( ap ); | ||
531 | mac_default_handler(buf); | ||
532 | #else | ||
533 | vfprintf( stderr, msg, ap ); | ||
534 | va_end( ap ); | ||
535 | fprintf( stderr, "\n" ); // add newline | ||
536 | #endif | ||
537 | #if defined(Q_OS_UNIX) && defined(QT_DEBUG) | ||
538 | abort(); // trap; generates core dump | ||
539 | #else | ||
540 | exit( 1 ); // goodbye cruel world | ||
541 | #endif | ||
542 | } | ||
543 | } | ||
544 | |||
545 | /*! | ||
546 | \relates QApplication | ||
547 | |||
548 | Prints the message \a msg and uses \a code to get a system specific | ||
549 | error message. When \a code is -1 (the default), the system's last | ||
550 | error code will be used if possible. Use this method to handle | ||
551 | failures in platform specific API calls. | ||
552 | |||
553 | This function does nothing when Qt is built with \c QT_NO_DEBUG | ||
554 | defined. | ||
555 | */ | ||
556 | void qSystemWarning( const char* msg, int code ) | ||
557 | { | ||
558 | #ifndef QT_NO_DEBUG | ||
559 | #if defined(Q_OS_WIN32) | ||
560 | if ( code == -1 ) | ||
561 | code = GetLastError(); | ||
562 | |||
563 | if ( !code ) | ||
564 | return; | ||
565 | |||
566 | #ifdef Q_OS_TEMP | ||
567 | unsigned short *string; | ||
568 | |||
569 | FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, | ||
570 | NULL, | ||
571 | code, | ||
572 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | ||
573 | (LPTSTR)&string, | ||
574 | 0, | ||
575 | NULL ); | ||
576 | |||
577 | qWarning( "%s\n\tError code %d - %s (###may need fixing in qglobal.h)", msg, code, (const char *)string ); | ||
578 | #else | ||
579 | char* string; | ||
580 | |||
581 | FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, | ||
582 | NULL, | ||
583 | code, | ||
584 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | ||
585 | (char*)&string, | ||
586 | 0, | ||
587 | NULL ); | ||
588 | |||
589 | qWarning( "%s\n\tError code %d - %s", msg, code, (const char*)string ); | ||
590 | #endif | ||
591 | |||
592 | LocalFree( (HLOCAL)string ); | ||
593 | #else | ||
594 | if ( code != -1 ) | ||
595 | qWarning( "%s\n\tError code %d - %s", msg, code, strerror( code ) ); | ||
596 | else | ||
597 | qWarning( msg ); | ||
598 | #endif | ||
599 | #endif | ||
600 | } | ||
601 | |||
602 | /*! | ||
603 | \fn void Q_ASSERT( bool test ) | ||
604 | |||
605 | \relates QApplication | ||
606 | |||
607 | Prints a warning message containing the source code file name and | ||
608 | line number if \a test is FALSE. | ||
609 | |||
610 | This is really a macro defined in \c qglobal.h. | ||
611 | |||
612 | Q_ASSERT is useful for testing pre- and post-conditions. | ||
613 | |||
614 | Example: | ||
615 | \code | ||
616 | // | ||
617 | // File: div.cpp | ||
618 | // | ||
619 | |||
620 | #include <qglobal.h> | ||
621 | |||
622 | int divide( int a, int b ) | ||
623 | { | ||
624 | Q_ASSERT( b != 0 ); // this is line 9 | ||
625 | return a/b; | ||
626 | } | ||
627 | \endcode | ||
628 | |||
629 | If \c b is zero, the Q_ASSERT statement will output the following | ||
630 | message using the qWarning() function: | ||
631 | \code | ||
632 | ASSERT: "b == 0" in div.cpp (9) | ||
633 | \endcode | ||
634 | |||
635 | \sa qWarning(), \link debug.html Debugging\endlink | ||
636 | */ | ||
637 | |||
638 | |||
639 | /*! | ||
640 | \fn void Q_CHECK_PTR( void *p ) | ||
641 | |||
642 | \relates QApplication | ||
643 | |||
644 | If \a p is null, a fatal messages says that the program ran out of | ||
645 | memory and exits. If \e p is not null, nothing happens. | ||
646 | |||
647 | This is really a macro defined in \c qglobal.h. | ||
648 | |||
649 | Example: | ||
650 | \code | ||
651 | int *a; | ||
652 | |||
653 | Q_CHECK_PTR( a = new int[80] ); // WRONG! | ||
654 | |||
655 | a = new int[80]; // Right | ||
656 | Q_CHECK_PTR( a ); | ||
657 | \endcode | ||
658 | |||
659 | \sa qFatal(), \link debug.html Debugging\endlink | ||
660 | */ | ||
661 | |||
662 | |||
663 | // | ||
664 | // The Q_CHECK_PTR macro calls this function to check if an allocation went ok. | ||
665 | // | ||
666 | #if (QT_VERSION-0 >= 0x040000) | ||
667 | #if defined(Q_CC_GNU) | ||
668 | #warning "Change Q_CHECK_PTR to '{if ((p)==0) qt_check_pointer(__FILE__,__LINE__);}'" | ||
669 | #warning "No need for qt_check_pointer() to return a value - make it void!" | ||
670 | #endif | ||
671 | #endif | ||
672 | bool qt_check_pointer( bool c, const char *n, int l ) | ||
673 | { | ||
674 | if ( c ) | ||
675 | qWarning( "In file %s, line %d: Out of memory", n, l ); | ||
676 | return TRUE; | ||
677 | } | ||
678 | |||
679 | |||
680 | static bool firstObsoleteWarning(const char *obj, const char *oldfunc ) | ||
681 | { | ||
682 | static QAsciiDict<int> *obsoleteDict = 0; | ||
683 | if ( !obsoleteDict ) { // first time func is called | ||
684 | obsoleteDict = new QAsciiDict<int>; | ||
685 | #if defined(QT_DEBUG) | ||
686 | qDebug( | ||
687 | "You are using obsolete functions in the Qt library. Call the function\n" | ||
688 | "qSuppressObsoleteWarnings() to suppress obsolete warnings.\n" | ||
689 | ); | ||
690 | #endif | ||
691 | } | ||
692 | QCString s( obj ); | ||
693 | s += "::"; | ||
694 | s += oldfunc; | ||
695 | if ( obsoleteDict->find(s.data()) == 0 ) { | ||
696 | obsoleteDict->insert( s.data(), (int*)1 );// anything different from 0 | ||
697 | return TRUE; | ||
698 | } | ||
699 | return FALSE; | ||
700 | } | ||
701 | |||
702 | static bool suppressObsolete = FALSE; | ||
703 | |||
704 | void qSuppressObsoleteWarnings( bool suppress ) | ||
705 | { | ||
706 | suppressObsolete = suppress; | ||
707 | } | ||
708 | |||
709 | void qObsolete( const char *obj, const char *oldfunc, const char *newfunc ) | ||
710 | { | ||
711 | if ( suppressObsolete ) | ||
712 | return; | ||
713 | if ( !firstObsoleteWarning(obj, oldfunc) ) | ||
714 | return; | ||
715 | if ( obj ) | ||
716 | qDebug( "%s::%s: This function is obsolete, use %s instead.", | ||
717 | obj, oldfunc, newfunc ); | ||
718 | else | ||
719 | qDebug( "%s: This function is obsolete, use %s instead.", | ||
720 | oldfunc, newfunc ); | ||
721 | } | ||
722 | |||
723 | void qObsolete( const char *obj, const char *oldfunc ) | ||
724 | { | ||
725 | if ( suppressObsolete ) | ||
726 | return; | ||
727 | if ( !firstObsoleteWarning(obj, oldfunc) ) | ||
728 | return; | ||
729 | if ( obj ) | ||
730 | qDebug( "%s::%s: This function is obsolete.", obj, oldfunc ); | ||
731 | else | ||
732 | qDebug( "%s: This function is obsolete.", oldfunc ); | ||
733 | } | ||
734 | |||
735 | void qObsolete( const char *message ) | ||
736 | { | ||
737 | if ( suppressObsolete ) | ||
738 | return; | ||
739 | if ( !firstObsoleteWarning( "Qt", message) ) | ||
740 | return; | ||
741 | qDebug( "%s", message ); | ||
742 | } | ||
743 | |||
744 | |||
745 | /*! | ||
746 | \relates QApplication | ||
747 | |||
748 | Installs a Qt message handler \a h. Returns a pointer to the | ||
749 | message handler previously defined. | ||
750 | |||
751 | The message handler is a function that prints out debug messages, | ||
752 | warnings and fatal error messages. The Qt library (debug version) | ||
753 | contains hundreds of warning messages that are printed when | ||
754 | internal errors (usually invalid function arguments) occur. If you | ||
755 | implement your own message handler, you get total control of these | ||
756 | messages. | ||
757 | |||
758 | The default message handler prints the message to the standard | ||
759 | output under X11 or to the debugger under Windows. If it is a | ||
760 | fatal message, the application aborts immediately. | ||
761 | |||
762 | Only one message handler can be defined, since this is usually | ||
763 | done on an application-wide basis to control debug output. | ||
764 | |||
765 | To restore the message handler, call \c qInstallMsgHandler(0). | ||
766 | |||
767 | Example: | ||
768 | \code | ||
769 | #include <qapplication.h> | ||
770 | #include <stdio.h> | ||
771 | #include <stdlib.h> | ||
772 | |||
773 | void myMessageOutput( QtMsgType type, const char *msg ) | ||
774 | { | ||
775 | switch ( type ) { | ||
776 | case QtDebugMsg: | ||
777 | fprintf( stderr, "Debug: %s\n", msg ); | ||
778 | break; | ||
779 | case QtWarningMsg: | ||
780 | fprintf( stderr, "Warning: %s\n", msg ); | ||
781 | break; | ||
782 | case QtFatalMsg: | ||
783 | fprintf( stderr, "Fatal: %s\n", msg ); | ||
784 | abort(); // deliberately core dump | ||
785 | } | ||
786 | } | ||
787 | |||
788 | int main( int argc, char **argv ) | ||
789 | { | ||
790 | qInstallMsgHandler( myMessageOutput ); | ||
791 | QApplication a( argc, argv ); | ||
792 | ... | ||
793 | return a.exec(); | ||
794 | } | ||
795 | \endcode | ||
796 | |||
797 | \sa qDebug(), qWarning(), qFatal(), \link debug.html Debugging\endlink | ||
798 | */ | ||
799 | |||
800 | QtMsgHandler qInstallMsgHandler( QtMsgHandler h ) | ||
801 | { | ||
802 | QtMsgHandler old = handler; | ||
803 | handler = h; | ||
804 | return old; | ||
805 | } | ||
806 | |||
807 | |||
808 | /* | ||
809 | Dijkstra's bisection algorithm to find the square root as an integer. | ||
810 | Deliberately not exported as part of the Qt API, but used in both | ||
811 | qsimplerichtext.cpp and qgfxraster_qws.cpp | ||
812 | */ | ||
813 | unsigned int qt_int_sqrt( unsigned int n ) | ||
814 | { | ||
815 | // n must be in the range 0...UINT_MAX/2-1 | ||
816 | if ( n >= ( UINT_MAX>>2 ) ) { | ||
817 | unsigned int r = 2 * qt_int_sqrt( n / 4 ); | ||
818 | unsigned int r2 = r + 1; | ||
819 | return ( n >= r2 * r2 ) ? r2 : r; | ||
820 | } | ||
821 | uint h, p= 0, q= 1, r= n; | ||
822 | while ( q <= n ) | ||
823 | q <<= 2; | ||
824 | while ( q != 1 ) { | ||
825 | q >>= 2; | ||
826 | h= p + q; | ||
827 | p >>= 1; | ||
828 | if ( r >= h ) { | ||
829 | p += q; | ||
830 | r -= h; | ||
831 | } | ||
832 | } | ||
833 | return p; | ||
834 | } | ||
835 | |||