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

Generated on Fri Oct 8 20:34:48 2004 for LibOFX by doxygen 1.3.7