File: sdlerr.c

package info (click to toggle)
tworld 1.3.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 6,600 kB
  • ctags: 1,403
  • sloc: ansic: 12,442; perl: 2,465; makefile: 165; sh: 9
file content (92 lines) | stat: -rw-r--r-- 1,805 bytes parent folder | download | duplicates (7)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* sdlerr.c: Notification functionality, not supplied by the SDL library.
 * 
 * Copyright (C) 2001-2006 by Brian Raiter, under the GNU General Public
 * License. No warranty. See COPYING for details.
 */

#include	<stdio.h>
#include	<stdarg.h>
#include	"sdlgen.h"

#ifdef WIN32

/*
 * Windows version
 */

#include	"windows.h"

/* Ring the bell already.
 */
void ding(void)
{
    MessageBeep(0);
}

/* Display a message box. If action is NOTIFY_LOG, the text of the
 * message is written to stderr instead.
 */
void usermessage(int action, char const *prefix,
		 char const *cfile, unsigned long lineno,
		 char const *fmt, va_list args)
{
    static char	errbuf[4096];
    char       *p;

    p = errbuf;

    if (prefix)
	p += sprintf(p, "%s: ", prefix);
    if (fmt)
	p += vsprintf(p, fmt, args);
    if (cfile)
	p += sprintf(p, " [%s:%lu]", cfile, lineno);

    switch (action) {
      case NOTIFY_DIE:
	MessageBox(NULL, errbuf, "Tile World", MB_ICONSTOP | MB_OK);
	break;
      case NOTIFY_ERR:
	MessageBox(NULL, errbuf, "Tile World", MB_ICONEXCLAMATION | MB_OK);
	break;
      case NOTIFY_LOG:
	fputs(errbuf, stderr);
	fputc('\n', stderr);
	fflush(stderr);
	break;
    }
}

#else

/*
 * Unix version
 */

/* Ring the bell already.
 */
void ding(void)
{
    fputc('\a', stderr);
    fflush(stderr);
}

/* Display a formatted message on stderr.
 */
void usermessage(int action, char const *prefix,
		 char const *cfile, unsigned long lineno,
		 char const *fmt, va_list args)
{
    fprintf(stderr, "%s: ", action == NOTIFY_DIE ? "FATAL" :
			    action == NOTIFY_ERR ? "error" : "warning");
    if (cfile)
	fprintf(stderr, "[%s:%lu] ", cfile, lineno);
    if (prefix)
	fprintf(stderr, "%s: ", prefix);
    if (fmt)
	vfprintf(stderr, fmt, args);
    fputc('\n', stderr);
    fflush(stderr);
}

#endif