From bdde31d787c4fe2da8e9fb168abbd22af2c27442 Mon Sep 17 00:00:00 2001 From: gavinandresen Date: Fri, 3 Dec 2010 19:38:09 +0000 Subject: [PATCH] All boolean options/flags now work the same way. git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@194 1a98c847-1fd6-4fd8-948a-caf3550aa51b --- init.cpp | 23 +++++++---------------- irc.cpp | 2 +- main.cpp | 8 ++++---- rpc.cpp | 10 +++++----- serialize.h | 2 +- ui.cpp | 8 ++++---- util.h | 11 +++++++++++ 7 files changed, 33 insertions(+), 31 deletions(-) diff --git a/init.cpp b/init.cpp index 78e842b5a..61ca4d2bd 100644 --- a/init.cpp +++ b/init.cpp @@ -206,14 +206,11 @@ bool AppInit2(int argc, char* argv[]) return false; } - if (mapArgs.count("-debug")) - fDebug = true; + fDebug = GetBoolArg("-debug"); - if (mapArgs.count("-printtodebugger")) - fPrintToDebugger = true; + fPrintToDebugger = GetBoolArg("-printtodebugger"); - if (mapArgs.count("-testnet")) - fTestNet = true; + fTestNet = GetBoolArg("-testnet"); if (fCommandLine) { @@ -232,7 +229,7 @@ bool AppInit2(int argc, char* argv[]) #endif printf("Default data directory %s\n", GetDefaultDataDir().c_str()); - if (mapArgs.count("-loadblockindextest")) + if (GetBoolArg("-loadblockindextest")) { CTxDB txdb("r"); txdb.LoadBlockIndex(); @@ -348,7 +345,7 @@ bool AppInit2(int argc, char* argv[]) // // Parameters // - if (mapArgs.count("-printblockindex") || mapArgs.count("-printblocktree")) + if (GetBoolArg("-printblockindex") || GetBoolArg("-printblocktree")) { PrintBlockTree(); return false; @@ -377,13 +374,7 @@ bool AppInit2(int argc, char* argv[]) return false; } - if (mapArgs.count("-gen")) - { - if (mapArgs["-gen"].empty()) - fGenerateBitcoins = true; - else - fGenerateBitcoins = (atoi(mapArgs["-gen"].c_str()) != 0); - } + fGenerateBitcoins = GetBoolArg("-gen"); if (mapArgs.count("-proxy")) { @@ -434,7 +425,7 @@ bool AppInit2(int argc, char* argv[]) if (!CreateThread(StartNode, NULL)) wxMessageBox("Error: CreateThread(StartNode) failed", "Bitcoin"); - if (mapArgs.count("-server") || fDaemon) + if (GetBoolArg("-server") || fDaemon) CreateThread(ThreadRPCServer, NULL); #if defined(__WXMSW__) && defined(GUI) diff --git a/irc.cpp b/irc.cpp index e246fcd10..55b23f2de 100644 --- a/irc.cpp +++ b/irc.cpp @@ -194,7 +194,7 @@ void ThreadIRCSeed2(void* parg) { if (mapArgs.count("-connect")) return; - if (mapArgs.count("-noirc")) + if (GetBoolArg("-noirc")) return; printf("ThreadIRCSeed started\n"); int nErrorWait = 10; diff --git a/main.cpp b/main.cpp index a1865a467..f4131395f 100644 --- a/main.cpp +++ b/main.cpp @@ -1891,7 +1891,7 @@ string GetWarnings(string strFor) int nPriority = 0; string strStatusBar; string strRPC; - if (mapArgs.count("-testsafemode")) + if (GetBoolArg("-testsafemode")) strRPC = "test"; // Misc warnings like out of disk space and clock is wrong @@ -3123,7 +3123,7 @@ CBlock* CreateNewBlock(CReserveKey& reservekey) dPriority += (double)nValueIn * nConf; - if (fDebug && mapArgs.count("-printpriority")) + if (fDebug && GetBoolArg("-printpriority")) printf("priority nValueIn=%-12I64d nConf=%-5d dPriority=%-20.1f\n", nValueIn, nConf, dPriority); } @@ -3135,7 +3135,7 @@ CBlock* CreateNewBlock(CReserveKey& reservekey) else mapPriority.insert(make_pair(-dPriority, &(*mi).second)); - if (fDebug && mapArgs.count("-printpriority")) + if (fDebug && GetBoolArg("-printpriority")) { printf("priority %-20.1f %s\n%s", dPriority, tx.GetHash().ToString().substr(0,10).c_str(), tx.ToString().c_str()); if (porphan) @@ -3312,7 +3312,7 @@ void BitcoinMiner() SetThreadPriority(THREAD_PRIORITY_LOWEST); bool f4WaySSE2 = Detect128BitSSE2(); if (mapArgs.count("-4way")) - f4WaySSE2 = (mapArgs["-4way"] != "0"); + f4WaySSE2 = GetBoolArg(mapArgs["-4way"]); // Each thread has its own key and counter CReserveKey reservekey; diff --git a/rpc.cpp b/rpc.cpp index 0d00f4cc8..b9ed61de7 100644 --- a/rpc.cpp +++ b/rpc.cpp @@ -1525,7 +1525,7 @@ void ThreadRPCServer2(void* parg) return; } - bool fUseSSL = (mapArgs.count("-rpcssl") > 0); + bool fUseSSL = GetBoolArg("-rpcssl"); asio::ip::address bindAddress = mapArgs.count("-rpcallowip") ? asio::ip::address_v4::any() : asio::ip::address_v4::loopback(); asio::io_service io_service; @@ -1552,7 +1552,7 @@ void ThreadRPCServer2(void* parg) } #else if (fUseSSL) - throw runtime_error("-rpcssl=true, but bitcoin compiled without full openssl libraries."); + throw runtime_error("-rpcssl=1, but bitcoin compiled without full openssl libraries."); #endif loop @@ -1642,7 +1642,7 @@ void ThreadRPCServer2(void* parg) // Observe safe mode string strWarning = GetWarnings("rpc"); - if (strWarning != "" && !mapArgs.count("-disablesafemode") && !setAllowInSafeMode.count(strMethod)) + if (strWarning != "" && !GetBoolArg("-disablesafemode") && !setAllowInSafeMode.count(strMethod)) throw JSONRPCError(-2, string("Safe mode: ") + strWarning); try @@ -1692,7 +1692,7 @@ Object CallRPC(const string& strMethod, const Array& params) GetConfigFile().c_str())); // Connect to localhost - bool fUseSSL = (mapArgs.count("-rpcssl") > 0); + bool fUseSSL = GetBoolArg("-rpcssl"); #ifdef USE_SSL asio::io_service io_service; ssl::context context(io_service, ssl::context::sslv23); @@ -1704,7 +1704,7 @@ Object CallRPC(const string& strMethod, const Array& params) throw runtime_error("couldn't connect to server"); #else if (fUseSSL) - throw runtime_error("-rpcssl=true, but bitcoin compiled without full openssl libraries."); + throw runtime_error("-rpcssl=1, but bitcoin compiled without full openssl libraries."); ip::tcp::iostream stream(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", "8332")); if (stream.fail()) diff --git a/serialize.h b/serialize.h index 3debdf08e..5088e3700 100644 --- a/serialize.h +++ b/serialize.h @@ -25,7 +25,7 @@ class CDataStream; class CAutoFile; static const unsigned int MAX_SIZE = 0x02000000; -static const int VERSION = 31701; +static const int VERSION = 31702; static const char* pszSubVer = ""; diff --git a/ui.cpp b/ui.cpp index 213cf7666..bf436444b 100644 --- a/ui.cpp +++ b/ui.cpp @@ -391,7 +391,7 @@ void CMainFrame::OnIconize(wxIconizeEvent& event) if (!event.Iconized()) fClosedToTray = false; #if defined(__WXGTK__) || defined(__WXMAC_OSX__) - if (mapArgs.count("-minimizetotray")) { + if (GetBoolArg("-minimizetotray")) { #endif // The tray icon sometimes disappears on ubuntu karmic // Hiding the taskbar button doesn't work cleanly on ubuntu lucid @@ -1633,7 +1633,7 @@ COptionsDialog::COptionsDialog(wxWindow* parent) : COptionsDialogBase(parent) #endif #if defined(__WXGTK__) || defined(__WXMAC_OSX__) m_checkBoxStartOnSystemStartup->SetLabel(_("&Start Bitcoin on window system startup")); - if (!mapArgs.count("-minimizetotray")) + if (!GetBoolArg("-minimizetotray")) { // Minimize to tray is just too buggy on Linux fMinimizeToTray = false; @@ -2741,10 +2741,10 @@ wxMenu* CMyTaskBarIcon::CreatePopupMenu() void CreateMainWindow() { pframeMain = new CMainFrame(NULL); - if (mapArgs.count("-min")) + if (GetBoolArg("-min")) pframeMain->Iconize(true); #if defined(__WXGTK__) || defined(__WXMAC_OSX__) - if (!mapArgs.count("-minimizetotray")) + if (!GetBoolArg("-minimizetotray")) fMinimizeToTray = false; #endif pframeMain->Show(true); // have to show first to get taskbar button to hide diff --git a/util.h b/util.h index 31ba4f522..f57e40106 100644 --- a/util.h +++ b/util.h @@ -417,6 +417,17 @@ inline int64 GetArg(const string& strArg, int64 nDefault) return nDefault; } +inline bool GetBoolArg(const string& strArg) +{ + if (mapArgs.count(strArg)) + { + if (mapArgs[strArg].empty()) + return true; + return (atoi(mapArgs[strArg]) != 0); + } + return false; +} + inline string FormatVersion(int nVersion) { if (nVersion%100 == 0)