FS2_Open
Open source remastering of the Freespace 2 engine
|
Parsing functions for the command line. Previously known as the command line scanner. More...
Go to the source code of this file.
Classes | |
class | errParse |
Class thrown when a required token is not found. More... | |
class | errParseString |
Class thrown when an expected string was not found. Can/should contain all of the expected strings. More... | |
class | errParseOverflow |
Class thrown when the parsed string or token could not be stuffed into the smaller destination container. More... | |
Macros | |
#define | MAX_CLI_LEN 512 |
#define | MAX_TOKEN_LENGTH 255 |
Enumerations | |
enum | dc_token { DCT_NONE = 0, DCT_STRING, DCT_FLOAT, DCT_INT, DCT_UINT, DCT_BYTE, DCT_UBYTE, DCT_BOOL, DCT_MAX_ITEMS } |
Functions | |
void | dc_parse_init (SCP_string &str) |
Initializes the DC command line parser. More... | |
void | dc_ignore_white_space (void) |
Advances the parser past whitespace characters. More... | |
void | dc_ignore_gray_space (void) |
Advances the parser past grayspace characters. More... | |
void | dc_required_string (char *pstr) |
Searches for a specified required string, throwing an errParse if not found. More... | |
int | dc_required_string_either (char *str1, char *str2) |
Searchs for either of the specified required strings, throwing an errParse if neither are found. More... | |
uint | dc_required_string_any (const uint n,...) |
Searches for specified required strings. More... | |
bool | dc_optional_string (const char *pstr) |
Searches for an optional string. More... | |
bool | dc_optional_string_either (const char *str1, const char *str2) |
Searches for an optional string and it's alias. More... | |
void | dc_stuff_float (float *f) |
Stuffs a float to the given variable. More... | |
void | dc_stuff_int (int *i) |
Stuffs an int to the given variable. Supports binary (0b), hexadecimal (0x), and octal (0o) formats. More... | |
void | dc_stuff_uint (uint *i) |
Stuffs an unsigned int to the given variable. Supports binary (0b), hexadecimal (0x), and octal (0o) formats. More... | |
void | dc_stuff_ubyte (ubyte *i) |
Stuffs an unsigned byte to the given variable. Supports binary (0b), hexadecimal (0x), and octal (0o) formats. More... | |
void | dc_stuff_boolean (bool *b) |
stuffs a boolean evaluated integer or string into the given variable. More... | |
void | dc_stuff_boolean (int *i) |
stuffs a boolean evaluated integer or string into the given variable. More... | |
void | dc_stuff_string (char *str, size_t maxlen) |
Stuffs a string to out_str from the command line, stopping at the end of the command line. More... | |
void | dc_stuff_string (SCP_string &str) |
Stuffs a string to out_str from the command line, stopping at the end of the command line. More... | |
void | dc_stuff_string_white (char *str, size_t len) |
Stuffs a whitespace delimited string to out_str from the command line, stopping at the end of the command line. More... | |
void | dc_stuff_string_white (SCP_string &str) |
Stuffs a whitespace delimited string to out_str from the command line, stopping at the end of the command line. More... | |
bool | dc_maybe_stuff_float (float *f) |
Tries to stuff a float from the Command_string. More... | |
bool | dc_maybe_stuff_int (int *i) |
Tries to stuff an int from the Command_string. More... | |
bool | dc_maybe_stuff_uint (uint *i) |
Tries to stuff an uint from the Command_string. More... | |
bool | dc_maybe_stuff_ubyte (ubyte *i) |
Tries to stuff an ubyte from the Command_string. More... | |
bool | dc_maybe_stuff_boolean (bool *b) |
Tries to stuff a bool from the Command_string. More... | |
bool | dc_maybe_stuff_boolean (int *i) |
Tries to stuff an int with a bool value from the Command_string. More... | |
bool | dc_maybe_stuff_string (char *str, size_t len) |
Tries to stuff a string to out_str from the command line, stopping at the end of the command line. More... | |
bool | dc_maybe_stuff_string (SCP_string &str) |
Tries to stuff a string to out_str from the command line, stopping at the end of the command line. More... | |
bool | dc_maybe_stuff_string_white (char *str, size_t len) |
Tries to stuff a whitespace delimited string to out_str from the command line, stopping at the end of the command line. More... | |
bool | dc_maybe_stuff_string_white (SCP_string &str) |
Tries to stuff a whitespace delimited string to out_str from the command line, stopping at the end of the command line. More... | |
Parsing functions for the command line. Previously known as the command line scanner.
A lot of functions here are blatently copied from parselo.h :D
Definition in file consoleparse.h.
#define MAX_CLI_LEN 512 |
Definition at line 22 of file consoleparse.h.
#define MAX_TOKEN_LENGTH 255 |
Definition at line 23 of file consoleparse.h.
enum dc_token |
Definition at line 25 of file consoleparse.h.
Advances the parser past grayspace characters.
Definition at line 273 of file consoleparse.cpp.
Advances the parser past whitespace characters.
Definition at line 267 of file consoleparse.cpp.
bool dc_maybe_stuff_boolean | ( | bool * | b | ) |
Tries to stuff a bool from the Command_string.
[in] | b | The bool variable to maybe stuff. |
If there's nothing on the command line, *b = false and false is returned
If there's something on the command line, and we're able to convert it, *b = the converted value, true is returned, and the parser is advanced past the token
If there's something on command line, but we can't convert it, an errParse is thrown
Definition at line 332 of file consoleparse.cpp.
bool dc_maybe_stuff_boolean | ( | int * | i | ) |
Tries to stuff an int with a bool value from the Command_string.
[in] | i | The int variable to maybe stuff. |
If there's nothing on the command line, *i = 0 and false is returned
If there's something on the command line, and we're able to convert it, *i = the converted value, true is returned, and the parser is advanced past the token
If there's something on command line, but we can't convert it, an errParse is thrown
Definition at line 345 of file consoleparse.cpp.
bool dc_maybe_stuff_float | ( | float * | f | ) |
Tries to stuff a float from the Command_string.
[in] | f | The float variable to maybe stuff. |
If there's nothing on the command line, *f = 0 and false is returned
If there's something on the command line, and we're able to convert it, *f = the converted value, true is returned, and the parser is advanced past the token
If there's something on command line, but we can't convert it, an errParse is thrown
Definition at line 279 of file consoleparse.cpp.
bool dc_maybe_stuff_int | ( | int * | i | ) |
Tries to stuff an int from the Command_string.
[in] | i | The int variable to maybe stuff. |
If there's nothing on the command line, *i = 0 and false is returned
If there's something on the command line, and we're able to convert it, *i = the converted value, true is returned, and the parser is advanced past the token
If there's something on command line, but we can't convert it, an errParse is thrown
Definition at line 293 of file consoleparse.cpp.
bool dc_maybe_stuff_string | ( | char * | str, |
size_t | len | ||
) |
Tries to stuff a string to out_str from the command line, stopping at the end of the command line.
[out] | str | Destination string. If nothing was found, str = "" |
[in] | len | Maximum length to copy. (len <= sizeof(str)) && (len <= MAX_TOKEN_LENGTH) |
true | if the operation was successful, |
false | otherwise |
errParseOverflow | when parser cannot stuff the entirety of the found string into out_str |
Definition at line 358 of file consoleparse.cpp.
bool dc_maybe_stuff_string | ( | SCP_string & | str | ) |
Tries to stuff a string to out_str from the command line, stopping at the end of the command line.
[out] | str | Destination string. If nothing was found, str = "" |
true | if the operation was successful, |
false | otherwise |
Definition at line 396 of file consoleparse.cpp.
bool dc_maybe_stuff_string_white | ( | char * | str, |
size_t | len | ||
) |
Tries to stuff a whitespace delimited string to out_str from the command line, stopping at the end of the command line.
[out] | str | Destination string. If nothing was found, str = "" |
[in] | len | Maximum length to copy. (maxlen <= sizeof(str)) && (maxlen <= MAX_TOKEN_LENGTH) |
true | if the operation was successful, |
false | otherwise |
errParseOverflow | when parser cannot stuff the entirety of the found string into out_str |
Definition at line 433 of file consoleparse.cpp.
bool dc_maybe_stuff_string_white | ( | SCP_string & | str | ) |
Tries to stuff a whitespace delimited string to out_str from the command line, stopping at the end of the command line.
[out] | str | Destination string. If nothing was found, str = "" |
true | if the operation was successful, |
false | otherwise |
Definition at line 446 of file consoleparse.cpp.
bool dc_maybe_stuff_ubyte | ( | ubyte * | i | ) |
Tries to stuff an ubyte from the Command_string.
[in] | i | The ubyte variable to maybe stuff. |
If there's nothing on the command line, *i = 0 and false is returned
If there's something on the command line, and we're able to convert it, *i = the converted value, true is returned, and the parser is advanced past the token
If there's something on command line, but we can't convert it, an errParse is thrown
Definition at line 319 of file consoleparse.cpp.
bool dc_maybe_stuff_uint | ( | uint * | i | ) |
Tries to stuff an uint from the Command_string.
[in] | i | The uint variable to maybe stuff. |
If there's nothing on the command line, *i = 0 and false is returned
If there's something on the command line, and we're able to convert it, *i = the converted value, true is returned, and the parser is advanced past the token
If there's something on command line, but we can't convert it, an errParse is thrown
Definition at line 306 of file consoleparse.cpp.
bool dc_optional_string | ( | const char * | pstr | ) |
Searches for an optional string.
[in] | pstr | The char[] to look for |
true | if the string was found, |
false | otherwise |
Definition at line 558 of file consoleparse.cpp.
bool dc_optional_string_either | ( | const char * | str1, |
const char * | str2 | ||
) |
Searches for an optional string and it's alias.
[in] | str1 | The char[] to look for |
[in] | str2 | The alternative char[] to look for |
true | if the string was found, |
false | otherwise |
Definition at line 574 of file consoleparse.cpp.
void dc_parse_init | ( | SCP_string & | str | ) |
Initializes the DC command line parser.
Definition at line 596 of file consoleparse.cpp.
void dc_required_string | ( | char * | pstr | ) |
Searches for a specified required string, throwing an errParse if not found.
[in] | pstr | The string to search for |
errParseString | with the required string |
Definition at line 459 of file consoleparse.cpp.
Searches for specified required strings.
[in] | n | The number of char[] or c_str's given |
[in] | ... | A comma delimited list of one or more required strings. |
errParseString | with the required strings |
Definition at line 516 of file consoleparse.cpp.
int dc_required_string_either | ( | char * | str1, |
char * | str2 | ||
) |
Searchs for either of the specified required strings, throwing an errParse if neither are found.
[in] | str1 | The first string to search for |
[in] | str2 | The second string to search for |
0 | if str1 was found, or |
1 | if str2 was found |
errParseString | with the required strings |
Definition at line 484 of file consoleparse.cpp.
void dc_stuff_boolean | ( | bool * | b | ) |
stuffs a boolean evaluated integer or string into the given variable.
[in] | b | The bool variable to stuff to |
Supports a number of literal strings as true and false, including "true", "false", "yes", "no" and the yes/no equivalents in other languages supported in localization. TODO: Make a static string map to handle this instead of being hard-coded
errParse | if an unexpected or otherwise malformed float string is found. |
errParse | if nothing was found |
Definition at line 1130 of file consoleparse.cpp.
stuffs a boolean evaluated integer or string into the given variable.
[in] | i | The int variable to stuff to. 0 is false, 1 is true |
Supports a number of literal strings as true and false, including "true", "false", "yes", "no" and the yes/no equivalents in other languages supported in localization. TODO: Make a static string map to handle this instead of being hard-coded
errParse | if an unexpected or otherwise malformed float string is found. |
errParse | if nothing was found |
Definition at line 1163 of file consoleparse.cpp.
Stuffs a float to the given variable.
[in] | f | The float variable to stuff to |
errParse | if an unexpected or otherwise malformed float string is found. |
errParse | if nothing was found |
Definition at line 1057 of file consoleparse.cpp.
Stuffs an int to the given variable. Supports binary (0b), hexadecimal (0x), and octal (0o) formats.
[in] | i | The int variable to stuff to |
The binary, hexadecimal, and octal formats must be prefixed by their associated string. Ex: "0xDEADBEEF" would be parsed properly while "DEADBEEF" would throw an error
errParse | if an unexpected or otherwise malformed float string is found. |
errParse | if nothing was found |
Definition at line 1075 of file consoleparse.cpp.
void dc_stuff_string | ( | char * | str, |
size_t | maxlen | ||
) |
Stuffs a string to out_str from the command line, stopping at the end of the command line.
[out] | str | Destination string |
[in] | maxlen | Maximum length to copy. (maxlen <= sizeof(str)) && (maxlen <= MAX_TOKEN_LENGTH) |
errParse | when nothing left was found on the command line |
errParseOverflow | when parser cannot stuff the entirety of the found string into out_str |
Definition at line 1172 of file consoleparse.cpp.
void dc_stuff_string | ( | SCP_string & | str | ) |
Stuffs a string to out_str from the command line, stopping at the end of the command line.
[out] | str | Destination string |
errParse | when nothing left was found on the command line |
Definition at line 1208 of file consoleparse.cpp.
void dc_stuff_string_white | ( | char * | str, |
size_t | len | ||
) |
Stuffs a whitespace delimited string to out_str from the command line, stopping at the end of the command line.
[out] | str | Destination string |
[in] | len | Maximum length to copy. (len <= sizeof(str)) && (len <= MAX_TOKEN_LENGTH) |
errParse | when nothing left was found on the command line |
errParseOverflow | when parser cannot stuff the entirety of the found string into out_str |
Definition at line 1241 of file consoleparse.cpp.
void dc_stuff_string_white | ( | SCP_string & | str | ) |
Stuffs a whitespace delimited string to out_str from the command line, stopping at the end of the command line.
[out] | str | Destination string |
errParse | when nothing left was found on the command line |
Definition at line 1275 of file consoleparse.cpp.
Stuffs an unsigned byte to the given variable. Supports binary (0b), hexadecimal (0x), and octal (0o) formats.
[in] | i | The ubyte variable to stuff to |
The binary, hexadecimal, and octal formats must be prefixed by their associated string. Ex: "0x0F" would be parsed properly while "0F" would throw an error
errParse | if an unexpected or otherwise malformed float string is found. |
errParse | if nothing was found |
Definition at line 1111 of file consoleparse.cpp.
Stuffs an unsigned int to the given variable. Supports binary (0b), hexadecimal (0x), and octal (0o) formats.
[in] | i | The unsigned int variable to stuff to |
The binary, hexadecimal, and octal formats must be prefixed by their associated string. Ex: "0xDEADBEEF" would be parsed properly while "DEADBEEF" would throw an error
errParse | if an unexpected or otherwise malformed float string is found. |
errParse | if nothing was found |
Definition at line 1093 of file consoleparse.cpp.