about summary refs log tree commit diff
path: root/src/libstore/globals.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-09-22T15·43+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-09-22T15·43+0000
commit4578a490ce5a5a6325b4ff2b8f44468464de2d94 (patch)
tree62a5118879990d20e71cccf263f4648bfa3ba253 /src/libstore/globals.cc
parentfbedf6056eb2acb5049b0372350b2c93b8185ab7 (diff)
* Parse multi-valued options.
Diffstat (limited to 'src/libstore/globals.cc')
-rw-r--r--src/libstore/globals.cc47
1 files changed, 33 insertions, 14 deletions
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index 8cbae54e20..9a3ac69813 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -1,6 +1,7 @@
 #include "globals.hh"
 
 #include <map>
+#include <algorithm>
 
 
 string nixStore = "/UNINIT";
@@ -22,7 +23,15 @@ list<string> buildUsers;
 
 static bool settingsRead = false;
 
-static map<string, string> settings;
+static map<string, Strings> settings;
+
+
+template<class T, class A> A & genericAt(T & container, unsigned int n)
+{
+    class T::iterator i = container.begin();
+    advance(i, n);
+    return *i;
+}
 
 
 static void readSettings()
@@ -43,34 +52,44 @@ static void readSettings()
         if (hash != string::npos)
             line = string(line, 0, hash);
 
-        if (line.find_first_not_of(" ") == string::npos) continue;
+        Strings tokens = tokenizeString(line);
+        if (tokens.empty()) continue;
 
-        istringstream is(line);
-        string name, sep, value;
-        is >> name >> sep >> value;
-        if (sep != "=" || !is)
+        if (tokens.size() < 2 || genericAt<Strings, string>(tokens, 1) != "=")
             throw Error(format("illegal configuration line `%1%' in `%2%'") % line % settingsFile);
-        
-        settings[name] = value;
+
+        string name = genericAt<Strings, string>(tokens, 0);
+
+        Strings::iterator i = tokens.begin();
+        advance(i, 2);
+        settings[name] = Strings(i, tokens.end());
     };
     
     settingsRead = true;
 }
 
 
-string querySetting(const string & name, const string & def)
+Strings querySetting(const string & name, const Strings & def)
 {
     if (!settingsRead) readSettings();
-    map<string, string>::iterator i = settings.find(name);
+    map<string, Strings>::iterator i = settings.find(name);
     return i == settings.end() ? def : i->second;
 }
 
 
 bool queryBoolSetting(const string & name, bool def)
 {
-    string value = querySetting(name, def ? "true" : "false");
-    if (value == "true") return true;
-    else if (value == "false") return false;
+    Strings defs;
+    if (def) defs.push_back("true"); else defs.push_back("false");
+    
+    Strings value = querySetting(name, defs);
+    if (value.size() != 1)
+        throw Error(format("configuration option `%1%' should be either `true' or `false', not a list")
+            % name);
+    
+    string v = value.front();
+    if (v == "true") return true;
+    else if (v == "false") return false;
     else throw Error(format("configuration option `%1%' should be either `true' or `false', not `%2%'")
-        % name % value);
+        % name % v);
 }