1 /***************************************************************************
3 NListviews.mcp - New Listview MUI Custom Class Preferences
4 Registered MUI class, Serial Number: 1d51 (0x9d510001 to 0x9d51001F
5 and 0x9d510101 to 0x9d51013F)
7 Copyright (C) 1996-2001 by Gilles Masson
8 Copyright (C) 2001-2014 NList Open Source Team
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 NList classes Support Site: http://www.sf.net/projects/nlist-classes
24 ***************************************************************************/
33 #include <proto/intuition.h>
34 #include <proto/utility.h>
35 #include <proto/dos.h>
36 #include <proto/exec.h>
38 #include "SDI_compiler.h"
42 // special flagging macros
43 #define isFlagSet(v,f) (((v) & (f)) == (f)) // return TRUE if the flag is set
44 #define hasFlag(v,f) (((v) & (f)) != 0) // return TRUE if one of the flags in f is set in v
45 #define isFlagClear(v,f) (((v) & (f)) == 0) // return TRUE if flag f is not set in v
46 #define SET_FLAG(v,f) ((v) |= (f)) // set the flag f in v
47 #define CLEAR_FLAG(v,f) ((v) &= ~(f)) // clear the flag f in v
48 #define MASK_FLAG(v,f) ((v) &= (f)) // mask the variable v with flag f bitwise
50 // our static variables with default values
51 static int indent_level
= 0;
52 static BOOL ansi_output
= FALSE
;
53 static ULONG debug_flags
= DBF_ALWAYS
| DBF_STARTUP
; // default debug flags
54 static ULONG debug_classes
= DBC_ERROR
| DBC_DEBUG
| DBC_WARNING
| DBC_ASSERT
| DBC_REPORT
; // default debug classes
56 /****************************************************************************/
62 kprintf("** NListviews.mcp v" LIB_REV_STRING
" startup ***********************\n");
63 kprintf("Initializing runtime debugging:\n");
65 if(GetVar("nlistviews.mcp.debug", var
, sizeof(var
), 0) > 0)
70 // static list of our debugging classes tokens.
71 // in the yamdebug variable these classes always start with a @
72 static struct { const char *token
; unsigned long flag
; } dbclasses
[] =
74 { "ctrace", DBC_CTRACE
},
75 { "report", DBC_REPORT
},
76 { "assert", DBC_ASSERT
},
77 { "timeval", DBC_TIMEVAL
},
78 { "debug", DBC_DEBUG
},
79 { "error", DBC_ERROR
},
80 { "warning", DBC_WARNING
},
85 static struct { const char *token
; unsigned long flag
; } dbflags
[] =
87 { "always", DBF_ALWAYS
},
88 { "startup", DBF_STARTUP
},
93 // we parse the env variable token-wise
94 while((tok
= strtok(debug
, ", ;")))
98 // check if the token is class definition or
99 // just a flag definition
102 // check if this call is a negation or not
105 // search for the token and clear the flag
106 for(i
=0; dbclasses
[i
].token
; i
++)
108 if(stricmp(tok
+2, dbclasses
[i
].token
) == 0)
110 kprintf("clear '%s' debug class flag.\n", dbclasses
[i
].token
);
111 CLEAR_FLAG(debug_classes
, dbclasses
[i
].flag
);
117 // search for the token and set the flag
118 for(i
=0; dbclasses
[i
].token
; i
++)
120 if(stricmp(tok
+1, dbclasses
[i
].token
) == 0)
122 kprintf("set '%s' debug class flag\n", dbclasses
[i
].token
);
123 SET_FLAG(debug_classes
, dbclasses
[i
].flag
);
130 // check if this call is a negation or not
133 for(i
=0; dbflags
[i
].token
; i
++)
135 if(stricmp(tok
+1, dbflags
[i
].token
) == 0)
137 kprintf("clear '%s' debug flag\n", dbflags
[i
].token
);
138 CLEAR_FLAG(debug_flags
, dbflags
[i
].flag
);
144 // check if the token was "ansi" and if so enable the ANSI color
146 if(stricmp(tok
, "ansi") == 0)
148 kprintf("ansi output enabled\n");
153 for(i
=0; dbflags
[i
].token
; i
++)
155 if(stricmp(tok
, dbflags
[i
].token
) == 0)
157 kprintf("set '%s' debug flag\n", dbflags
[i
].token
);
158 SET_FLAG(debug_flags
, dbflags
[i
].flag
);
169 kprintf("set debug classes/flags (env:nlistviews.mcp.debug): %08lx/%08lx\n", debug_classes
, debug_flags
);
170 kprintf("** Normal processing follows ***************************************\n");
173 /****************************************************************************/
175 void CleanupDebug(void)
177 kprintf("** Cleaned up debugging ********************************************\n");
180 /****************************************************************************/
182 // define variables for using ANSI colors in our debugging scheme
183 #define ANSI_ESC_CLR "\033[0m"
184 #define ANSI_ESC_BOLD "\033[1m"
185 #define ANSI_ESC_UNDERLINE "\033[4m"
186 #define ANSI_ESC_BLINK "\033[5m"
187 #define ANSI_ESC_REVERSE "\033[7m"
188 #define ANSI_ESC_INVISIBLE "\033[8m"
189 #define ANSI_ESC_FG_BLACK "\033[0;30m"
190 #define ANSI_ESC_FG_RED "\033[0;31m"
191 #define ANSI_ESC_FG_GREEN "\033[0;32m"
192 #define ANSI_ESC_FG_BROWN "\033[0;33m"
193 #define ANSI_ESC_FG_BLUE "\033[0;34m"
194 #define ANSI_ESC_FG_PURPLE "\033[0;35m"
195 #define ANSI_ESC_FG_CYAN "\033[0;36m"
196 #define ANSI_ESC_FG_LGRAY "\033[0;37m"
197 #define ANSI_ESC_FG_DGRAY "\033[1;30m"
198 #define ANSI_ESC_FG_LRED "\033[1;31m"
199 #define ANSI_ESC_FG_LGREEN "\033[1;32m"
200 #define ANSI_ESC_FG_YELLOW "\033[1;33m"
201 #define ANSI_ESC_FG_LBLUE "\033[1;34m"
202 #define ANSI_ESC_FG_LPURPLE "\033[1;35m"
203 #define ANSI_ESC_FG_LCYAN "\033[1;36m"
204 #define ANSI_ESC_FG_WHITE "\033[1;37m"
205 #define ANSI_ESC_BG "\033[0;4" // background esc-squ start with 4x
206 #define ANSI_ESC_BG_BLACK "\033[0;40m"
207 #define ANSI_ESC_BG_RED "\033[0;41m"
208 #define ANSI_ESC_BG_GREEN "\033[0;42m"
209 #define ANSI_ESC_BG_BROWN "\033[0;43m"
210 #define ANSI_ESC_BG_BLUE "\033[0;44m"
211 #define ANSI_ESC_BG_PURPLE "\033[0;45m"
212 #define ANSI_ESC_BG_CYAN "\033[0;46m"
213 #define ANSI_ESC_BG_LGRAY "\033[0;47m"
215 /****************************************************************************/
217 INLINE
void _INDENT(void)
220 for(i
=0; i
< indent_level
; i
++)
224 /****************************************************************************/
226 void _ENTER(unsigned long dclass
, const char *file
, int line
, const char *function
)
228 if(isFlagSet(debug_classes
, dclass
))
232 kprintf("%s%s:%ld:Entering %s%s\n", ANSI_ESC_FG_BROWN
, file
, line
, function
, ANSI_ESC_CLR
);
234 kprintf("%s:%ld:Entering %s\n", file
, line
, function
);
240 void _LEAVE(unsigned long dclass
, const char *file
, int line
, const char *function
)
244 if(isFlagSet(debug_classes
, dclass
))
248 kprintf("%s%s:%ld:Leaving %s%s\n", ANSI_ESC_FG_BROWN
, file
, line
, function
, ANSI_ESC_CLR
);
250 kprintf("%s:%ld:Leaving %s\n", file
, line
, function
);
254 void _RETURN(unsigned long dclass
, const char *file
, int line
, const char *function
, unsigned long result
)
258 if(isFlagSet(debug_classes
, dclass
))
262 kprintf("%s%s:%ld:Leaving %s (result 0x%08lx, %ld)%s\n", ANSI_ESC_FG_BROWN
, file
, line
, function
, result
, result
, ANSI_ESC_CLR
);
264 kprintf("%s:%ld:Leaving %s (result 0x%08lx, %ld)\n", file
, line
, function
, result
, result
);
268 /****************************************************************************/
270 void _SHOWVALUE(unsigned long dclass
, unsigned long dflags
, unsigned long value
, int size
, const char *name
, const char *file
, int line
)
272 if(isFlagSet(debug_classes
, dclass
) &&
273 isFlagSet(debug_flags
, dflags
))
280 fmt
= "%s:%ld:%s = %ld, 0x%02lx";
284 fmt
= "%s:%ld:%s = %ld, 0x%04lx";
288 fmt
= "%s:%ld:%s = %ld, 0x%08lx";
295 kprintf(ANSI_ESC_FG_GREEN
);
297 kprintf(fmt
, file
, line
, name
, value
, value
);
299 if(size
== 1 && value
< 256)
301 if(value
< ' ' || (value
>= 127 && value
< 160))
302 kprintf(", '\\x%02lx'", value
);
304 kprintf(", '%lc'", value
);
308 kprintf("%s\n", ANSI_ESC_CLR
);
314 /****************************************************************************/
316 void _SHOWPOINTER(unsigned long dclass
, unsigned long dflags
, const void *p
, const char *name
, const char *file
, int line
)
318 if(isFlagSet(debug_classes
, dclass
) &&
319 isFlagSet(debug_flags
, dflags
))
326 fmt
= "%s:%ld:%s = 0x%08lx\n";
328 fmt
= "%s:%ld:%s = NULL\n";
332 kprintf(ANSI_ESC_FG_GREEN
);
333 kprintf(fmt
, file
, line
, name
, p
);
334 kprintf(ANSI_ESC_CLR
);
337 kprintf(fmt
, file
, line
, name
, p
);
341 /****************************************************************************/
343 void _SHOWSTRING(unsigned long dclass
, unsigned long dflags
, const char *string
, const char *name
, const char *file
, int line
)
345 if(isFlagSet(debug_classes
, dclass
) &&
346 isFlagSet(debug_flags
, dflags
))
351 kprintf("%s%s:%ld:%s = 0x%08lx \"%s\"%s\n", ANSI_ESC_FG_GREEN
, file
, line
, name
, string
, string
, ANSI_ESC_CLR
);
353 kprintf("%s:%ld:%s = 0x%08lx \"%s\"\n", file
, line
, name
, string
, string
);
357 /****************************************************************************/
359 void _SHOWMSG(unsigned long dclass
, unsigned long dflags
, const char *msg
, const char *file
, int line
)
361 if(isFlagSet(debug_classes
, dclass
) &&
362 isFlagSet(debug_flags
, dflags
))
367 kprintf("%s%s:%ld:%s%s\n", ANSI_ESC_FG_GREEN
, file
, line
, msg
, ANSI_ESC_CLR
);
369 kprintf("%s:%ld:%s\n", file
, line
, msg
);
373 /****************************************************************************/
375 void _DPRINTF(unsigned long dclass
, unsigned long dflags
, const char *file
, int line
, const char *format
, ...)
377 if((isFlagSet(debug_classes
, dclass
) && isFlagSet(debug_flags
, dflags
)) ||
378 (isFlagSet(dclass
, DBC_ERROR
) || isFlagSet(dclass
, DBC_WARNING
)))
381 static char buf
[1024];
385 va_start(args
, format
);
386 vsnprintf(buf
, 1024, format
, args
);
391 const char *highlight
= ANSI_ESC_FG_GREEN
;
395 case DBC_CTRACE
: highlight
= ANSI_ESC_FG_BROWN
; break;
396 case DBC_REPORT
: highlight
= ANSI_ESC_FG_GREEN
; break;
397 case DBC_ASSERT
: highlight
= ANSI_ESC_FG_RED
; break;
398 case DBC_TIMEVAL
: highlight
= ANSI_ESC_FG_GREEN
; break;
399 case DBC_DEBUG
: highlight
= ANSI_ESC_FG_GREEN
; break;
400 case DBC_ERROR
: highlight
= ANSI_ESC_FG_RED
; break;
401 case DBC_WARNING
: highlight
= ANSI_ESC_FG_PURPLE
;break;
404 kprintf("%s%s:%ld:%s%s\n", highlight
, file
, line
, buf
, ANSI_ESC_CLR
);
407 kprintf("%s:%ld:%s\n", file
, line
, buf
);
411 /****************************************************************************/