mirror of
https://github.com/znc/znc.git
synced 2026-05-18 07:15:54 +02:00
Move DEBUG() from Utils.h into new ZNCDebug.h
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
+1
-1
@@ -31,7 +31,7 @@ INSTALL_DATA := @INSTALL_DATA@
|
||||
LIB_SRCS := ZNCString.cpp Csocket.cpp znc.cpp User.cpp IRCSock.cpp Client.cpp DCCBounce.cpp \
|
||||
DCCSock.cpp Chan.cpp Nick.cpp Server.cpp Modules.cpp MD5.cpp Buffer.cpp Utils.cpp \
|
||||
FileUtils.cpp HTTPSock.cpp Template.cpp ClientCommand.cpp Socket.cpp SHA256.cpp \
|
||||
WebModules.cpp Listener.cpp Config.cpp
|
||||
WebModules.cpp Listener.cpp Config.cpp ZNCDebug.cpp
|
||||
BIN_SRCS := main.cpp
|
||||
LIB_OBJS := $(patsubst %cpp,%o,$(LIB_SRCS))
|
||||
BIN_OBJS := $(patsubst %cpp,%o,$(BIN_SRCS))
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
#include "zncconfig.h"
|
||||
#include "WebModules.h"
|
||||
#include "Utils.h"
|
||||
#include "main.h"
|
||||
#include <set>
|
||||
#include <queue>
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "Utils.h"
|
||||
#include "MD5.h"
|
||||
#include "main.h"
|
||||
#include "ZNCDebug.h"
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_LIBSSL
|
||||
#include <openssl/ssl.h>
|
||||
@@ -24,14 +25,6 @@
|
||||
|
||||
using std::stringstream;
|
||||
|
||||
bool CUtils::stdoutIsTTY = true;
|
||||
bool CUtils::debug =
|
||||
#ifdef _DEBUG
|
||||
true;
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
|
||||
CUtils::CUtils() {}
|
||||
CUtils::~CUtils() {}
|
||||
|
||||
@@ -271,7 +264,7 @@ bool CUtils::GetInput(const CString& sPrompt, CString& sRet, const CString& sDef
|
||||
}
|
||||
|
||||
void CUtils::PrintError(const CString& sMessage) {
|
||||
if (stdoutIsTTY)
|
||||
if (CDebug::StdoutIsTTY())
|
||||
fprintf(stdout, "\033[1m\033[34m[\033[31m ** \033[34m]\033[39m\033[22m %s\n", sMessage.c_str());
|
||||
else
|
||||
fprintf(stdout, "%s\n", sMessage.c_str());
|
||||
@@ -279,7 +272,7 @@ void CUtils::PrintError(const CString& sMessage) {
|
||||
}
|
||||
|
||||
void CUtils::PrintPrompt(const CString& sMessage) {
|
||||
if (stdoutIsTTY)
|
||||
if (CDebug::StdoutIsTTY())
|
||||
fprintf(stdout, "\033[1m\033[34m[\033[33m ?? \033[34m]\033[39m\033[22m %s: ", sMessage.c_str());
|
||||
else
|
||||
fprintf(stdout, "[ ?? ] %s: ", sMessage.c_str());
|
||||
@@ -287,7 +280,7 @@ void CUtils::PrintPrompt(const CString& sMessage) {
|
||||
}
|
||||
|
||||
void CUtils::PrintMessage(const CString& sMessage, bool bStrong) {
|
||||
if (stdoutIsTTY) {
|
||||
if (CDebug::StdoutIsTTY()) {
|
||||
if (bStrong)
|
||||
fprintf(stdout, "\033[1m\033[34m[\033[33m ** \033[34m]\033[39m\033[22m \033[1m%s\033[22m\n",
|
||||
sMessage.c_str());
|
||||
@@ -301,7 +294,7 @@ void CUtils::PrintMessage(const CString& sMessage, bool bStrong) {
|
||||
}
|
||||
|
||||
void CUtils::PrintAction(const CString& sMessage) {
|
||||
if (stdoutIsTTY)
|
||||
if (CDebug::StdoutIsTTY())
|
||||
fprintf(stdout, "\033[1m\033[34m[\033[32m \033[34m]\033[39m\033[22m %s... ", sMessage.c_str());
|
||||
else
|
||||
fprintf(stdout, "%s... ", sMessage.c_str());
|
||||
@@ -309,7 +302,7 @@ void CUtils::PrintAction(const CString& sMessage) {
|
||||
}
|
||||
|
||||
void CUtils::PrintStatus(bool bSuccess, const CString& sMessage) {
|
||||
if (stdoutIsTTY) {
|
||||
if (CDebug::StdoutIsTTY()) {
|
||||
if (!sMessage.empty()) {
|
||||
if (bSuccess) {
|
||||
fprintf(stdout, "%s", sMessage.c_str());
|
||||
|
||||
@@ -19,30 +19,10 @@
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
using std::map;
|
||||
using std::vector;
|
||||
using std::pair;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
/** Output a debug info if debugging is enabled.
|
||||
* If ZNC was compiled with <code>--enable-debug</code> or was started with
|
||||
* <code>--debug</code>, the given argument will be sent to stdout.
|
||||
*
|
||||
* You can use all the features of C++ streams:
|
||||
* @code
|
||||
* DEBUG("I had " << errors << " errors");
|
||||
* @endcode
|
||||
*
|
||||
* @param f The expression you want to display.
|
||||
*/
|
||||
#define DEBUG(f) do { \
|
||||
if (CUtils::Debug()) { \
|
||||
cout << f << endl; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static inline void SetFdCloseOnExec(int fd)
|
||||
{
|
||||
@@ -62,10 +42,6 @@ public:
|
||||
|
||||
static CString GetIP(unsigned long addr);
|
||||
static unsigned long GetLongIP(const CString& sIP);
|
||||
static void SetStdoutIsTTY(bool b) { stdoutIsTTY = b; }
|
||||
static bool StdoutIsTTY() { return stdoutIsTTY; }
|
||||
static void SetDebug(bool b) { debug = b; }
|
||||
static bool Debug() { return debug; }
|
||||
|
||||
static void PrintError(const CString& sMessage);
|
||||
static void PrintMessage(const CString& sMessage, bool bStrong = false);
|
||||
@@ -99,8 +75,6 @@ public:
|
||||
|
||||
private:
|
||||
protected:
|
||||
static bool stdoutIsTTY;
|
||||
static bool debug;
|
||||
};
|
||||
|
||||
class CException {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2011 See the AUTHORS file for details.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 as published
|
||||
* by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#include "ZNCDebug.h"
|
||||
|
||||
bool CDebug::stdoutIsTTY = true;
|
||||
bool CDebug::debug =
|
||||
#ifdef _DEBUG
|
||||
true;
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2011 See the AUTHORS file for details.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 as published
|
||||
* by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#ifndef ZNCDEBUG_H
|
||||
#define ZNCDEBUG_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
/** Output a debug info if debugging is enabled.
|
||||
* If ZNC was compiled with <code>--enable-debug</code> or was started with
|
||||
* <code>--debug</code>, the given argument will be sent to stdout.
|
||||
*
|
||||
* You can use all the features of C++ streams:
|
||||
* @code
|
||||
* DEBUG("I had " << errors << " errors");
|
||||
* @endcode
|
||||
*
|
||||
* @param f The expression you want to display.
|
||||
*/
|
||||
#define DEBUG(f) do { \
|
||||
if (CDebug::Debug()) { \
|
||||
cout << f << endl; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
class CDebug {
|
||||
public:
|
||||
static void SetStdoutIsTTY(bool b) { stdoutIsTTY = b; }
|
||||
static bool StdoutIsTTY() { return stdoutIsTTY; }
|
||||
static void SetDebug(bool b) { debug = b; }
|
||||
static bool Debug() { return debug; }
|
||||
|
||||
protected:
|
||||
static bool stdoutIsTTY;
|
||||
static bool debug;
|
||||
};
|
||||
|
||||
#endif // !ZNCDEBUG_H
|
||||
@@ -13,7 +13,8 @@
|
||||
|
||||
// This header file is just for Csocket
|
||||
|
||||
#include "Utils.h"
|
||||
#include "ZNCDebug.h"
|
||||
#include "ZNCString.h"
|
||||
|
||||
#define CS_STRING CString
|
||||
#define _NO_CSOCKET_NS
|
||||
|
||||
@@ -117,7 +117,7 @@ int main(int argc, char** argv) {
|
||||
CString sDataDir = "";
|
||||
|
||||
seedPRNG();
|
||||
CUtils::SetStdoutIsTTY(isatty(1));
|
||||
CDebug::SetStdoutIsTTY(isatty(1));
|
||||
|
||||
int iArg, iOptIndex = -1;
|
||||
bool bMakeConf = false;
|
||||
@@ -142,7 +142,7 @@ int main(int argc, char** argv) {
|
||||
cout << CZNC::GetTag() << endl;
|
||||
return 0;
|
||||
case 'n':
|
||||
CUtils::SetStdoutIsTTY(false);
|
||||
CDebug::SetStdoutIsTTY(false);
|
||||
break;
|
||||
case 'r':
|
||||
bAllowRoot = true;
|
||||
@@ -166,7 +166,7 @@ int main(int argc, char** argv) {
|
||||
break;
|
||||
case 'D':
|
||||
bForeground = true;
|
||||
CUtils::SetDebug(true);
|
||||
CDebug::SetDebug(true);
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
@@ -285,7 +285,7 @@ int main(int argc, char** argv) {
|
||||
close(1); open("/dev/null", O_WRONLY);
|
||||
close(2); open("/dev/null", O_WRONLY);
|
||||
|
||||
CUtils::SetStdoutIsTTY(false);
|
||||
CDebug::SetStdoutIsTTY(false);
|
||||
|
||||
// We are the child. There is no way we can be a process group
|
||||
// leader, thus setsid() must succeed.
|
||||
@@ -334,11 +334,11 @@ int main(int argc, char** argv) {
|
||||
NULL
|
||||
};
|
||||
int pos = 3;
|
||||
if (CUtils::Debug())
|
||||
if (CDebug::Debug())
|
||||
args[pos++] = strdup("--debug");
|
||||
else if (bForeground)
|
||||
args[pos++] = strdup("--foreground");
|
||||
if (!CUtils::StdoutIsTTY())
|
||||
if (!CDebug::StdoutIsTTY())
|
||||
args[pos++] = strdup("--no-color");
|
||||
if (bAllowRoot)
|
||||
args[pos++] = strdup("--allow-root");
|
||||
|
||||
@@ -677,7 +677,7 @@ bool CZNC::WriteNewConfig(const CString& sConfigFile) {
|
||||
const CModInfo& Info = *it;
|
||||
CString sName = Info.GetName();
|
||||
|
||||
if (CUtils::StdoutIsTTY()) {
|
||||
if (CDebug::StdoutIsTTY()) {
|
||||
if (CUtils::GetBoolInput("Load global module <\033[1m" + sName + "\033[22m>?", false))
|
||||
vsLines.push_back("LoadModule = " + sName);
|
||||
} else {
|
||||
@@ -783,7 +783,7 @@ bool CZNC::WriteNewConfig(const CString& sConfigFile) {
|
||||
const CModInfo& Info = *it;
|
||||
CString sName = Info.GetName();
|
||||
|
||||
if (CUtils::StdoutIsTTY()) {
|
||||
if (CDebug::StdoutIsTTY()) {
|
||||
if (CUtils::GetBoolInput("Load module <\033[1m" + sName + "\033[22m>?", false))
|
||||
vsLines.push_back("\tLoadModule = " + sName);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user