author | mickeyl <mickeyl> | 2003-03-30 02:17:58 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-03-30 02:17:58 (UTC) |
commit | 35e4d0b2a71b8ca15baeb0b0383af21fc1d8d3ae (patch) (unidiff) | |
tree | 335bb12952530b397788e0b02e2072c48788b920 /libopie2 | |
parent | 4ace7ac9fff84df80d3066236ff970b9b393cf48 (diff) | |
download | opie-35e4d0b2a71b8ca15baeb0b0383af21fc1d8d3ae.zip opie-35e4d0b2a71b8ca15baeb0b0383af21fc1d8d3ae.tar.gz opie-35e4d0b2a71b8ca15baeb0b0383af21fc1d8d3ae.tar.bz2 |
one more fix for gcc 2.9x
-rw-r--r-- | libopie2/opiecore/odebug.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/libopie2/opiecore/odebug.cpp b/libopie2/opiecore/odebug.cpp index b4eaf2d..b2a37bc 100644 --- a/libopie2/opiecore/odebug.cpp +++ b/libopie2/opiecore/odebug.cpp | |||
@@ -1,511 +1,515 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | (C) 2003 Michael 'Mickey' Lauer (mickey@tm.informatik.uni-frankfurt.de) | 3 | (C) 2003 Michael 'Mickey' Lauer (mickey@tm.informatik.uni-frankfurt.de) |
4 | Inspired by the KDE debug classes, which are | 4 | Inspired by the KDE debug classes, which are |
5 | (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) | 5 | (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) |
6 | (C) 2002 Holger Freyther (freyther@kde.org) | 6 | (C) 2002 Holger Freyther (freyther@kde.org) |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | */ | 31 | */ |
32 | 32 | ||
33 | // Include this header without OPIE_NO_DEBUG defined to avoid having the oDebugInfo | 33 | // Include this header without OPIE_NO_DEBUG defined to avoid having the oDebugInfo |
34 | // functions inlined to noops (which would then conflict with their definition here). | 34 | // functions inlined to noops (which would then conflict with their definition here). |
35 | 35 | ||
36 | #include <opie2/odebug.h> | 36 | #include <opie2/odebug.h> |
37 | 37 | ||
38 | #ifdef OPIE_NO_DEBUG | 38 | #ifdef OPIE_NO_DEBUG |
39 | #undef odDebug | 39 | #undef odDebug |
40 | #undef odBacktrace | 40 | #undef odBacktrace |
41 | #endif | 41 | #endif |
42 | 42 | ||
43 | /* OPIE */ | 43 | /* OPIE */ |
44 | 44 | ||
45 | #include <opie2/oapplication.h> | 45 | #include <opie2/oapplication.h> |
46 | #include <opie2/oglobalsettings.h> | 46 | #include <opie2/oglobalsettings.h> |
47 | #include <opie2/oconfig.h> | 47 | #include <opie2/oconfig.h> |
48 | 48 | ||
49 | /* QT */ | 49 | /* QT */ |
50 | 50 | ||
51 | #include <qbrush.h> | 51 | #include <qbrush.h> |
52 | #include <qdatetime.h> | 52 | #include <qdatetime.h> |
53 | #include <qfile.h> | 53 | #include <qfile.h> |
54 | #include <qhostaddress.h> | 54 | #include <qhostaddress.h> |
55 | #include <qmessagebox.h> | 55 | #include <qmessagebox.h> |
56 | #include <qintdict.h> | 56 | #include <qintdict.h> |
57 | #include <qpoint.h> | 57 | #include <qpoint.h> |
58 | #include <qrect.h> | 58 | #include <qrect.h> |
59 | #include <qregion.h> | 59 | #include <qregion.h> |
60 | #include <qsize.h> | 60 | #include <qsize.h> |
61 | #include <qsocketdevice.h> | 61 | #include <qsocketdevice.h> |
62 | #include <qstring.h> | 62 | #include <qstring.h> |
63 | #include <qstringlist.h> | 63 | #include <qstringlist.h> |
64 | #include <qtextstream.h> | 64 | #include <qtextstream.h> |
65 | 65 | ||
66 | /* UNIX */ | 66 | /* UNIX */ |
67 | 67 | ||
68 | #include <stdlib.h> // abort | 68 | #include <stdlib.h> // abort |
69 | #include <unistd.h> // getpid | 69 | #include <unistd.h> // getpid |
70 | #include <stdarg.h> // vararg stuff | 70 | #include <stdarg.h> // vararg stuff |
71 | #include <ctype.h> // isprint | 71 | #include <ctype.h> // isprint |
72 | #include <syslog.h> | 72 | #include <syslog.h> |
73 | #include <errno.h> | 73 | #include <errno.h> |
74 | #include <string.h> | 74 | #include <string.h> |
75 | 75 | ||
76 | #ifndef OPIE_NO_BACKTRACE | 76 | #ifndef OPIE_NO_BACKTRACE |
77 | #include <execinfo.h> | 77 | #include <execinfo.h> |
78 | #endif | 78 | #endif |
79 | 79 | ||
80 | 80 | ||
81 | /*====================================================================================== | 81 | /*====================================================================================== |
82 | * debug levels | 82 | * debug levels |
83 | *======================================================================================*/ | 83 | *======================================================================================*/ |
84 | 84 | ||
85 | enum DebugLevels { | 85 | enum DebugLevels { |
86 | ODEBUG_INFO = 0, | 86 | ODEBUG_INFO = 0, |
87 | ODEBUG_WARN = 1, | 87 | ODEBUG_WARN = 1, |
88 | ODEBUG_ERROR = 2, | 88 | ODEBUG_ERROR = 2, |
89 | ODEBUG_FATAL = 3 | 89 | ODEBUG_FATAL = 3 |
90 | }; | 90 | }; |
91 | 91 | ||
92 | /*====================================================================================== | 92 | /*====================================================================================== |
93 | * oDebug private data | 93 | * oDebug private data |
94 | *======================================================================================*/ | 94 | *======================================================================================*/ |
95 | 95 | ||
96 | /*====================================================================================== | 96 | /*====================================================================================== |
97 | * the main debug function | 97 | * the main debug function |
98 | *======================================================================================*/ | 98 | *======================================================================================*/ |
99 | 99 | ||
100 | static void oDebugBackend( unsigned short level, unsigned int area, const char *data) | 100 | static void oDebugBackend( unsigned short level, unsigned int area, const char *data) |
101 | { | 101 | { |
102 | //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data ); | 102 | //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data ); |
103 | 103 | ||
104 | // ML: OPIE doesn't use areacodes at the moment. See the KDE debug classes for an | 104 | // ML: OPIE doesn't use areacodes at the moment. See the KDE debug classes for an |
105 | // ML: example use. I think it's not necessary to implement such a strategy here. | 105 | // ML: example use. I think it's not necessary to implement such a strategy here. |
106 | // ML: Comments? | 106 | // ML: Comments? |
107 | 107 | ||
108 | int priority = 0; | 108 | int priority = 0; |
109 | QString caption; | 109 | QString caption; |
110 | QString lev; | 110 | QString lev; |
111 | switch( level ) | 111 | switch( level ) |
112 | { | 112 | { |
113 | case ODEBUG_INFO: lev = "(Info)"; caption = "Info"; priority = LOG_INFO; break; | 113 | case ODEBUG_INFO: lev = "(Info)"; caption = "Info"; priority = LOG_INFO; break; |
114 | case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break; | 114 | case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break; |
115 | case ODEBUG_FATAL: lev = "(Fatal)"; caption = "Fatal Error"; priority = LOG_CRIT; break; | 115 | case ODEBUG_FATAL: lev = "(Fatal)"; caption = "Fatal Error"; priority = LOG_CRIT; break; |
116 | default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." ); | 116 | default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." ); |
117 | case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break; | 117 | case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break; |
118 | } | 118 | } |
119 | 119 | ||
120 | short output = OGlobalSettings::debugMode(); | 120 | short output = OGlobalSettings::debugMode(); |
121 | if (!oApp && (output == 1)) | 121 | if (!oApp && (output == 1)) |
122 | { | 122 | { |
123 | qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" ); | 123 | qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" ); |
124 | output = 2; // need an application object to use MsgBox | 124 | output = 2; // need an application object to use MsgBox |
125 | } | 125 | } |
126 | 126 | ||
127 | QString areaName = (oApp) ? oApp->appName() : "<unknown>"; | 127 | // gcc 2.9x is dumb and sucks... can you hear it? |
128 | //QString areaName = (oApp) ? oApp->appName() : "<unknown>"; | ||
129 | QString areaName; | ||
130 | if ( oApp ) areaName = oApp->appName(); | ||
131 | else areaName = "<unknown>"; | ||
128 | 132 | ||
129 | // Output | 133 | // Output |
130 | switch( output ) | 134 | switch( output ) |
131 | { | 135 | { |
132 | case -1: // ignore | 136 | case -1: // ignore |
133 | { | 137 | { |
134 | return; | 138 | return; |
135 | } | 139 | } |
136 | case 0: // File | 140 | case 0: // File |
137 | { | 141 | { |
138 | QString outputFilename = OGlobalSettings::debugOutput(); | 142 | QString outputFilename = OGlobalSettings::debugOutput(); |
139 | 143 | ||
140 | const int BUFSIZE = 4096; | 144 | const int BUFSIZE = 4096; |
141 | char buf[BUFSIZE] = ""; | 145 | char buf[BUFSIZE] = ""; |
142 | buf[BUFSIZE-1] = '\0'; | 146 | buf[BUFSIZE-1] = '\0'; |
143 | int nSize; | 147 | int nSize; |
144 | 148 | ||
145 | nSize = snprintf( buf, BUFSIZE-1, "%s: %s", (const char*) areaName, data); | 149 | nSize = snprintf( buf, BUFSIZE-1, "%s: %s", (const char*) areaName, data); |
146 | 150 | ||
147 | QFile outputFile( outputFilename ); | 151 | QFile outputFile( outputFilename ); |
148 | if ( outputFile.open( IO_WriteOnly | IO_Append ) ) | 152 | if ( outputFile.open( IO_WriteOnly | IO_Append ) ) |
149 | { | 153 | { |
150 | if ( ( nSize == -1 ) || ( nSize >= BUFSIZE ) ) | 154 | if ( ( nSize == -1 ) || ( nSize >= BUFSIZE ) ) |
151 | { | 155 | { |
152 | outputFile.writeBlock( buf, BUFSIZE-1 ); | 156 | outputFile.writeBlock( buf, BUFSIZE-1 ); |
153 | } | 157 | } |
154 | else | 158 | else |
155 | { | 159 | { |
156 | outputFile.writeBlock( buf, nSize ); | 160 | outputFile.writeBlock( buf, nSize ); |
157 | } | 161 | } |
158 | } | 162 | } |
159 | else | 163 | else |
160 | { | 164 | { |
161 | qDebug( "ODebug: can't write to file '%s' (%s)", (const char*) outputFilename, strerror(errno) ); | 165 | qDebug( "ODebug: can't write to file '%s' (%s)", (const char*) outputFilename, strerror(errno) ); |
162 | } | 166 | } |
163 | break; | 167 | break; |
164 | } // automatic close of file here | 168 | } // automatic close of file here |
165 | 169 | ||
166 | case 1: // Message Box | 170 | case 1: // Message Box |
167 | { | 171 | { |
168 | // Since we are in opiecore here, we cannot use OMsgBox and use | 172 | // Since we are in opiecore here, we cannot use OMsgBox and use |
169 | // QMessageBox instead | 173 | // QMessageBox instead |
170 | 174 | ||
171 | caption += QString("(") + areaName + ")"; | 175 | caption += QString("(") + areaName + ")"; |
172 | QMessageBox::warning( 0L, caption, data, ("&OK") ); // tr? | 176 | QMessageBox::warning( 0L, caption, data, ("&OK") ); // tr? |
173 | break; | 177 | break; |
174 | } | 178 | } |
175 | 179 | ||
176 | case 2: // Shell | 180 | case 2: // Shell |
177 | { | 181 | { |
178 | FILE *output = stderr; | 182 | FILE *output = stderr; |
179 | fprintf( output, "%s: ", (const char*) areaName ); | 183 | fprintf( output, "%s: ", (const char*) areaName ); |
180 | fputs( data, output); | 184 | fputs( data, output); |
181 | break; | 185 | break; |
182 | } | 186 | } |
183 | 187 | ||
184 | case 3: // syslog | 188 | case 3: // syslog |
185 | { | 189 | { |
186 | syslog( priority, "%s", data); | 190 | syslog( priority, "%s", data); |
187 | break; | 191 | break; |
188 | } | 192 | } |
189 | 193 | ||
190 | case 4: // socket | 194 | case 4: // socket |
191 | { | 195 | { |
192 | QString destination = OGlobalSettings::debugOutput(); | 196 | QString destination = OGlobalSettings::debugOutput(); |
193 | if ( destination && destination.find(":") != -1 ) | 197 | if ( destination && destination.find(":") != -1 ) |
194 | { | 198 | { |
195 | QString host = destination.left( destination.find(":") ); | 199 | QString host = destination.left( destination.find(":") ); |
196 | QString port = destination.right( destination.length()-host.length()-1 ); | 200 | QString port = destination.right( destination.length()-host.length()-1 ); |
197 | QHostAddress addr; | 201 | QHostAddress addr; |
198 | addr.setAddress( host ); | 202 | addr.setAddress( host ); |
199 | // TODO: sanity check the address | 203 | // TODO: sanity check the address |
200 | QString line; | 204 | QString line; |
201 | line.sprintf( "%s: %s", (const char*) areaName, (const char*) data ); | 205 | line.sprintf( "%s: %s", (const char*) areaName, (const char*) data ); |
202 | QSocketDevice s( QSocketDevice::Datagram ); | 206 | QSocketDevice s( QSocketDevice::Datagram ); |
203 | int result = s.writeBlock( (const char*) line, line.length(), addr, port.toInt() ); | 207 | int result = s.writeBlock( (const char*) line, line.length(), addr, port.toInt() ); |
204 | if ( result == -1 ) | 208 | if ( result == -1 ) |
205 | { | 209 | { |
206 | qDebug( "ODebug: can't send to address '%s:%d' (%s)", (const char*) host, port.toInt(), strerror(errno) ); | 210 | qDebug( "ODebug: can't send to address '%s:%d' (%s)", (const char*) host, port.toInt(), strerror(errno) ); |
207 | } | 211 | } |
208 | } | 212 | } |
209 | break; | 213 | break; |
210 | } | 214 | } |
211 | } | 215 | } |
212 | 216 | ||
213 | // check if we should abort | 217 | // check if we should abort |
214 | 218 | ||
215 | /* | 219 | /* |
216 | 220 | ||
217 | if( ( nLevel == ODEBUG_FATAL ) | 221 | if( ( nLevel == ODEBUG_FATAL ) |
218 | && ( !oDebug_data->config || oDebug_data->config->readNumEntry( "AbortFatal", 1 ) ) ) | 222 | && ( !oDebug_data->config || oDebug_data->config->readNumEntry( "AbortFatal", 1 ) ) ) |
219 | abort(); | 223 | abort(); |
220 | 224 | ||
221 | */ | 225 | */ |
222 | } | 226 | } |
223 | 227 | ||
224 | /*====================================================================================== | 228 | /*====================================================================================== |
225 | * odbgstream | 229 | * odbgstream |
226 | *======================================================================================*/ | 230 | *======================================================================================*/ |
227 | 231 | ||
228 | odbgstream& perror( odbgstream &s) | 232 | odbgstream& perror( odbgstream &s) |
229 | { | 233 | { |
230 | return s << QString::fromLocal8Bit(strerror(errno)); | 234 | return s << QString::fromLocal8Bit(strerror(errno)); |
231 | } | 235 | } |
232 | 236 | ||
233 | odbgstream odDebug(int area) | 237 | odbgstream odDebug(int area) |
234 | { | 238 | { |
235 | return odbgstream(area, ODEBUG_INFO); | 239 | return odbgstream(area, ODEBUG_INFO); |
236 | } | 240 | } |
237 | odbgstream odDebug(bool cond, int area) | 241 | odbgstream odDebug(bool cond, int area) |
238 | { | 242 | { |
239 | if (cond) return odbgstream(area, ODEBUG_INFO); | 243 | if (cond) return odbgstream(area, ODEBUG_INFO); |
240 | else return odbgstream(0, 0, false); | 244 | else return odbgstream(0, 0, false); |
241 | } | 245 | } |
242 | 246 | ||
243 | odbgstream odError(int area) | 247 | odbgstream odError(int area) |
244 | { | 248 | { |
245 | return odbgstream("ERROR: ", area, ODEBUG_ERROR); | 249 | return odbgstream("ERROR: ", area, ODEBUG_ERROR); |
246 | } | 250 | } |
247 | 251 | ||
248 | odbgstream odError(bool cond, int area) | 252 | odbgstream odError(bool cond, int area) |
249 | { | 253 | { |
250 | if (cond) return odbgstream("ERROR: ", area, ODEBUG_ERROR); else return odbgstream(0,0,false); | 254 | if (cond) return odbgstream("ERROR: ", area, ODEBUG_ERROR); else return odbgstream(0,0,false); |
251 | } | 255 | } |
252 | 256 | ||
253 | odbgstream odWarning(int area) | 257 | odbgstream odWarning(int area) |
254 | { | 258 | { |
255 | return odbgstream("WARNING: ", area, ODEBUG_WARN); | 259 | return odbgstream("WARNING: ", area, ODEBUG_WARN); |
256 | } | 260 | } |
257 | 261 | ||
258 | odbgstream odWarning(bool cond, int area) | 262 | odbgstream odWarning(bool cond, int area) |
259 | { | 263 | { |
260 | if (cond) return odbgstream("WARNING: ", area, ODEBUG_WARN); else return odbgstream(0,0,false); | 264 | if (cond) return odbgstream("WARNING: ", area, ODEBUG_WARN); else return odbgstream(0,0,false); |
261 | } | 265 | } |
262 | 266 | ||
263 | odbgstream odFatal(int area) | 267 | odbgstream odFatal(int area) |
264 | { | 268 | { |
265 | return odbgstream("FATAL: ", area, ODEBUG_FATAL); | 269 | return odbgstream("FATAL: ", area, ODEBUG_FATAL); |
266 | } | 270 | } |
267 | 271 | ||
268 | odbgstream odFatal(bool cond, int area) | 272 | odbgstream odFatal(bool cond, int area) |
269 | { | 273 | { |
270 | if (cond) return odbgstream("FATAL: ", area, ODEBUG_FATAL); else return odbgstream(0,0,false); | 274 | if (cond) return odbgstream("FATAL: ", area, ODEBUG_FATAL); else return odbgstream(0,0,false); |
271 | } | 275 | } |
272 | 276 | ||
273 | odbgstream::odbgstream(unsigned int _area, unsigned int _level, bool _print) | 277 | odbgstream::odbgstream(unsigned int _area, unsigned int _level, bool _print) |
274 | :area(_area), level(_level), print(_print) | 278 | :area(_area), level(_level), print(_print) |
275 | { | 279 | { |
276 | } | 280 | } |
277 | 281 | ||
278 | 282 | ||
279 | odbgstream::odbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print) | 283 | odbgstream::odbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print) |
280 | :output(QString::fromLatin1(initialString)), area(_area), level(_level), print(_print) | 284 | :output(QString::fromLatin1(initialString)), area(_area), level(_level), print(_print) |
281 | { | 285 | { |
282 | } | 286 | } |
283 | 287 | ||
284 | 288 | ||
285 | odbgstream::odbgstream(odbgstream &str) | 289 | odbgstream::odbgstream(odbgstream &str) |
286 | :output(str.output), area(str.area), level(str.level), print(str.print) | 290 | :output(str.output), area(str.area), level(str.level), print(str.print) |
287 | { | 291 | { |
288 | str.output.truncate(0); | 292 | str.output.truncate(0); |
289 | } | 293 | } |
290 | 294 | ||
291 | 295 | ||
292 | odbgstream::odbgstream(const odbgstream &str) | 296 | odbgstream::odbgstream(const odbgstream &str) |
293 | :output(str.output), area(str.area), level(str.level), print(str.print) | 297 | :output(str.output), area(str.area), level(str.level), print(str.print) |
294 | { | 298 | { |
295 | } | 299 | } |
296 | 300 | ||
297 | odbgstream& odbgstream::operator<<(bool i) | 301 | odbgstream& odbgstream::operator<<(bool i) |
298 | { | 302 | { |
299 | if (!print) return *this; | 303 | if (!print) return *this; |
300 | output += QString::fromLatin1(i ? "true" : "false"); | 304 | output += QString::fromLatin1(i ? "true" : "false"); |
301 | return *this; | 305 | return *this; |
302 | } | 306 | } |
303 | 307 | ||
304 | 308 | ||
305 | odbgstream& odbgstream::operator<<(short i) | 309 | odbgstream& odbgstream::operator<<(short i) |
306 | { | 310 | { |
307 | if (!print) return *this; | 311 | if (!print) return *this; |
308 | QString tmp; tmp.setNum(i); output += tmp; | 312 | QString tmp; tmp.setNum(i); output += tmp; |
309 | return *this; | 313 | return *this; |
310 | } | 314 | } |
311 | 315 | ||
312 | 316 | ||
313 | odbgstream& odbgstream::operator<<(unsigned short i) | 317 | odbgstream& odbgstream::operator<<(unsigned short i) |
314 | { | 318 | { |
315 | if (!print) return *this; | 319 | if (!print) return *this; |
316 | QString tmp; tmp.setNum(i); output += tmp; | 320 | QString tmp; tmp.setNum(i); output += tmp; |
317 | return *this; | 321 | return *this; |
318 | } | 322 | } |
319 | 323 | ||
320 | 324 | ||
321 | odbgstream& odbgstream::operator<<(unsigned char i) | 325 | odbgstream& odbgstream::operator<<(unsigned char i) |
322 | { | 326 | { |
323 | return operator<<( static_cast<char>( i ) ); | 327 | return operator<<( static_cast<char>( i ) ); |
324 | } | 328 | } |
325 | 329 | ||
326 | 330 | ||
327 | odbgstream& odbgstream::operator<<(int i) | 331 | odbgstream& odbgstream::operator<<(int i) |
328 | { | 332 | { |
329 | if (!print) return *this; | 333 | if (!print) return *this; |
330 | QString tmp; tmp.setNum(i); output += tmp; | 334 | QString tmp; tmp.setNum(i); output += tmp; |
331 | return *this; | 335 | return *this; |
332 | } | 336 | } |
333 | 337 | ||
334 | 338 | ||
335 | odbgstream& odbgstream::operator<<(unsigned int i) | 339 | odbgstream& odbgstream::operator<<(unsigned int i) |
336 | { | 340 | { |
337 | if (!print) return *this; | 341 | if (!print) return *this; |
338 | QString tmp; tmp.setNum(i); output += tmp; | 342 | QString tmp; tmp.setNum(i); output += tmp; |
339 | return *this; | 343 | return *this; |
340 | } | 344 | } |
341 | 345 | ||
342 | 346 | ||
343 | odbgstream& odbgstream::operator<<(long i) | 347 | odbgstream& odbgstream::operator<<(long i) |
344 | { | 348 | { |
345 | if (!print) return *this; | 349 | if (!print) return *this; |
346 | QString tmp; tmp.setNum(i); output += tmp; | 350 | QString tmp; tmp.setNum(i); output += tmp; |
347 | return *this; | 351 | return *this; |
348 | } | 352 | } |
349 | 353 | ||
350 | 354 | ||
351 | odbgstream& odbgstream::operator<<(unsigned long i) | 355 | odbgstream& odbgstream::operator<<(unsigned long i) |
352 | { | 356 | { |
353 | if (!print) return *this; | 357 | if (!print) return *this; |
354 | QString tmp; tmp.setNum(i); output += tmp; | 358 | QString tmp; tmp.setNum(i); output += tmp; |
355 | return *this; | 359 | return *this; |
356 | } | 360 | } |
357 | 361 | ||
358 | 362 | ||
359 | odbgstream& odbgstream::operator<<(const QString& string) | 363 | odbgstream& odbgstream::operator<<(const QString& string) |
360 | { | 364 | { |
361 | if (!print) return *this; | 365 | if (!print) return *this; |
362 | output += string; | 366 | output += string; |
363 | if (output.at(output.length() -1 ) == '\n') | 367 | if (output.at(output.length() -1 ) == '\n') |
364 | flush(); | 368 | flush(); |
365 | return *this; | 369 | return *this; |
366 | } | 370 | } |
367 | 371 | ||
368 | 372 | ||
369 | odbgstream& odbgstream::operator<<(const char *string) | 373 | odbgstream& odbgstream::operator<<(const char *string) |
370 | { | 374 | { |
371 | if (!print) return *this; | 375 | if (!print) return *this; |
372 | output += QString::fromUtf8(string); | 376 | output += QString::fromUtf8(string); |
373 | if (output.at(output.length() - 1) == '\n') | 377 | if (output.at(output.length() - 1) == '\n') |
374 | flush(); | 378 | flush(); |
375 | return *this; | 379 | return *this; |
376 | } | 380 | } |
377 | 381 | ||
378 | 382 | ||
379 | odbgstream& odbgstream::operator<<(const QCString& string) | 383 | odbgstream& odbgstream::operator<<(const QCString& string) |
380 | { | 384 | { |
381 | *this << string.data(); | 385 | *this << string.data(); |
382 | return *this; | 386 | return *this; |
383 | } | 387 | } |
384 | 388 | ||
385 | 389 | ||
386 | odbgstream& odbgstream::operator<<(const void * p) | 390 | odbgstream& odbgstream::operator<<(const void * p) |
387 | { | 391 | { |
388 | form("%p", p); | 392 | form("%p", p); |
389 | return *this; | 393 | return *this; |
390 | } | 394 | } |
391 | 395 | ||
392 | odbgstream& odbgstream::operator<<(double d) | 396 | odbgstream& odbgstream::operator<<(double d) |
393 | { | 397 | { |
394 | QString tmp; tmp.setNum(d); output += tmp; | 398 | QString tmp; tmp.setNum(d); output += tmp; |
395 | return *this; | 399 | return *this; |
396 | } | 400 | } |
397 | 401 | ||
398 | /* | 402 | /* |
399 | odbgstream::odbgstream &form(const char *format, ...) | 403 | odbgstream::odbgstream &form(const char *format, ...) |
400 | #ifdef __GNUC__ | 404 | #ifdef __GNUC__ |
401 | __attribute__ ( ( format ( printf, 2, 3 ) ) ) | 405 | __attribute__ ( ( format ( printf, 2, 3 ) ) ) |
402 | #endif | 406 | #endif |
403 | ; | 407 | ; |
404 | */ | 408 | */ |
405 | 409 | ||
406 | void odbgstream::flush() | 410 | void odbgstream::flush() |
407 | { | 411 | { |
408 | if ( output.isEmpty() || !print ) | 412 | if ( output.isEmpty() || !print ) |
409 | { | 413 | { |
410 | return; | 414 | return; |
411 | } | 415 | } |
412 | else | 416 | else |
413 | { | 417 | { |
414 | oDebugBackend( level, area, output.local8Bit().data() ); | 418 | oDebugBackend( level, area, output.local8Bit().data() ); |
415 | output = QString::null; | 419 | output = QString::null; |
416 | } | 420 | } |
417 | } | 421 | } |
418 | 422 | ||
419 | odbgstream& odbgstream::form(const char *format, ...) | 423 | odbgstream& odbgstream::form(const char *format, ...) |
420 | { | 424 | { |
421 | char buf[4096]; | 425 | char buf[4096]; |
422 | va_list arguments; | 426 | va_list arguments; |
423 | va_start( arguments, format ); | 427 | va_start( arguments, format ); |
424 | buf[sizeof(buf)-1] = '\0'; | 428 | buf[sizeof(buf)-1] = '\0'; |
425 | vsnprintf( buf, sizeof(buf)-1, format, arguments ); | 429 | vsnprintf( buf, sizeof(buf)-1, format, arguments ); |
426 | va_end(arguments); | 430 | va_end(arguments); |
427 | *this << buf; | 431 | *this << buf; |
428 | return *this; | 432 | return *this; |
429 | } | 433 | } |
430 | 434 | ||
431 | odbgstream::~odbgstream() | 435 | odbgstream::~odbgstream() |
432 | { | 436 | { |
433 | if (!output.isEmpty()) | 437 | if (!output.isEmpty()) |
434 | { | 438 | { |
435 | fprintf(stderr, "ASSERT: debug output not ended with \\n\n"); | 439 | fprintf(stderr, "ASSERT: debug output not ended with \\n\n"); |
436 | *this << "\n"; | 440 | *this << "\n"; |
437 | } | 441 | } |
438 | } | 442 | } |
439 | 443 | ||
440 | odbgstream& odbgstream::operator<<(char ch) | 444 | odbgstream& odbgstream::operator<<(char ch) |
441 | { | 445 | { |
442 | if (!print) return *this; | 446 | if (!print) return *this; |
443 | if (!isprint(ch)) | 447 | if (!isprint(ch)) |
444 | { | 448 | { |
445 | output += "\\x" + QString::number( static_cast<uint>( ch ) + 0x100, 16 ).right(2); | 449 | output += "\\x" + QString::number( static_cast<uint>( ch ) + 0x100, 16 ).right(2); |
446 | } | 450 | } |
447 | else | 451 | else |
448 | { | 452 | { |
449 | output += ch; | 453 | output += ch; |
450 | if (ch == '\n') flush(); | 454 | if (ch == '\n') flush(); |
451 | } | 455 | } |
452 | return *this; | 456 | return *this; |
453 | } | 457 | } |
454 | 458 | ||
455 | odbgstream& odbgstream::operator<<( QWidget* widget ) | 459 | odbgstream& odbgstream::operator<<( QWidget* widget ) |
456 | { | 460 | { |
457 | QString string, temp; | 461 | QString string, temp; |
458 | // ----- | 462 | // ----- |
459 | if(widget==0) | 463 | if(widget==0) |
460 | { | 464 | { |
461 | string=(QString)"[Null pointer]"; | 465 | string=(QString)"[Null pointer]"; |
462 | } else | 466 | } else |
463 | { | 467 | { |
464 | temp.setNum((ulong)widget, 16); | 468 | temp.setNum((ulong)widget, 16); |
465 | string=(QString)"["+widget->className()+" pointer " + "(0x" + temp + ")"; | 469 | string=(QString)"["+widget->className()+" pointer " + "(0x" + temp + ")"; |
466 | if(widget->name(0)==0) | 470 | if(widget->name(0)==0) |
467 | { | 471 | { |
468 | string += " to unnamed widget, "; | 472 | string += " to unnamed widget, "; |
469 | } else | 473 | } else |
470 | { | 474 | { |
471 | string += (QString)" to widget " + widget->name() + ", "; | 475 | string += (QString)" to widget " + widget->name() + ", "; |
472 | } | 476 | } |
473 | string += "geometry=" | 477 | string += "geometry=" |
474 | + QString().setNum(widget->width()) | 478 | + QString().setNum(widget->width()) |
475 | + "x"+QString().setNum(widget->height()) | 479 | + "x"+QString().setNum(widget->height()) |
476 | + "+"+QString().setNum(widget->x()) | 480 | + "+"+QString().setNum(widget->x()) |
477 | + "+"+QString().setNum(widget->y()) | 481 | + "+"+QString().setNum(widget->y()) |
478 | + "]"; | 482 | + "]"; |
479 | } | 483 | } |
480 | if (!print) return *this; | 484 | if (!print) return *this; |
481 | 485 | ||
482 | output += string; | 486 | output += string; |
483 | if (output.at(output.length()-1) == '\n') | 487 | if (output.at(output.length()-1) == '\n') |
484 | { | 488 | { |
485 | flush(); | 489 | flush(); |
486 | } | 490 | } |
487 | return *this; | 491 | return *this; |
488 | } | 492 | } |
489 | 493 | ||
490 | /* | 494 | /* |
491 | * either use 'output' directly and do the flush if needed | 495 | * either use 'output' directly and do the flush if needed |
492 | * or use the QString operator which calls the char* operator | 496 | * or use the QString operator which calls the char* operator |
493 | * | 497 | * |
494 | */ | 498 | */ |
495 | odbgstream& odbgstream::operator<<( const QDateTime& time) | 499 | odbgstream& odbgstream::operator<<( const QDateTime& time) |
496 | { | 500 | { |
497 | *this << time.toString(); | 501 | *this << time.toString(); |
498 | return *this; | 502 | return *this; |
499 | } | 503 | } |
500 | 504 | ||
501 | 505 | ||
502 | odbgstream& odbgstream::operator<<( const QDate& date) | 506 | odbgstream& odbgstream::operator<<( const QDate& date) |
503 | { | 507 | { |
504 | *this << date.toString(); | 508 | *this << date.toString(); |
505 | 509 | ||
506 | return *this; | 510 | return *this; |
507 | } | 511 | } |
508 | 512 | ||
509 | 513 | ||
510 | odbgstream& odbgstream::operator<<( const QTime& time ) | 514 | odbgstream& odbgstream::operator<<( const QTime& time ) |
511 | { | 515 | { |