/////////////////////////////////////////////////////////////// // cmdline.cpp - 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 // /////////////////////////////////////////////////////////////// #pragma warning(disable : 4786) #include #include #include "cmdline.h" using namespace std; //----< remove extension from a file name >-------------------- std::string commandLine::name(string name) { int pos = name.find("."); if(pos == name.size()) return name; name.resize(pos); return name; } //----< set usage message >------------------------------------ void commandLine::usage(const string &msg) { usageMsg = msg; } //----< extract usage message >-------------------------------- string commandLine::usage() { return usageMsg; } //----< is the current arg name that of a new module? >-------- bool commandLine::isNewModule() { if(next == orderedArgs.begin()) return true; if(next == orderedArgs.end()) return true; vector::iterator it = next; --it; if(name(*it) != name(*next)) return true; return false; } // //----< make C string lower case >----------------------------- string commandLine::makeLower(const char *s) { string temp; int len = strlen(s); int i; for(i=0; i----------------------------- string commandLine::makeLower(const string &s) { string temp; int len = s.size(); int i; for(i=0; i------ // // arg collection is order into modules and orphan files // commandLine::commandLine(int argc, char *argv[]) { set args, bachelors; int i; for(i=1; i pairs, singles; bool isPair; set::iterator it,nextItem,last; for(it=args.begin(); it!=args.end(); it++) { nextItem = it; ++nextItem; isPair = false; if(nextItem != args.end()) { if(name(*it) == name(*nextItem)) isPair = true; } if(!isPair && pairs.size() > 0) { last = --(pairs.end()); if(name(*it) == name(*last)) isPair = true; } if(isPair) pairs.insert(*it); else singles.insert(*it); } for(it=pairs.begin(); it!=pairs.end(); it++) orderedArgs.push_back(*it); for(it=singles.begin(); it!=singles.end(); it++) orderedArgs.push_back(*it); next = orderedArgs.begin(); } //----< is this string a command collected from cmdline? >----- bool commandLine::isCommand(const string &s) const { set::const_iterator it = cmds.find(s); if(it == cmds.end()) return false; return true; } // //----< extract the next command line argument >--------------- string commandLine::nextArg() { vector::iterator it = next++; if(it == orderedArgs.end()) { --next; return ""; } return (*it); } //----< get ready to extract cmdline args again >-------------- void commandLine::resetArgs() { next = orderedArgs.begin(); } //----< test stub >-------------------------------------------- #ifdef TEST_CMDLINE #include void main(int argc, char *argv[]) { cout << "\n testing cmdline module " << "\n ========================\n"; cout << "\n command line arguments are:" << "\n ----------------------------"; int i; for(i=1; i