summaryrefslogtreecommitdiff
path: root/config.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-09-23 02:37:42 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-09-23 02:37:42 -0400
commit4e6157b74a8fb55eb4e6ab786858dfb055839f55 (patch)
treeb4040bd771302c4df1bd139bea78a6ef9ed149d0 /config.cc
parent12c0c08f1ea8cda276f390c6929a7b59b86448ed (diff)
downloadfork-ledger-4e6157b74a8fb55eb4e6ab786858dfb055839f55.tar.gz
fork-ledger-4e6157b74a8fb55eb4e6ab786858dfb055839f55.tar.bz2
fork-ledger-4e6157b74a8fb55eb4e6ab786858dfb055839f55.zip
added some error checking
Diffstat (limited to 'config.cc')
-rw-r--r--config.cc13
1 files changed, 10 insertions, 3 deletions
diff --git a/config.cc b/config.cc
index cea5ac86..d8304d95 100644
--- a/config.cc
+++ b/config.cc
@@ -3,6 +3,7 @@
#include "quotes.h"
#include <fstream>
+#include <stdlib.h>
namespace ledger {
@@ -206,14 +207,16 @@ void parse_ledger_data(journal_t * journal,
{
int entry_count = 0;
- if (! config.init_file.empty()) {
+ if (! config.init_file.empty() &&
+ access(config.init_file.c_str(), R_OK) != -1) {
if (parse_journal_file(config.init_file, journal))
throw error("Entries not allowed in initialization file");
journal->sources.pop_front(); // remove init file
}
if (cache_parser && config.use_cache &&
- ! config.cache_file.empty() && ! config.data_file.empty()) {
+ ! config.cache_file.empty() &&
+ ! config.data_file.empty()) {
config.cache_dirty = true;
if (access(config.cache_file.c_str(), R_OK) != -1) {
std::ifstream stream(config.cache_file.c_str());
@@ -355,7 +358,11 @@ OPT_BEGIN(init, "i:") {
} OPT_END(init);
OPT_BEGIN(file, "f:") {
- config.data_file = optarg;
+ if (access(optarg, R_OK) != -1)
+ config.data_file = optarg;
+ else
+ throw error(std::string("The ledger file '") + optarg +
+ "' does not exist or is not readable");
} OPT_END(file);
OPT_BEGIN(cache, ":") {