changeset 313:aa4185f3d972 draft

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
author gavinandresen <gavinandresen@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
date Fri, 03 Dec 2010 19:38:09 +0000
parents 876d9c331744
children 3cb14ba4a1aa
files init.cpp irc.cpp main.cpp rpc.cpp serialize.h ui.cpp util.h
diffstat 7 files changed, 33 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/init.cpp
+++ b/init.cpp
@@ -206,14 +206,11 @@
         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 @@
 #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 @@
     //
     // Parameters
     //
-    if (mapArgs.count("-printblockindex") || mapArgs.count("-printblocktree"))
+    if (GetBoolArg("-printblockindex") || GetBoolArg("-printblocktree"))
     {
         PrintBlockTree();
         return false;
@@ -377,13 +374,7 @@
         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 @@
     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)
--- a/irc.cpp
+++ b/irc.cpp
@@ -194,7 +194,7 @@
 {
     if (mapArgs.count("-connect"))
         return;
-    if (mapArgs.count("-noirc"))
+    if (GetBoolArg("-noirc"))
         return;
     printf("ThreadIRCSeed started\n");
     int nErrorWait = 10;
--- a/main.cpp
+++ b/main.cpp
@@ -1891,7 +1891,7 @@
     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 @@
 
                 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 @@
             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 @@
     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;
--- a/rpc.cpp
+++ b/rpc.cpp
@@ -1525,7 +1525,7 @@
         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 @@
     }
 #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 @@
 
             // 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 @@
                 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 @@
         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())
--- a/serialize.h
+++ b/serialize.h
@@ -25,7 +25,7 @@
 class CAutoFile;
 static const unsigned int MAX_SIZE = 0x02000000;
 
-static const int VERSION = 31701;
+static const int VERSION = 31702;
 static const char* pszSubVer = "";
 
 
--- a/ui.cpp
+++ b/ui.cpp
@@ -391,7 +391,7 @@
     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 @@
 #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 @@
 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
--- a/util.h
+++ b/util.h
@@ -417,6 +417,17 @@
     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)