Sysconfig.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00013 #include <iostream>
00014 #include <fstream>
00015
00016 #include "zypp/base/Logger.h"
00017 #include "zypp/base/String.h"
00018 #include "zypp/Pathname.h"
00019
00020 #include "zypp/base/Sysconfig.h"
00021
00022 using namespace std;
00023 using namespace zypp::base;
00024
00025 namespace zypp {
00026 namespace base {
00027
00028 namespace sysconfig {
00029 map<string,string> read( const Pathname & _path )
00030 {
00031 DBG << "Load '" << _path << "'" << endl;
00032 map<string,string> ret;
00033
00034 string line;
00035 ifstream in( _path.asString().c_str() );
00036 if ( in.fail() ) {
00037 WAR << "Unable to load '" << _path << "'" << endl;
00038 return ret;
00039 }
00040
00041 while( getline( in, line ) ) {
00042 if ( *line.begin() != '#' ) {
00043
00044 string::size_type pos = line.find( '=', 0 );
00045
00046 if ( pos != string::npos ) {
00047
00048 string key = str::trim( line.substr( 0, pos ) );
00049 string value = str::trim( line.substr( pos + 1, line.length() - pos - 1 ) );
00050
00051 if ( value.length() >= 2
00052 && *(value.begin()) == '"'
00053 && *(value.rbegin()) == '"' )
00054 {
00055 value = value.substr( 1, value.length() - 2 );
00056 }
00057 if ( value.length() >= 2
00058 && *(value.begin()) == '\''
00059 && *(value.rbegin()) == '\'' )
00060 {
00061 value = value.substr( 1, value.length() - 2 );
00062 }
00063 XXX << "KEY: '" << key << "' VALUE: '" << value << "'" << endl;
00064 ret[key] = value;
00065
00066 }
00067
00068 }
00069
00070 }
00071 MIL << "done reading '" << _path << "'" << endl;
00072 return ret;
00073 }
00074
00075 }
00076 }
00077 }