#include <command_line.h>

Public Member Functions | |
| command_line (int argc, char *argv[]) | |
| takes command line parameters in the form of "argc" and "argv". | |
| command_line (const istring &to_parse) | |
| takes a string form of the command line. | |
| virtual | ~command_line () |
| IMPLEMENT_CLASS_NAME ("command_line") | |
| filename | program_name () const |
| Returns the program name found in the command line. | |
| int | entries () const |
| Returns the number of fields found on the command line. | |
| const command_parameter & | get (int field) const |
| Returns the parameter at the "field" specified. | |
| bool | zap (int field) |
| eats the entry at position "field". | |
| bool | find (char option_character, int &index, bool case_sense=true) const |
| Returns true if the "option_character" is found in the parameters. | |
| bool | find (const istring &option_string, int &index, bool case_sense=true) const |
| Returns true if the "option_string" is found in the parameters. | |
| bool | get_value (char option_character, istring &value, bool case_sense=true) const |
| retrieves the "value" found for the option flag specified. | |
| bool | get_value (const istring &option_string, istring &value, bool case_sense=true) const |
| retrieves the "value" found for the "option_string" specified. | |
| istring | gather (int &index) const |
| coalesces parameters together until the next option flag. | |
| istring | text_form () const |
| returns a string with all the information we have for the command line. | |
Static Public Member Functions | |
| static void | separate_command_line (const istring &cmd_line, istring &app, istring &parms) |
| breaks apart a command line in "cmd_line" into "app" and "parms". | |
| static string_array | get_command_line () |
| returns the command line passed to the program as a list of strings. | |
Definition at line 86 of file command_line.h.
| 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 is tossed because it is assumed that it is the program name. these are available in the global variables __argc and __argv (see basis/portable).
Definition at line 92 of file command_line.cpp.
| command_line::command_line | ( | const istring & | 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 108 of file command_line.cpp.
References directory::absolute_path(), istring::get(), istring::length(), istring::t(), parser_bits::white_space(), and array< contents >::zap().
| command_line::~command_line | ( | ) | [virtual] |
| command_line::IMPLEMENT_CLASS_NAME | ( | "command_line" | ) |
| filename command_line::program_name | ( | ) | const |
Returns the program name found in the command line.
Definition at line 165 of file command_line.cpp.
Referenced by service_root::instruct(), and main().
| void command_line::separate_command_line | ( | const istring & | cmd_line, | |
| istring & | app, | |||
| istring & | parms | |||
| ) | [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 173 of file command_line.cpp.
References istring::end(), istring::find(), istring::length(), negative(), and istring::substring().
| int 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 163 of file command_line.cpp.
Referenced by find(), gather(), get(), get_value(), service_root::initialize(), main(), text_form(), and zap().
| const command_parameter & 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 167 of file command_line.cpp.
References bounds_return, and entries().
Referenced by service_root::initialize(), and main().
| bool 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 218 of file command_line.cpp.
References bounds_return, and entries().
| bool 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 323 of file command_line.cpp.
References command_parameter::CHAR_FLAG, entries(), and istring::to_lower().
Referenced by get_value(), service_root::initialize(), and main().
| bool command_line::find | ( | const istring & | option_string, | |
| int & | index, | |||
| bool | case_sense = true | |||
| ) | const |
Returns true if the "option_string" is found in the parameters.
Definition at line 343 of file command_line.cpp.
References entries(), FUNCDEF, istring::length(), LOG, and command_parameter::STRING_FLAG.
| bool command_line::get_value | ( | char | option_character, | |
| istring & | 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 364 of file command_line.cpp.
References entries(), find(), command_parameter::text(), command_parameter::type(), and command_parameter::VALUE.
Referenced by main().
| bool command_line::get_value | ( | const istring & | option_string, | |
| istring & | value, | |||
| bool | case_sense = true | |||
| ) | const |
retrieves the "value" found for the "option_string" specified.
Definition at line 384 of file command_line.cpp.
References entries(), find(), FUNCDEF, istring::length(), LOG, command_parameter::text(), command_parameter::type(), and command_parameter::VALUE.
| istring 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 469 of file command_line.cpp.
References command_parameter::CHAR_FLAG, and entries().
| istring command_line::text_form | ( | ) | const |
returns a string with all the information we have for the command line.
Definition at line 300 of file command_line.cpp.
References command_parameter::CHAR_FLAG, entries(), log_base::platform_ending(), command_parameter::STRING_FLAG, command_parameter::text(), command_parameter::type(), and command_parameter::VALUE.
| string_array command_line::get_command_line | ( | ) | [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 231 of file command_line.cpp.
References __argc, __argv, COMPLAIN_CMDS, istring::find(), FUNCDEF, portable::get_cmdline_from_proc(), istring::length(), non_negative(), and istring::substring().
1.5.6