Initial commit of Command & Conquer Red Alert source code.

This commit is contained in:
LFeenanEA
2025-02-27 16:15:05 +00:00
parent b685cea758
commit 5e733d5dcc
2082 changed files with 797727 additions and 0 deletions

51
LAUNCHER/UTIL/FILED.H Normal file
View File

@@ -0,0 +1,51 @@
/*
** Command & Conquer Red Alert(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FILED_HEADER
#define FILED_HEADER
#include "odevice.h"
class FileD : public OutputDevice
{
public:
FileD(char *filename)
{
out=fopen(filename,"w");
if (out==NULL)
out=fopen("FileDev.out","w");
}
virtual ~FileD()
{ fclose(out); }
virtual int print(const char *str,int len)
{
char *string=new char[len+1];
memset(string,0,len+1);
memcpy(string,str,len);
fprintf(out,"%s",string);
delete[](string);
fflush(out);
return(len);
}
FILE *out;
};
#endif

40
LAUNCHER/UTIL/MBOXD.H Normal file
View File

@@ -0,0 +1,40 @@
/*
** Command & Conquer Red Alert(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MBOXD_HEADER
#define MBOXD_HEADER
#include "odevice.h"
class MboxD : public OutputDevice
{
public:
virtual int print(const char *str,int len)
{
char *string=new char[len+1];
memset(string,0,len+1);
memcpy(string,str,len);
MessageBox(NULL,string,"Debug Message", MB_OK | MB_ICONINFORMATION);
delete[](string);
return(len);
}
};
#endif

57
LAUNCHER/UTIL/MONOD.CPP Normal file
View File

@@ -0,0 +1,57 @@
/*
** Command & Conquer Red Alert(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "monod.h"
MonoD::MonoD(void)
{
#ifdef _WIN32
unsigned long retval;
handle = CreateFile("\\\\.\\MONO", GENERIC_READ|GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (handle != INVALID_HANDLE_VALUE)
{
DeviceIoControl(handle, (DWORD)IOCTL_MONO_CLEAR_SCREEN, NULL, 0, NULL, 0,
&retval,0);
}
#endif
}
MonoD::~MonoD()
{
#ifdef _WIN32
CloseHandle(handle);
handle=NULL;
#endif
}
int MonoD::print(const char *str, int len)
{
#ifdef _WIN32
unsigned long retval;
WriteFile(handle, str, len, &retval, NULL);
////DeviceIoControl(handle, (DWORD)IOCTL_MONO_PRINT_RAW, (void *)str, len, NULL, 0,
//// &retval,0);
return(len);
#else
for (int i=0; i<len; i++)
fprintf(stderr,"%c",str[i]);
return(len);
#endif
}

74
LAUNCHER/UTIL/MONOD.H Normal file
View File

@@ -0,0 +1,74 @@
/*
** Command & Conquer Red Alert(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MONOD_HEADER
#define MONOD_HEADER
#include <stdlib.h>
#include <stdio.h>
#include "odevice.h"
///////////////////////// WIN32 ONLY ///////////////////////////////////
#ifdef _WIN32
#include <windows.h>
#include <winioctl.h>
/*
** This is the identifier for the Monochrome Display Driver
*/
#define FILE_DEVICE_MONO 0x00008000
/*
** These are the IOCTL commands supported by the Monochrome Display Driver.
*/
#define IOCTL_MONO_HELP_SCREEN CTL_CODE(FILE_DEVICE_MONO, 0x800, METHOD_BUFFERED, FILE_WRITE_DATA)
#define IOCTL_MONO_CLEAR_SCREEN CTL_CODE(FILE_DEVICE_MONO, 0x801, METHOD_BUFFERED, FILE_WRITE_DATA)
#define IOCTL_MONO_PRINT_RAW CTL_CODE(FILE_DEVICE_MONO, 0x802, METHOD_BUFFERED, FILE_WRITE_DATA)
#define IOCTL_MONO_SET_CURSOR CTL_CODE(FILE_DEVICE_MONO, 0x803, METHOD_BUFFERED, FILE_WRITE_DATA)
#define IOCTL_MONO_SCROLL CTL_CODE(FILE_DEVICE_MONO, 0x804, METHOD_BUFFERED, FILE_WRITE_DATA)
#define IOCTL_MONO_BRING_TO_TOP CTL_CODE(FILE_DEVICE_MONO, 0x805, METHOD_BUFFERED, FILE_WRITE_DATA)
#define IOCTL_MONO_SET_ATTRIBUTE CTL_CODE(FILE_DEVICE_MONO, 0x806, METHOD_BUFFERED, FILE_WRITE_DATA)
#define IOCTL_MONO_PAN CTL_CODE(FILE_DEVICE_MONO, 0x807, METHOD_BUFFERED, FILE_WRITE_DATA)
#define IOCTL_MONO_LOCK CTL_CODE(FILE_DEVICE_MONO, 0x808, METHOD_BUFFERED, FILE_WRITE_DATA)
#define IOCTL_MONO_UNLOCK CTL_CODE(FILE_DEVICE_MONO, 0x809, METHOD_BUFFERED, FILE_WRITE_DATA)
#define IOCTL_MONO_SET_WINDOW CTL_CODE(FILE_DEVICE_MONO, 0x80A, METHOD_BUFFERED, FILE_WRITE_DATA)
#define IOCTL_MONO_RESET_WINDOW CTL_CODE(FILE_DEVICE_MONO, 0x80B, METHOD_BUFFERED, FILE_WRITE_DATA)
#define IOCTL_MONO_SET_FLAG CTL_CODE(FILE_DEVICE_MONO, 0x80C, METHOD_BUFFERED, FILE_WRITE_DATA)
#define IOCTL_MONO_CLEAR_FLAG CTL_CODE(FILE_DEVICE_MONO, 0x80D, METHOD_BUFFERED, FILE_WRITE_DATA)
#define IOCTL_MONO_FILL_ATTRIB CTL_CODE(FILE_DEVICE_MONO, 0x80E, METHOD_BUFFERED, FILE_WRITE_DATA)
#endif // ifdef _WIN32
class MonoD : public OutputDevice
{
public:
MonoD();
~MonoD();
virtual int print(const char *str,int len);
private:
#ifdef _WIN32
HANDLE handle;
#endif
};
#endif

