-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.c
84 lines (73 loc) · 1.93 KB
/
log.c
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
/*
* log.c - A logging facility for debugging
*
* Copyright (C) 1995-1998 David Firth
* Copyright (C) 1998-2005 Atari800 development team (see DOC/CREDITS)
*
* This file is part of the Atari800 emulator project which emulates
* the Atari 400, 800, 800XL, 130XE, and 5200 8-bit computers.
*
* Atari800 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Atari800 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Atari800; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "log.h"
#ifdef MACOSX
# define PRINT(a) ControlManagerMessagePrint(a)
#else
# define PRINT(a) printf("%s", a)
#endif
#ifdef BUFFERED_LOG
char Log_buffer[Log_BUFFER_SIZE] = "";
#endif
void Log_print(char *format, ...)
{
va_list args;
char buffer[8192];
#ifdef BUFFERED_LOG
int buflen;
#endif
va_start(args, format);
#ifdef HAVE_VSNPRINTF
vsnprintf(buffer, sizeof(buffer) - 2 /* -2 for the strcat() */, format, args);
#else
vsprintf(buffer, format, args);
#endif
va_end(args);
#ifdef __PLUS
strcat(buffer, "\r\n");
#else
strcat(buffer, "\n");
#endif
#ifdef BUFFERED_LOG
buflen = strlen(buffer);
if ((strlen(Log_buffer) + strlen(buffer) + 1) > Log_BUFFER_SIZE)
*Log_buffer = 0;
strcat(Log_buffer, buffer);
#else
PRINT(buffer);
#endif
}
void Log_flushlog(void)
{
#ifdef BUFFERED_LOG
if (*Log_buffer) {
PRINT(Log_buffer);
*Log_buffer = 0;
}
#endif
}