feisty meow concerns codebase
2.140
|
#include <command_line.h>
Public Member Functions | |
command_line (int argc, char *argv[]) | |
takes command line parameters in the form of "argc" and "argv". More... | |
command_line (const basis::astring &to_parse) | |
takes a string form of the command line. More... | |
virtual | ~command_line () |
DEFINE_CLASS_NAME ("command_line") | |
filesystem::filename | program_name () const |
Returns the program name found in the command line. More... | |
int | entries () const |
Returns the number of fields found on the command line. More... | |
const command_parameter & | get (int field) const |
Returns the parameter at the "field" specified. More... | |
bool | zap (int field) |
eats the entry at position "field". More... | |
bool | find (char option_character, int &index, bool case_sense=true) const |
Returns true if the "option_character" is found in the parameters. More... | |
bool | find (const basis::astring &option_string, int &index, bool case_sense=true) const |
Returns true if the "option_string" is found in the parameters. More... | |
bool | get_value (char option_character, basis::astring &value, bool case_sense=true) const |
retrieves the "value" found for the option flag specified. More... | |
bool | get_value (const basis::astring &option_string, basis::astring &value, bool case_sense=true) const |
retrieves the "value" found for the "option_string" specified. More... | |
basis::astring | gather (int &index) const |
coalesces parameters together until the next option flag. More... | |
basis::astring | text_form () const |
returns a string with all the information we have for the command line. More... | |
Static Public Member Functions | |
static void | separate_command_line (const basis::astring &cmd_line, basis::astring &app, basis::astring &parms) |
breaks apart a command line in "cmd_line" into "app" and "parms". More... | |
static structures::string_array | get_command_line () |
returns the command line passed to the program as a list of strings. More... | |
Definition at line 86 of file command_line.h.
application::command_line::command_line | ( | int | argc, |
char * | argv[] | ||
) |
takes command line parameters in the form of "argc" and "argv".
this is suitable for most C++ main programs. the first "argv" string (element zero) is ignored because it is assumed that it is the program name. that means that the array of command parameters here will be (argc - 1) in length, and that index zero of our array has the first "real" parameter that was passed to the program (i.e., not it's name). note that the unaltered command parameters of argc and argv become available in the global variables _global_argc and _global_argv.
Definition at line 90 of file command_line.cpp.
application::command_line::command_line | ( | const basis::astring & | to_parse | ) |
takes a string form of the command line.
this is the form rendered by GetCommandLine() in Win32. on certain win32 platforms, this may not return a full path for the program_name() method. this uses the separate_command_line() method to pick out the relevant pieces and supports embedded, escaped quotes.
Definition at line 106 of file command_line.cpp.
References basis::astring::get(), basis::astring::length(), basis::astring::t(), and basis::array< contents >::zap().
|
virtual |
Definition at line 156 of file command_line.cpp.
References basis::WHACK().
application::command_line::DEFINE_CLASS_NAME | ( | "command_line" | ) |
int application::command_line::entries | ( | ) | const |
Returns the number of fields found on the command line.
This does not include the program name found; that's only accessible through the program_name() method.
Definition at line 162 of file command_line.cpp.
Referenced by find(), gather(), get(), get_value(), main(), text_form(), and zap().
bool application::command_line::find | ( | char | option_character, |
int & | index, | ||
bool | case_sense = true |
||
) | const |
Returns true if the "option_character" is found in the parameters.
The search starts at the "index" specified, and if the item is found, its location is returned in "index" and the function returns true. Otherwise false is returned and the "index" is not modified.
Definition at line 321 of file command_line.cpp.
References application::command_parameter::CHAR_FLAG, entries(), get(), basis::astring::iequals(), application::command_parameter::text(), basis::astring::to_lower(), and application::command_parameter::type().
Referenced by get_value(), and main().
bool application::command_line::find | ( | const basis::astring & | option_string, |
int & | index, | ||
bool | case_sense = true |
||
) | const |
Returns true if the "option_string" is found in the parameters.
Definition at line 341 of file command_line.cpp.
References entries(), FUNCDEF, get(), basis::astring::iequals(), basis::astring::length(), LOG, application::command_parameter::STRING_FLAG, application::command_parameter::text(), and application::command_parameter::type().
astring application::command_line::gather | ( | int & | index | ) | const |
coalesces parameters together until the next option flag.
Returns a string constructed from the concatenation of the strings for the parameters at all indices in the list starting at "index" until an option character is found. Note that this means an empty string will be returned if the parameter at "index" has an option character, or if "index" is greater than or equal to "elements()". After gather, "index" is set to the last location included in the string. "index" is set to the last index in the list if "index" was past the end to begin with or if strings are gathered up to the last index. otherwise, "index" is unchanged if nothing was gathered.
Definition at line 472 of file command_line.cpp.
References application::command_parameter::CHAR_FLAG, entries(), get(), application::command_parameter::text(), and application::command_parameter::type().
const command_parameter & application::command_line::get | ( | int | field | ) | const |
Returns the parameter at the "field" specified.
The "field" ranges from zero through "entries() - 1" inclusive. if an invalid index is used, then the type will be BOGUS_ITEM.
Definition at line 166 of file command_line.cpp.
References bounds_return, and entries().
Referenced by find(), gather(), get_value(), main(), and text_form().
|
static |
returns the command line passed to the program as a list of strings.
the string at index zero is the program name. this is just a useful helper function and is not normally needed by users of the command_line object.
Definition at line 230 of file command_line.cpp.
References application::_global_argc, application::_global_argv, COMPLAIN_CMDS, basis::astring::find(), FUNCDEF, basis::astring::length(), basis::non_negative(), and basis::astring::substring().
bool application::command_line::get_value | ( | char | option_character, |
basis::astring & | value, | ||
bool | case_sense = true |
||
) | const |
retrieves the "value" found for the option flag specified.
this is useful for command lines with standard spacing. for example, if the command line is "-Q query.bop --Linkage plorgs.txt", then this function would return "query.bop" for a search on 'Q' and the find() method below would return "plorgs.txt" for the string flag search on "Linkage".
Definition at line 362 of file command_line.cpp.
References entries(), find(), FUNCDEF, get(), application::command_parameter::text(), application::command_parameter::type(), and application::command_parameter::VALUE.
bool application::command_line::get_value | ( | const basis::astring & | option_string, |
basis::astring & | value, | ||
bool | case_sense = true |
||
) | const |
retrieves the "value" found for the "option_string" specified.
Definition at line 383 of file command_line.cpp.
References entries(), find(), FUNCDEF, get(), basis::astring::length(), LOG, application::command_parameter::text(), application::command_parameter::type(), and application::command_parameter::VALUE.
filename application::command_line::program_name | ( | ) | const |
Returns the program name found in the command line.
Definition at line 164 of file command_line.cpp.
Referenced by main().
|
static |
breaks apart a command line in "cmd_line" into "app" and "parms".
when given a full command line, where the application to run is the first chunk and its parameters (if any) are subsequent chunks, this will store the application name in "app" and the rest of the parameters in "parms". this expects any paths in the "cmd_line" that contain spaces to be surrounded by quotes. if there are any quote characters that are escaped, they are considered to be embedded in the parameter string; they will not be considered as matching any pending closing quotes.
Definition at line 172 of file command_line.cpp.
References basis::astring::end(), basis::astring::find(), basis::astring::length(), basis::negative(), and basis::astring::substring().
astring application::command_line::text_form | ( | ) | const |
returns a string with all the information we have for the command line.
Definition at line 298 of file command_line.cpp.
References application::command_parameter::CHAR_FLAG, entries(), get(), application::command_parameter::STRING_FLAG, application::command_parameter::text(), application::command_parameter::type(), and application::command_parameter::VALUE.
bool application::command_line::zap | ( | int | field | ) |
eats the entry at position "field".
this is useful for cleaning out entries that have already been dealt with.
Definition at line 217 of file command_line.cpp.
References bounds_return, and entries().