alsa.audio: build the bridge link lib only for linux architecture
[AROS.git] / workbench / network / smbfs / source_code / assert.c
blobb47f4400ede37272c09efe76627a74e79b3a53b0
1 /*
2 * $Id$
4 * :ts=8
6 * SMB file system wrapper for AmigaOS, using the AmiTCP V3 API
8 * Copyright (C) 2000-2009 by Olaf `Olsen' Barthel <obarthel -at- gmx -dot- net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program 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
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 /****************************************************************************/
27 #include <dos/dos.h>
29 #include <clib/exec_protos.h>
30 #include <clib/dos_protos.h>
32 #ifdef __SASC
33 #include <pragmas/exec_pragmas.h>
34 #include <pragmas/dos_pragmas.h>
35 #else
36 #include <inline/exec.h>
37 #include <inline/dos.h>
38 #endif /* __SASC */
40 #include <string.h>
42 #if !defined(__AROS__)
43 extern struct Library * AbsExecBase;
45 #define SysBase AbsExecBase
46 #endif
48 extern void kprintf(const char *,...);
49 extern void __stdargs kputc(char c);
51 /****************************************************************************/
53 #include <stdarg.h>
55 /****************************************************************************/
57 #define DEBUGLEVEL_OnlyAsserts 0
58 #define DEBUGLEVEL_Reports 1
59 #define DEBUGLEVEL_CallTracing 2
61 /****************************************************************************/
63 static int indent_level = 0;
64 int __debug_level = DEBUGLEVEL_CallTracing;
66 static char program_name[40];
67 static int program_name_len = 0;
69 /****************************************************************************/
71 void
72 _SETPROGRAMNAME(char *name)
74 if(name != NULL && name[0] != '\0')
76 program_name_len = strlen(name);
77 if(program_name_len >= sizeof(program_name))
78 program_name_len = sizeof(program_name)-1;
80 strncpy(program_name,name,program_name_len);
81 program_name[program_name_len] = '\0';
83 else
85 program_name_len = 0;
89 /****************************************************************************/
91 int
92 _SETDEBUGLEVEL(int level)
94 int old_level = __debug_level;
96 __debug_level = level;
98 return(old_level);
101 /****************************************************************************/
104 _GETDEBUGLEVEL(void)
106 return(__debug_level);
109 /****************************************************************************/
111 static int previous_debug_level = -1;
113 void
114 _PUSHDEBUGLEVEL(int level)
116 previous_debug_level = _SETDEBUGLEVEL(level);
119 void
120 _POPDEBUGLEVEL(void)
122 if(previous_debug_level != -1)
124 _SETDEBUGLEVEL(previous_debug_level);
126 previous_debug_level = -1;
130 /****************************************************************************/
132 void
133 _INDENT(void)
135 if(program_name_len > 0)
136 kprintf("(%s) ",program_name);
138 if(__debug_level >= DEBUGLEVEL_CallTracing)
140 int i;
142 for(i = 0 ; i < indent_level ; i++)
143 kprintf(" ");
147 /****************************************************************************/
149 void
150 _SHOWVALUE(
151 unsigned long value,
152 int size,
153 const char *name,
154 const char *file,
155 int line)
157 if(__debug_level >= DEBUGLEVEL_Reports)
159 char *fmt;
161 switch(size)
163 case 1:
165 fmt = "%s:%ld:%s = %ld, 0x%02lx";
166 break;
168 case 2:
170 fmt = "%s:%ld:%s = %ld, 0x%04lx";
171 break;
173 default:
175 fmt = "%s:%ld:%s = %ld, 0x%08lx";
176 break;
179 _INDENT();
181 kprintf(fmt,file,line,name,value,value);
183 if(size == 1 && value < 256)
185 if(value < ' ' || (value >= 127 && value < 160))
186 kprintf(", '\\x%02lx'",value);
187 else
188 kprintf(", '%lc'",value);
191 kprintf("\n");
195 /****************************************************************************/
197 void
198 _SHOWPOINTER(
199 void *pointer,
200 const char *name,
201 const char *file,
202 int line)
204 if(__debug_level >= DEBUGLEVEL_Reports)
206 char *fmt;
208 _INDENT();
210 if(pointer != NULL)
211 fmt = "%s:%ld:%s = 0x%08lx\n";
212 else
213 fmt = "%s:%ld:%s = NULL\n";
215 kprintf(fmt,file,line,name,pointer);
219 /****************************************************************************/
221 void
222 _SHOWSTRING(
223 const char *string,
224 const char *name,
225 const char *file,
226 int line)
228 if(__debug_level >= DEBUGLEVEL_Reports)
230 _INDENT();
231 kprintf("%s:%ld:%s = 0x%08lx \"%s\"\n",file,line,name,string,string);
235 /****************************************************************************/
237 void
238 _SHOWMSG(
239 const char *string,
240 const char *file,
241 int line)
243 if(__debug_level >= DEBUGLEVEL_Reports)
245 _INDENT();
246 kprintf("%s:%ld:%s\n",file,line,string);
250 /****************************************************************************/
252 void
253 _DPRINTF_HEADER(
254 const char *file,
255 int line)
257 if(__debug_level >= DEBUGLEVEL_Reports)
259 _INDENT();
260 kprintf("%s:%ld:",file,line);
264 #ifdef __SASC
266 static void __asm
267 putch(register __d0 UBYTE c)
269 if(c != '\0')
270 kputc(c);
273 #else
275 static void
276 putch(UBYTE c __asm("d0"))
278 if(c != '\0')
279 kputc(c);
282 #endif /* __SASC */
284 void
285 _DPRINTF(const char *fmt,...)
287 if(__debug_level >= DEBUGLEVEL_Reports)
289 va_list args;
291 va_start(args,fmt);
292 RawDoFmt((char *)fmt,args,(VOID (*)())putch,NULL);
293 va_end(args);
295 kprintf("\n");
299 void
300 _DLOG(const char *fmt,...)
302 if(__debug_level >= DEBUGLEVEL_Reports)
304 va_list args;
306 va_start(args,fmt);
307 RawDoFmt((char *)fmt,args,(VOID (*)())putch,NULL);
308 va_end(args);
312 /****************************************************************************/
314 void
315 _ENTER(
316 const char *file,
317 int line,
318 const char *function)
320 if(__debug_level >= DEBUGLEVEL_CallTracing)
322 _INDENT();
323 kprintf("%s:%ld:Entering %s\n",file,line,function);
326 indent_level++;
329 void
330 _LEAVE(
331 const char *file,
332 int line,
333 const char *function)
335 indent_level--;
337 if(__debug_level >= DEBUGLEVEL_CallTracing)
339 _INDENT();
340 kprintf("%s:%ld: Leaving %s\n",file,line,function);
344 void
345 _RETURN(
346 const char *file,
347 int line,
348 const char *function,
349 unsigned long result)
351 indent_level--;
353 if(__debug_level >= DEBUGLEVEL_CallTracing)
355 _INDENT();
356 kprintf("%s:%ld: Leaving %s (result 0x%08lx, %ld)\n",file,line,function,result,result);
360 /****************************************************************************/
362 void
363 _ASSERT(
364 int x,
365 const char *xs,
366 const char *file,
367 int line,
368 const char *function)
370 #ifdef CONFIRM
372 STATIC BOOL ScrollMode = FALSE;
373 STATIC BOOL BatchMode = FALSE;
375 if(BatchMode == FALSE)
377 if(x == 0)
379 kprintf("%s:%ld:Expression `%s' failed assertion in %s().\n",
380 file,
381 line,
383 function);
385 if(ScrollMode == FALSE)
387 ULONG Signals;
389 SetSignal(0,SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D | SIGBREAKF_CTRL_E);
391 kprintf(" ^C to continue, ^D to enter scroll mode, ^E to enter batch mode\r");
393 Signals = Wait(SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D | SIGBREAKF_CTRL_E);
395 if(Signals & SIGBREAKF_CTRL_D)
397 ScrollMode = TRUE;
399 kprintf("Ok, entering scroll mode\033[K\n");
401 else if (Signals & SIGBREAKF_CTRL_E)
403 BatchMode = TRUE;
405 kprintf("Ok, entering batch mode\033[K\n");
407 else
409 /* Continue */
411 kprintf("\033[K\r");
417 #else
419 if(x == 0)
421 _INDENT();
422 kprintf("%s:%ld:Expression `%s' failed assertion in %s().\n",
423 file,
424 line,
426 function);
429 #endif /* CONFIRM */