libzypp  11.13.5
Sysconfig.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
13 #include <iostream>
14 #include <fstream>
15 
16 #include "zypp/base/Logger.h"
17 #include "zypp/base/String.h"
18 #include "zypp/Pathname.h"
19 
20 #include "zypp/base/Sysconfig.h"
21 
22 using namespace std;
23 using namespace zypp::base;
24 
25 namespace zypp {
26  namespace base {
27 
28  namespace sysconfig {
29  map<string,string> read( const Pathname & _path )
30  {
31  DBG << "Load '" << _path << "'" << endl;
33 
34  string line;
35  ifstream in( _path.asString().c_str() );
36  if ( in.fail() ) {
37  WAR << "Unable to load '" << _path << "'" << endl;
38  return ret;
39  }
40 
41  while( getline( in, line ) ) {
42  if ( *line.begin() != '#' ) {
43 
44  string::size_type pos = line.find( '=', 0 );
45 
46  if ( pos != string::npos ) {
47 
48  string key = str::trim( line.substr( 0, pos ) );
49  string value = str::trim( line.substr( pos + 1, line.length() - pos - 1 ) );
50 
51  if ( value.length() >= 2
52  && *(value.begin()) == '"'
53  && *(value.rbegin()) == '"' )
54  {
55  value = value.substr( 1, value.length() - 2 );
56  }
57  if ( value.length() >= 2
58  && *(value.begin()) == '\''
59  && *(value.rbegin()) == '\'' )
60  {
61  value = value.substr( 1, value.length() - 2 );
62  }
63  XXX << "KEY: '" << key << "' VALUE: '" << value << "'" << endl;
64  ret[key] = value;
65 
66  } // '=' found
67 
68  } // not comment
69 
70  } // while getline
71  MIL << "done reading '" << _path << "'" << endl;
72  return ret;
73  }
74 
75  } // namespace sysconfig
76  } // namespace base
77 } // namespace zypp