1
//------------------------------------------------------------------------
2
// DISPLAY : Command-line display routines
3
//------------------------------------------------------------------------
5
// GL-Friendly Node Builder (C) 2000-2005 Andrew Apted
7
// Based on 'BSP 2.3' by Colin Reed, Lee Killough and others.
9
// This program is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU General Public License
11
// as published by the Free Software Foundation; either version 2
12
// of the License, or (at your option) any later version.
14
// This program is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
// GNU General Public License for more details.
19
//------------------------------------------------------------------------
32
#if defined(MSDOS) || defined(__MSDOS__)
36
#if defined(UNIX) || defined(__UNIX__)
37
#include <unistd.h> // Unix: isatty()
38
#include <signal.h> // Unix: raise()
46
#error GLBSP_TEXT should be defined when compiling this file
50
#define FATAL_COREDUMP 0
53
static boolean_g disable_progress = FALSE;
55
static displaytype_e curr_disp = DIS_INVALID;
57
static int progress_target = 0;
58
static int progress_shown;
61
const nodebuildfuncs_t cmdline_funcs =
70
TextDisplaySetBarLimit,
71
TextDisplaySetBarText,
79
void TextStartup(void)
84
// no whirling baton if stderr is redirected
86
disable_progress = TRUE;
93
void TextShutdown(void)
99
// TextDisableProgress
101
void TextDisableProgress(void)
103
disable_progress = TRUE;
109
void TextPrintMsg(const char *str, ...)
123
// Terminates the program reporting an error.
125
void TextFatalError(const char *str, ...)
130
vfprintf(stderr, str, args);
133
#if FATAL_COREDUMP && defined(UNIX)
143
void TextTicker(void)
149
static void ClearProgress(void)
151
fprintf(stderr, " \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
157
boolean_g TextDisplayOpen(displaytype_e type)
159
// shutdown any existing display
164
case DIS_BUILDPROGRESS:
165
case DIS_FILEPROGRESS:
170
curr_disp = DIS_INVALID;
181
// TextDisplaySetTitle
183
void TextDisplaySetTitle(const char *str)
189
// TextDisplaySetBarText
191
void TextDisplaySetBarText(int barnum, const char *str)
197
// TextDisplaySetBarLimit
199
void TextDisplaySetBarLimit(int barnum, int limit)
201
if (curr_disp == DIS_INVALID || disable_progress)
204
// select the correct bar
205
if ((curr_disp == DIS_FILEPROGRESS && barnum != 1) ||
206
(curr_disp == DIS_BUILDPROGRESS && barnum != 1))
211
progress_target = limit;
218
void TextDisplaySetBar(int barnum, int count)
222
if (curr_disp == DIS_INVALID || disable_progress ||
223
progress_target <= 0)
228
// select the correct bar
229
if ((curr_disp == DIS_FILEPROGRESS && barnum != 1) ||
230
(curr_disp == DIS_BUILDPROGRESS && barnum != 1))
235
if (count > progress_target)
236
TextFatalError("\nINTERNAL ERROR: Progress went past target !\n\n");
238
perc = count * 100 / progress_target;
240
if (perc == progress_shown)
246
fprintf(stderr, "--%3d%%--\b\b\b\b\b\b\b\b", perc);
248
progress_shown = perc;
254
void TextDisplayClose(void)
256
if (curr_disp == DIS_INVALID || disable_progress)