home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Online / Samba / source / amiga_rcs / Assert.c < prev    next >
C/C++ Source or Header  |  2000-08-17  |  7KB  |  419 lines

  1. head    1.2;
  2. access;
  3. symbols
  4.     V1_15:1.2
  5.     V1_12:1.1
  6.     V1_11:1.1
  7.     V1_10:1.1
  8.     V1_9:1.1
  9.     V1_8:1.1
  10.     V1_7:1.1
  11.     V1_6:1.1
  12.     V1_5:1.1
  13.     V1_4:1.1
  14.     V1_3:1.1
  15.     V1_2:1.1
  16.     V1_1:1.1;
  17. locks
  18.     olsen:1.2; strict;
  19. comment    @ * @;
  20.  
  21.  
  22. 1.2
  23. date    2000.05.22.19.10.25;    author olsen;    state Exp;
  24. branches;
  25. next    1.1;
  26.  
  27. 1.1
  28. date    99.02.06.12.18.32;    author olsen;    state Exp;
  29. branches;
  30. next    ;
  31.  
  32.  
  33. desc
  34. @.
  35. @
  36.  
  37.  
  38. 1.2
  39. log
  40. @.
  41. @
  42. text
  43. @/*
  44.  * $Id: Assert.c 1.1 1999/02/06 12:18:32 olsen Exp olsen $
  45.  *
  46.  * :ts=8
  47.  *
  48.  * AmigaOS wrapper routines for Samba 2.0.0, using the AmiTCP V4 API
  49.  * and the SAS/C V6.58 compiler.
  50.  *
  51.  * Copyright (C) 1999-2000 by Olaf `Olsen' Barthel <olsen@@sourcery.han.de>
  52.  *
  53.  * This program is free software; you can redistribute it and/or modify
  54.  * it under the terms of the GNU General Public License as published by
  55.  * the Free Software Foundation; either version 2 of the License, or
  56.  * (at your option) any later version.
  57.  * 
  58.  * This program is distributed in the hope that it will be useful,
  59.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  60.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  61.  * GNU General Public License for more details.
  62.  * 
  63.  * You should have received a copy of the GNU General Public License
  64.  * along with this program; if not, write to the Free Software
  65.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  66.  */
  67.  
  68. /****************************************************************************/
  69.  
  70. #include <dos/dos.h>
  71.  
  72. #include <clib/exec_protos.h>
  73. #include <clib/dos_protos.h>
  74.  
  75. #include <pragmas/exec_pragmas.h>
  76. #include <pragmas/dos_pragmas.h>
  77.  
  78. #include <string.h>
  79.  
  80. extern struct Library * SysBase;
  81.  
  82. extern void kprintf(const char *,...);
  83. extern void __stdargs kputc(char c);
  84.  
  85. /****************************************************************************/
  86.  
  87. #include <stdarg.h>
  88.  
  89. /****************************************************************************/
  90.  
  91. #define DEBUGLEVEL_OnlyAsserts    0
  92. #define DEBUGLEVEL_Reports    1
  93. #define DEBUGLEVEL_CallTracing    2
  94.  
  95. /****************************************************************************/
  96.  
  97. static int indent_level = 0;
  98. static int debug_level = DEBUGLEVEL_CallTracing;
  99.  
  100. static char program_name[40];
  101. static int program_name_len = 0;
  102.  
  103. /****************************************************************************/
  104.  
  105. void
  106. _SETPROGRAMNAME(char *name)
  107. {
  108.     if(name != NULL && name[0] != '\0')
  109.     {
  110.         program_name_len = strlen(name);
  111.         if(program_name_len >= sizeof(program_name))
  112.             program_name_len = sizeof(program_name)-1;
  113.  
  114.         strncpy(program_name,name,program_name_len);
  115.         program_name[program_name_len] = '\0';
  116.     }
  117.     else
  118.     {
  119.         program_name_len = 0;
  120.     }
  121. }
  122.  
  123. /****************************************************************************/
  124.  
  125. int
  126. _SETDEBUGLEVEL(int level)
  127. {
  128.     int old_level = debug_level;
  129.  
  130.     debug_level = level;
  131.  
  132.     return(old_level);
  133. }
  134.  
  135. /****************************************************************************/
  136.  
  137. static int previous_debug_level = -1;
  138.  
  139. void
  140. _PUSHDEBUGLEVEL(int level)
  141. {
  142.     previous_debug_level = _SETDEBUGLEVEL(level);
  143. }
  144.  
  145. void
  146. _POPDEBUGLEVEL(void)
  147. {
  148.     if(previous_debug_level != -1)
  149.     {
  150.         _SETDEBUGLEVEL(previous_debug_level);
  151.  
  152.         previous_debug_level = -1;
  153.     }
  154. }
  155.  
  156. /****************************************************************************/
  157.  
  158. void
  159. _INDENT(void)
  160. {
  161.     if(program_name_len > 0)
  162.         kprintf("(%s) ",program_name);
  163.  
  164.     if(debug_level >= DEBUGLEVEL_CallTracing)
  165.     {
  166.         int i;
  167.  
  168.         for(i = 0 ; i < indent_level ; i++)
  169.             kprintf("   ");
  170.     }
  171. }
  172.  
  173. /****************************************************************************/
  174.  
  175. void
  176. _SHOWVALUE(
  177.     unsigned long value,
  178.     int size,
  179.     const char *name,
  180.     const char *file,
  181.     int line)
  182. {
  183.     if(debug_level >= DEBUGLEVEL_Reports)
  184.     {
  185.         char *fmt;
  186.  
  187.         switch(size)
  188.         {
  189.             case 1:
  190.     
  191.                 fmt = "%s:%ld:%s = %ld, 0x%02lx";
  192.                 break;
  193.     
  194.             case 2:
  195.     
  196.                 fmt = "%s:%ld:%s = %ld, 0x%04lx";
  197.                 break;
  198.     
  199.             default:
  200.     
  201.                 fmt = "%s:%ld:%s = %ld, 0x%08lx";
  202.                 break;
  203.         }
  204.     
  205.         _INDENT();
  206.     
  207.         kprintf(fmt,file,line,name,value,value);
  208.     
  209.         if(size == 1 && value < 256)
  210.         {
  211.             if(value < ' ' || (value >= 127 && value < 160))
  212.                 kprintf(", '\\x%02lx'",value);
  213.             else
  214.                 kprintf(", '%lc'",value);
  215.         }
  216.     
  217.         kprintf("\n");
  218.     }
  219. }
  220.  
  221. /****************************************************************************/
  222.  
  223. void
  224. _SHOWSTRING(
  225.     const char *string,
  226.     const char *name,
  227.     const char *file,
  228.     int line)
  229. {
  230.     if(debug_level >= DEBUGLEVEL_Reports)
  231.     {
  232.         _INDENT();
  233.         kprintf("%s:%ld:%s = 0x%08lx \"%s\"\n",file,line,name,string,string);
  234.     }
  235. }
  236.  
  237. /****************************************************************************/
  238.  
  239. void
  240. _SHOWMSG(
  241.     const char *string,
  242.     const char *file,
  243.     int line)
  244. {
  245.     if(debug_level >= DEBUGLEVEL_Reports)
  246.     {
  247.         _INDENT();
  248.         kprintf("%s:%ld:%s\n",file,line,string);
  249.     }
  250. }
  251.  
  252. /****************************************************************************/
  253.  
  254. void
  255. _DPRINTF_HEADER(
  256.     const char *file,
  257.     int line)
  258. {
  259.     if(debug_level >= DEBUGLEVEL_Reports)
  260.     {
  261.         _INDENT();
  262.         kprintf("%s:%ld:",file,line);
  263.     }
  264. }
  265.  
  266. static void __asm
  267. putch(register __d0 c)
  268. {
  269.     if(c != '\0')
  270.         kputc(c);
  271. }
  272.  
  273. void
  274. _DPRINTF(const char *fmt,...)
  275. {
  276.     if(debug_level >= DEBUGLEVEL_Reports)
  277.     {
  278.         va_list args;
  279.  
  280.         va_start(args,fmt);
  281.         RawDoFmt((char *)fmt,args,(VOID (*)())putch,NULL);
  282.         va_end(args);
  283.  
  284.         kprintf("\n");
  285.     }
  286. }
  287.  
  288. /****************************************************************************/
  289.  
  290. void
  291. _ENTER(
  292.     const char *file,
  293.     int line,
  294.     const char *function)
  295. {
  296.     if(debug_level >= DEBUGLEVEL_CallTracing)
  297.     {
  298.         _INDENT();
  299.         kprintf("%s:%ld:Entering %s\n",file,line,function);
  300.     }
  301.  
  302.     indent_level++;
  303. }
  304.  
  305. void
  306. _LEAVE(
  307.     const char *file,
  308.     int line,
  309.     const char *function)
  310. {
  311.     indent_level--;
  312.  
  313.     if(debug_level >= DEBUGLEVEL_CallTracing)
  314.     {
  315.         _INDENT();
  316.         kprintf("%s:%ld: Leaving %s\n",file,line,function);
  317.     }
  318. }
  319.  
  320. void
  321. _RETURN(
  322.     const char *file,
  323.     int line,
  324.     const char *function,
  325.     unsigned long result)
  326. {
  327.     indent_level--;
  328.  
  329.     if(debug_level >= DEBUGLEVEL_CallTracing)
  330.     {
  331.         _INDENT();
  332.         kprintf("%s:%ld: Leaving %s (result 0x%08lx, %ld)\n",file,line,function,result,result);
  333.     }
  334. }
  335.  
  336. /****************************************************************************/
  337.  
  338. void
  339. _ASSERT(
  340.     int x,
  341.     const char *xs,
  342.     const char *file,
  343.     int line,
  344.     const char *function)
  345. {
  346.     #ifdef CONFIRM
  347.     {
  348.         STATIC BOOL ScrollMode    = FALSE;
  349.         STATIC BOOL BatchMode    = FALSE;
  350.     
  351.         if(BatchMode == FALSE)
  352.         {
  353.             if(x == 0)
  354.             {
  355.                 kprintf("%s:%ld:Expression `%s' failed assertion in %s().\n",
  356.                         file,
  357.                         line,
  358.                         xs,
  359.                         function);
  360.     
  361.                 if(ScrollMode == FALSE)
  362.                 {
  363.                     ULONG Signals;
  364.     
  365.                     SetSignal(0,SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D | SIGBREAKF_CTRL_E);
  366.     
  367.                     kprintf(" ^C to continue, ^D to enter scroll mode, ^E to enter batch mode\r");
  368.     
  369.                     Signals = Wait(SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D | SIGBREAKF_CTRL_E);
  370.     
  371.                     if(Signals & SIGBREAKF_CTRL_D)
  372.                     {
  373.                         ScrollMode = TRUE;
  374.     
  375.                         kprintf("Ok, entering scroll mode\033[K\n");
  376.                     }
  377.                     else if (Signals & SIGBREAKF_CTRL_E)
  378.                     {
  379.                         BatchMode = TRUE;
  380.     
  381.                         kprintf("Ok, entering batch mode\033[K\n");
  382.                     }
  383.                     else
  384.                     {
  385.                         /* Continue */
  386.     
  387.                         kprintf("\033[K\r");
  388.                     }
  389.                 }
  390.             }
  391.         }
  392.     }
  393.     #else
  394.     {
  395.         if(x == 0)
  396.         {
  397.             _INDENT();
  398.             kprintf("%s:%ld:Expression `%s' failed assertion in %s().\n",
  399.                     file,
  400.                     line,
  401.                     xs,
  402.                     function);
  403.         }
  404.     }
  405.     #endif    /* CONFIRM */
  406. }
  407. @
  408.  
  409.  
  410. 1.1
  411. log
  412. @.
  413. @
  414. text
  415. @d9 1
  416. a9 1
  417.  * Copyright (C) 1999 by Olaf `Olsen' Barthel <olsen@@sourcery.han.de>
  418. @
  419.