static int ms2csv( const char *ms_dirp ) { Metastock ms; bool dumpdata = true; if( args_info.output_given ) { if( ! ms.set_outfile( args_info.output_arg ) ) { goto ms_error; } } if( !ms.set_ignore_masters( args_info.ignore_master_given, args_info.ignore_emaster_given, args_info.ignore_xmaster_given) ) { goto ms_error; } if( ! ms.setDir( ms_dirp ) ) { goto ms_error; } if( args_info.field_separator_given ) { if( ! ms.set_field_sep(args_info.field_separator_arg) ) { goto ms_error; } } ms.set_skip_header( args_info.skip_header_given ); if( !ms.set_out_format( args_info.format_given ? args_info.format_arg : NULL) ) { goto ms_error; } if( !ms.setForceFloat( args_info.float_openint_given, args_info.float_volume_given) ) { goto ms_error; } if( args_info.fdat_given ) { if( ! ms.incudeFile( args_info.fdat_arg ) ) { goto ms_error; } } if( args_info.date_from_given ) { if( !ms.setPrintDateFrom( args_info.date_from_arg ) ) { goto ms_error; } } if( args_info.exclude_older_than_given ) { if( !ms.excludeFiles( args_info.exclude_older_than_arg ) ) { goto ms_error; } } if( args_info.dump_master_given ) { dumpdata = false; ms.dumpMaster(); } if( args_info.dump_emaster_given ) { dumpdata = false; ms.dumpEMaster(); } if( args_info.dump_xmaster_given ) { dumpdata = false; ms.dumpXMaster(); } if( args_info.symbols_given ) { dumpdata = false; if( ! ms.dumpSymbolInfo() ) { goto ms_error; } } if( dumpdata ) { if( ! ms.dumpData() ) { goto ms_error; } } return 0; ms_error: fprintf( stderr, "error: %s\n", ms.lastError() ); return 2; }
int main(int argc, char *argv[]) { #ifdef _WIN32 /* never write CRLF line feeds */ _setmode(_fileno(stderr),_O_BINARY); _setmode(_fileno(stdout),_O_BINARY); #endif atexit( gengetopt_free ); if( cmdline_parser(argc, argv, &args_info) != 0 ) { return 2; // exit } check_display_args(); const char *ms_dirp = "."; if( args_info.inputs_num == 1 ) { ms_dirp = args_info.inputs[0]; } else if( args_info.inputs_num > 1 ) { fprintf( stderr, "error: bad usage\n" ); return 2; // exit } Metastock ms; if( args_info.output_given ) { if( ! ms.set_outfile( args_info.output_arg ) ) { fprintf( stderr, "error: %s\n", ms.lastError() ); return 2; // exit } } if( ! ms.setDir( ms_dirp ) ) { fprintf( stderr, "error: %s\n", ms.lastError() ); return 2; // exit } if( !ms.setOutputFormat( args_info.field_separator_given ?*args_info.field_separator_arg :'\t', args_info.format_given ? args_info.format_arg : 0, args_info.skip_header_given ) ) { fprintf( stderr, "error: %s\n", ms.lastError() ); return 2; // exit } if( args_info.fdat_given ) { if( ! ms.incudeFile( args_info.fdat_arg ) ) { fprintf( stderr, "error: %s\n", ms.lastError() ); return 2; // exit } } if( args_info.date_from_given ) { if( !ms.setPrintDateFrom( args_info.date_from_arg ) ) { fprintf( stderr, "error: %s\n", ms.lastError() ); return 2; // exit } } if( args_info.exclude_older_than_given ) { if( !ms.excludeFiles( args_info.exclude_older_than_arg ) ) { fprintf( stderr, "error: %s\n", ms.lastError() ); return 2; // exit } } bool dumpdata = true; if( args_info.dump_master_given ) { dumpdata = false; ms.dumpMaster(); } if( args_info.dump_emaster_given ) { dumpdata = false; ms.dumpEMaster(); } if( args_info.dump_xmaster_given ) { dumpdata = false; if( ms.hasXMaster() ) { ms.dumpXMaster(); } } if( args_info.symbols_given ) { dumpdata = false; if( ! ms.dumpSymbolInfo() ) { fprintf( stderr, "error: %s\n", ms.lastError() ); return 2; // exit } } if( dumpdata ) { if( ! ms.dumpData() ) { fprintf( stderr, "error: %s\n", ms.lastError() ); return 2; // exit } } return 0; }