diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | amount.cc | 29 | ||||
-rw-r--r-- | ledger.h | 4 | ||||
-rw-r--r-- | main.cc | 12 |
4 files changed, 41 insertions, 6 deletions
@@ -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 @@ -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(); @@ -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 @@ -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 |