summaryrefslogtreecommitdiff
path: root/libopie2
authormickeyl <mickeyl>2003-03-30 02:17:58 (UTC)
committer mickeyl <mickeyl>2003-03-30 02:17:58 (UTC)
commit35e4d0b2a71b8ca15baeb0b0383af21fc1d8d3ae (patch) (unidiff)
tree335bb12952530b397788e0b02e2072c48788b920 /libopie2
parent4ace7ac9fff84df80d3066236ff970b9b393cf48 (diff)
downloadopie-35e4d0b2a71b8ca15baeb0b0383af21fc1d8d3ae.zip
opie-35e4d0b2a71b8ca15baeb0b0383af21fc1d8d3ae.tar.gz
opie-35e4d0b2a71b8ca15baeb0b0383af21fc1d8d3ae.tar.bz2
one more fix for gcc 2.9x
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/odebug.cpp6
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
@@ -63,129 +63,133 @@
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
85enum DebugLevels { 85enum 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
100static void oDebugBackend( unsigned short level, unsigned int area, const char *data) 100static 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 {