summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt4
-rw-r--r--src/global.h1
-rw-r--r--src/history.cc23
-rw-r--r--src/ledger.hh.in76
-rw-r--r--src/main.cc6
-rw-r--r--src/ptree.cc2
-rw-r--r--src/report.cc6
-rw-r--r--src/report.h2
-rw-r--r--src/select.cc4
-rw-r--r--src/system.hh.in71
-rw-r--r--src/textual.cc12
-rw-r--r--src/utils.cc8
-rw-r--r--src/utils.h25
13 files changed, 127 insertions, 113 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c6afcd7b..712aa714 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -315,6 +315,10 @@ configure_file(
${PROJECT_SOURCE_DIR}/src/system.hh.in
${PROJECT_BINARY_DIR}/system.hh)
+configure_file(
+ ${PROJECT_SOURCE_DIR}/src/ledger.hh.in
+ ${PROJECT_BINARY_DIR}/ledger.hh)
+
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ")
endif()
diff --git a/src/global.h b/src/global.h
index 9607ba1a..4892a471 100644
--- a/src/global.h
+++ b/src/global.h
@@ -37,6 +37,7 @@
*/
#pragma once
+#include <ledger.hh>
#include "option.h"
#include "report.h"
diff --git a/src/history.cc b/src/history.cc
index 5dc56b89..dbcdc823 100644
--- a/src/history.cc
+++ b/src/history.cc
@@ -467,13 +467,6 @@ commodity_history_impl_t::find_price(const commodity_t& source,
const commodity_t * last_target = &target;
-#if defined(REVERSE_PREDECESSOR_MAP)
- typedef tuple<const commodity_t *, const commodity_t *,
- const price_point_t *> results_tuple;
- std::vector<results_tuple> results;
- bool results_reversed = false;
-#endif
-
vertex_descriptor v = tv;
for (vertex_descriptor u = predecessorMap[v];
u != v;
@@ -494,23 +487,7 @@ commodity_history_impl_t::find_price(const commodity_t& source,
const commodity_t * u_comm = get(namemap, u);
const commodity_t * v_comm = get(namemap, v);
-#if defined(REVERSE_PREDECESSOR_MAP)
- if (v == tv && u_comm != last_target && v_comm != last_target)
- results_reversed = true;
-
- results.push_back(results_tuple(u_comm, v_comm, &point));
- }
-
- if (results_reversed)
- std::reverse(results.begin(), results.end());
-
- foreach (const results_tuple& edge, results) {
- const commodity_t * u_comm = edge.get<0>();
- const commodity_t * v_comm = edge.get<1>();
- const price_point_t& point(*edge.get<2>());
-#else
assert(u_comm == last_target || v_comm == last_target);
-#endif
bool first_run = false;
if (price.is_null()) {
diff --git a/src/ledger.hh.in b/src/ledger.hh.in
new file mode 100644
index 00000000..54e7797c
--- /dev/null
+++ b/src/ledger.hh.in
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2003-2023, John Wiegley. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - Neither the name of New Artisans LLC nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @addtogroup util
+ *
+ * @file ledger.hh
+ * @author John Wiegley
+ */
+#pragma once
+
+#include <system.hh>
+
+#define Ledger_VERSION_MAJOR @Ledger_VERSION_MAJOR@
+#define Ledger_VERSION_MINOR @Ledger_VERSION_MINOR@
+#define Ledger_VERSION_PATCH @Ledger_VERSION_PATCH@
+#define Ledger_VERSION_PRERELEASE "@Ledger_VERSION_PRERELEASE@"
+#define Ledger_VERSION_DATE @Ledger_VERSION_DATE@
+
+/**
+ * @name Default values
+ */
+/*@{*/
+
+#cmakedefine01 DEBUG_MODE
+#cmakedefine01 NO_ASSERTS
+
+#if DEBUG_MODE
+#define DEBUG_ON 1
+#define VERIFY_ON 1
+#define TRACING_ON 1
+#elif NO_ASSERTS
+#define DEBUG_ON 0
+#define VERIFY_ON 0
+#define TRACING_ON 0
+#else
+#define DEBUG_ON 0
+#define VERIFY_ON 0
+#define TRACING_ON 1 // use --trace X to enable
+#endif
+
+#define LOGGING_ON 1
+
+#define DOCUMENT_MODEL 0
+#define REDUCE_TO_INTEGER 0
+
+/*@}*/
+
diff --git a/src/main.cc b/src/main.cc
index bc2a1e28..6b3e1eb3 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -39,7 +39,7 @@
#include <boost/nowide/args.hpp>
#endif
-#ifdef HAVE_EDIT
+#if HAVE_EDIT
#include <editline/readline.h>
#endif
@@ -137,7 +137,7 @@ int main(int argc, char * argv[], char * envp[])
bool exit_loop = false;
-#ifdef HAVE_EDIT
+#if HAVE_EDIT
rl_readline_name = const_cast<char *>("Ledger");
// TODO: rl_attempted_completion_function = ledger_completion;
@@ -178,7 +178,7 @@ int main(int argc, char * argv[], char * envp[])
global_scope->execute_command_wrapper(split_arguments(p), true);
}
-#ifdef HAVE_EDIT
+#if HAVE_EDIT
if (expansion)
std::free(expansion);
std::free(p);
diff --git a/src/ptree.cc b/src/ptree.cc
index 01bf16b0..dc1d7f3d 100644
--- a/src/ptree.cc
+++ b/src/ptree.cc
@@ -29,7 +29,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <system.hh>
+#include <ledger.hh>
#include "ptree.h"
#include "xact.h"
diff --git a/src/report.cc b/src/report.cc
index 991f3a6d..6c957767 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -56,7 +56,7 @@ void report_t::normalize_options(const string& verb)
// Patch up some of the reporting options based on what kind of
// command it was.
-#ifdef HAVE_ISATTY
+#if HAVE_ISATTY
if (! HANDLED(force_color)) {
if (! HANDLED(no_color) && isatty(STDOUT_FILENO))
HANDLER(color).on("?normalize");
@@ -183,14 +183,14 @@ void report_t::normalize_options(const string& verb)
}
long cols = 0;
-#ifdef HAVE_IOCTL
+#if HAVE_IOCTL
struct winsize ws;
#endif
if (HANDLED(columns_))
cols = lexical_cast<long>(HANDLER(columns_).value);
else if (const char * columns = std::getenv("COLUMNS"))
cols = lexical_cast<long>(columns);
-#ifdef HAVE_IOCTL
+#if HAVE_IOCTL
else if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) != -1)
cols = ws.ws_col;
#endif
diff --git a/src/report.h b/src/report.h
index a63360ca..daa9c7c0 100644
--- a/src/report.h
+++ b/src/report.h
@@ -806,7 +806,7 @@ public:
OPTION(report_t, output_); // -o
// setenv() is not available on WIN32
-#if defined(HAVE_ISATTY) and !defined(_WIN32) and !defined(__CYGWIN__)
+#if HAVE_ISATTY and !defined(_WIN32) and !defined(__CYGWIN__)
OPTION__
(report_t, pager_,
CTOR(report_t, pager_) {
diff --git a/src/select.cc b/src/select.cc
index 6660f1ab..ccec34ec 100644
--- a/src/select.cc
+++ b/src/select.cc
@@ -145,14 +145,14 @@ value_t select_command(call_scope_t& args)
string thus_far = "";
std::size_t cols = 0;
-#ifdef HAVE_IOCTL
+#if HAVE_IOCTL
struct winsize ws;
#endif
if (report.HANDLED(columns_))
cols = lexical_cast<std::size_t>(report.HANDLER(columns_).value);
else if (const char * columns_env = std::getenv("COLUMNS"))
cols = lexical_cast<std::size_t>(columns_env);
-#ifdef HAVE_IOCTL
+#if HAVE_IOCTL
else if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) != -1)
cols = ws.ws_col;
#endif
diff --git a/src/system.hh.in b/src/system.hh.in
index a6c465df..95dedbc2 100644
--- a/src/system.hh.in
+++ b/src/system.hh.in
@@ -41,9 +41,7 @@
* None of these header files (with the exception of acconf.h, when
* configure is re-run) are expected to change.
*/
-
-#ifndef INCLUDED_SYSTEM_HH
-#define INCLUDED_SYSTEM_HH
+#pragma once
//#warning("Loading system.hh. This should occur only once!")
@@ -51,37 +49,27 @@
/* Application configuration */
/*------------------------------------------------------------------------*/
-#define Ledger_VERSION_MAJOR @Ledger_VERSION_MAJOR@
-#define Ledger_VERSION_MINOR @Ledger_VERSION_MINOR@
-#define Ledger_VERSION_PATCH @Ledger_VERSION_PATCH@
-#define Ledger_VERSION_PRERELEASE "@Ledger_VERSION_PRERELEASE@"
-#define Ledger_VERSION_DATE @Ledger_VERSION_DATE@
-
-#define HAVE_GETTEXT @HAVE_GETTEXT@
-
-#cmakedefine HAVE_EDIT
-#cmakedefine HAVE_GETPWUID
-#cmakedefine HAVE_GETPWNAM
-#cmakedefine HAVE_IOCTL
-#cmakedefine HAVE_ISATTY
-
-#define HAVE_UNIX_PIPES @HAVE_UNIX_PIPES@
+#cmakedefine01 HAVE_GETTEXT
-#define HAVE_BOOST_PYTHON @HAVE_BOOST_PYTHON@
-#define HAVE_GPGME @HAVE_GPGME@
-#define HAVE_BOOST_REGEX_UNICODE @HAVE_BOOST_REGEX_UNICODE@
-#define HAVE_BOOST_NOWIDE @HAVE_BOOST_NOWIDE@
+#cmakedefine01 HAVE_EDIT
+#cmakedefine01 HAVE_GETPWUID
+#cmakedefine01 HAVE_GETPWNAM
+#cmakedefine01 HAVE_IOCTL
+#cmakedefine01 HAVE_ISATTY
-#define DEBUG_MODE @DEBUG_MODE@
-#define NO_ASSERTS @NO_ASSERTS@
+#cmakedefine01 HAVE_UNIX_PIPES
-#define DOCUMENT_MODEL 0
-#define REDUCE_TO_INTEGER 0
+#cmakedefine01 HAVE_BOOST_PYTHON
+#cmakedefine01 HAVE_GPGME
+#cmakedefine01 HAVE_BOOST_REGEX_UNICODE
+#cmakedefine01 HAVE_BOOST_NOWIDE
/*------------------------------------------------------------------------*/
/* System includes */
/*------------------------------------------------------------------------*/
+#include "utf8.h"
+
#include <algorithm>
#include <exception>
#include <typeinfo>
@@ -109,17 +97,19 @@
#include <cstdlib>
#include <cstring>
#include <csignal>
+#include <cstddef> /* needed for gcc 4.9 */
#if defined(_WIN32) || defined(__CYGWIN__)
#include <io.h>
#else
#include <unistd.h>
#endif
-#if defined(HAVE_GETPWUID) || defined(HAVE_GETPWNAM)
+
+#if HAVE_GETPWUID || HAVE_GETPWNAM
#include <pwd.h>
#endif
-#ifdef HAVE_IOCTL
+#if HAVE_IOCTL
#include <sys/ioctl.h>
#endif
@@ -128,10 +118,16 @@
#include <sys/wait.h>
#endif
-#include <cstddef> /* needed for gcc 4.9 */
+#if HAVE_GETTEXT
+#include <libintl.h>
+#define _(str) gettext(str)
+#else
+#define _(str) str
+#endif
+#define _f(str) boost::format(_(str))
+
#include <gmp.h>
#include <mpfr.h>
-#include "utf8.h"
#include <boost/algorithm/string.hpp>
#include <boost/any.hpp>
@@ -194,27 +190,12 @@
#include <boost/variant.hpp>
#include <boost/version.hpp>
-#if HAVE_GETTEXT
-#include <libintl.h>
-#define _(str) gettext(str)
-#else
-#define _(str) str
-#endif
-#define _f(str) boost::format(_(str))
-
#include <boost/ptr_container/ptr_deque.hpp>
#if HAVE_BOOST_PYTHON
-
#include <boost/python.hpp>
-
#include <boost/python/detail/wrap_python.hpp>
-
#include <boost/python/module_init.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
-
#include <boost/iterator/indirect_iterator.hpp>
-
#endif // HAVE_BOOST_PYTHON
-
-#endif // INCLUDED_SYSTEM_HH
diff --git a/src/textual.cc b/src/textual.cc
index 38142119..2da123a7 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -46,7 +46,7 @@
#endif
#define TIMELOG_SUPPORT 1
-#if defined(TIMELOG_SUPPORT)
+#if TIMELOG_SUPPORT
#include "timelog.h"
#endif
@@ -79,7 +79,7 @@ namespace {
instance_t * parent;
std::list<application_t> apply_stack;
bool no_assertions;
-#if defined(TIMELOG_SUPPORT)
+#if TIMELOG_SUPPORT
time_log_t timelog;
#endif
@@ -138,7 +138,7 @@ namespace {
void read_next_directive(bool& error_flag);
-#if defined(TIMELOG_SUPPORT)
+#if TIMELOG_SUPPORT
void clock_in_directive(char * line, bool capitalized);
void clock_out_directive(char * line, bool capitalized);
#endif
@@ -295,7 +295,7 @@ void instance_t::parse()
apply_stack.pop_front();
-#if defined(TIMELOG_SUPPORT)
+#if TIMELOG_SUPPORT
timelog.close();
#endif // TIMELOG_SUPPORT
@@ -405,7 +405,7 @@ void instance_t::read_next_directive(bool& error_flag)
default: // some other directive
if (! general_directive(line)) {
switch (line[0]) {
-#if defined(TIMELOG_SUPPORT)
+#if TIMELOG_SUPPORT
case 'i':
clock_in_directive(line, false);
break;
@@ -451,7 +451,7 @@ void instance_t::read_next_directive(bool& error_flag)
}
}
-#if defined(TIMELOG_SUPPORT)
+#if TIMELOG_SUPPORT
void instance_t::clock_in_directive(char * line, bool capitalized)
{
diff --git a/src/utils.cc b/src/utils.cc
index baf5a27a..6ca7eeb7 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -29,7 +29,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <system.hh>
+#include <ledger.hh>
#include "times.h"
@@ -662,7 +662,7 @@ static struct __maybe_enable_debugging {
* Timers (allows log xacts to specify cumulative time spent)
*/
-#if LOGGING_ON && defined(TIMERS_ON)
+#if LOGGING_ON && TIMERS_ON
namespace ledger {
@@ -807,7 +807,7 @@ path expand_path(const path& pathname)
if (path_string.length() == 1 || pos == 1) {
pfx = std::getenv("HOME");
-#ifdef HAVE_GETPWUID
+#if HAVE_GETPWUID
if (! pfx) {
// Punt. We're trying to expand ~/, but HOME isn't set
struct passwd * pw = getpwuid(getuid());
@@ -816,7 +816,7 @@ path expand_path(const path& pathname)
}
#endif
}
-#ifdef HAVE_GETPWNAM
+#if HAVE_GETPWNAM
else {
string user(path_string, 1, pos == string::npos ?
string::npos : pos - 1);
diff --git a/src/utils.h b/src/utils.h
index 7ca5935a..a3fc9de5 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -45,30 +45,8 @@
#include <boost/uuid/detail/sha1.hpp>
-/**
- * @name Default values
- */
-/*@{*/
-
#define TIMERS_ON 1
-#if DEBUG_MODE
-#define DEBUG_ON 1
-#define VERIFY_ON 1
-#define TRACING_ON 1
-#elif NO_ASSERTS
-#define DEBUG_ON 0
-#define VERIFY_ON 0
-#define TRACING_ON 0
-//#define NO_LOGGING 1
-#else
-#define DEBUG_ON 0
-#define VERIFY_ON 0
-#define TRACING_ON 1 // use --trace X to enable
-#endif
-
-/*@}*/
-
/**
* @name Forward declarations
*/
@@ -217,9 +195,6 @@ inline string operator+(const char * left, const string& right) {
*/
/*@{*/
-#if ! defined(NO_LOGGING)
-#define LOGGING_ON 1
-#endif
#if LOGGING_ON
namespace ledger {