| 1 |
/* Emacs style mode select -*- C -*- |
| 2 |
*----------------------------------------------------------------------------- |
| 3 |
* |
| 4 |
* |
| 5 |
* PrBoom: a Doom port merged with LxDoom and LSDLDoom |
| 6 |
* based on BOOM, a modified and improved DOOM engine |
| 7 |
* Copyright (C) 1999 by |
| 8 |
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman |
| 9 |
* Copyright (C) 1999-2000 by |
| 10 |
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze |
| 11 |
* Copyright 2005, 2006 by |
| 12 |
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko |
| 13 |
* |
| 14 |
* This program is free software; you can redistribute it and/or |
| 15 |
* modify it under the terms of the GNU General Public License |
| 16 |
* as published by the Free Software Foundation; either version 2 |
| 17 |
* of the License, or (at your option) any later version. |
| 18 |
* |
| 19 |
* This program is distributed in the hope that it will be useful, |
| 20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
* GNU General Public License for more details. |
| 23 |
* |
| 24 |
* You should have received a copy of the GNU General Public License |
| 25 |
* along with this program; if not, write to the Free Software |
| 26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 27 |
* 02111-1307, USA. |
| 28 |
* |
| 29 |
* DESCRIPTION: |
| 30 |
* Provides a logical console output routine that allows what is |
| 31 |
* output to console normally and when output is redirected to |
| 32 |
* be controlled.. |
| 33 |
* |
| 34 |
*-----------------------------------------------------------------------------*/ |
| 35 |
|
| 36 |
#ifdef HAVE_CONFIG_H |
| 37 |
#include "config.h" |
| 38 |
#endif |
| 39 |
#ifdef _MSC_VER |
| 40 |
#include <io.h> |
| 41 |
#endif |
| 42 |
#include <stdio.h> |
| 43 |
#include <stdlib.h> |
| 44 |
#include <stdarg.h> |
| 45 |
#include <string.h> |
| 46 |
#include <assert.h> |
| 47 |
#ifdef HAVE_UNISTD_H |
| 48 |
#include <unistd.h> |
| 49 |
#endif |
| 50 |
#include "doomtype.h" |
| 51 |
#include "lprintf.h" |
| 52 |
#include "i_main.h" |
| 53 |
#include "i_system.h" |
| 54 |
#include "e6y.h"//e6y |
| 55 |
#include "i_capture.h" |
| 56 |
|
| 57 |
#include "dsda/args.h" |
| 58 |
|
| 59 |
static dboolean disable_message_box; |
| 60 |
|
| 61 |
int cons_stdout_mask = LO_INFO; |
| 62 |
int cons_stderr_mask = LO_WARN | LO_ERROR; |
| 63 |
|
| 64 |
/* cphipps - enlarged message buffer and made non-static |
| 65 |
* We still have to be careful here, this function can be called after exit |
| 66 |
*/ |
| 67 |
#define MAX_MESSAGE_SIZE 2048 |
| 68 |
|
| 69 |
int lprintf(OutputLevels pri, const char *s, ...) |
| 70 |
{ |
| 71 |
int r=0; |
| 72 |
char msg[MAX_MESSAGE_SIZE]; |
| 73 |
int lvl=pri; |
| 74 |
|
| 75 |
va_list v; |
| 76 |
va_start(v,s); |
| 77 |
vsnprintf(msg,sizeof(msg),s,v); /* print message in buffer */ |
| 78 |
va_end(v); |
| 79 |
|
| 80 |
#ifdef _WIN32 |
| 81 |
// do not crash with unicode dirs |
| 82 |
if (fileno(stdout) != -1) |
| 83 |
#endif |
| 84 |
if (lvl & cons_stdout_mask) |
| 85 |
r = fprintf(stdout,"%s",msg); |
| 86 |
|
| 87 |
#ifdef _WIN32 |
| 88 |
// do not crash with unicode dirs |
| 89 |
if (fileno(stderr) != -1) |
| 90 |
#endif |
| 91 |
if (lvl & cons_stderr_mask) |
| 92 |
r = fprintf(stderr,"%s",msg); |
| 93 |
|
| 94 |
return r; |
| 95 |
} |
| 96 |
|
| 97 |
void I_EnableVerboseLogging(void) |
| 98 |
{ |
| 99 |
cons_stdout_mask = LO_INFO | LO_DEBUG; |
| 100 |
} |
| 101 |
|
| 102 |
void I_DisableAllLogging(void) |
| 103 |
{ |
| 104 |
cons_stdout_mask = 0; |
| 105 |
cons_stderr_mask = 0; |
| 106 |
} |
| 107 |
|
| 108 |
void I_DisableMessageBoxes(void) |
| 109 |
{ |
| 110 |
disable_message_box = true; |
| 111 |
} |
| 112 |
|
| 113 |
/* |
| 114 |
* I_Error |
| 115 |
* |
| 116 |
* cphipps - moved out of i_* headers, to minimise source files that depend on |
| 117 |
* the low-level headers. All this does is print the error, then call the |
| 118 |
* low-level safe exit function. |
| 119 |
* killough 3/20/98: add const |
| 120 |
*/ |
| 121 |
|
| 122 |
void I_Error(const char *error, ...) |
| 123 |
{ |
| 124 |
char errmsg[MAX_MESSAGE_SIZE]; |
| 125 |
va_list argptr; |
| 126 |
va_start(argptr,error); |
| 127 |
vsnprintf(errmsg,sizeof(errmsg),error,argptr); |
| 128 |
va_end(argptr); |
| 129 |
lprintf(LO_ERROR, "%s\n", errmsg); |
| 130 |
#ifdef _WIN32 |
| 131 |
if (!disable_message_box && !dsda_Flag(dsda_arg_nodraw) && !capturing_video) { |
| 132 |
I_MessageBox(errmsg, PRB_MB_OK); |
| 133 |
} |
| 134 |
#endif |
| 135 |
I_SafeExit(-1); |
| 136 |
} |
| 137 |
|
| 138 |
void I_Warn(const char *error, ...) |
| 139 |
{ |
| 140 |
char errmsg[MAX_MESSAGE_SIZE]; |
| 141 |
va_list argptr; |
| 142 |
va_start(argptr, error); |
| 143 |
vsnprintf(errmsg, sizeof(errmsg), error, argptr); |
| 144 |
va_end(argptr); |
| 145 |
lprintf(LO_WARN, "%s\n", errmsg); |
| 146 |
#ifdef _WIN32 |
| 147 |
if (!dsda_Flag(dsda_arg_nodraw) && !capturing_video) { |
| 148 |
I_MessageBox(errmsg, PRB_MB_OK); |
| 149 |
} |
| 150 |
#endif |
| 151 |
} |