00001
00002
00003
00004
00005
00006
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <iostream>
00031 #include <iomanip>
00032 #include <string>
00033 #include "libofx.h"
00034 #include <stdio.h>
00035 #include <config.h>
00036 #include "lib/messages.hh"
00037
00038 using namespace std;
00039
00040
00041 int main (int argc, char *argv[])
00042 {
00044 extern int ofx_PARSER_msg;
00045 extern int ofx_DEBUG_msg;
00046 extern int ofx_WARNING_msg;
00047 extern int ofx_ERROR_msg;
00048 extern int ofx_INFO_msg;
00049 extern int ofx_STATUS_msg;
00050
00051 ofx_PARSER_msg = false;
00052 ofx_DEBUG_msg = false;
00053 ofx_WARNING_msg = true;
00054 ofx_ERROR_msg = true;
00055 ofx_INFO_msg = true;
00056 ofx_STATUS_msg = true;
00057
00058 int special_options (char *argv[]);
00059 int count, ret = 0;;
00060
00061 printf ("This program was called with \"%s\".\n",argv[0]);
00062 if (argc > 1)
00063 {
00064 for (count = 1; count < argc; count++)
00065 {
00066 printf("argv[%d] = %s\n", count, argv[count]);
00067 }
00068 if (0 == special_options(argv)) ;
00069 else ofx_proc_file(argc, argv);
00070 }
00071 else { ofx_proc_file(argc, argv);
00072 }
00073 return 0;
00074 }
00075
00076
00077 int special_options (char *argv[])
00078 {
00079 int count;
00080
00081
00082 const int spoptver = 0;
00083 const int spopthelp = 1;
00084
00085
00086 const char *spoptar[] = {"--version", "-V", "--help"};
00087 const int spoptdim = sizeof(spoptar)/sizeof(spoptar[0]);
00088 const int spoptcasear[spoptdim] = {spoptver, spoptver, spopthelp};
00089
00090
00091 const char *helpar[] =
00092 {
00093 "ofxdump command synopsis:\n",
00094 "ofxdump special_option\n",
00095 "ofxdump ofx_file\n",
00096 "\n",
00097 "Special options are:\n",
00098 "--version, V libofx version\n",
00099 "--help help text\n",
00100 "\n",
00101 "If the first argument is a special option, it is processed and any remaining \
00102 arguments are ignored; otherwise, control goes to ofx_proc_file.\n\n"
00103 };
00104 const int helpardim = sizeof(helpar)/sizeof(helpar[1]);
00105
00106
00107 for (count = 0; (count < spoptdim) && (strcmp(argv[1], spoptar[count]) != 0) ; count++);
00108
00109 if (count < spoptdim)
00110 {
00111 switch (spoptcasear[count])
00112 {
00113 case spoptver: printf ("libofx version: %s \n", VERSION ); return 0;
00114 case spopthelp:
00115 {
00116 for (int i=0; i < helpardim; i++) printf (helpar[i]);
00117 return 0;
00118 }
00119 default:
00120 {
00121 message_out (ERROR, "Impossible special option case");
00122 return -1;
00123 }
00124 }
00125 }
00126 return 1;
00127 }
00128
00129
00130
00131
00132 int ofx_proc_status_cb(struct OfxStatusData data)
00133 {
00134 cout<<"ofx_proc_status():\n";
00135 if(data.ofx_element_name_valid==true){
00136 cout<<" Ofx entity this status is relevent to: "<< data.ofx_element_name<<" \n";
00137 }
00138 if(data.severity_valid==true){
00139 cout<<" Severity: ";
00140 switch(data.severity){
00141 case OfxStatusData::INFO : cout<<"INFO\n";
00142 break;
00143 case OfxStatusData::WARN : cout<<"WARN\n";
00144 break;
00145 case OfxStatusData::ERROR : cout<<"ERROR\n";
00146 break;
00147 default: cout<<"WRITEME: Unknown status severity!\n";
00148 }
00149 }
00150 if(data.code_valid==true){
00151 cout<<" Code: "<<data.code<<", name: "<<data.name<<"\n Description: "<<data.description<<"\n";
00152 }
00153 if(data.server_message_valid==true){
00154 cout<<" Server Message: "<<data.server_message<<"\n";
00155 }
00156 cout<<"\n";
00157 return 0;
00158 }
00159
00160 int ofx_proc_security_cb(struct OfxSecurityData data)
00161 {
00162 char dest_string[255];
00163 cout<<"ofx_proc_security():\n";
00164 if(data.unique_id_valid==true){
00165 cout<<" Unique ID of the security being traded: "<<data.unique_id<<"\n";
00166 }
00167 if(data.unique_id_type_valid==true){
00168 cout<<" Format of the Unique ID: "<<data.unique_id_type<<"\n";
00169 }
00170 if(data.secname_valid==true){
00171 cout<<" Name of the security: "<<data.secname<<"\n";
00172 }
00173 if(data.ticker_valid==true){
00174 cout<<" Ticker symbol: "<<data.ticker<<"\n";
00175 }
00176 if(data.unitprice_valid==true){
00177 cout<<" Price of each unit of the security: "<<data.unitprice<<"\n";
00178 }
00179 if(data.date_unitprice_valid==true){
00180 strftime(dest_string,sizeof(dest_string),"%c %Z",localtime(&(data.date_unitprice)));
00181 cout<<" Date as of which the unitprice is valid: "<<dest_string<<"\n";
00182 }
00183 if(data.currency_valid==true){
00184 cout<<" Currency of the unitprice: "<<data.currency<<"\n";
00185 }
00186 if(data.memo_valid==true){
00187 cout<<" Extra transaction information (memo): "<<data.memo<<"\n";
00188 }
00189 cout<<"\n";
00190 return 0;
00191 }
00192
00193 int ofx_proc_transaction_cb(struct OfxTransactionData data)
00194 {
00195 char dest_string[255];
00196 cout<<"ofx_proc_transaction():\n";
00197
00198 if(data.account_id_valid==true){
00199 cout<<" Account ID : "<<data.account_id<<"\n";
00200 }
00201
00202 if(data.transactiontype_valid==true){
00203 switch(data.transactiontype){
00204 case data.OFX_CREDIT: strncpy(dest_string, "CREDIT: Generic credit", sizeof(dest_string));
00205 break;
00206 case data.OFX_DEBIT: strncpy(dest_string, "DEBIT: Generic debit", sizeof(dest_string));
00207 break;
00208 case data.OFX_INT: strncpy(dest_string, "INT: Interest earned or paid (Note: Depends on signage of amount)", sizeof(dest_string));
00209 break;
00210 case data.OFX_DIV: strncpy(dest_string, "DIV: Dividend", sizeof(dest_string));
00211 break;
00212 case data.OFX_FEE: strncpy(dest_string, "FEE: FI fee", sizeof(dest_string));
00213 break;
00214 case data.OFX_SRVCHG: strncpy(dest_string, "SRVCHG: Service charge", sizeof(dest_string));
00215 break;
00216 case data.OFX_DEP: strncpy(dest_string, "DEP: Deposit", sizeof(dest_string));
00217 break;
00218 case data.OFX_ATM: strncpy(dest_string, "ATM: ATM debit or credit (Note: Depends on signage of amount)", sizeof(dest_string));
00219 break;
00220 case data.OFX_POS: strncpy(dest_string, "POS: Point of sale debit or credit (Note: Depends on signage of amount)", sizeof(dest_string));
00221 break;
00222 case data.OFX_XFER: strncpy(dest_string, "XFER: Transfer", sizeof(dest_string));
00223 break;
00224 case data.OFX_CHECK: strncpy(dest_string, "CHECK: Check", sizeof(dest_string));
00225 break;
00226 case data.OFX_PAYMENT: strncpy(dest_string, "PAYMENT: Electronic payment", sizeof(dest_string));
00227 break;
00228 case data.OFX_CASH: strncpy(dest_string, "CASH: Cash withdrawal", sizeof(dest_string));
00229 break;
00230 case data.OFX_DIRECTDEP: strncpy(dest_string, "DIRECTDEP: Direct deposit", sizeof(dest_string));
00231 break;
00232 case data.OFX_DIRECTDEBIT: strncpy(dest_string, "DIRECTDEBIT: Merchant initiated debit", sizeof(dest_string));
00233 break;
00234 case data.OFX_REPEATPMT: strncpy(dest_string, "REPEATPMT: Repeating payment/standing order", sizeof(dest_string));
00235 break;
00236 case data.OFX_OTHER: strncpy(dest_string, "OTHER: Other", sizeof(dest_string));
00237 break;
00238 default : strncpy(dest_string, "Unknown transaction type", sizeof(dest_string));
00239 break;
00240 }
00241 cout<<" Transaction type: "<<dest_string<<"\n";
00242 }
00243 if(data.date_initiated_valid==true){
00244 strftime(dest_string,sizeof(dest_string),"%c %Z",localtime(&(data.date_initiated)));
00245 cout<<" Date initiated: "<<dest_string<<"\n";
00246 }
00247 if(data.date_posted_valid==true){
00248 strftime(dest_string,sizeof(dest_string),"%c %Z",localtime(&(data.date_posted)));
00249 cout<<" Date posted: "<<dest_string<<"\n";
00250 }
00251 if(data.date_funds_available_valid==true){
00252 strftime(dest_string,sizeof(dest_string),"%c %Z",localtime(&(data.date_funds_available)));
00253 cout<<" Date funds are available: "<<dest_string<<"\n";
00254 }
00255 if(data.amount_valid==true){
00256 cout<<" Total money amount: "<<setiosflags(ios::fixed)<<setiosflags(ios::showpoint)<<setprecision(2)<<data.amount<<"\n";
00257 }
00258 if(data.units_valid==true){
00259 cout<<" # of units: "<<setiosflags(ios::fixed)<<setiosflags(ios::showpoint)<<setprecision(2)<<data.units<<"\n";
00260 }
00261 if(data.unitprice_valid==true){
00262 cout<<" Unit price: "<<setiosflags(ios::fixed)<<setiosflags(ios::showpoint)<<setprecision(2)<<data.unitprice<<"\n";
00263 }
00264 if(data.fi_id_valid==true){
00265 cout<<" Financial institution's ID for this transaction: "<<data.fi_id<<"\n";
00266 }
00267 if(data.fi_id_corrected_valid==true){
00268 cout<<" Financial institution ID replaced or corrected by this transaction: "<<data.fi_id_corrected<<"\n";
00269 }
00270 if(data.fi_id_correction_action_valid==true){
00271 cout<<" Action to take on the corrected transaction: ";
00272 switch(data.fi_id_correction_action){
00273 case data.DELETE : cout<<"DELETE\n";
00274 break;
00275 case data.REPLACE : cout<<"REPLACE\n";
00276 break;
00277 default:
00278 cout<<"ofx_proc_transaction(): This should not happen!\n";
00279 }
00280 }
00281 if(data.invtransactiontype_valid==true){
00282 cout<<" Investment transaction type: ";
00283 switch(data.invtransactiontype){
00284 case data.OFX_BUYDEBT: strncpy(dest_string, "BUYDEBT (Buy debt security)", sizeof(dest_string));
00285 break;
00286 case data.OFX_BUYMF: strncpy(dest_string, "BUYMF (Buy mutual fund)", sizeof(dest_string));
00287 break;
00288 case data.OFX_BUYOPT: strncpy(dest_string, "BUYOPT (Buy option)", sizeof(dest_string));
00289 break;
00290 case data.OFX_BUYOTHER: strncpy(dest_string, "BUYOTHER (Buy other security type)", sizeof(dest_string));
00291 break;
00292 case data.OFX_BUYSTOCK: strncpy(dest_string, "BUYSTOCK (Buy stock))", sizeof(dest_string));
00293 break;
00294 case data.OFX_CLOSUREOPT: strncpy(dest_string, "CLOSUREOPT (Close a position for an option)", sizeof(dest_string));
00295 break;
00296 case data.OFX_INCOME: strncpy(dest_string, "INCOME (Investment income is realized as cash into the investment account)", sizeof(dest_string));
00297 break;
00298 case data.OFX_INVEXPENSE: strncpy(dest_string, "INVEXPENSE (Misc investment expense that is associated with a specific security)", sizeof(dest_string));
00299 break;
00300 case data.OFX_JRNLFUND: strncpy(dest_string, "JRNLFUND (Journaling cash holdings between subaccounts within the same investment account)", sizeof(dest_string));
00301 break;
00302 case data.OFX_MARGININTEREST: strncpy(dest_string, "MARGININTEREST (Margin interest expense)", sizeof(dest_string));
00303 break;
00304 case data.OFX_REINVEST: strncpy(dest_string, "REINVEST (Reinvestment of income)", sizeof(dest_string));
00305 break;
00306 case data.OFX_RETOFCAP: strncpy(dest_string, "RETOFCAP (Return of capital)", sizeof(dest_string));
00307 break;
00308 case data.OFX_SELLDEBT: strncpy(dest_string, "SELLDEBT (Sell debt security. Used when debt is sold, called, or reached maturity)", sizeof(dest_string));
00309 break;
00310 case data.OFX_SELLMF: strncpy(dest_string, "SELLMF (Sell mutual fund)", sizeof(dest_string));
00311 break;
00312 case data.OFX_SELLOPT: strncpy(dest_string, "SELLOPT (Sell option)", sizeof(dest_string));
00313 break;
00314 case data.OFX_SELLOTHER: strncpy(dest_string, "SELLOTHER (Sell other type of security)", sizeof(dest_string));
00315 break;
00316 case data.OFX_SELLSTOCK: strncpy(dest_string, "SELLSTOCK (Sell stock)", sizeof(dest_string));
00317 break;
00318 case data.OFX_SPLIT: strncpy(dest_string, "SPLIT (Stock or mutial fund split)", sizeof(dest_string));
00319 break;
00320 case data.OFX_TRANSFER: strncpy(dest_string, "TRANSFER (Transfer holdings in and out of the investment account)", sizeof(dest_string));
00321 break;
00322 default: strncpy(dest_string, "ERROR, this investment transaction type is unknown. This is a bug in ofxdump", sizeof(dest_string));
00323 break;
00324 }
00325 cout<<dest_string<<"\n";
00326 }
00327 if(data.unique_id_valid==true){
00328 cout<<" Unique ID of the security being traded: "<<data.unique_id<<"\n";
00329 }
00330 if(data.unique_id_type_valid==true){
00331 cout<<" Format of the Unique ID: "<<data.unique_id_type<<"\n";
00332 }
00333 if(data.security_data_valid==true){
00334 cout<<" Security data is available:\n START security_data content----------\n";
00335 ofx_proc_security_cb(*(data.security_data_ptr));
00336 cout<<" END security_data content----------\n";
00337
00338 }
00339
00340 if(data.server_transaction_id_valid==true){
00341 cout<<" Server's transaction ID (confirmation number): "<<data.server_transaction_id<<"\n";
00342 }
00343 if(data.check_number_valid==true){
00344 cout<<" Check number: "<<data.check_number<<"\n";
00345 }
00346 if(data.reference_number_valid==true){
00347 cout<<" Reference number: "<<data.reference_number<<"\n";
00348 }
00349 if(data.standard_industrial_code_valid==true){
00350 cout<<" Standard Industrial Code: "<<data.standard_industrial_code<<"\n";
00351 }
00352 if(data.payee_id_valid==true){
00353 cout<<" Payee_id: "<<data.payee_id<<"\n";
00354 }
00355 if(data.name_valid==true){
00356 cout<<" Name of payee or transaction description: "<<data.name<<"\n";
00357 }
00358 if(data.memo_valid==true){
00359 cout<<" Extra transaction information (memo): "<<data.memo<<"\n";
00360 }
00361 cout<<"\n";
00362 return 0;
00363 }
00364
00365 int ofx_proc_statement_cb(struct OfxStatementData data)
00366 {
00367 char dest_string[255];
00368 cout<<"ofx_proc_statement():\n";
00369 if(data.currency_valid==true){
00370 cout<<" Currency: "<<data.currency<<"\n";
00371 }
00372 if(data.account_id_valid==true){
00373 cout<<" Account ID: "<<data.account_id<<"\n";
00374 }
00375 if(data.date_start_valid==true){
00376 strftime(dest_string,sizeof(dest_string),"%c %Z",localtime(&(data.date_start)));
00377 cout<<" Start date of this statement: "<<dest_string<<"\n";
00378 }
00379 if(data.date_end_valid==true){
00380 strftime(dest_string,sizeof(dest_string),"%c %Z",localtime(&(data.date_end)));
00381 cout<<" End date of this statement: "<<dest_string<<"\n";
00382 }
00383 if(data.ledger_balance_valid==true){
00384 cout<<" Ledger balance: "<<setiosflags(ios::fixed)<<setiosflags(ios::showpoint)<<setprecision(2)<<data.ledger_balance<<"\n";
00385 }
00386 if(data.ledger_balance_date_valid==true){
00387 strftime(dest_string,sizeof(dest_string),"%c %Z",localtime(&(data.ledger_balance_date)));
00388 cout<<" Ledger balance date: "<<dest_string<<"\n";
00389 }
00390 if(data.available_balance_valid==true){
00391 cout<<" Available balance: "<<setiosflags(ios::fixed)<<setiosflags(ios::showpoint)<<setprecision(2)<<data.available_balance<<"\n";
00392 }
00393 if(data.available_balance_date_valid==true){
00394 strftime(dest_string,sizeof(dest_string),"%c %Z",localtime(&(data.available_balance_date)));
00395 cout<<" Ledger balance date: "<<dest_string<<"\n";
00396 }
00397 if(data.marketing_info_valid==true){
00398 cout<<" Marketing information: "<<data.marketing_info<<"\n";
00399 }
00400 cout<<"\n";
00401 return 0;
00402 }
00403
00404 int ofx_proc_account_cb(struct OfxAccountData data)
00405 {
00406 cout<<"ofx_proc_account():\n";
00407 if(data.account_id_valid==true){
00408 cout<<" Account ID: "<<data.account_id<<"\n";
00409 cout<<" Account name: "<<data.account_name<<"\n";
00410 }
00411 if(data.account_type_valid==true){
00412 cout<<" Account type: ";
00413 switch(data.account_type){
00414 case OfxAccountData::OFX_CHECKING : cout<<"CHECKING\n";
00415 break;
00416 case OfxAccountData::OFX_SAVINGS : cout<<"SAVINGS\n";
00417 break;
00418 case OfxAccountData::OFX_MONEYMRKT : cout<<"MONEYMRKT\n";
00419 break;
00420 case OfxAccountData::OFX_CREDITLINE : cout<<"CREDITLINE\n";
00421 break;
00422 case OfxAccountData::OFX_CMA : cout<<"CMA\n";
00423 break;
00424 case OfxAccountData::OFX_CREDITCARD : cout<<"CREDITCARD\n";
00425 break;
00426 case OfxAccountData::OFX_INVESTMENT : cout<<"INVESTMENT\n";
00427 break;
00428 default: cout<<"ofx_proc_account() WRITEME: This is an unknown account type!";
00429 }
00430 }
00431 if(data.currency_valid==true){
00432 cout<<" Currency: "<<data.currency<<"\n";
00433 }
00434
00435 cout<<"\n";
00436 return 0;
00437 }