From 9d5172792af05321a05e63b186f477c2af93b2ea Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 1 Oct 2003 05:04:37 +0000 Subject: Added support for dynamic downloading of stock quote information. --- amount.cc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'amount.cc') 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(); -- cgit v1.2.3