// *************************************************************************** // bamtools_options.cpp (c) 2010 Derek Barnett, Erik Garrison // Marth Lab, Department of Biology, Boston College // --------------------------------------------------------------------------- // Last modified: 10 October 2011 // --------------------------------------------------------------------------- // Parses command line arguments and creates a help menu // --------------------------------------------------------------------------- // Modified from: // The Mosaik suite's command line parser class: COptions // (c) 2006 - 2009 Michael Str�mberg // Marth Lab, Department of Biology, Boston College // Re-licensed under MIT License with author's permission. // // * Modified slightly to fit BamTools, otherwise code is same. // * (BamTools namespace, added stdin/stdout) (DB) // *************************************************************************** #include "utils/bamtools_options.h" using namespace BamTools; #include #include #include #include #include using namespace std; string Options::m_programName; // the program name string Options::m_description; // the main description string Options::m_exampleArguments; // the example arguments vector Options::m_optionGroups; // stores the option groups map Options::m_optionsMap; // stores the options in a map const string Options::m_stdin = "stdin"; // string representation of stdin const string Options::m_stdout = "stdout"; // string representation of stdout // adds a simple option to the parser void Options::AddOption(const string& argument, const string& optionDescription, bool& foundArgument, OptionGroup* group) { Option o; o.Argument = argument; o.Description = optionDescription; o.StoreValue = false; group->Options.push_back(o); OptionValue ov; ov.pFoundArgument = &foundArgument; ov.StoreValue = false; m_optionsMap[argument] = ov; } // creates an option group OptionGroup* Options::CreateOptionGroup(const string& groupName) { OptionGroup og; og.Name = groupName; m_optionGroups.push_back(og); return &m_optionGroups[m_optionGroups.size() - 1]; } // displays the help menu void Options::DisplayHelp(void) { // initialize char argumentBuffer[ARGUMENT_LENGTH + 1]; ostringstream sb; char indentBuffer[MAX_LINE_LENGTH - DESC_LENGTH + 1]; memset(indentBuffer, ' ', MAX_LINE_LENGTH - DESC_LENGTH); indentBuffer[MAX_LINE_LENGTH - DESC_LENGTH] = 0; // display the menu printf("Description: %s.\n\n", m_description.c_str()); printf("Usage: "); printf("%s", m_programName.c_str()); printf(" %s\n\n", m_exampleArguments.c_str()); vector