summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am2
-rw-r--r--src/derive.cc59
-rw-r--r--src/derive.h59
-rw-r--r--src/ledger.h4
-rw-r--r--src/precmd.cc19
-rw-r--r--src/report.cc19
-rw-r--r--src/report.h10
-rw-r--r--src/scope.h7
8 files changed, 72 insertions, 107 deletions
diff --git a/Makefile.am b/Makefile.am
index 8547e6c5..cc3301e0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -116,8 +116,6 @@ pkginclude_HEADERS = \
src/output.h \
src/emacs.h \
src/help.h \
- \
- src/derive.h \
src/quotes.h \
\
src/global.h \
diff --git a/src/derive.cc b/src/derive.cc
index dd261ed6..ec9b1ed8 100644
--- a/src/derive.cc
+++ b/src/derive.cc
@@ -29,15 +29,27 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "derive.h"
-#include "session.h"
-#include "iterators.h"
+#include "report.h"
+#include "output.h"
namespace ledger {
-entry_t * derive_new_entry(report_t& report,
- strings_list::iterator i,
- strings_list::iterator end)
+value_t entry_command(call_scope_t& args)
+{
+ report_t& report(find_scope<report_t>(args));
+ scoped_ptr<entry_t> entry(derive_new_entry(report, args.begin(),
+ args.end()));
+ xact_handler_ptr handler
+ (new format_xacts(report, report.HANDLER(print_format_).str()));
+
+ report.entry_report(handler, *entry.get());
+
+ return true;
+}
+
+entry_t * derive_new_entry(report_t& report,
+ value_t::sequence_t::const_iterator i,
+ value_t::sequence_t::const_iterator end)
{
session_t& session(report.session);
@@ -45,11 +57,11 @@ entry_t * derive_new_entry(report_t& report,
entry_t * matching = NULL;
- added->_date = parse_date(*i++);
+ added->_date = parse_date((*i++).to_string());
if (i == end)
throw std::runtime_error("Too few arguments to 'entry'");
- mask_t regexp(*i++);
+ mask_t regexp((*i++).to_string());
entries_list::reverse_iterator j;
@@ -64,15 +76,16 @@ entry_t * derive_new_entry(report_t& report,
added->payee = matching ? matching->payee : regexp.expr.str();
+ string arg = (*i).to_string();
if (! matching) {
account_t * acct;
- if (i == end || ((*i)[0] == '-' || std::isdigit((*i)[0]))) {
+ if (i == end || (arg[0] == '-' || std::isdigit(arg[0]))) {
acct = session.master->find_account("Expenses");
}
else if (i != end) {
- acct = session.master->find_account_re(*i);
+ acct = session.master->find_account_re(arg);
if (! acct)
- acct = session.master->find_account(*i);
+ acct = session.master->find_account(arg);
assert(acct);
i++;
}
@@ -80,7 +93,7 @@ entry_t * derive_new_entry(report_t& report,
if (i == end) {
added->add_xact(new xact_t(acct));
} else {
- xact_t * xact = new xact_t(acct, amount_t(*i++));
+ xact_t * xact = new xact_t(acct, amount_t((*i++).to_string()));
added->add_xact(xact);
if (! xact->amount.commodity()) {
@@ -102,9 +115,9 @@ entry_t * derive_new_entry(report_t& report,
if (i != end) {
if (! acct)
- acct = session.master->find_account_re(*i);
+ acct = session.master->find_account_re((*i).to_string());
if (! acct)
- acct = session.master->find_account(*i);
+ acct = session.master->find_account((*i).to_string());
}
if (! acct) {
@@ -124,11 +137,11 @@ entry_t * derive_new_entry(report_t& report,
foreach (xact_t * xact, matching->xacts)
added->add_xact(new xact_t(*xact));
}
- else if ((*i)[0] == '-' || std::isdigit((*i)[0])) {
+ else if (arg[0] == '-' || std::isdigit(arg[0])) {
xact_t * m_xact, * xact, * first;
m_xact = matching->xacts.front();
- first = xact = new xact_t(m_xact->account, amount_t(*i++));
+ first = xact = new xact_t(m_xact->account, amount_t((*i++).to_string()));
added->add_xact(xact);
if (! xact->amount.commodity())
@@ -140,9 +153,9 @@ entry_t * derive_new_entry(report_t& report,
added->add_xact(xact);
if (i != end) {
- account_t * acct = session.master->find_account_re(*i);
+ account_t * acct = session.master->find_account_re((*i).to_string());
if (! acct)
- acct = session.master->find_account(*i);
+ acct = session.master->find_account((*i).to_string());
assert(acct);
added->xacts.back()->account = acct;
}
@@ -151,7 +164,7 @@ entry_t * derive_new_entry(report_t& report,
account_t * draw_acct = NULL;
while (i != end) {
- string& re_pat(*i++);
+ string re_pat((*i++).to_string());
account_t * acct = NULL;
amount_t * amt = NULL;
@@ -177,13 +190,13 @@ entry_t * derive_new_entry(report_t& report,
else
xact = new xact_t(acct);
} else {
- amount_t amount(*i++);
+ amount_t amount((*i++).to_string());
- strings_list::iterator x = i;
+ value_t::sequence_t::const_iterator x = i;
if (i != end && ++x == end) {
- draw_acct = session.master->find_account_re(*i);
+ draw_acct = session.master->find_account_re((*i).to_string());
if (! draw_acct)
- draw_acct = session.master->find_account(*i);
+ draw_acct = session.master->find_account((*i).to_string());
i++;
}
diff --git a/src/derive.h b/src/derive.h
deleted file mode 100644
index dd05e615..00000000
--- a/src/derive.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2003-2009, 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 extra
- */
-
-/**
- * @file derive.h
- * @author John Wiegley
- *
- * @ingroup extra
- *
- * @brief Brief
- *
- * Long.
- */
-#ifndef _DERIVE_H
-#define _DERIVE_H
-
-#include "report.h"
-
-namespace ledger {
-
-entry_t * derive_new_entry(report_t& report,
- strings_list::iterator begin,
- strings_list::iterator end);
-
-} // namespace ledger
-
-#endif // _DERIVE_H
diff --git a/src/ledger.h b/src/ledger.h
index 89d34048..2ead60d6 100644
--- a/src/ledger.h
+++ b/src/ledger.h
@@ -80,11 +80,9 @@
#include <session.h>
#include <report.h>
-#include <help.h>
-
-#include <derive.h>
#include <quotes.h>
#include <emacs.h>
+#include <help.h>
#if defined(HAVE_BOOST_PYTHON)
#include <pyinterp.h>
diff --git a/src/precmd.cc b/src/precmd.cc
index 16b7e5f1..5ec6c7c6 100644
--- a/src/precmd.cc
+++ b/src/precmd.cc
@@ -34,25 +34,6 @@
namespace ledger {
-namespace {
- string join_args(call_scope_t& args)
- {
- std::ostringstream buf;
- bool first = true;
-
- for (std::size_t i = 0; i < args.size(); i++) {
- if (first) {
- buf << args[i];
- first = false;
- } else {
- buf << ' ' << args[i];
- }
- }
-
- return buf.str();
- }
-}
-
value_t parse_command(call_scope_t& args)
{
string arg = join_args(args);
diff --git a/src/report.cc b/src/report.cc
index 97d7ba0c..78d91fdf 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -521,7 +521,7 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
(reporter<account_t, acct_handler_ptr, &report_t::accounts_report>
(new format_equity(*this, HANDLER(print_format_).str()), *this));
else if (is_eq(p, "entry"))
- return NULL; // jww (2009-02-07): NYI
+ return WRAP_FUNCTOR(entry_command);
else if (is_eq(p, "emacs"))
return NULL; // jww (2009-02-07): NYI
break;
@@ -631,4 +631,21 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
return NULL;
}
+string join_args(call_scope_t& args)
+{
+ std::ostringstream buf;
+ bool first = true;
+
+ for (std::size_t i = 0; i < args.size(); i++) {
+ if (first) {
+ buf << args[i];
+ first = false;
+ } else {
+ buf << ' ' << args[i];
+ }
+ }
+
+ return buf.str();
+}
+
} // namespace ledger
diff --git a/src/report.h b/src/report.h
index 35cdda41..4a99fe74 100644
--- a/src/report.h
+++ b/src/report.h
@@ -392,6 +392,16 @@ public:
OPTION(report_t, yearly); // -Y
};
+// jww (2009-02-10): These should perhaps live elsewhere
+value_t entry_command(call_scope_t& args);
+
+entry_t * derive_new_entry(report_t& report,
+ value_t::sequence_t::const_iterator i,
+ value_t::sequence_t::const_iterator end);
+
+string join_args(call_scope_t& args);
+
+
} // namespace ledger
#endif // _REPORT_H
diff --git a/src/scope.h b/src/scope.h
index 8323f224..42825606 100644
--- a/src/scope.h
+++ b/src/scope.h
@@ -182,6 +182,13 @@ public:
args.pop_back();
}
+ value_t::sequence_t::const_iterator begin() const {
+ return args.begin();
+ }
+ value_t::sequence_t::const_iterator end() const {
+ return args.end();
+ }
+
std::size_t size() const {
return args.size();
}