diff options
author | John Wiegley <johnw@newartisans.com> | 2009-01-21 18:54:06 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-01-21 18:54:06 -0400 |
commit | eb04b8be85e1af46ba94a00758a50cd1d97bf69e (patch) | |
tree | e4e3df56289b9ee69643c3b5a8db5c2c24eb9f8f /src/main.cc | |
parent | e4c7b1753bf5c0fb5f1dd89efeee733fb7b5be23 (diff) | |
download | fork-ledger-eb04b8be85e1af46ba94a00758a50cd1d97bf69e.tar.gz fork-ledger-eb04b8be85e1af46ba94a00758a50cd1d97bf69e.tar.bz2 fork-ledger-eb04b8be85e1af46ba94a00758a50cd1d97bf69e.zip |
Changed the order in which options are processed, to provide for the correct
overrides.
1. Global defaults
2. Environment variable settings
3. Initialization file
4. Command-line arguments
Whatever is later in the list overrides what is earlier.
Diffstat (limited to 'src/main.cc')
-rw-r--r-- | src/main.cc | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/src/main.cc b/src/main.cc index 0c9c901a..35efaa90 100644 --- a/src/main.cc +++ b/src/main.cc @@ -58,8 +58,49 @@ namespace ledger { session_t& session(report.session); + // Setup global defaults + + optional<path> home; + if (const char * home_var = std::getenv("HOME")) + home = home_var; + + session.init_file = home ? *home / ".ledgerrc" : "./.ledgerrc"; + session.price_db = home ? *home / ".pricedb" : "./.pricedb"; + session.cache_file = home ? *home / ".ledger-cache" : "./.ledger-cache"; + + // Process the environment settings + + TRACE_START(environment, 1, "Processed environment variables"); + + process_environment(const_cast<const char **>(envp), "LEDGER_", report); + +#if 1 + // These are here for backwards compatability, but are deprecated. + + if (const char * p = std::getenv("LEDGER")) + process_option("file", report, p); + if (const char * p = std::getenv("LEDGER_INIT")) + process_option("init-file", report, p); + if (const char * p = std::getenv("PRICE_HIST")) + process_option("price-db", report, p); + if (const char * p = std::getenv("PRICE_EXP")) + process_option("price-exp", report, p); +#endif + + TRACE_FINISH(environment, 1); + + // Read the initialization file + + TRACE_START(init, 1, "Read initialization file"); + + session.read_init(); + + TRACE_FINISH(init, 1); + // Handle the command-line arguments + TRACE_START(arguments, 1, "Processing command-line arguments"); + strings_list args; process_arguments(argc - 1, argv + 1, false, report, args); @@ -76,24 +117,6 @@ namespace ledger { DEBUG("ledger.session.cache", "1. use_cache = " << session.use_cache); - // Process the environment settings - - TRACE_START(environment, 1, "Processed environment variables"); - process_environment(const_cast<const char **>(envp), "LEDGER_", report); - TRACE_FINISH(environment, 1); - - optional<path> home; - if (const char * home_var = std::getenv("HOME")) - home = home_var; - - if (! session.init_file) - session.init_file = home ? *home / ".ledgerrc" : "./.ledgerrc"; - if (! session.price_db) - session.price_db = home ? *home / ".pricedb" : "./.pricedb"; - - if (! session.cache_file) - session.cache_file = home ? *home / ".ledger-cache" : "./.ledger-cache"; - if (session.data_file == *session.cache_file) session.use_cache = false; @@ -107,6 +130,8 @@ namespace ledger { if (! session.use_cache) INFO("Binary cache mechanism will not be used"); + TRACE_FINISH(arguments, 1); + // Configure the output stream #ifdef HAVE_UNIX_PIPES |