aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp82
1 files changed, 70 insertions, 12 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 752ebb7bf1..30590912ff 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -14,6 +14,8 @@
#include <stdarg.h>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
#ifndef WIN32
// for posix_fallocate
#ifdef __linux_
@@ -92,7 +94,6 @@ bool fPrintToDebugLog = true;
bool fDaemon = false;
bool fServer = false;
string strMiscWarning;
-bool fNoListen = false;
bool fLogTimestamps = false;
volatile bool fReopenDebugLog = false;
CClientUIInterface uiInterface;
@@ -881,12 +882,6 @@ static std::string FormatException(std::exception* pex, const char* pszThread)
"UNKNOWN EXCEPTION \n%s in %s \n", pszModule, pszThread);
}
-void LogException(std::exception* pex, const char* pszThread)
-{
- std::string message = FormatException(pex, pszThread);
- LogPrintf("\n%s", message);
-}
-
void PrintExceptionContinue(std::exception* pex, const char* pszThread)
{
std::string message = FormatException(pex, pszThread);
@@ -963,13 +958,15 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific)
void ClearDatadirCache()
{
std::fill(&pathCached[0], &pathCached[CChainParams::MAX_NETWORK_TYPES+1],
- boost::filesystem::path());
+ boost::filesystem::path());
}
boost::filesystem::path GetConfigFile()
{
boost::filesystem::path pathConfigFile(GetArg("-conf", "bitcoin.conf"));
- if (!pathConfigFile.is_complete()) pathConfigFile = GetDataDir(false) / pathConfigFile;
+ if (!pathConfigFile.is_complete())
+ pathConfigFile = GetDataDir(false) / pathConfigFile;
+
return pathConfigFile;
}
@@ -1029,9 +1026,9 @@ bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
#endif /* WIN32 */
}
-
-// Ignores exceptions thrown by boost's create_directory if the requested directory exists.
-// Specifically handles case where path p exists, but it wasn't possible for the user to write to the parent directory.
+// Ignores exceptions thrown by Boost's create_directory if the requested directory exists.
+// Specifically handles case where path p exists, but it wasn't possible for the user to
+// write to the parent directory.
bool TryCreateDirectory(const boost::filesystem::path& p)
{
try
@@ -1380,3 +1377,64 @@ bool ParseInt32(const std::string& str, int32_t *out)
n <= std::numeric_limits<int32_t>::max();
}
+void SetupEnvironment()
+{
+#ifndef WIN32
+ try
+ {
+#if BOOST_FILESYSTEM_VERSION == 3
+ boost::filesystem::path::codecvt(); // Raises runtime error if current locale is invalid
+#else // boost filesystem v2
+ std::locale(); // Raises runtime error if current locale is invalid
+#endif
+ } catch(std::runtime_error &e)
+ {
+ setenv("LC_ALL", "C", 1); // Force C locale
+ }
+#endif
+}
+
+std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime)
+{
+ // std::locale takes ownership of the pointer
+ std::locale loc(std::locale::classic(), new boost::posix_time::time_facet(pszFormat));
+ std::stringstream ss;
+ ss.imbue(loc);
+ ss << boost::posix_time::from_time_t(nTime);
+ return ss.str();
+}
+
+std::string FormatParagraph(const std::string in, size_t width, size_t indent)
+{
+ std::stringstream out;
+ size_t col = 0;
+ size_t ptr = 0;
+ while(ptr < in.size())
+ {
+ // Find beginning of next word
+ ptr = in.find_first_not_of(' ', ptr);
+ if (ptr == std::string::npos)
+ break;
+ // Find end of next word
+ size_t endword = in.find_first_of(' ', ptr);
+ if (endword == std::string::npos)
+ endword = in.size();
+ // Add newline and indentation if this wraps over the allowed width
+ if (col > 0)
+ {
+ if ((col + endword - ptr) > width)
+ {
+ out << '\n';
+ for(size_t i=0; i<indent; ++i)
+ out << ' ';
+ col = 0;
+ } else
+ out << ' ';
+ }
+ // Append word
+ out << in.substr(ptr, endword - ptr);
+ col += endword - ptr;
+ ptr = endword;
+ }
+ return out.str();
+}