📄 cmdl_05.cc
字号:
// file: $isip/class/shell/CommandLine/cmdl_05.cc// version: $Id: cmdl_05.cc,v 1.8 2002/10/03 19:21:42 huang Exp $//// isip include files// #include "CommandLine.h" // method: addOptionParam//// arguments:// void* var: (input) void variable// const String& name: (input) class name// const String& param: (input) parameter//// return: a boolean value indicating status//// this method checks whether the option is unique and adds the input// option to the internal lists//boolean CommandLine::addOptionParam(void* var_a, const String& name_a, const String& param_a) { // make sure this option isn't the Sdb list option // if ((sdb_d != (Sdb*)NULL) && param_a.eq(Sdb::LIST_FILE_OPTION)) { Console::put(L"this parameter is reserved by Sdb\n"); param_a.debug(L"this parameter"); name_a.debug(L"this parameter"); return Error::handle(name(), L"addOptionParam", ERR_OPTMULT, __FILE__, __LINE__); } // make sure the option is unique // if (options_d.first(param_a) >= 0) { param_a.debug(L"this parameter"); name_a.debug(L"this class name"); return Error::handle(name(), L"addOptionParam", ERR_OPTMULT, __FILE__, __LINE__); } // check the size of objects_d[], // if ((options_d.length() + 1) >= objects_size_d) { mgr_d.reallocateBlock((void***)&objects_d, objects_size_d); } // add this option to the internal lists // objects_d[options_d.length()] = var_a; options_d.concat(param_a); types_d.concat(name_a); Boolean use(false); used_d.concat(use); // exit gracefully // return true;}// method: getOptionIndex//// arguments:// const String& pname: (input) input string//// return: a long value containing the index of string//// this function does partial match, gives error in case of ambiguous// or duplicate options on command line. in case of no such errors it// returns the index of the string.//long CommandLine::getOptionIndex(const String& pname_a) { // declare a string // String match; // this is a class error, not a user error // if (pname_a.firstStr(DEF_PARAM_PREFIX) != 0) { return Error::handle(name(), L"getOptionIndex", Error::ARG, __FILE__, __LINE__); } // remove the prefix from the token to get the match string // pname_a.substr(match, DEF_PARAM_PREFIX.length(), pname_a.length() - DEF_PARAM_PREFIX.length()); // if we are using Sdb, test for the LIST option // if (sdb_d != (Sdb*)NULL) { if (match.eq(Sdb::LIST_FILE_OPTION)) { return OPT_INDEX_SDB; } } // declare and initialize initial variables // long num_found = 0; boolean exact_found = false; long index = Integral::NO_POS; String mult_matches; // loop over all the commandline options // for (long i = 0; i < options_d.length(); i++) { if (options_d(i).eq(match)) { // has there already been an exact match? // if (exact_found) { printUsage(); Error::handle(name(), L"getOptionIndex", ERR_OPTDUPL, __FILE__, __LINE__, Error::WARNING); return Integral::NO_POS; } exact_found = true; num_found = 1; index = i; } // the substring matches the start of the string // if ((!exact_found) && (options_d(i).firstStr(match) == 0)) { // has there already been a match? // if (num_found > 0) { if (mult_matches.length() == 0) { mult_matches.assign(L"option name /"); mult_matches.concat(match); mult_matches.concat(L".*/ matches ("); mult_matches.concat(options_d(index)); } mult_matches.concat(L", "); mult_matches.concat(options_d(i)); } num_found++; index = i; } } // has there already been a match? // if (num_found > 1) { mult_matches.concat(L")"); Console::put(mult_matches); printUsage(); Error::handle(name(), L"getOptionIndex", ERR_OPTAMB, __FILE__, __LINE__, Error::WARNING); return Integral::NO_POS; } // if the option is found, mark it as used // if (index >= 0) { if (used_d(index) && (!isMultipleParam(index))) { printUsage(); Error::handle(name(), L"getOptionIndex", ERR_OPTDUPL, __FILE__, __LINE__, Error::WARNING); } used_d(index).assign(true); } // return the index // return index;} // method: getArgument//// arguments:// String& arg: (output) string// long ordinal_number: (input) ordinal number//// return: a boolean value indicating status//// this method gives the unused arguments after all good parameters// have been passed//boolean CommandLine::getArgument(String& arg_a, long ordinal_number_a) const { // loop through all the unused parameters // for (long i = 0; i < args_d.length(); i++) { // check the indices of args_d // if (i == ordinal_number_a) { return arg_a.assign(args_d(i)); } } // exit ungracefully // return false;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -