summaryrefslogtreecommitdiff
path: root/amount.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2003-10-01 05:04:37 +0000
committerJohn Wiegley <johnw@newartisans.com>2003-10-01 05:04:37 +0000
commit9d5172792af05321a05e63b186f477c2af93b2ea (patch)
tree62d939d05ae08413f19b70f5e34d11c97e663931 /amount.cc
parentf93341edfccba98c7c709dfd172467b37017cc3f (diff)
downloadfork-ledger-9d5172792af05321a05e63b186f477c2af93b2ea.tar.gz
fork-ledger-9d5172792af05321a05e63b186f477c2af93b2ea.tar.bz2
fork-ledger-9d5172792af05321a05e63b186f477c2af93b2ea.zip
Added support for dynamic downloading of stock quote information.
Diffstat (limited to 'amount.cc')
-rw-r--r--amount.cc29
1 files changed, 29 insertions, 0 deletions
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();