Main Page | Class Hierarchy | Data Structures | File List | Data Fields | Globals

ofxdump.cpp

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

Generated on Fri Sep 12 00:35:47 2003 for LibOFX by doxygen 1.3.3