LTP GCOV extension - code coverage report
Current view: directory - src/libstore - globals.cc
Test: app.info
Date: 2006-10-11 Instrumented lines: 54
Code covered: 90.7 % Executed lines: 49

       1                 : #include "globals.hh"
       2                 : #include "util.hh"
       3                 : 
       4                 : #include <map>
       5                 : #include <algorithm>
       6                 : 
       7                 : 
       8                 : namespace nix {
       9                 : 
      10                 : 
      11             690 : string nixStore = "/UNINIT";
      12             690 : string nixDataDir = "/UNINIT";
      13             690 : string nixLogDir = "/UNINIT";
      14             690 : string nixStateDir = "/UNINIT";
      15             690 : string nixDBPath = "/UNINIT";
      16             690 : string nixConfDir = "/UNINIT";
      17             690 : string nixLibexecDir = "/UNINIT";
      18                 : 
      19                 : bool keepFailed = false;
      20                 : bool keepGoing = false;
      21                 : bool tryFallback = false;
      22                 : Verbosity buildVerbosity = lvlInfo;
      23                 : unsigned int maxBuildJobs = 1;
      24                 : bool readOnlyMode = false;
      25             690 : string thisSystem = "unset";
      26                 : 
      27                 : 
      28                 : static bool settingsRead = false;
      29                 : 
      30             345 : static std::map<string, Strings> settings;
      31                 : 
      32                 : 
      33                 : string & at(Strings & ss, unsigned int n)
      34            1908 : {
      35            1908 :     Strings::iterator i = ss.begin();
      36            1908 :     advance(i, n);
      37            1908 :     return *i;
      38                 : }
      39                 : 
      40                 : 
      41                 : static void readSettings()
      42             372 : {
      43             372 :     Path settingsFile = (format("%1%/%2%") % nixConfDir % "nix.conf").str();
      44             372 :     if (!pathExists(settingsFile)) return;
      45             318 :     string contents = readFile(settingsFile);
      46                 : 
      47             318 :     unsigned int pos = 0;
      48                 : 
      49            1272 :     while (pos < contents.size()) {
      50             954 :         string line;
      51           25758 :         while (pos < contents.size() && contents[pos] != '\n')
      52           24804 :             line += contents[pos++];
      53             954 :         pos++;
      54                 : 
      55             954 :         string::size_type hash = line.find('#');
      56             954 :         if (hash != string::npos)
      57               0 :             line = string(line, 0, hash);
      58                 : 
      59             954 :         Strings tokens = tokenizeString(line);
      60             954 :         if (tokens.empty()) continue;
      61                 : 
      62             954 :         if (tokens.size() < 2 || at(tokens, 1) != "=")
      63               0 :             throw Error(format("illegal configuration line `%1%' in `%2%'") % line % settingsFile);
      64                 : 
      65             954 :         string name = at(tokens, 0);
      66                 : 
      67             954 :         Strings::iterator i = tokens.begin();
      68             954 :         advance(i, 2);
      69             954 :         settings[name] = Strings(i, tokens.end());
      70                 :     };
      71                 :     
      72             318 :     settingsRead = true;
      73                 : }
      74                 : 
      75                 : 
      76                 : Strings querySetting(const string & name, const Strings & def)
      77            1054 : {
      78            1054 :     if (!settingsRead) readSettings();
      79            1054 :     std::map<string, Strings>::iterator i = settings.find(name);
      80            1054 :     return i == settings.end() ? def : i->second;
      81                 : }
      82                 : 
      83                 : 
      84                 : string querySetting(const string & name, const string & def)
      85            1054 : {
      86            1054 :     Strings defs;
      87            1054 :     defs.push_back(def);
      88                 : 
      89            1054 :     Strings value = querySetting(name, defs);
      90            1054 :     if (value.size() != 1)
      91               0 :         throw Error(format("configuration option `%1%' should not be a list") % name);
      92                 : 
      93            1054 :     return value.front();
      94                 : }
      95                 : 
      96                 : 
      97                 : bool queryBoolSetting(const string & name, bool def)
      98             147 : {
      99             147 :     string v = querySetting(name, def ? "true" : "false");
     100             147 :     if (v == "true") return true;
     101              86 :     else if (v == "false") return false;
     102               0 :     else throw Error(format("configuration option `%1%' should be either `true' or `false', not `%2%'")
     103                 :         % name % v);
     104                 : }
     105                 : 
     106                 :  
     107             345 : }

Generated by: LTP GCOV extension version 1.1