FS2_Open
Open source remastering of the Freespace 2 engine
consoleparse.h File Reference

Parsing functions for the command line. Previously known as the command line scanner. More...

#include "debugconsole/console.h"
#include "globalincs/pstypes.h"
#include <cstdarg>

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...
 

Detailed Description

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.

Macro Definition Documentation

#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.

Enumeration Type Documentation

enum dc_token
Enumerator
DCT_NONE 

No token.

DCT_STRING 

String.

DCT_FLOAT 

Floating point.

DCT_INT 

Integral.

DCT_UINT 

Unsigned Integral.

DCT_BYTE 

Integral with values between -128 and 127.

DCT_UBYTE 

Integral with values between 0 and 255.

DCT_BOOL 

Integral or string evaluated as a boolean.

DCT_MAX_ITEMS 

Maximum number of dc_token elements. Primarily used as an end value in loops.

Definition at line 25 of file consoleparse.h.

Function Documentation

void dc_ignore_gray_space ( void  )

Advances the parser past grayspace characters.

Definition at line 273 of file consoleparse.cpp.

void dc_ignore_white_space ( void  )

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.

Parameters
[in]bThe 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.

Parameters
[in]iThe 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.

Parameters
[in]fThe 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.

Parameters
[in]iThe 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.

Parameters
[out]strDestination string. If nothing was found, str = ""
[in]lenMaximum length to copy. (len <= sizeof(str)) && (len <= MAX_TOKEN_LENGTH)
Return values
trueif the operation was successful,
falseotherwise
Exceptions
errParseOverflowwhen 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.

Parameters
[out]strDestination string. If nothing was found, str = ""
Return values
trueif the operation was successful,
falseotherwise

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.

Parameters
[out]strDestination string. If nothing was found, str = ""
[in]lenMaximum length to copy. (maxlen <= sizeof(str)) && (maxlen <= MAX_TOKEN_LENGTH)
Return values
trueif the operation was successful,
falseotherwise
Exceptions
errParseOverflowwhen 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.

Parameters
[out]strDestination string. If nothing was found, str = ""
Return values
trueif the operation was successful,
falseotherwise

Definition at line 446 of file consoleparse.cpp.

bool dc_maybe_stuff_ubyte ( ubyte i)

Tries to stuff an ubyte from the Command_string.

Parameters
[in]iThe 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.

Parameters
[in]iThe 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.

Parameters
[in]pstrThe char[] to look for
Return values
trueif the string was found,
falseotherwise

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.

Parameters
[in]str1The char[] to look for
[in]str2The alternative char[] to look for
Return values
trueif the string was found,
falseotherwise

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.

Parameters
[in]pstrThe string to search for
Exceptions
errParseStringwith the required string

Definition at line 459 of file consoleparse.cpp.

uint dc_required_string_any ( const uint  n,
  ... 
)

Searches for specified required strings.

Parameters
[in]nThe number of char[] or c_str's given
[in]...A comma delimited list of one or more required strings.
Returns
The index of the specified required strings (as if they were an array)
Exceptions
errParseStringwith 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.

Parameters
[in]str1The first string to search for
[in]str2The second string to search for
Return values
0if str1 was found, or
1if str2 was found
Exceptions
errParseStringwith 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.

Parameters
[in]bThe 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

Exceptions
errParseif an unexpected or otherwise malformed float string is found.
errParseif nothing was found

Definition at line 1130 of file consoleparse.cpp.

void dc_stuff_boolean ( int i)

stuffs a boolean evaluated integer or string into the given variable.

Parameters
[in]iThe 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

Exceptions
errParseif an unexpected or otherwise malformed float string is found.
errParseif nothing was found

Definition at line 1163 of file consoleparse.cpp.

void dc_stuff_float ( float f)

Stuffs a float to the given variable.

Parameters
[in]fThe float variable to stuff to
Exceptions
errParseif an unexpected or otherwise malformed float string is found.
errParseif nothing was found

Definition at line 1057 of file consoleparse.cpp.

void dc_stuff_int ( int i)

Stuffs an int to the given variable. Supports binary (0b), hexadecimal (0x), and octal (0o) formats.

Parameters
[in]iThe 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

Exceptions
errParseif an unexpected or otherwise malformed float string is found.
errParseif 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.

Parameters
[out]strDestination string
[in]maxlenMaximum length to copy. (maxlen <= sizeof(str)) && (maxlen <= MAX_TOKEN_LENGTH)
Exceptions
errParsewhen nothing left was found on the command line
errParseOverflowwhen 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.

Parameters
[out]strDestination string
Exceptions
errParsewhen 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.

Parameters
[out]strDestination string
[in]lenMaximum length to copy. (len <= sizeof(str)) && (len <= MAX_TOKEN_LENGTH)
Exceptions
errParsewhen nothing left was found on the command line
errParseOverflowwhen 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.

Parameters
[out]strDestination string
Exceptions
errParsewhen nothing left was found on the command line

Definition at line 1275 of file consoleparse.cpp.

void dc_stuff_ubyte ( ubyte i)

Stuffs an unsigned byte to the given variable. Supports binary (0b), hexadecimal (0x), and octal (0o) formats.

Parameters
[in]iThe 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

Exceptions
errParseif an unexpected or otherwise malformed float string is found.
errParseif nothing was found

Definition at line 1111 of file consoleparse.cpp.

void dc_stuff_uint ( uint i)

Stuffs an unsigned int to the given variable. Supports binary (0b), hexadecimal (0x), and octal (0o) formats.

Parameters
[in]iThe 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

Exceptions
errParseif an unexpected or otherwise malformed float string is found.
errParseif nothing was found

Definition at line 1093 of file consoleparse.cpp.