32
LAUNCHER/UTIL/ODEVICE.H Normal file
View File

@@ -0,0 +1,32 @@
/*
** Command & Conquer Red Alert(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ODEVICE_HEADER
#define ODEVICE_HEADER
// This virtual base class provides an interface for output devices
// that can be used for the debugging package.
class OutputDevice
{
public:
OutputDevice() {}
virtual ~OutputDevice() {};
virtual int print(const char *s,int len)=0;
};
#endif

39
LAUNCHER/UTIL/STDERRD.H Normal file
View File

@@ -0,0 +1,39 @@
/*
** Command & Conquer Red Alert(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef STDERRD_HEADER
#define STDERRD_HEADER
#include "odevice.h"
class StderrD : public OutputDevice
{
public:
virtual int print(const char *str,int len)
{
char *string=new char[len+1];
memset(string,0,len+1);
memcpy(string,str,len);
fprintf(stderr,"%s",string);
delete[](string);
return(len);
}
};
#endif

40
LAUNCHER/UTIL/STDOUTD.H Normal file
View File

@@ -0,0 +1,40 @@
/*
** Command & Conquer Red Alert(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef STDOUTD_HEADER
#define STDOUTD_HEADER
#include "odevice.h"
class StdoutD : public OutputDevice
{
public:
virtual int print(const char *str,int len)
{
char *string=new char[len+1];
memcpy(string,str,len);
string[len]=0;
fprintf(stdout,"%s",string);
fflush(stdout);
delete[](string);
return(len);
}
};
#endif

139
LAUNCHER/UTIL/STREAMER.CPP Normal file
View File

@@ -0,0 +1,139 @@
/*
** Command & Conquer Red Alert(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "streamer.h"
#ifdef _WIN32
#include <windows.h>
#endif
Streamer::Streamer() : streambuf()
{
int state=unbuffered();
unbuffered(0); // 0 = buffered, 1 = unbuffered
}
Streamer::~Streamer()
{
sync();
delete[](base());
}
int Streamer::setOutputDevice(OutputDevice *device)
{
Output_Device=device;
return(0);
}
// put n chars from string into buffer
int Streamer::xsputn(const char* buf, int size) //implementation of sputn
{
if (size<=0) // Nothing to do
return(0);
const unsigned char *ptr=(const unsigned char *)buf;
for (int i=0; i<size; i++, ptr++)
{
if(*ptr=='\n')
{
if (overflow(*ptr)==EOF)
return(i);
}
else if (sputc(*ptr)==EOF)
return(i);
}
return(size);
}
// Flush the buffer and make more room if needed
int Streamer::overflow(int c)
{
if (c==EOF)
return(sync());
if ((pbase()==0) && (doallocate()==0))
return(EOF);
if((pptr() >= epptr()) && (sync()==EOF))
return(EOF);
else {
sputc(c);
if ((unbuffered() && c=='\n' || pptr() >= epptr())
&& sync()==EOF) {
return(EOF);
}
return(c);
}
}
// This is a write only stream, this should never happen
int Streamer::underflow(void)
{
return(EOF);
}
int Streamer::doallocate()
{
if (base()==NULL)
{
char *buf=new char[(2*STREAMER_BUFSIZ)]; // deleted by destructor
memset(buf,0,2*STREAMER_BUFSIZ);
// Buffer
setb(
buf, // base pointer
buf+STREAMER_BUFSIZ, // ebuf pointer (end of buffer);
0); // 0 = manual deletion of buff
// Get area
setg(
buf, // eback
buf, // gptr
buf); // egptr
buf+=STREAMER_BUFSIZ;
// Put area
setp(buf,buf+STREAMER_BUFSIZ);
return(1);
}
else
return(0);
}
int Streamer::sync()
{
if (pptr()<=pbase()) {
return(0);
}
int wlen=pptr()-pbase();
if (Output_Device)
{
Output_Device->print(pbase(),wlen);
}
if (unbuffered()) {
setp(pbase(),pbase());
}
else {
setp(pbase(),pbase()+STREAMER_BUFSIZ);
}
return(0);
}

60
LAUNCHER/UTIL/STREAMER.H Normal file
View File

@@ -0,0 +1,60 @@
/*
** Command & Conquer Red Alert(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef STREAMER_HEADER
#define STREAMER_HEADER
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <iostream.h>
#include <string.h>
#include "odevice.h"
#ifndef STREAMER_BUFSIZ
// This limits the number of characters that can be sent to a single 'print'
// call. If your debug message is bigger than this, it will get split over
// multiple 'print' calls. That's usually not a problem.
#define STREAMER_BUFSIZ 2048
#endif
// Provide a streambuf interface for a class that can 'print'
class Streamer : public streambuf
{
public:
Streamer();
virtual ~Streamer();
int setOutputDevice(OutputDevice *output_device);
protected:
// Virtual methods from streambuf
int xsputn(const char* s, int n); // buffer some characters
int overflow(int = EOF); // flush buffer and make more room
int underflow(void); // Does nothing
int sync();
int doallocate(); // allocate a buffer
OutputDevice *Output_Device;
};
#endif

35
LAUNCHER/UTIL/SYSLOGD.CPP Normal file
View File

@@ -0,0 +1,35 @@
/*
** Command & Conquer Red Alert(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "syslogd.h"
SyslogD::SyslogD(char *ident,int logopt,int facility,int _priority)
{
openlog(ident,logopt,facility);
priority=_priority;
}
int SyslogD::print(const char *str, int len)
{
char *temp_str=new char[len+1];
memset(temp_str,0,len+1);
strncpy(temp_str,str,len);
syslog(priority,temp_str);
delete[](temp_str);
return(len);
}

38
LAUNCHER/UTIL/SYSLOGD.H Normal file
View File

@@ -0,0 +1,38 @@
/*
** Command & Conquer Red Alert(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SYSLOGD_HEADER
#define SYSLOGD_HEADER
#include <stdlib.h>
#include <stdio.h>
#include <syslog.h>
#include <string.h>
#include "odevice.h"
class SyslogD : public OutputDevice
{
public:
SyslogD(char *ident,int logopt,int facility,int priority);
virtual int print(const char *str,int len);
private:
int priority;
};
#endif

148
LAUNCHER/UTIL/WDEBUG.CPP Normal file
View File

@@ -0,0 +1,148 @@
/*
** Command & Conquer Red Alert(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include "wdebug.h"
#include "streamer.h"
#include "odevice.h"
static MsgManager *msg_manager=NULL;
static int debug_enabled=0;
static ostream *debug_ostream=NULL;
static Streamer debug_streamer;
static int info_enabled=0;
static ostream *info_ostream=NULL;
static Streamer info_streamer;
static int warn_enabled=0;
static ostream *warn_ostream=NULL;
static Streamer warn_streamer;
static int error_enabled=0;
static ostream *error_ostream=NULL;
static Streamer error_streamer;
// Don't dare touch this semaphore in application code!
Sem4 DebugLibSemaphore;
int MsgManager::setAllStreams(OutputDevice *device)
{
if (device==NULL)
return(1);
DebugLibSemaphore.Wait();
debug_streamer.setOutputDevice(device);
delete(debug_ostream);
debug_ostream=new ostream(&debug_streamer);
info_streamer.setOutputDevice(device);
delete(info_ostream);
info_ostream=new ostream(&info_streamer);
warn_streamer.setOutputDevice(device);
delete(warn_ostream);
warn_ostream=new ostream(&warn_streamer);
error_streamer.setOutputDevice(device);
delete(error_ostream);
error_ostream=new ostream(&error_streamer);
DebugLibSemaphore.Post();
return(0);
}
int MsgManager::setDebugStream(OutputDevice *device)
{
if (device==NULL)
return(1);
DebugLibSemaphore.Wait();
debug_streamer.setOutputDevice(device);
delete(debug_ostream);
debug_ostream=new ostream(&debug_streamer);
DebugLibSemaphore.Post();
return(0);
}
int MsgManager::setInfoStream(OutputDevice *device)
{
if (device==NULL)
return(1);
DebugLibSemaphore.Wait();
info_streamer.setOutputDevice(device);
delete(info_ostream);
info_ostream=new ostream(&info_streamer);
DebugLibSemaphore.Post();
return(0);
}
int MsgManager::setWarnStream(OutputDevice *device)
{
if (device==NULL)
return(1);
DebugLibSemaphore.Wait();
warn_streamer.setOutputDevice(device);
delete(warn_ostream);
warn_ostream=new ostream(&warn_streamer);
DebugLibSemaphore.Post();
return(0);
}
int MsgManager::setErrorStream(OutputDevice *device)
{
if (device==NULL)
return(1);
DebugLibSemaphore.Wait();
error_streamer.setOutputDevice(device);
delete(error_ostream);
error_ostream=new ostream(&error_streamer);
DebugLibSemaphore.Post();
return(0);
}
ostream *MsgManager::debugStream(void)
{
return(debug_ostream);
}
ostream *MsgManager::infoStream(void)
{
return(info_ostream);
}
ostream *MsgManager::warnStream(void)
{
return(warn_ostream);
}
ostream *MsgManager::errorStream(void)
{
return(error_ostream);
}

216
LAUNCHER/UTIL/WDEBUG.H Normal file
View File

@@ -0,0 +1,216 @@
/*
** Command & Conquer Red Alert(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************\
wdebug Neal Kettler
MT-LEVEL
MT-Safe
The debugging module is pretty good for debugging and it has some message
printing stuff as well. The basic idea is that you write a class that
inherits from OutputDevice (severall are provided) and assign that output
device to a stream. There are seperate streams for debugging, information,
warning, and error messages. Each one can have a seperate output device,
or they can all have the same one. Debugging messages only get compiled
in if your module defines 'DEBUG'. If you don't define debug, then not even
the text of the debugging message gets into the binary. All the other
output streams get printed regardless of whether DEBUG is defined.
Sample usage:
FileD debug_device("gameres.debug"); // create a file device
MsgManager::setDebugStream(&debug_device);
DBGMSG("This debug message #" << 1 << " you use C++ streams");
Note that since these are defines you really don't need to put a semicolon
at the end, and it can be bad in situations like this:
if (x)
DBGMSG("Stuff is broken");
else
DBGMSG("Stuff is NOT broken");
This won't compile, read the code until you figure it out. Only then
will you be ready to leave grasshopper.
\*****************************************************************************/
#ifndef WDEBUG_HEADER
#define WDEBUG_HEADER
#include <iostream.h>
#include "sem4.h"
#include "odevice.h"
#include "streamer.h"
// This is needed because the streams return a pointer. Every time you
// change the output device the old stream is deleted, and a new one
// is created.
extern Sem4 DebugLibSemaphore;
// Print an information message
#define INFMSG(X)\
{\
char timebuf[40]; \
time_t clock=time(NULL); \
cftime(timebuf,"%D %T",&clock); \
DebugLibSemaphore.Wait(); \
if (MsgManager::infoStream()) \
(*(MsgManager::infoStream())) << "INF " << timebuf << " [" << \
__FILE__ << " " << __LINE__ << "] " << X << endl; \
DebugLibSemaphore.Post(); \
}
// Print a warning message
#define WRNMSG(X)\
{\
char timebuf[40]; \
time_t clock=time(NULL); \
cftime(timebuf,"%D %T",&clock); \
DebugLibSemaphore.Wait(); \
if (MsgManager::warnStream()) \
(*(MsgManager::warnStream())) << "WRN " << timebuf << " [" << \
__FILE__ << " " << __LINE__ << "] " << X << endl; \
DebugLibSemaphore.Post(); \
}
// Print an error message
#define ERRMSG(X)\
{\
char timebuf[40]; \
time_t clock=time(NULL); \
cftime(timebuf,"%D %T",&clock); \
DebugLibSemaphore.Wait(); \
if (MsgManager::errorStream()) \
(*(MsgManager::errorStream())) << "ERR " << timebuf << " [" << \
__FILE__ << " " << __LINE__ << "] " << X << endl; \
DebugLibSemaphore.Post(); \
}
// Just get a stream to the information device, no extra junk
#define INFSTREAM(X)\
{\
DebugLibSemaphore.Wait(); \
if (MsgManager::infoStream()) \
(*(MsgManager::infoStream())) << X;\
DebugLibSemaphore.Post(); \
}
// Just get a stream to the warning device, no extra junk
#define WRNSTREAM(X)\
{\
DebugLibSemaphore.Wait(); \
if (MsgManager::warnStream()) \
(*(MsgManager::warnStream())) << X;\
DebugLibSemaphore.Post(); \
}
// Just get a stream to the error device, no extra junk
#define ERRSTREAM(X)\
{\
DebugLibSemaphore.Wait(); \
if (MsgManager::errorStream()) \
(*(MsgManager::errorStream())) << X;\
DebugLibSemaphore.Post(); \
}
#ifndef DEBUG
// No debugging, no debug messages.
// Note that anything enclosed in "DBG()" will NOT get executed
// unless DEBUG is defined.
// They are defined to {} for consistency when DEBUG is defined
#define DBG(X)
#define DBGSTREAM(X) {}
#define PVAR(v) {}
#define DBGMSG(X) {}
#define VERBOSE(X) {}
#else // DEBUG _is_ defined
// Execute only if in debugging mode
#define DBG(X) X
// Print a variable
#define PVAR(v) \
{ \
DebugLibSemaphore.Wait(); \
if (MsgManager::debugStream()) \
(*(MsgManager::debugStream())) << __FILE__ << "[" << __LINE__ << \
"]: " << ##V << " = " << V << endl; \
DebugLibSemaphore.Post(); \
}
#define DBGMSG(X)\
{\
DebugLibSemaphore.Wait(); \
if (MsgManager::debugStream()) \
(*(MsgManager::debugStream())) << "DBG [" << __FILE__ << \
" " << __LINE__ << "] " << X << endl;\
DebugLibSemaphore.Post(); \
}
// Just get a stream to the debugging device, no extra junk
#define DBGSTREAM(X)\
{\
DebugLibSemaphore.Wait(); \
if (MsgManager::debugStream()) \
(*(MsgManager::debugStream())) << X;\
DebugLibSemaphore.Post(); \
}
// Verbosely execute a statement
#define VERBOSE(X)\
{ \
DebugLibSemaphore.Wait(); \
if (MsgManager::debugStream()) \
(*(DebugManager::debugStream())) << __FILE__ << "[" << __LINE__ << \
"]: " << ##X << endl; X \
DebugLibSemaphore.Post(); \
}
#endif // DEBUG
class MsgManager
{
protected:
MsgManager();
public:
static int setAllStreams(OutputDevice *device);
static int setDebugStream(OutputDevice *device);
static int setInfoStream(OutputDevice *device);
static int setWarnStream(OutputDevice *device);
static int setErrorStream(OutputDevice *device);
static void enableDebug(int flag);
static void enableInfo(int flag);
static void enableWarn(int flag);
static void enableError(int flag);
static ostream *debugStream(void);
static ostream *infoStream(void);
static ostream *warnStream(void);
static ostream *errorStream(void);
};
#endif