FS2_Open
Open source remastering of the Freespace 2 engine
|
#include "debugconsole/consoleparse.h"
#include "parse/parselo.h"
#include <algorithm>
#include <cmath>
#include <cstdarg>
#include <cstring>
#include <limits.h>
Go to the source code of this file.
Enumerations | |
enum | state_int { si_start = 0, si_end = 1, si_invalid, si_sign, si_prefix, si_numeral, si_numeral_bin, si_numeral_octal, si_numeral_hex } |
enum | state_float { sf_start = 0, sf_end = 1, sf_invalid, sf_sign, sf_whole, sf_decimal, sf_fraction, sf_expprefix, sf_expsign, sf_exponent } |
Functions | |
bool | ch_is_sign (char ch) |
bool | ch_is_numeral (char ch) |
bool | ch_is_decimal (char ch) |
bool | ch_is_binary (char ch) |
bool | ch_is_octal (char ch) |
bool | ch_is_hex (char ch) |
bool | ch_is_prefix (char ch) |
bool | ch_is_binary_prefix (char ch) |
bool | ch_is_octal_prefix (char ch) |
bool | ch_is_hex_prefix (char ch) |
bool | ch_is_exp_prefix (char ch) |
void | dc_get_token (SCP_string &out_str) |
Returns/Advances past a single token. More... | |
void | dc_get_token_no_advance (SCP_string &out_str) |
Returns a single token, but does not advances Cp. More... | |
double | dc_parse_double (const char *ch, dc_token type) |
Parses a double-precision floating point type. Supports, Whole, Fractional, and Mixed numbers, and supports scientific notation (exponent prefixed by 'e' or 'E'). More... | |
long | dc_parse_long (const char *ch, dc_token type) |
Parses a long integral type. Supports decimal, binary, octal, and hexidecimal strings. More... | |
ulong | dc_parse_ulong (const char *ch, dc_token type) |
Parses an unsigned long integral type. Supports decimal, binary, octal, and hexidecimal strings. More... | |
state_float | dc_parse_double_sign (const char *&ch_ptr, SCP_string &buffer_str) |
state_float | dc_parse_double_whole (const char *&ch_ptr, SCP_string &buffer_str) |
state_float | dc_parse_double_decimal (const char *&ch_ptr, SCP_string &buffer_str) |
state_float | dc_parse_double_fraction (const char *&ch_ptr, SCP_string &buffer_str) |
state_float | dc_parse_double_expprefix (const char *&ch_ptr, SCP_string &buffer_str) |
state_float | dc_parse_double_expsign (const char *&ch_ptr, SCP_string &buffer_str) |
state_float | dc_parse_double_exponent (const char *&ch_ptr, SCP_string &buffer_str) |
state_int | dc_parse_long_prefix (const char *&ch_ptr, SCP_string &buffer_str, int &base) |
state_int | dc_parse_long_sign (const char *&ch_ptr, SCP_string &buffer_str) |
state_int | dc_parse_long_numeral (const char *&ch_ptr, SCP_string &buffer_str) |
state_int | dc_parse_long_numeral_bin (const char *&ch_ptr, SCP_string &buffer_str) |
state_int | dc_parse_long_numeral_hex (const char *&ch_ptr, SCP_string &buffer_str) |
state_int | dc_parse_long_numeral_octal (const char *&ch_ptr, SCP_string &buffer_str) |
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... | |
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 *out_str, size_t maxlen) |
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 &out_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... | |
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_parse_init (SCP_string &str) |
Initializes the DC command line parser. 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 *out_str, size_t maxlen=MAX_TOKEN_LENGTH) |
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 &out_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 *out_str, size_t maxlen) |
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 &out_str) |
Stuffs a whitespace delimited string to out_str from the command line, stopping at the end of the command line. More... | |
Variables | |
char | Command_string [MAX_CLI_LEN] |
Command string buffer. More... | |
char * | Cp = NULL |
Pointer to the commant string. More... | |
enum state_float |
Definition at line 42 of file consoleparse.cpp.
enum state_int |
Definition at line 30 of file consoleparse.cpp.
|
inline |
Definition at line 167 of file consoleparse.cpp.
|
inline |
Definition at line 191 of file consoleparse.cpp.
|
inline |
Definition at line 161 of file consoleparse.cpp.
|
inline |
Definition at line 209 of file consoleparse.cpp.
|
inline |
Definition at line 179 of file consoleparse.cpp.
|
inline |
Definition at line 203 of file consoleparse.cpp.
|
inline |
Definition at line 155 of file consoleparse.cpp.
|
inline |
Definition at line 173 of file consoleparse.cpp.
|
inline |
Definition at line 197 of file consoleparse.cpp.
|
inline |
Definition at line 185 of file consoleparse.cpp.
|
inline |
Definition at line 149 of file consoleparse.cpp.
void dc_get_token | ( | SCP_string & | out_str | ) |
Returns/Advances past a single token.
Similar in operation to dc_stuff_string_white, but won't throw any error messages and will only grab the first word. (dc_stuff_string_white may grab quoted strings)
Definition at line 214 of file consoleparse.cpp.
void dc_get_token_no_advance | ( | SCP_string & | out_str | ) |
Returns a single token, but does not advances Cp.
Similar in operation to dc_stuff_string_white, but won't throw any error messages and will only grab the first word. (dc_stuff_string_white may grab quoted strings).
Definition at line 242 of file consoleparse.cpp.
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.
double dc_parse_double | ( | const char * | ch, |
dc_token | type | ||
) |
Parses a double-precision floating point type. Supports, Whole, Fractional, and Mixed numbers, and supports scientific notation (exponent prefixed by 'e' or 'E').
[in] | ch | Points to the start of the string to parse |
[in] | type | The expected type. is thrown along with ch when an unexpected/malformed float is found |
The returned double may be cast to a single-precision float, but be sure to check it before doing so!
Definition at line 602 of file consoleparse.cpp.
state_float dc_parse_double_decimal | ( | const char *& | ch_ptr, |
SCP_string & | buffer_str | ||
) |
Definition at line 749 of file consoleparse.cpp.
state_float dc_parse_double_exponent | ( | const char *& | ch_ptr, |
SCP_string & | buffer_str | ||
) |
Definition at line 846 of file consoleparse.cpp.
state_float dc_parse_double_expprefix | ( | const char *& | ch_ptr, |
SCP_string & | buffer_str | ||
) |
Definition at line 803 of file consoleparse.cpp.
state_float dc_parse_double_expsign | ( | const char *& | ch_ptr, |
SCP_string & | buffer_str | ||
) |
Definition at line 827 of file consoleparse.cpp.
state_float dc_parse_double_fraction | ( | const char *& | ch_ptr, |
SCP_string & | buffer_str | ||
) |
Definition at line 776 of file consoleparse.cpp.
state_float dc_parse_double_sign | ( | const char *& | ch_ptr, |
SCP_string & | buffer_str | ||
) |
Definition at line 693 of file consoleparse.cpp.
state_float dc_parse_double_whole | ( | const char *& | ch_ptr, |
SCP_string & | buffer_str | ||
) |
Definition at line 717 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.
long dc_parse_long | ( | const char * | ch, |
dc_token | type | ||
) |
Parses a long integral type. Supports decimal, binary, octal, and hexidecimal strings.
[in] | ch | Points to the start of the string to parse. |
[in] | type | The expected type. Is thrown along with ch when an unexpected/malformed integral is found |
! Non-decimal values must be prefixed by their corresponding sequence. Binary: "0b", Octal: "0o", Hex: "0x"
The returned long may be cast to a smaller integral, but be sure to check it before doing so!
The only thing left making this function specific to the DC is the expected type. So, if you want to use this for parsing something other than the debug CL, you'll have to make a set of errParse classes that take a different expected type.
Definition at line 868 of file consoleparse.cpp.
|
inline |
Definition at line 1375 of file consoleparse.cpp.
|
inline |
Definition at line 1397 of file consoleparse.cpp.
|
inline |
Definition at line 1418 of file consoleparse.cpp.
|
inline |
Definition at line 1438 of file consoleparse.cpp.
|
inline |
Definition at line 1309 of file consoleparse.cpp.
|
inline |
Definition at line 1349 of file consoleparse.cpp.
Parses an unsigned long integral type. Supports decimal, binary, octal, and hexidecimal strings.
[in] | ch | Points to the start of the string to parse. |
[in] | type | The expected type. Is thrown along with ch when an unexpected/malformed integral is found |
! Non-decimal values must be delimited by their corresponding sequence. Binary: "0b", Octal: "0o", Hex: "0x" The returned long may be cast to a smaller integral, but be sure to check it before doing so! The only thing left making this function specific to the DC is the expected type. So, if you want to use this for parsing something other than the debug CL, you'll have to make a set of errParse classes that take a different expected type.
Definition at line 968 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.
char Command_string[MAX_CLI_LEN] |
Command string buffer.
Definition at line 27 of file consoleparse.cpp.
char* Cp = NULL |
Pointer to the commant string.
Definition at line 28 of file consoleparse.cpp.