home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / games / volume16 / nethack31 / patch2a / sys / mac / dprintf.c
C/C++ Source or Header  |  1993-06-16  |  1KB  |  58 lines

  1. /*    SCCS Id: @(#)dprintf.c    3.1    93/05/14          */
  2. /* Copyright (c) Jon W{tte, 1993.                  */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. #include "hack.h"
  6.  
  7. #include <Types.h>
  8. #include <stdarg.h>
  9. #include <stdio.h>
  10. #include <strings.h>
  11. #include <GestaltEqu.h>
  12.  
  13.  
  14. Boolean
  15. HasDebugger ( void ) {
  16. long osAttr ;
  17.     if ( Gestalt ( gestaltOSAttr , & osAttr ) ||
  18.         ! ( osAttr & ( 1 << gestaltSysDebuggerSupport ) ) ) {
  19.         return 0 ;
  20.     }
  21.     return 1 ;
  22. }
  23.  
  24.  
  25. Boolean
  26. KeyDown ( unsigned short code ) {
  27. unsigned char keys [ 16 ] ;
  28.  
  29.     GetKeys ( ( void * ) keys ) ;
  30.     return ( ( keys [ code >> 3 ] >> ( code & 7 ) ) & 1 ) != 0 ;
  31. }
  32.  
  33.  
  34. void
  35. dprintf ( char * format , ... ) {
  36. static char buffer [ 100 ] ;
  37. va_list list ;
  38. static Boolean checkedTrap = 0 ;
  39. static Boolean trapAvailable = 0 ;
  40.  
  41.     if ( ! checkedTrap ) {
  42.         checkedTrap = 1 ;
  43.         trapAvailable = HasDebugger ( ) ;
  44.     }
  45.     list = va_start ( list , format ) ;
  46.     vsprintf ( & buffer [ 1 ] , format , list ) ;
  47.     va_end ( list )  ;
  48.     buffer [ 0 ] = strlen ( & buffer [ 1 ] ) ;
  49.     if ( trapAvailable ) {
  50.         if ( KeyDown ( 0x39 ) ) {                                    /* Caps Lock */
  51.             DebugStr ( buffer ) ;
  52.         } else if ( KeyDown ( 0x3B ) && flags . window_inited &&    /* Control */
  53.             ( WIN_MESSAGE != -1 ) && theWindows [ WIN_MESSAGE ] . theWindow ) {
  54.             pline ( "%s" , & buffer [ 1 ] ) ;
  55.         }
  56.     }
  57. }
  58.