//============================================================================= // drt/sys/scmdpars.cpp // Command line option argument parsing classes. // These classes provide a simple command line argument parsing capability // so that the program can parse its command line arguments easily. // // History // 0.01, 1998-10-24, David R Tribble. // First cut. // // 0.02, 1999-02-26, David R Tribble. // Moved to drt/sys/. // // Copyright ©1998-1999, by David R. Tribble, all rights reserved. // See "drt/sys/copyr.txt" for more information. //----------------------------------------------------------------------------- // Identification static const char id[] = "@(#)drt/sys/scmdpars.cpp 0.02"; // Special includes #include "sdefs.h" // System includes #include #define drt_std_assert_h 1 // Local includes #include "scmdargs.h" #include "sdebug.h" // Local wrappers drt_namespace_begin //----------------------------------------------------------------------------- // Shared class constants //----------------------------------------------------------------------------- #if DrtCmdParser_VS/100 != 1 #error DrtCmdParser_VS has changed #endif /*static*/ const int DrtCmdParser::VS = DrtCmdParser_VS; // Class version /*static*/ const unsigned int DrtCmdParser::MAGIC = 0xD2D0____; // Class magic number //----------------------------------------------------------------------------- // Shared class variables //----------------------------------------------------------------------------- #if DrtCmdParser_VS/100 != 1 #error DrtCmdParser_VS has changed #endif /*static*/ DrtTraceGroup DrtCmdParser::s_grp("DrtCmdParser", __FILE__, __DATE__, __TIME__); //----------------------------------------------------------------------------- // DrtCmdParser::~DrtCmdParser() // Destructor. //----------------------------------------------------------------------------- /*void*/ DrtCmdParser::~DrtCmdParser() { #if DrtCmdParser_VS != 100 #error DrtCmdParser_VS has changed #endif DrtTrace dbg(s_grp, "~DrtCmdParser", this); // Validate this object validate(); // De-initialize the members ... } //----------------------------------------------------------------------------- // DrtCmdParser::DrtCmdParser() // Constructor. //----------------------------------------------------------------------------- /*DrtCmdParser*/ DrtCmdParser::DrtCmdParser(const DrtCmdOptDef *opts, int argc, const char *const *argv): DrtMagic(MAGIC, VS), m_argv(static_cast(const void *const *, argv)), m_argc(argc), m_opts(null), m_optc(0), m_flags(F_DFL), m_state(ST_INIT) { #if DrtCmdParser_VS != 100 #error DrtCmdParser_VS has changed #endif DrtTrace dbg(s_grp, "DrtCmdParser", this); // Initialize the members ... } //----------------------------------------------------------------------------- // DrtCmdParser::DrtCmdParser() // Constructor. //----------------------------------------------------------------------------- /*DrtCmdParser*/ DrtCmdParser::DrtCmdParser(const DrtCmdOptDef *opts, int argc, const wchar_t *const *argv): DrtMagic(MAGIC, VS), m_argv(static_cast(const void *const *, argv)), m_argc(argc), m_opts(null), m_optc(0), m_flags(F_WCHAR), m_state(ST_INIT) { #if DrtCmdParser_VS != 100 #error DrtCmdParser_VS has changed #endif DrtTrace dbg(s_grp, "DrtCmdParser", this); // Initialize the members ... } //----------------------------------------------------------------------------- // DrtCmdParser::validate() // Validate this object. // // Notes // Fails an assert() if this object is invalid. //----------------------------------------------------------------------------- void DrtCmdParser::validate() const { #if DrtCmdParser_VS/100 != 1 #error DrtCmdParser_VS has changed #endif //DrtTrace dbg(s_grp, "validate", this); // Validate this object assert(("DrtCmdParser", this != null)); // Check for null assert(DrtCmdParser::m_magic == MAGIC); // Check magic number assert(DrtCmdParser::m_vs/100 == VS/100); // Check version number // Note: Do not validate the base portion of this object: //DrtMagic::validate(); } //----------------------------------------------------------------------------- // DrtCmdParser::dump() // Dump the contents of this object to the debugging trace output. //----------------------------------------------------------------------------- void DrtCmdParser::dump() const { #if DrtCmdParser_VS != 100 #error DrtCmdParser_VS has changed #endif //DrtTrace dbg(s_grp, "dump", this); // Validate this object validate(); // Lock the debug output context DrtTrace::enterContext(); // Dump the contents of this object #if is_incomplete___ ... #else drt_std::printf("DrtCmdParser::dump() is incomplete\n"); #endif // Done DrtTrace::leaveContext(); } //----------------------------------------------------------------------------- // DrtCmdParser::hasMore() // Determines if this command line parser has more remaining command line // arguments to parse. // // Returns // True if there are command line arguments remaining, other false. // Returns false on error. //----------------------------------------------------------------------------- bool DrtCmdParser::hasMore() const { #if DrtCmdParser_VS/100 != 1 #error DrtCmdParser_VS has changed #endif DrtTrace dbg(s_grp, "hasMore", this); // Validate this object validate(); // Check the number of remaining command line args to be parsed return (m_optc < m_argc); } drt_namespace_end //============================================================================= //============================================================================= //============================================================================= #if TEST //----------------------------------------------------------------------------- // ::main() // Test driver. //----------------------------------------------------------------------------- int main(int argc, char **argv) { printf("Create an DrtCmdParser object...\n"); drt_namespace::DrtCmdParser parse(argc, argv); #error Incomplete return (0); } #endif // TEST // End scmdpars.cpp