00001 /* 00002 =========================================================================== 00003 Copyright (C) 1999-2005 Id Software, Inc. 00004 00005 This file is part of Quake III Arena source code. 00006 00007 Quake III Arena source code is free software; you can redistribute it 00008 and/or modify it under the terms of the GNU General Public License as 00009 published by the Free Software Foundation; either version 2 of the License, 00010 or (at your option) any later version. 00011 00012 Quake III Arena source code is distributed in the hope that it will be 00013 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with Foobar; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 =========================================================================== 00021 */ 00022 00023 /***************************************************************************** 00024 * name: l_log.c 00025 * 00026 * desc: log file 00027 * 00028 * $Archive: /MissionPack/CODE/botlib/l_log.c $ 00029 * 00030 *****************************************************************************/ 00031 00032 #include <stdlib.h> 00033 #include <stdio.h> 00034 #include <string.h> 00035 00036 #include "../game/q_shared.h" 00037 #include "../game/botlib.h" 00038 #include "be_interface.h" //for botimport.Print 00039 #include "l_libvar.h" 00040 00041 #define MAX_LOGFILENAMESIZE 1024 00042 00043 typedef struct logfile_s 00044 { 00045 char filename[MAX_LOGFILENAMESIZE]; 00046 FILE *fp; 00047 int numwrites; 00048 } logfile_t; 00049 00050 static logfile_t logfile; 00051 00052 //=========================================================================== 00053 // 00054 // Parameter: - 00055 // Returns: - 00056 // Changes Globals: - 00057 //=========================================================================== 00058 void Log_Open(char *filename) 00059 { 00060 if (!LibVarValue("log", "0")) return; 00061 if (!filename || !strlen(filename)) 00062 { 00063 botimport.Print(PRT_MESSAGE, "openlog <filename>\n"); 00064 return; 00065 } //end if 00066 if (logfile.fp) 00067 { 00068 botimport.Print(PRT_ERROR, "log file %s is already opened\n", logfile.filename); 00069 return; 00070 } //end if 00071 logfile.fp = fopen(filename, "wb"); 00072 if (!logfile.fp) 00073 { 00074 botimport.Print(PRT_ERROR, "can't open the log file %s\n", filename); 00075 return; 00076 } //end if 00077 strncpy(logfile.filename, filename, MAX_LOGFILENAMESIZE); 00078 botimport.Print(PRT_MESSAGE, "Opened log %s\n", logfile.filename); 00079 } //end of the function Log_Create 00080 //=========================================================================== 00081 // 00082 // Parameter: - 00083 // Returns: - 00084 // Changes Globals: - 00085 //=========================================================================== 00086 void Log_Close(void) 00087 { 00088 if (!logfile.fp) return; 00089 if (fclose(logfile.fp)) 00090 { 00091 botimport.Print(PRT_ERROR, "can't close log file %s\n", logfile.filename); 00092 return; 00093 } //end if 00094 logfile.fp = NULL; 00095 botimport.Print(PRT_MESSAGE, "Closed log %s\n", logfile.filename); 00096 } //end of the function Log_Close 00097 //=========================================================================== 00098 // 00099 // Parameter: - 00100 // Returns: - 00101 // Changes Globals: - 00102 //=========================================================================== 00103 void Log_Shutdown(void) 00104 { 00105 if (logfile.fp) Log_Close(); 00106 } //end of the function Log_Shutdown 00107 //=========================================================================== 00108 // 00109 // Parameter: - 00110 // Returns: - 00111 // Changes Globals: - 00112 //=========================================================================== 00113 void QDECL Log_Write(char *fmt, ...) 00114 { 00115 va_list ap; 00116 00117 if (!logfile.fp) return; 00118 va_start(ap, fmt); 00119 vfprintf(logfile.fp, fmt, ap); 00120 va_end(ap); 00121 //fprintf(logfile.fp, "\r\n"); 00122 fflush(logfile.fp); 00123 } //end of the function Log_Write 00124 //=========================================================================== 00125 // 00126 // Parameter: - 00127 // Returns: - 00128 // Changes Globals: - 00129 //=========================================================================== 00130 void QDECL Log_WriteTimeStamped(char *fmt, ...) 00131 { 00132 va_list ap; 00133 00134 if (!logfile.fp) return; 00135 fprintf(logfile.fp, "%d %02d:%02d:%02d:%02d ", 00136 logfile.numwrites, 00137 (int) (botlibglobals.time / 60 / 60), 00138 (int) (botlibglobals.time / 60), 00139 (int) (botlibglobals.time), 00140 (int) ((int) (botlibglobals.time * 100)) - 00141 ((int) botlibglobals.time) * 100); 00142 va_start(ap, fmt); 00143 vfprintf(logfile.fp, fmt, ap); 00144 va_end(ap); 00145 fprintf(logfile.fp, "\r\n"); 00146 logfile.numwrites++; 00147 fflush(logfile.fp); 00148 } //end of the function Log_Write 00149 //=========================================================================== 00150 // 00151 // Parameter: - 00152 // Returns: - 00153 // Changes Globals: - 00154 //=========================================================================== 00155 FILE *Log_FilePointer(void) 00156 { 00157 return logfile.fp; 00158 } //end of the function Log_FilePointer 00159 //=========================================================================== 00160 // 00161 // Parameter: - 00162 // Returns: - 00163 // Changes Globals: - 00164 //=========================================================================== 00165 void Log_Flush(void) 00166 { 00167 if (logfile.fp) fflush(logfile.fp); 00168 } //end of the function Log_Flush 00169
1.3.9.1