diff options
author | Reid <reidyaro@gmail.com> | 2012-03-01 22:03:01 +0100 |
---|---|---|
committer | Reid <reidyaro@gmail.com> | 2012-03-01 22:03:01 +0100 |
commit | 490862919d79369112c75955a9c36ff8a081efd3 (patch) | |
tree | 6fe89466b9c53ba811f298174e6d787bbae71e09 /src/utils | |
parent | dff814619d63496acd3c4e8730b828b5d4d931fb (diff) | |
parent | d873da3e8e57480016596f714845c1bc7e712e68 (diff) | |
download | mv-490862919d79369112c75955a9c36ff8a081efd3.tar.gz mv-490862919d79369112c75955a9c36ff8a081efd3.tar.bz2 mv-490862919d79369112c75955a9c36ff8a081efd3.tar.xz mv-490862919d79369112c75955a9c36ff8a081efd3.zip |
Merge branch 'master' of gitorious.org:manaplus/manaplus
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/checkutils.cpp | 2 | ||||
-rw-r--r-- | src/utils/copynpaste.cpp | 12 | ||||
-rw-r--r-- | src/utils/copynpaste.h | 1 | ||||
-rw-r--r-- | src/utils/langs.cpp | 8 | ||||
-rw-r--r-- | src/utils/mathutils.h | 7 | ||||
-rw-r--r-- | src/utils/physfsrwops.cpp | 24 | ||||
-rw-r--r-- | src/utils/process.cpp | 8 | ||||
-rw-r--r-- | src/utils/stringutils.cpp | 22 | ||||
-rw-r--r-- | src/utils/stringutils.h | 2 | ||||
-rw-r--r-- | src/utils/translation/poparser.cpp | 2 |
10 files changed, 62 insertions, 26 deletions
diff --git a/src/utils/checkutils.cpp b/src/utils/checkutils.cpp index 64bb42d0c..abbc6138a 100644 --- a/src/utils/checkutils.cpp +++ b/src/utils/checkutils.cpp @@ -24,6 +24,8 @@ #include "logger.h" +#include "debug.h" + bool reportFalseReal(bool val, const char* file, unsigned line) { if (!val) diff --git a/src/utils/copynpaste.cpp b/src/utils/copynpaste.cpp index d918c8108..763b579d0 100644 --- a/src/utils/copynpaste.cpp +++ b/src/utils/copynpaste.cpp @@ -1,7 +1,7 @@ /* * Retrieve string pasted depending on OS mechanisms. * Copyright (C) 2001-2010 Wormux Team - * Copyright (C) 2011 ManaPlus Developers + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -442,9 +442,15 @@ bool runxsel(std::string& text, const char *p1, const char *p2) close(fd[0]); } if (p2) - execl("/usr/bin/xsel", "xsel", p1, p2, (char *)nullptr); + { + execl("/usr/bin/xsel", "xsel", p1, p2, + static_cast<char *>(nullptr)); + } else - execl("/usr/bin/xsel", "xsel", p1, (char *)nullptr); + { + execl("/usr/bin/xsel", "xsel", p1, + static_cast<char *>(nullptr)); + } exit(1); } diff --git a/src/utils/copynpaste.h b/src/utils/copynpaste.h index 03596d5d1..5e95a1152 100644 --- a/src/utils/copynpaste.h +++ b/src/utils/copynpaste.h @@ -1,6 +1,7 @@ /* * Retrieve string pasted depending on OS mechanisms. * Copyright (C) 2001-2010 Wormux Team + * Copyright (C) 2011-2012 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/utils/langs.cpp b/src/utils/langs.cpp index 2efbd781a..c1f9f7ecf 100644 --- a/src/utils/langs.cpp +++ b/src/utils/langs.cpp @@ -44,11 +44,11 @@ std::vector<std::string> getLang() } int dot = lang.find("."); - if (dot != (signed)std::string::npos) + if (dot != static_cast<signed>(std::string::npos)) lang = lang.substr(0, dot); langs.push_back(lang); dot = lang.find("_"); - if (dot != (signed)std::string::npos) + if (dot != static_cast<signed>(std::string::npos)) langs.push_back(lang.substr(0, dot)); return langs; } @@ -78,10 +78,10 @@ std::string getLangShort() } int dot = lang.find("."); - if (dot != (signed)std::string::npos) + if (dot != static_cast<signed>(std::string::npos)) lang = lang.substr(0, dot); dot = lang.find("_"); - if (dot != (signed)std::string::npos) + if (dot != static_cast<signed>(std::string::npos)) return lang.substr(0, dot); return lang; } diff --git a/src/utils/mathutils.h b/src/utils/mathutils.h index 9f6818146..6d5a8339d 100644 --- a/src/utils/mathutils.h +++ b/src/utils/mathutils.h @@ -23,7 +23,9 @@ #ifndef UTILS_MATHUTILS_H #define UTILS_MATHUTILS_H +#include <string> #include <stdint.h> +#include <cstring> static uint16_t crc_table[256] = { @@ -112,4 +114,9 @@ inline float weightedAverage(float n1, float n2, float w) return w * n2 + (1.0f - w) * n1; } +inline int roundDouble(double v) +{ + return (v > 0.0) ? (v + 0.5) : (v - 0.5); +} + #endif // UTILS_MATHUTILS_H diff --git a/src/utils/physfsrwops.cpp b/src/utils/physfsrwops.cpp index 1960f0dee..19b08d4c7 100644 --- a/src/utils/physfsrwops.cpp +++ b/src/utils/physfsrwops.cpp @@ -27,9 +27,11 @@ #include "localconsts.h" +#include "debug.h" + static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) { - PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1; + PHYSFS_file *handle = static_cast<PHYSFS_file *>(rw->hidden.unknown.data1); int pos = 0; if (whence == SEEK_SET) @@ -46,8 +48,8 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) return -1; } /* if */ - pos = (int)current; - if (((PHYSFS_sint64)pos) != current) + pos = static_cast<int>(current); + if (static_cast<PHYSFS_sint64>(pos) != current) { SDL_SetError("Can't fit current file position in an int!"); return -1; @@ -67,8 +69,8 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) return -1; } /* if */ - pos = (int)len; - if (((PHYSFS_sint64)pos) != len) + pos = static_cast<int>(len); + if (static_cast<PHYSFS_sint64>(pos) != len) { SDL_SetError("Can't fit end-of-file position in an int!"); return -1; @@ -88,7 +90,7 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) return -1; } /* if */ - if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos)) + if (!PHYSFS_seek(handle, static_cast<PHYSFS_uint64>(pos))) { SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); return -1; @@ -99,7 +101,7 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum) { - PHYSFS_file *handle = (PHYSFS_file*)rw->hidden.unknown.data1; + PHYSFS_file *handle = static_cast<PHYSFS_file*>(rw->hidden.unknown.data1); PHYSFS_sint64 rc = PHYSFS_read(handle, ptr, size, maxnum); if (rc != maxnum) { @@ -107,22 +109,22 @@ static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum) SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); } /* if */ - return (int)rc; + return static_cast<int>(rc); } /* physfsrwops_read */ static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num) { - PHYSFS_file *handle = (PHYSFS_file*)rw->hidden.unknown.data1; + PHYSFS_file *handle = static_cast<PHYSFS_file*>(rw->hidden.unknown.data1); PHYSFS_sint64 rc = PHYSFS_write(handle, ptr, size, num); if (rc != num) SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); - return (int) rc; + return static_cast<int>(rc); } /* physfsrwops_write */ static int physfsrwops_close(SDL_RWops *rw) { - PHYSFS_file *handle = (PHYSFS_file*)rw->hidden.unknown.data1; + PHYSFS_file *handle = static_cast<PHYSFS_file*>(rw->hidden.unknown.data1); if (!PHYSFS_close(handle)) { SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); diff --git a/src/utils/process.cpp b/src/utils/process.cpp index 4a2081514..0106c597d 100644 --- a/src/utils/process.cpp +++ b/src/utils/process.cpp @@ -112,12 +112,12 @@ int execFile(std::string pathName, std::string name, if (arg2.empty()) { execl(pathName.c_str(), name.c_str(), - arg1.c_str(), (char *)nullptr); + arg1.c_str(), static_cast<char *>(nullptr)); } else { - execl(pathName.c_str(), name.c_str(), - arg1.c_str(), arg2.c_str(), (char *)nullptr); + execl(pathName.c_str(), name.c_str(), arg1.c_str(), + arg2.c_str(), static_cast<char *>(nullptr)); } exit(-1); } @@ -130,7 +130,7 @@ int execFile(std::string pathName, std::string name, } else if (!sleep_pid) { // sleep pid - sleep (timeOut); + sleep (waitTime); // printf ("time out\n"); exit(-1); } diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 9184ba79d..5a7ea87fd 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -28,6 +28,8 @@ #include <cstdio> #include <list> +#include <sys/time.h> + #include "debug.h" static int UTF8_MAX_SIZE = 10; @@ -520,9 +522,9 @@ std::string stringToHexPath(const std::string &str) if (str.empty()) return ""; - std::string hex = strprintf("%%%2x/", (int)str[0]); + std::string hex = strprintf("%%%2x/", static_cast<int>(str[0])); for (unsigned f = 1; f < str.size(); f ++) - hex += strprintf("%%%2x", (int)str[f]); + hex += strprintf("%%%2x", static_cast<int>(str[f])); return hex; } @@ -598,7 +600,7 @@ bool findCutFirst(std::string &str1, std::string str2) std::string &removeProtocol(std::string &url) { int i = url.find("://"); - if (i != (int)std::string::npos) + if (i != static_cast<int>(std::string::npos)) url = url.substr(i + 3); return url; } @@ -609,3 +611,17 @@ bool strStartWith(std::string str1, std::string str2) return false; return str1.substr(0, str2.size()) == str2; } + +std::string getDateString() +{ + char buffer[80]; + + time_t rawtime; + struct tm *timeinfo; + + time (&rawtime); + timeinfo = localtime(&rawtime); + + strftime(buffer, 79, "%Y-%m-%d", timeinfo); + return std::string(buffer); +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 47d495dd0..31ee6d51f 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -206,4 +206,6 @@ std::string &removeProtocol(std::string &url); bool strStartWith(std::string str, std::string start); +std::string getDateString(); + #endif // UTILS_STRINGUTILS_H diff --git a/src/utils/translation/poparser.cpp b/src/utils/translation/poparser.cpp index 24d2ee4d4..521774592 100644 --- a/src/utils/translation/poparser.cpp +++ b/src/utils/translation/poparser.cpp @@ -144,7 +144,7 @@ bool PoParser::readMsgId() mLine = ""; return true; } - // stop reading if we dont read msgid before + // stop reading if we don't read msgid before return mMsgId.empty(); } } |