1 | // $Id: main_utility.cc 1070 2010-06-06 03:32:03Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2010 Peter Johansson |
---|
5 | |
---|
6 | This file is part of svndigest, http://dev.thep.lu.se/svndigest |
---|
7 | |
---|
8 | svndigest is free software; you can redistribute it and/or modify it |
---|
9 | under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 3 of the License, or |
---|
11 | (at your option) any later version. |
---|
12 | |
---|
13 | svndigest is distributed in the hope that it will be useful, but |
---|
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
---|
20 | */ |
---|
21 | |
---|
22 | #include "main_utility.h" |
---|
23 | |
---|
24 | #include "Configuration.h" |
---|
25 | #include "utility.h" |
---|
26 | |
---|
27 | #include <cctype> |
---|
28 | #include <fstream> |
---|
29 | #include <iostream> |
---|
30 | #include <string> |
---|
31 | #include <stdexcept> |
---|
32 | |
---|
33 | namespace theplu { |
---|
34 | namespace svndigest { |
---|
35 | |
---|
36 | void load_config(const std::string& file) |
---|
37 | { |
---|
38 | // Reading configuration file |
---|
39 | Configuration& config = Configuration::instance(); |
---|
40 | if (node_exist(file)) { |
---|
41 | std::ifstream is(file.c_str()); |
---|
42 | assert(is.good()); |
---|
43 | try { |
---|
44 | config.load(is); |
---|
45 | } |
---|
46 | catch (std::runtime_error& e) { |
---|
47 | std::string msg = "invalid config file\n"; |
---|
48 | msg += e.what(); |
---|
49 | throw std::runtime_error(msg); |
---|
50 | } |
---|
51 | is.close(); |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | void write_config_and_exit(void) |
---|
57 | { |
---|
58 | std::cout << Configuration::instance(); |
---|
59 | exit(EXIT_SUCCESS); |
---|
60 | } |
---|
61 | |
---|
62 | }} // end of namespace svndigest and namespace theplu |
---|