1 /***************************************************************************
3 NListview.mcc - New Listview MUI Custom Class
4 Registered MUI class, Serial Number: 1d51 (0x9d510020 to 0x9d51002F)
6 Copyright (C) 1996-2001 by Gilles Masson
7 Copyright (C) 2001-2014 NList Open Source Team
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 NList classes Support Site: http://www.sf.net/projects/nlist-classes
23 ***************************************************************************/
32 #include <proto/intuition.h>
33 #include <proto/utility.h>
34 #include <proto/dos.h>
35 #include <proto/exec.h>
37 #include "SDI_compiler.h"
41 // special flagging macros
42 #define isFlagSet(v,f) (((v) & (f)) == (f)) // return TRUE if the flag is set
43 #define hasFlag(v,f) (((v) & (f)) != 0) // return TRUE if one of the flags in f is set in v
44 #define isFlagClear(v,f) (((v) & (f)) == 0) // return TRUE if flag f is not set in v
45 #define SET_FLAG(v,f) ((v) |= (f)) // set the flag f in v
46 #define CLEAR_FLAG(v,f) ((v) &= ~(f)) // clear the flag f in v
47 #define MASK_FLAG(v,f) ((v) &= (f)) // mask the variable v with flag f bitwise
49 // our static variables with default values
50 static int indent_level
= 0;
51 static BOOL ansi_output
= FALSE
;
52 static ULONG debug_flags
= DBF_ALWAYS
| DBF_STARTUP
; // default debug flags
53 static ULONG debug_classes
= DBC_ERROR
| DBC_DEBUG
| DBC_WARNING
| DBC_ASSERT
| DBC_REPORT
; // default debug classes
55 /****************************************************************************/
61 kprintf("** NListview.mcc v" LIB_REV_STRING
" startup ***********************\n");
62 kprintf("Initializing runtime debugging:\n");
64 if(GetVar("nlistview.mcc.debug", var
, sizeof(var
), 0) > 0)
69 // static list of our debugging classes tokens.
70 // in the yamdebug variable these classes always start with a @
71 static struct { const char *token
; unsigned long flag
; } dbclasses
[] =
73 { "ctrace", DBC_CTRACE
},
74 { "report", DBC_REPORT
},
75 { "assert", DBC_ASSERT
},
76 { "timeval", DBC_TIMEVAL
},
77 { "debug", DBC_DEBUG
},
78 { "error", DBC_ERROR
},
79 { "warning", DBC_WARNING
},
84 static struct { const char *token
; unsigned long flag
; } dbflags
[] =
86 { "always", DBF_ALWAYS
},
87 { "startup", DBF_STARTUP
},
92 // we parse the env variable token-wise
93 while((tok
= strtok(debug
, ", ;")))
97 // check if the token is class definition or
98 // just a flag definition
101 // check if this call is a negation or not
104 // search for the token and clear the flag
105 for(i
=0; dbclasses
[i
].token
; i
++)
107 if(stricmp(tok
+2, dbclasses
[i
].token
) == 0)
109 kprintf("clear '%s' debug class flag.\n", dbclasses
[i
].token
);
110 CLEAR_FLAG(debug_classes
, dbclasses
[i
].flag
);
116 // search for the token and set the flag
117 for(i
=0; dbclasses
[i
].token
; i
++)
119 if(stricmp(tok
+1, dbclasses
[i
].token
) == 0)
121 kprintf("set '%s' debug class flag\n", dbclasses
[i
].token
);
122 SET_FLAG(debug_classes
, dbclasses
[i
].flag
);
129 // check if this call is a negation or not
132 for(i
=0; dbflags
[i
].token
; i
++)
134 if(stricmp(tok
+1, dbflags
[i
].token
) == 0)
136 kprintf("clear '%s' debug flag\n", dbflags
[i
].token
);
137 CLEAR_FLAG(debug_flags
, dbflags
[i
].flag
);
143 // check if the token was "ansi" and if so enable the ANSI color
145 if(stricmp(tok
, "ansi") == 0)
147 kprintf("ansi output enabled\n");
152 for(i
=0; dbflags
[i
].token
; i
++)
154 if(stricmp(tok
, dbflags
[i
].token
) == 0)
156 kprintf("set '%s' debug flag\n", dbflags
[i
].token
);
157 SET_FLAG(debug_flags
, dbflags
[i
].flag
);
168 kprintf("set debug classes/flags (env:nlistview.mcc.debug): %08lx/%08lx\n", debug_classes
, debug_flags
);
169 kprintf("** Normal processing follows ***************************************\n");
172 /****************************************************************************/
174 void CleanupDebug(void)
176 kprintf("** Cleaned up debugging ********************************************\n");
179 /****************************************************************************/
181 // define variables for using ANSI colors in our debugging scheme
182 #define ANSI_ESC_CLR "\033[0m"
183 #define ANSI_ESC_BOLD "\033[1m"
184 #define ANSI_ESC_UNDERLINE "\033[4m"
185 #define ANSI_ESC_BLINK "\033[5m"
186 #define ANSI_ESC_REVERSE "\033[7m"
187 #define ANSI_ESC_INVISIBLE "\033[8m"
188 #define ANSI_ESC_FG_BLACK "\033[0;30m"
189 #define ANSI_ESC_FG_RED "\033[0;31m"
190 #define ANSI_ESC_FG_GREEN "\033[0;32m"
191 #define ANSI_ESC_FG_BROWN "\033[0;33m"
192 #define ANSI_ESC_FG_BLUE "\033[0;34m"
193 #define ANSI_ESC_FG_PURPLE "\033[0;35m"
194 #define ANSI_ESC_FG_CYAN "\033[0;36m"
195 #define ANSI_ESC_FG_LGRAY "\033[0;37m"
196 #define ANSI_ESC_FG_DGRAY "\033[1;30m"
197 #define ANSI_ESC_FG_LRED "\033[1;31m"
198 #define ANSI_ESC_FG_LGREEN "\033[1;32m"
199 #define ANSI_ESC_FG_YELLOW "\033[1;33m"
200 #define ANSI_ESC_FG_LBLUE "\033[1;34m"
201 #define ANSI_ESC_FG_LPURPLE "\033[1;35m"
202 #define ANSI_ESC_FG_LCYAN "\033[1;36m"
203 #define ANSI_ESC_FG_WHITE "\033[1;37m"
204 #define ANSI_ESC_BG "\033[0;4" // background esc-squ start with 4x
205 #define ANSI_ESC_BG_BLACK "\033[0;40m"
206 #define ANSI_ESC_BG_RED "\033[0;41m"
207 #define ANSI_ESC_BG_GREEN "\033[0;42m"
208 #define ANSI_ESC_BG_BROWN "\033[0;43m"
209 #define ANSI_ESC_BG_BLUE "\033[0;44m"
210 #define ANSI_ESC_BG_PURPLE "\033[0;45m"
211 #define ANSI_ESC_BG_CYAN "\033[0;46m"
212 #define ANSI_ESC_BG_LGRAY "\033[0;47m"
214 /****************************************************************************/
216 INLINE
void _INDENT(void)
219 for(i
=0; i
< indent_level
; i
++)
223 /****************************************************************************/
225 void _ENTER(unsigned long dclass
, const char *file
, int line
, const char *function
)
227 if(isFlagSet(debug_classes
, dclass
))
231 kprintf("%s%s:%ld:Entering %s%s\n", ANSI_ESC_FG_BROWN
, file
, line
, function
, ANSI_ESC_CLR
);
233 kprintf("%s:%ld:Entering %s\n", file
, line
, function
);
239 void _LEAVE(unsigned long dclass
, const char *file
, int line
, const char *function
)
243 if(isFlagSet(debug_classes
, dclass
))
247 kprintf("%s%s:%ld:Leaving %s%s\n", ANSI_ESC_FG_BROWN
, file
, line
, function
, ANSI_ESC_CLR
);
249 kprintf("%s:%ld:Leaving %s\n", file
, line
, function
);
253 void _RETURN(unsigned long dclass
, const char *file
, int line
, const char *function
, unsigned long result
)
257 if(isFlagSet(debug_classes
, dclass
))
261 kprintf("%s%s:%ld:Leaving %s (result 0x%08lx, %ld)%s\n", ANSI_ESC_FG_BROWN
, file
, line
, function
, result
, result
, ANSI_ESC_CLR
);
263 kprintf("%s:%ld:Leaving %s (result 0x%08lx, %ld)\n", file
, line
, function
, result
, result
);
267 /****************************************************************************/
269 void _SHOWVALUE(unsigned long dclass
, unsigned long dflags
, unsigned long value
, int size
, const char *name
, const char *file
, int line
)
271 if(isFlagSet(debug_classes
, dclass
) &&
272 isFlagSet(debug_flags
, dflags
))
279 fmt
= "%s:%ld:%s = %ld, 0x%02lx";
283 fmt
= "%s:%ld:%s = %ld, 0x%04lx";
287 fmt
= "%s:%ld:%s = %ld, 0x%08lx";
294 kprintf(ANSI_ESC_FG_GREEN
);
296 kprintf(fmt
, file
, line
, name
, value
, value
);
298 if(size
== 1 && value
< 256)
300 if(value
< ' ' || (value
>= 127 && value
< 160))
301 kprintf(", '\\x%02lx'", value
);
303 kprintf(", '%lc'", value
);
307 kprintf("%s\n", ANSI_ESC_CLR
);
313 /****************************************************************************/
315 void _SHOWPOINTER(unsigned long dclass
, unsigned long dflags
, const void *p
, const char *name
, const char *file
, int line
)
317 if(isFlagSet(debug_classes
, dclass
) &&
318 isFlagSet(debug_flags
, dflags
))
325 fmt
= "%s:%ld:%s = 0x%08lx\n";
327 fmt
= "%s:%ld:%s = NULL\n";
331 kprintf(ANSI_ESC_FG_GREEN
);
332 kprintf(fmt
, file
, line
, name
, p
);
333 kprintf(ANSI_ESC_CLR
);
336 kprintf(fmt
, file
, line
, name
, p
);
340 /****************************************************************************/
342 void _SHOWSTRING(unsigned long dclass
, unsigned long dflags
, const char *string
, const char *name
, const char *file
, int line
)
344 if(isFlagSet(debug_classes
, dclass
) &&
345 isFlagSet(debug_flags
, dflags
))
350 kprintf("%s%s:%ld:%s = 0x%08lx \"%s\"%s\n", ANSI_ESC_FG_GREEN
, file
, line
, name
, string
, string
, ANSI_ESC_CLR
);
352 kprintf("%s:%ld:%s = 0x%08lx \"%s\"\n", file
, line
, name
, string
, string
);
356 /****************************************************************************/
358 void _SHOWMSG(unsigned long dclass
, unsigned long dflags
, const char *msg
, const char *file
, int line
)
360 if(isFlagSet(debug_classes
, dclass
) &&
361 isFlagSet(debug_flags
, dflags
))
366 kprintf("%s%s:%ld:%s%s\n", ANSI_ESC_FG_GREEN
, file
, line
, msg
, ANSI_ESC_CLR
);
368 kprintf("%s:%ld:%s\n", file
, line
, msg
);
372 /****************************************************************************/
374 void _DPRINTF(unsigned long dclass
, unsigned long dflags
, const char *file
, int line
, const char *format
, ...)
376 if((isFlagSet(debug_classes
, dclass
) && isFlagSet(debug_flags
, dflags
)) ||
377 (isFlagSet(dclass
, DBC_ERROR
) || isFlagSet(dclass
, DBC_WARNING
)))
380 static char buf
[1024];
384 va_start(args
, format
);
385 vsnprintf(buf
, 1024, format
, args
);
390 const char *highlight
= ANSI_ESC_FG_GREEN
;
394 case DBC_CTRACE
: highlight
= ANSI_ESC_FG_BROWN
; break;
395 case DBC_REPORT
: highlight
= ANSI_ESC_FG_GREEN
; break;
396 case DBC_ASSERT
: highlight
= ANSI_ESC_FG_RED
; break;
397 case DBC_TIMEVAL
: highlight
= ANSI_ESC_FG_GREEN
; break;
398 case DBC_DEBUG
: highlight
= ANSI_ESC_FG_GREEN
; break;
399 case DBC_ERROR
: highlight
= ANSI_ESC_FG_RED
; break;
400 case DBC_WARNING
: highlight
= ANSI_ESC_FG_PURPLE
;break;
403 kprintf("%s%s:%ld:%s%s\n", highlight
, file
, line
, buf
, ANSI_ESC_CLR
);
406 kprintf("%s:%ld:%s\n", file
, line
, buf
);
410 /****************************************************************************/