Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/consoleinterface.cc26
-rw-r--r--src/sys/consoleinterface.h54
-rw-r--r--src/sys/sys.cc44
3 files changed, 59 insertions, 65 deletions
diff --git a/src/sys/consoleinterface.cc b/src/sys/consoleinterface.cc
index 438a8de..45f678d 100644
--- a/src/sys/consoleinterface.cc
+++ b/src/sys/consoleinterface.cc
@@ -34,20 +34,20 @@ void fallback_print(const std::string &text)
bool is_color_code = false;
int ansi_bold = 0;
int ansi_color = 39;
-
+
const char *c = text.c_str();
while (*c) {
-
+
if ((*c) == '\n') {
std::cout << std::endl;
-
+
} else if ((*c) == '^') {
-
+
is_color_code = true;
ansi_bold = 0;
ansi_color = 39;
-
- switch (*(c+1)) {
+
+ switch (*(c + 1)) {
case '0': // black
ansi_color = 0;
ansi_bold = 1;
@@ -75,7 +75,7 @@ void fallback_print(const std::string &text)
ansi_bold = 1;
ansi_color = 39;
break;
-
+
case 'N': // normal
ansi_bold = 0;
ansi_color = 39;
@@ -103,7 +103,7 @@ void fallback_print(const std::string &text)
default:
is_color_code = false;
}
-
+
if (is_color_code) {
if (con_ansicolor)
std::cout << "\033[" << ansi_bold << ";" << ansi_color << "m";
@@ -111,11 +111,11 @@ void fallback_print(const std::string &text)
} else {
std::cout << *c;
}
-
+
} else {
std::cout << *c;
}
-
+
c++;
}
}
@@ -126,7 +126,7 @@ int ConsoleBuffer::overflow(int c)
{
if (c == Traits::eof())
return Traits::not_eof(c);
-
+
if (c == '\n') {
if (ConsoleInterface::instance()) {
ConsoleInterface::instance()->event_text(con_buffer);
@@ -168,7 +168,7 @@ ConsoleInterface::ConsoleInterface()
std::cerr << "multiple sys::ConsoleInterface instances!" << std::endl;
sys::quit(2);
}
-
+
consoleinterface_rcon = false;
consoleinterface_instance = this;
consoleinterface_logsize = DEFAULT_LOGSIZE;
@@ -203,7 +203,7 @@ void ConsoleInterface::event_text(const std::string & text)
while (consoleinterface_log.size() >= consoleinterface_logsize) {
consoleinterface_log.pop_front();
}
-
+
consoleinterface_log.push_back(text);
print(text);
}
diff --git a/src/sys/consoleinterface.h b/src/sys/consoleinterface.h
index 2eae1d8..a7fde2e 100644
--- a/src/sys/consoleinterface.h
+++ b/src/sys/consoleinterface.h
@@ -34,15 +34,14 @@ typedef std::char_traits<char> Traits;
class ConsoleBuffer : public std::basic_streambuf<char, Traits >
{
public:
- const std::string & str() const
- {
+ const std::string & str() const {
return con_buffer;
}
-
+
protected:
/// stream overflow
virtual int overflow(int c = Traits::eof());
-
+
private:
std::string con_buffer;
};
@@ -56,12 +55,11 @@ class ConsoleStream : public std::basic_ostream<char, Traits >
public:
ConsoleStream();
~ConsoleStream();
-
- inline ConsoleBuffer & buf()
- {
+
+ inline ConsoleBuffer & buf() {
return con_buffer;
}
-
+
private:
ConsoleBuffer con_buffer;
};
@@ -79,55 +77,51 @@ class ConsoleInterface
public:
/// default constructor
ConsoleInterface();
-
+
/// default destructor
virtual ~ConsoleInterface();
-
+
/// set maximal number of lines in the log
void set_logsize(const size_t logsize);
-
+
/// return rcon state
- inline bool rcon()
- {
+ inline bool rcon() {
return consoleinterface_rcon;
}
-
+
/// enable or disable rcon
void set_rcon(bool enable = true);
-
+
typedef std::deque<std::string> Queue;
-
- inline Queue & rconbuf()
- {
+
+ inline Queue & rconbuf() {
return consoleinterface_rconbuf;
}
-
- inline Queue & log()
- {
+
+ inline Queue & log() {
return consoleinterface_log;
}
-
+
/// a pointer to the current console instance
static ConsoleInterface *instance();
-
+
/// incoming text event handler
void event_text(const std::string & text);
-
+
/// ncurses resize event
- virtual void resize()
- {};
-
+ virtual void resize() {};
+
protected:
/// print one line of text
virtual void print(const std::string & text);
-
+
private:
/// console singleton
static ConsoleInterface *consoleinterface_instance;
-
+
bool consoleinterface_rcon;
Queue consoleinterface_rconbuf;
-
+
Queue consoleinterface_log;
size_t consoleinterface_logsize;
};
diff --git a/src/sys/sys.cc b/src/sys/sys.cc
index f99d533..f4e915d 100644
--- a/src/sys/sys.cc
+++ b/src/sys/sys.cc
@@ -37,11 +37,11 @@ bool file_exists(const std::string &filename)
#ifdef _WIN32
struct ::_stat path_stat;
memset(&path_stat, 0, sizeof(struct ::_stat));
-
+
if (::_stat(filename.c_str(), &path_stat) != 0) {
return false;
}
-
+
if (path_stat.st_mode & _S_IFDIR) {
return false;
}
@@ -49,15 +49,15 @@ bool file_exists(const std::string &filename)
#else
struct stat path_stat;
memset(&path_stat, 0, sizeof(path_stat));
-
+
if (stat(filename.c_str(), &path_stat) != 0) {
return false;
}
-
+
if (path_stat.st_mode & S_IFDIR) {
return false;
}
-
+
return true;
#endif
}
@@ -68,11 +68,11 @@ bool directory_exists(const std::string &path)
#ifdef _WIN32
struct ::_stat path_stat;
memset(&path_stat, 0, sizeof(struct ::_stat));
-
+
if (::_stat(path.c_str(), &path_stat) != 0) {
return false;
}
-
+
if (path_stat.st_mode & _S_IFDIR) {
return true;
}
@@ -80,15 +80,15 @@ bool directory_exists(const std::string &path)
#else
struct stat path_stat;
memset(&path_stat, 0, sizeof(path_stat));
-
+
if (stat(path.c_str(), &path_stat) != 0) {
return false;
}
-
+
if (path_stat.st_mode & S_IFDIR) {
return true;
}
-
+
return false;
#endif
}
@@ -100,13 +100,13 @@ void mkdir(const std::string &path)
for (size_t i = 0; i < p.size(); i++)
if (p[i] == '/') p[i] = '\\';
if (p.size() && (p[p.size()-1] == '\\'))
- p.erase(p.size() -1, 1);
-
+ p.erase(p.size() - 1, 1);
+
if (_mkdir(p.c_str()) != 0) {
con_warn << "Could not create directory '" << p << "'" << std::endl;
}
#else
-
+
::mkdir(path.c_str(), 0777);
#endif
}
@@ -115,12 +115,12 @@ void signal(int signum, signalfunc handler)
{
#ifndef _WIN32
struct sigaction sa;
-
+
sa.sa_sigaction = 0;
- memset(&sa.sa_mask, 0 ,sizeof(sigset_t));
+ memset(&sa.sa_mask, 0 , sizeof(sigset_t));
sa.sa_flags = 0;
sa.sa_handler = handler;
-
+
::sigaction(signum, &sa, 0);
#endif
}
@@ -130,7 +130,7 @@ void signal(int signum, signalfunc handler)
POSIX:
struct tm {
- int tm_sec; // seconds
+ int tm_sec; // seconds
int tm_min; // minutes
int tm_hour; // hours
int tm_mday; // day of the month
@@ -140,7 +140,7 @@ POSIX:
int tm_yday; // day in the year
int tm_isdst; // daylight saving time
};
-
+
WIN32:
typedef struct _SYSTEMTIME {
@@ -153,7 +153,7 @@ WIN32:
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME;
-
+
*/
unsigned long time()
@@ -166,7 +166,7 @@ unsigned long time()
#else
SYSTEMTIME localtime;
::GetLocalTime(&localtime);
-
+
return ((unsigned long)(localtime.wSecond + localtime.wMinute*60 + localtime.wHour*3600));
#endif
}
@@ -188,7 +188,7 @@ void get_datetime(int &year, int & month, int & day, int & hours, int & minutes)
::localtime_r(&epochtime, &localtime);
year = localtime.tm_year + 1900;
- month = localtime.tm_mon +1;
+ month = localtime.tm_mon + 1;
day = localtime.tm_mday;
hours = localtime.tm_hour;
@@ -196,7 +196,7 @@ void get_datetime(int &year, int & month, int & day, int & hours, int & minutes)
#else
SYSTEMTIME localtime;
::GetLocalTime(&localtime);
-
+
year = localtime.wYear;
month = localtime.wMonth;
day = localtime.wDay;