// Hennig86ToNexus.cpp #if defined(_WIN32) || defined(_WIN64) // C4290 - the compiler ignores exception specifications #pragma warning(disable: 4290) #endif #include #include #include #include #include #include #include "Hennig86Reader.hpp" #include "NexusWriter.hpp" #include "SystemError.hpp" using namespace Cipres; using namespace Cipres::SequenceFormats; int main(int argc, char **argv) { try { std::ios_base::sync_with_stdio(false); if(argc > 3) throw std::invalid_argument("usage: hennig86-to-nexus [ inputname [ outputname ]]"); boost::scoped_ptr input_file; boost::scoped_ptr output_file; if(argc > 1) { if(std::memcmp(argv[1], "-", 2) != 0) { input_file.reset(new std::ifstream(argv[1])); if(!input_file->good()) { std::string message("can't open "); message.append(argv[1]); throw SystemError("main", message, errno); } } if(argc == 3 && std::memcmp(argv[2], "-", 2) != 0) { output_file.reset(new std::ofstream(argv[2])); if(!output_file->good()) { std::string message("can't open "); message.append(argv[2]); throw SystemError("main", message, errno); } } } std::istream &input = input_file ? *input_file : std::cin; std::ostream &output = output_file ? *output_file : std::cout; Hennig86Reader reader; NexusWriter writer; reader.Read(input, writer); writer.Write(output); return 0; } catch(const std::ios_base::failure &io_err) { std::cerr << "a std::ios_base::failure was thrown: " << io_err.what() << std::endl; return 1; } catch(const std::exception &err) { std::cerr << err.what() << std::endl; return 1; } catch(...) { std::cerr << "an unknown exception was thrown" << std::endl; return 1; } }