use the dynamic buffer for both curses and stdout

This commit is contained in:
Bill Currie 2001-09-25 16:19:26 +00:00
parent 9ffe53178c
commit 3909176957
1 changed files with 18 additions and 20 deletions

View File

@ -174,24 +174,26 @@ C_Shutdown (void)
static void static void
C_Print (const char *fmt, va_list args) C_Print (const char *fmt, va_list args)
{ {
static unsigned char *buffer;
unsigned char *txt;
int size;
static int buffer_size;
size = vsnprintf (buffer, buffer_size, fmt, args);
if (size + 1 > buffer_size) {
buffer_size = ((size + 1 + 1024) / 1024) * 1024; // 1k multiples
buffer = realloc (buffer, buffer_size);
if (!buffer)
Sys_Error ("console: could not allocate %d bytes\n",
buffer_size);
vsnprintf (buffer, buffer_size, fmt, args);
}
txt = buffer;
#ifdef HAVE_CURSES_H #ifdef HAVE_CURSES_H
if (use_curses) { if (use_curses) {
char *txt;
static char *buffer;
int size;
static int buffer_size;
chtype ch; chtype ch;
size = vsnprintf (buffer, buffer_size, fmt, args);
if (size + 1 > buffer_size) {
buffer_size = ((size + 1 + 1024) / 1024) * 1024; // 1k multiples
buffer = realloc (buffer, buffer_size);
if (!buffer)
Sys_Error ("console: could not allocate %d bytes\n",
buffer_size);
vsnprintf (buffer, buffer_size, fmt, args);
}
txt = buffer; txt = buffer;
while ((ch = (byte)*txt++)) { while ((ch = (byte)*txt++)) {
@ -203,12 +205,8 @@ C_Print (const char *fmt, va_list args)
} else } else
#endif #endif
{ {
char msg[4096]; while (*txt)
unsigned char *p; putc (sys_char_map[*txt++], stdout);
vsnprintf (msg, sizeof (msg), fmt, args);
for (p = (unsigned char *) msg; *p; p++)
putc (sys_char_map[*p], stdout);
fflush (stdout); fflush (stdout);
} }
} }