summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--amount.cc29
-rw-r--r--ledger.h4
-rw-r--r--main.cc12
4 files changed, 41 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index de1c0fc1..0cffe073 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ endif
OBJS = $(patsubst %.cc,%.o,$(CODE))
-CFLAGS = -Wall -ansi -pedantic -DHUQUQULLAH=1
+CFLAGS = -Wall -ansi -pedantic -DDEFAULT_COMMODITY="\"\$$\"" -DHUQUQULLAH=1
#DFLAGS = -O3 -fomit-frame-pointer
DFLAGS = -g # -pg
INCS = -I/usr/include/xmltok
diff --git a/amount.cc b/amount.cc
index 4caac14d..ac2288ad 100644
--- a/amount.cc
+++ b/amount.cc
@@ -222,15 +222,44 @@ amount * gmp_amount::street() const
amount * cost = NULL;
const amount * amt = this;
+ extern bool get_quotes;
+
for (int cycles = 0; cycles < 10; cycles++) {
totals::iterator pi = main_ledger.prices.amounts.find(amt->comm_symbol());
if (pi == main_ledger.prices.amounts.end()) {
+ if (get_quotes && amt->comm_symbol() != DEFAULT_COMMODITY) {
+ using namespace std;
+
+ char buf[256];
+ buf[0] = '\0';
+
+ if (FILE * fp = popen((std::string("getquote ") +
+ amt->comm_symbol()).c_str(), "r")) {
+ if (feof(fp) || ! fgets(buf , 255, fp)) {
+ fclose(fp);
+ break;
+ }
+ fclose(fp);
+ }
+
+ if (buf[0]) {
+ char * p = strchr(buf, '\n');
+ if (p) *p = '\0';
+
+ main_ledger.record_price((amt->comm_symbol() + "=" + buf).c_str());
+ continue;
+ }
+ }
break;
} else {
amount * temp = cost;
amt = cost = amt->value((*pi).second);
+
+ bool same = temp && temp->comm() == cost->comm();
if (temp)
delete temp;
+ if (same)
+ break;
}
}
return cost ? cost : copy();
diff --git a/ledger.h b/ledger.h
index d3f6de12..e2678be6 100644
--- a/ledger.h
+++ b/ledger.h
@@ -1,5 +1,5 @@
#ifndef _LEDGER_H
-#define _LEDGER_H "$Revision: 1.9 $"
+#define _LEDGER_H "$Revision: 1.10 $"
//////////////////////////////////////////////////////////////////////
//
@@ -289,8 +289,6 @@ typedef std::pair<const std::string, account *> accounts_entry;
#ifdef HUQUQULLAH
-#define DEFAULT_COMMODITY "$"
-
extern bool compute_huquq;
extern std::list<mask> huquq_categories;
#endif
diff --git a/main.cc b/main.cc
index 1b2884ec..b2c2fd6a 100644
--- a/main.cc
+++ b/main.cc
@@ -11,7 +11,8 @@ namespace ledger {
extern void print_ledger(int argc, char *argv[], std::ostream& out);
extern void equity_ledger(int argc, char **argv, std::ostream& out);
- bool show_cleared;
+ bool show_cleared;
+ bool get_quotes;
std::time_t begin_date;
bool have_beginning;
@@ -57,7 +58,7 @@ int main(int argc, char *argv[])
show_cleared = false;
int c;
- while (-1 != (c = getopt(argc, argv, "+b:e:cChHwf:i:p:"))) {
+ while (-1 != (c = getopt(argc, argv, "+b:e:cChHwf:i:p:P"))) {
switch (char(c)) {
case 'b': {
struct tm * when = getdate(optarg);
@@ -116,6 +117,10 @@ int main(int argc, char *argv[])
main_ledger.record_price(optarg);
}
break;
+
+ case 'P':
+ get_quotes = true;
+ break;
}
}
@@ -135,6 +140,9 @@ int main(int argc, char *argv[])
#endif
<< " -i FILE read the list of inclusion regexps from FILE" << std::endl
<< " -p FILE read the list of prices from FILE" << std::endl
+ << " -P download price quotes from the Internet" << std::endl
+ << " (this works by running the command \"getquote SYMBOL\")"
+ << std::endl
<< " -w print out warnings where applicable" << std::endl
<< std::endl
<< "commands:" << std::endl