From d698cf9bca1ac7f5c1a989161ea959a895900273 Mon Sep 17 00:00:00 2001 From: Zdenek Prikryl Date: Thu, 19 Mar 2009 14:29:35 +0100 Subject: replaced language and application plugins by analyzer plugin added action plugin simplify plugin iface --- lib/Utils/DebugDump.h | 3 +- lib/Utils/Makefile.am | 2 +- lib/Utils/Settings.h | 98 +++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 94 insertions(+), 9 deletions(-) (limited to 'lib/Utils') diff --git a/lib/Utils/DebugDump.h b/lib/Utils/DebugDump.h index 32e03967..5805a82e 100644 --- a/lib/Utils/DebugDump.h +++ b/lib/Utils/DebugDump.h @@ -35,8 +35,7 @@ #define FILENAME_UID "uid" #define FILENAME_PACKAGE "package" #define FILENAME_DESCRIPTION "description" -#define FILENAME_LANGUAGE "language" -#define FILENAME_APPLICATION "application" +#define FILENAME_ANALYZER "analyzer" #define FILENAME_TEXTDATA1 "text_data1" #define FILENAME_TEXTDATA2 "text_data2" #define FILENAME_BINARYDATA1 "binary_data1" diff --git a/lib/Utils/Makefile.am b/lib/Utils/Makefile.am index 592bdb5b..c9bef6d4 100644 --- a/lib/Utils/Makefile.am +++ b/lib/Utils/Makefile.am @@ -1,5 +1,5 @@ lib_LTLIBRARIES = libUtils.la -libUtils_la_SOURCES = DebugDump.cpp DebugDump.h +libUtils_la_SOURCES = DebugDump.cpp DebugDump.h Settings.h libUtils_la_LDFLAGS = -version-info 0:1:0 install-data-local: diff --git a/lib/Utils/Settings.h b/lib/Utils/Settings.h index 1629ce9e..31138d05 100644 --- a/lib/Utils/Settings.h +++ b/lib/Utils/Settings.h @@ -22,13 +22,99 @@ #ifndef SETTINGSFUNC_H_ #define SETTINGSFUNC_H_ -#include "MiddleWareTypes.h" +#include +#include +#include -typedef map_string_string_t map_settings_t; -typedef set_strings_t set_settings_t; +typedef std::map map_settings_t; +typedef std::set set_settings_t; -void load_settings(const std::string& path, map_settings_t& settings); -void save_settings(const std::string& path, const map_settings_t& settings); -void parse_settings(const std::string& pLine, set_settings_t& settings); +inline void load_settings(const std::string& path, map_settings_t& settings) +{ + std::ifstream fIn; + fIn.open(path.c_str()); + if (fIn.is_open()) + { + std::string line; + while (!fIn.eof()) + { + getline(fIn, line); + + int ii; + bool is_value = false; + bool valid = false; + std::string key = ""; + std::string value = ""; + for (ii = 0; ii < line.length(); ii++) + { + if (isspace(line[ii])) + { + continue; + } + if (line[ii] == '#') + { + break; + } + else if (line[ii] == '=') + { + is_value = true; + } + else if (line[ii] == '=' && is_value) + { + key = ""; + value = ""; + break; + } + else if (!is_value) + { + key += line[ii]; + } + else + { + valid = true; + value += line[ii]; + } + } + if (valid) + { + settings[key] = value; + } + } + fIn.close(); + } +} + +inline void save_settings(const std::string& path, const map_settings_t& settings) +{ + map_settings_t::const_iterator it; + std::ofstream fOut; + fOut.open(path.c_str()); + if (fOut.is_open()) + { + fOut << "# !DO NOT EDIT THIS FILE BY HAND. IT IS GENERATED BY ABRT!" << std::endl; + for (it = settings.begin(); it != settings.end(); it++) + { + fOut << it->first << " = " << it->second << std::endl << std::endl; + } + fOut.close(); + } + else + { + throw std::string("save_settings(): Cannot write configuration file '"+path+"'."); + } +} + +inline void parse_settings(const std::string& pLine, set_settings_t& settings) +{ + std::string::size_type ii_old = 0, ii_new = 0; + ii_new = pLine.find(","); + while (ii_new != std::string::npos) + { + settings.insert(pLine.substr(ii_old, ii_new - ii_old)); + ii_old = ii_new + 1; + ii_new = pLine.find(",",ii_old); + } + settings.insert(pLine.substr(ii_old)); +} #endif /* SETTINGSFUNC_H_ */ -- cgit