Consolidate duplicated simple Log functions

The various small utilities do not use the engine Log implementation but
one that simply prints to stdout. Instead of duplicating that one, link a
common one into the utilities.
Günther Brammer 2011-11-02 21:36:39 +01:00
parent b911630578
commit ccbf4d1d45
8 changed files with 91 additions and 73 deletions

View File

@ -885,12 +885,14 @@ add_executable(c4group
src/platform/StdFile.cpp
src/platform/StdRegistry.cpp
src/lib/StdResStr2.cpp
src/lib/C4SimpleLog.cpp
src/zlib/gzio.c
src/C4Include.cpp
)
add_executable(netpuncher EXCLUDE_FROM_ALL
src/C4Include.cpp
src/lib/C4SimpleLog.cpp
src/lib/StdBuf.cpp
src/lib/Standard.cpp
src/platform/GetTime.cpp
@ -907,6 +909,7 @@ add_executable(c4script
src/c4group/CStdFile.h
src/lib/C4InputValidation.cpp
src/lib/C4InputValidation.h
src/lib/C4SimpleLog.cpp
src/lib/Standard.cpp
src/lib/Standard.h
src/lib/StdBuf.cpp

View File

@ -604,6 +604,7 @@ c4group_CPPFLAGS = \
-I$(srcdir)/src/script
c4group_SOURCES = \
src/lib/C4SimpleLog.cpp \
src/c4group/c4group_ng.cpp
if WIN32
@ -619,6 +620,7 @@ c4group_LDADD = \
## gunzip4c4group
gunzip4c4group_SOURCES = \
src/lib/C4SimpleLog.cpp \
src/c4group/gunzip4c4group.cpp
gunzip4c4group_LDADD = \
@ -629,6 +631,7 @@ gunzip4c4group_LDADD = \
## puncher
puncher_SOURCES = \
src/lib/C4SimpleLog.cpp \
src/netpuncher/main.cpp
puncher_LDADD = \
@ -642,9 +645,11 @@ endif
## tstc4netio
tstc4netio_SOURCES = \
src/lib/C4SimpleLog.cpp \
src/netio/TstC4NetIO.cpp
tstc4netio_LDADD = \
lib.a \
$(Z_LIBS) \
$(PTHREAD_LIBS)
@ -654,6 +659,7 @@ endif
## c4script shell
c4script_SOURCES = \
src/lib/C4SimpleLog.cpp \
src/lib/C4Real.cpp \
src/lib/C4Random.cpp \
src/script/shell.cpp \
@ -677,8 +683,14 @@ c4script_LDADD = \
lib.a \
$(Z_LIBS)
if WIN32
c4script_LDADD += -lwinmm
endif
## documentation
dist_doc_DATA = planet/AUTHORS planet/COPYING licenses/LGPL.txt licenses/OpenSSL.txt Credits.txt
## game data
c4groups = \
Graphics.ocg \
Material.ocg \
@ -700,6 +712,7 @@ AM_CXXFLAGS += -DOC_SYSTEM_DATA_DIR=\"${pkgdatadir}\"
%.ocf: planet/%.ocf c4group$(EXEEXT)
./c4group$(EXEEXT) $< -t $@ || c4group $< -t $@
## windows setup.exe
setup_openclonk.exe: $(srcdir)/tools/install/oc.nsi c4group$(EXEEXT) clonk$(EXEEXT) $(c4groups)
makensis -NOCD -DSRCDIR=$(srcdir) '-DPROGRAMFILES=$$PROGRAMFILES' \
-DPRODUCT_NAME="$$(sed -n 's/SET(C4ENGINENAME\s\+"\(.\+\)")/\1/ p' $(srcdir)/Version.txt)$$(sed -n 's/SET(C4VERSIONBUILDNAME\s\+"\(.\+\)")/\1/ p' $(srcdir)/Version.txt)" \

View File

@ -55,7 +55,7 @@ int globalArgC;
char **globalArgV;
int iFirstCommand = 0;
bool fQuiet = true;
extern bool fQuiet;
bool fRecursive = false;
bool fRegisterShell = false;
bool fUnregisterShell = false;
@ -68,24 +68,6 @@ bool EraseItemSafe(const char *szFilename)
return false;
}
bool Log(const char *msg)
{
if (!fQuiet)
printf("%s\n", msg);
return 1;
}
#define IMPLEMENT_LOGF(func) \
bool func(const char *msg, ...) { \
va_list args; va_start(args, msg); \
StdStrBuf Buf; \
Buf.FormatV(msg, args); \
return Log(Buf.getData()); \
}
IMPLEMENT_LOGF(DebugLogF)
IMPLEMENT_LOGF(LogF)
IMPLEMENT_LOGF(LogSilentF)
bool ProcessGroup(const char *FilenamePar)
{

View File

@ -1,6 +1,3 @@
#include <CStdFile.h>
#include <stdio.h>
/*
* Copyright (c) 2007, 2010 Günther Brammer
* Copyright (c) 2010 Benjamin Herr
@ -18,6 +15,10 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <C4Include.h>
#include <CStdFile.h>
#include <stdio.h>
bool EraseItemSafe(const char *szFilename)
{
return false;
@ -25,22 +26,35 @@ bool EraseItemSafe(const char *szFilename)
int main(int argc, char *argv[])
{
char *pData; int iSize;
CStdFile MyFile;
if (argc < 2)
{
fprintf(stderr, "%s infile [outfile]", argv[0]);
return 1;
}
MyFile.Load(argv[1], (BYTE **)&pData, &iSize, 0, true);
CStdFile MyFile;
MyFile.Open(argv[1], true);
char Data [4096];
size_t iSize;
if (argc < 3)
{
fwrite(pData, 1, iSize, stdout);
do
{
MyFile.Read(Data,sizeof(Data),&iSize);
fwrite(Data, 1, iSize, stdout);
}
while(iSize);
}
else
{
MyFile.Create(argv[2], false);
MyFile.Write(pData, iSize);
CStdFile OutFile;
OutFile.Create(argv[2], false);
do
{
MyFile.Read(Data,sizeof(Data),&iSize);
OutFile.Write(Data, iSize);
}
while(iSize);
OutFile.Close();
}
MyFile.Close();
}

View File

@ -0,0 +1,50 @@
/*
* OpenClonk, http://www.openclonk.org
*
* Copyright (c) 2005, 2011 Günther Brammer
* Copyright (c) 2009 Nicolas Hake
* Copyright (c) 2010-2011 Armin Burgmeier
*
* Portions might be copyrighted by other authors who have contributed
* to OpenClonk.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
* See isc_license.txt for full license and disclaimer.
*
* "Clonk" is a registered trademark of Matthes Bender.
* See clonk_trademark_license.txt for full license.
*/
// Implement a simplified version of Log so that we don't get undefined
// references when e.g. StdFile attempts to call it - we are not compiling
// C4Log.cpp into the small utility programs because it pulls in a whole
// lot of other dependencies.
#include <C4Include.h>
#include <C4Log.h>
bool fQuiet = true;
bool Log(const char *msg)
{
if (!fQuiet)
printf("%s\n", msg);
return true;
}
bool DebugLog(const char *strMessage) { return Log(strMessage); }
bool LogFatal(const char *strMessage) { return Log(strMessage); }
#define IMPLEMENT_LOGF(func) \
bool func(const char *msg, ...) { \
va_list args; va_start(args, msg); \
StdStrBuf Buf; \
Buf.FormatV(msg, args); \
return Log(Buf.getData()); \
}
IMPLEMENT_LOGF(DebugLogF)
IMPLEMENT_LOGF(LogF)
IMPLEMENT_LOGF(LogSilentF)

View File

@ -32,8 +32,6 @@
using namespace std;
bool Log(char const * text) { std::cout << text << std::endl; return true; }
bool fHost;
int iCnt = 0, iSize = 0;
char DummyData[1024 * 1024];

View File

@ -26,29 +26,7 @@
const uint16_t C4PuncherPort = 11115;
bool fQuiet = false;
// Implement a simplified version of Log so that we don't get undefined
// references when e.g. StdFile attempts to call it - we are not compiling
// C4Log.cpp into the netpuncher because it pulls in a whole lot of other
// dependencies.
bool Log(const char *msg)
{
if (!fQuiet)
printf("%s\n", msg);
return 1;
}
#define IMPLEMENT_LOGF(func) \
bool func(const char *msg, ...) { \
va_list args; va_start(args, msg); \
StdStrBuf Buf; \
Buf.FormatV(msg, args); \
return Log(Buf.getData()); \
}
IMPLEMENT_LOGF(DebugLogF)
IMPLEMENT_LOGF(LogF)
IMPLEMENT_LOGF(LogSilentF)
extern bool fQuiet;
class C4PuncherServer : public C4NetIOUDP, private C4NetIO::CBClass
{

View File

@ -29,26 +29,6 @@
#include <C4Reloc.h>
#include <C4Record.h>
bool Log(const char *msg)
{
printf("%s\n", msg);
return 1;
}
bool DebugLog(const char *strMessage) { return Log(strMessage); }
bool LogFatal(const char *strMessage) { return Log(strMessage); }
#define IMPLEMENT_LOGF(func) \
bool func(const char *msg, ...) { \
va_list args; va_start(args, msg); \
StdStrBuf Buf; \
Buf.FormatV(msg, args); \
return Log(Buf.getData()); \
}
IMPLEMENT_LOGF(DebugLogF)
IMPLEMENT_LOGF(LogF)
IMPLEMENT_LOGF(LogSilentF)
C4Config Config;
C4Config::C4Config() {}
C4Config::~C4Config() {}