summaryrefslogtreecommitdiff
path: root/3dc/win95/DEBUGLOG.CPP
diff options
context:
space:
mode:
authorRebellion Developments <rebellion@nomail>2000-03-16 11:25:00 +0100
committerPatryk Obara <dreamer.tan@gmail.com>2019-08-19 05:45:17 +0200
commit218ca90543758a20ac326e444ca0643174ca7384 (patch)
tree16bfe3e5307f9f515489000f28728224291a0e3b /3dc/win95/DEBUGLOG.CPP
Import Aliens vs Predator - Gold (Build 116)
Source code release, imported from: https://www.gamefront.com/games/aliens-vs-predator-3/file/avp-gold-complete-source-code All text files were converted to Unix format.
Diffstat (limited to '3dc/win95/DEBUGLOG.CPP')
-rw-r--r--3dc/win95/DEBUGLOG.CPP122
1 files changed, 122 insertions, 0 deletions
diff --git a/3dc/win95/DEBUGLOG.CPP b/3dc/win95/DEBUGLOG.CPP
new file mode 100644
index 0000000..2e76b9f
--- /dev/null
+++ b/3dc/win95/DEBUGLOG.CPP
@@ -0,0 +1,122 @@
+#include <string.h>
+#include <stdlib.h>
+#include <windows.h>
+#include "debuglog.hpp"
+
+LogFile::LogFile(char const * const _fname) : fname(0) , ever_written(0)
+{
+ FILE * fp = fopen(_fname,"w");
+ if (fp)
+ {
+ fclose(fp);
+ fname = new char[strlen(_fname)+1];
+ strcpy(fname,_fname);
+ return;
+ }
+ char const * path = getenv("TEMP");
+ if (!path) path = getenv("TMP");
+ if (!path) return;
+ fname = new char[strlen(path)+1+strlen(_fname)+1];
+ strcpy(fname,path);
+ strncat(fname,"\\",1);
+ strcat(fname,_fname);
+ fp = fopen(fname,"w");
+ if (fp)
+ fclose(fp);
+ else
+ {
+ delete[] fname;
+ fname = 0;
+ }
+}
+
+LogFile::~LogFile()
+{
+ if (unwritten.size())
+ {
+ FILE * fp = fopen(fname,"a");
+ for (int attempt=0; !fp && attempt<10; ++attempt)
+ {
+ Sleep(100);
+ fp = fopen(fname,"a");
+ }
+ if (fp)
+ {
+ FlushOut(fp);
+ fclose(fp);
+ }
+ }
+ if (fname) delete[] fname;
+}
+
+LogFile & LogFile::operator = (LogFile const & l)
+{
+ if (&l != this)
+ {
+ if (fname) delete[] fname;
+ if (l.fname)
+ {
+ fname = new char[strlen(l.fname)+1];
+ strcpy(fname,l.fname);
+ }
+ else
+ fname = 0;
+
+ unwritten = l.unwritten;
+ ever_written = l.ever_written;
+ }
+ return *this;
+}
+
+LogFile::LogFile(LogFile const & l)
+: unwritten(l.unwritten)
+, ever_written(l.ever_written)
+{
+ if (l.fname)
+ {
+ fname = new char[strlen(l.fname)+1];
+ strcpy(fname,l.fname);
+ }
+ else
+ fname = 0;
+}
+
+void LogFile::FlushOut(FILE * fp)
+{
+ while (unwritten.size())
+ {
+ char * str = unwritten.first_entry();
+ unwritten.delete_first_entry();
+ fputs(str,fp);
+ delete[] str;
+ }
+}
+
+int vlfprintf(LOGFILE * lfp, char const * format, va_list args )
+{
+ return lfp->vlprintf(format,args);
+}
+
+int lfprintf(LOGFILE * lfp, char const * format, ... )
+{
+ va_list ap;
+ va_start(ap, format);
+ int rv = lfp->vlprintf(format,ap);
+ va_end(ap);
+ return rv;
+}
+
+int lfputs(LOGFILE * lfp, char const * str)
+{
+ return lfp->lputs(str);
+}
+
+LOGFILE * lfopen(char const * fname)
+{
+ return new LogFile(fname);
+}
+
+void lfclose(LOGFILE * lfp)
+{
+ delete lfp;
+}