File: dprintf.c

package info (click to toggle)
nethack 3.6.7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,468 kB
  • sloc: ansic: 266,495; cpp: 13,652; yacc: 2,903; perl: 1,426; lex: 581; sh: 535; xml: 372; awk: 98; makefile: 68; fortran: 51; sed: 11
file content (48 lines) | stat: -rw-r--r-- 1,278 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* NetHack 3.6	dprintf.c	$NHDT-Date: 1432512798 2015/05/25 00:13:18 $  $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */
/* Copyright (c) Jon W{tte, 1993.				  */
/* NetHack may be freely redistributed.  See license for details. */

#include "hack.h"
#include "macwin.h"

static Boolean
KeyDown(unsigned short code)
{
    unsigned char keys[16];

    GetKeys((void *) keys);
    return ((keys[code >> 3] >> (code & 7)) & 1) != 0;
}

void
dprintf(char *format, ...)
{
    char buffer[500];
    va_list list;
    int doit;
#define DO_DEBUGSTR 1
#define DO_PLINE 2

    if (flags.debug) {
        doit = 0;
        if (macFlags.hasDebugger && KeyDown(0x39)) { /* Caps Lock */
            doit = DO_DEBUGSTR;
        } else if (KeyDown(0x3B) && iflags.window_inited && /* Control */
                   (WIN_MESSAGE != -1)
                   && theWindows[WIN_MESSAGE].its_window) {
            doit = DO_PLINE;
        }

        if (doit) {
            va_start(list, format);
            vsprintf(&buffer[1], format, list);
            va_end(list);

            if (doit == DO_DEBUGSTR) {
                buffer[0] = strlen(&buffer[1]);
                DebugStr((uchar *) buffer);
            } else if (doit == DO_PLINE)
                pline("%s", &buffer[1]);
        }
    }
}