#ifndef CMDLINE_H #define CMDLINE_H /////////////////////////////////////////////////////////////// // cmdline.h - extract arguments and commands from the // // ver 1.0 executive module's command line // // // // Language: Visual C++, ver 6.0 // // Platform: Micron Dual Pentium Pro 200, Win NT 4.0 // // Application: CSE784 Project #1, Fall 1999 // // Author: Jim Fawcett, CST 2-187, Syracuse Univ. // // (315) 443-3948, fawcett@ecs.syr.edu // /////////////////////////////////////////////////////////////// /* Module Operations ================= The commandLine class helps to manage the extraction of commands and arguments from a program's command line. The most important operation of the class, implemented in its constructor, is to group the arguments into module names. That is, all files with the same name are ordered together. If two or more files have the same name a commandLine object assumes they belong to the same module. Arguments are grouped with multi-file modules first and orphan files (those with no matching partners) last. Public Interface: ================= commandLine cl(int argc, char *argv[]); // construct object int nargs = size(); // number of args string arg = nextArg(); // get next arg resetArgs(); // restart arg counting if(isNewModule()) ... // arg start new module? if(isCommand("s") ... // received this command? if(argc == 1) usage(); // show usage message usage("..."); // store usage message even(int i); // is i an even number? odd (int i); // is i an odd number? */ // /////////////////////////////////////////////////////////////// // build process // /////////////////////////////////////////////////////////////// // Required Files: // // cmdline.h, cmdline.cpp // // Compile Command: // // cl -GX -DTEST_CMDLINE cmdline.cpp // /////////////////////////////////////////////////////////////// /* Maintenance History =================== ver 1.0 : 05 Dec 99 - first release */ #pragma warning(disable : 4786) #include #include #include class commandLine { public: commandLine(int argc, char *argv[]); int size(); std::string nextArg(); void resetArgs(); bool isNewModule(); bool isCommand(const std::string &s) const; void usage(const std::string &s); std::string usage(); bool even(int i); bool odd (int i); private: std::vector orderedArgs; std::set cmds; std::vector::iterator next; std::string usageMsg; std::string name(std::string name); std::string makeLower(const char *s); std::string makeLower(const std::string &s); }; inline int commandLine::size() { return orderedArgs.size(); } inline bool commandLine::even(int i) { return (i%2 == 0); } inline bool commandLine::odd(int i) { return !even(i); } #endif