FS2_Open
Open source remastering of the Freespace 2 engine
consoleparse.h
Go to the documentation of this file.
1 #ifndef _CONSOLEPARSE_H
2 #define _CONSOLEPARSE_H
3 // Command-line parsing functions for z64555's debug console, created for the FreeSpace Source Code project
5 //
6 // Portions of this source code are based on works by Volition, Inc. circa 1999. You may not sell or otherwise
7 // commercially exploit the source or things you created based on the source.
9 
17 #include "debugconsole/console.h"
18 #include "globalincs/pstypes.h"
19 
20 #include <cstdarg>
21 
22 #define MAX_CLI_LEN 512
23 #define MAX_TOKEN_LENGTH 255
24 
25 enum dc_token {
26  DCT_NONE = 0,
34 
36 };
37 
49 class errParse {
50 public:
53 
59  errParse(const char *found_str, dc_token expected_dct)
60  : found_token(found_str), expected_type(expected_dct)
61  {
62  }
63 };
64 
70 class errParseString : public errParse
71 {
72 public:
74 
81  errParseString(const char *found_str, char *str)
82  : errParse(found_str, DCT_STRING)
83  {
84  expected_tokens.push_back(str);
85  }
86 
94  errParseString(const char *found_str, char *str1, char *str2)
95  : errParse(found_str, DCT_STRING)
96  {
97  expected_tokens.push_back(str1);
98  expected_tokens.push_back(str2);
99  }
100 
108  : errParse(found_str, DCT_STRING), expected_tokens(strings)
109  {
110  }
111 };
112 
121 {
122 public:
123  size_t len;
124 
125  errParseOverflow(const char *found_str, size_t _len)
126  : errParse(found_str, DCT_STRING), len(_len)
127  {
128  }
129 };
130 
134 void dc_parse_init(SCP_string &str);
135 
139 void dc_ignore_white_space(void);
140 
144 void dc_ignore_gray_space(void);
145 
146 // Required/Optional Token
154 void dc_required_string(char *pstr);
155 
167 int dc_required_string_either(char *str1, char *str2);
168 
179 uint dc_required_string_any(const uint n, ...);
180 
189 bool dc_optional_string(const char *pstr);
190 
200 bool dc_optional_string_either(const char *str1, const char *str2);
201 
202 
203 // ==========================
204 // Stuffers
205 // ==========================
206 
215 void dc_stuff_float(float *f);
216 
228 void dc_stuff_int(int *i);
229 
241 void dc_stuff_uint(uint *i);
242 
254 void dc_stuff_ubyte(ubyte *i);
255 
268 void dc_stuff_boolean(bool *b);
269 
282 void dc_stuff_boolean(int *i);
283 
293 void dc_stuff_string(char *str, size_t maxlen);
294 
302 void dc_stuff_string(SCP_string &str);
303 
313 void dc_stuff_string_white(char *str, size_t len);
314 
323 
337 bool dc_maybe_stuff_float(float *f);
338 
352 bool dc_maybe_stuff_int(int *i);
353 
367 bool dc_maybe_stuff_uint(uint *i);
368 
383 
397 bool dc_maybe_stuff_boolean(bool *b);
398 
412 bool dc_maybe_stuff_boolean(int *i);
413 
425 bool dc_maybe_stuff_string(char *str, size_t len);
426 
436 
448 bool dc_maybe_stuff_string_white(char *str, size_t len);
449 
459 
460 #endif // _CONSOLEPARSE_H
void dc_stuff_ubyte(ubyte *i)
Stuffs an unsigned byte to the given variable. Supports binary (0b), hexadecimal (0x), and octal (0o) formats.
int i
Definition: multi_pxo.cpp:466
String.
Definition: consoleparse.h:27
bool dc_maybe_stuff_int(int *i)
Tries to stuff an int from the Command_string.
bool dc_maybe_stuff_float(float *f)
Tries to stuff a float from the Command_string.
errParseOverflow(const char *found_str, size_t _len)
Definition: consoleparse.h:125
GLclampf f
Definition: Glext.h:7097
void dc_ignore_white_space(void)
Advances the parser past whitespace characters.
Class thrown when the parsed string or token could not be stuffed into the smaller destination contai...
Definition: consoleparse.h:120
void dc_stuff_int(int *i)
Stuffs an int to the given variable. Supports binary (0b), hexadecimal (0x), and octal (0o) formats...
void dc_stuff_float(float *f)
Stuffs a float to the given variable.
errParseString(const char *found_str, char *str)
Invalid/Unexpected token constructor.
Definition: consoleparse.h:81
Integral or string evaluated as a boolean.
Definition: consoleparse.h:33
bool dc_maybe_stuff_boolean(bool *b)
Tries to stuff a bool from the Command_string.
Class thrown when a required token is not found.
Definition: consoleparse.h:49
std::basic_string< char, std::char_traits< char >, std::allocator< char > > SCP_string
Definition: vmallocator.h:21
bool dc_optional_string_either(const char *str1, const char *str2)
Searches for an optional string and it's alias.
bool dc_optional_string(const char *pstr)
Searches for an optional string.
errParseString(const char *found_str, SCP_vector< SCP_string > &strings)
Invalid/Unexpected token constructor.
Definition: consoleparse.h:107
SCP_string found_token
Definition: consoleparse.h:51
int dc_required_string_either(char *str1, char *str2)
Searchs for either of the specified required strings, throwing an errParse if neither are found...
bool dc_maybe_stuff_uint(uint *i)
Tries to stuff an uint from the Command_string.
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 com...
unsigned int uint
Definition: pstypes.h:64
Maximum number of dc_token elements. Primarily used as an end value in loops.
Definition: consoleparse.h:35
Integral with values between -128 and 127.
Definition: consoleparse.h:31
errParseString(const char *found_str, char *str1, char *str2)
Invalid/Unexpected token constructor.
Definition: consoleparse.h:94
Unsigned Integral.
Definition: consoleparse.h:30
void dc_parse_init(SCP_string &str)
Initializes the DC command line parser.
GLclampd n
Definition: Glext.h:7286
void dc_ignore_gray_space(void)
Advances the parser past grayspace characters.
void dc_stuff_boolean(bool *b)
stuffs a boolean evaluated integer or string into the given variable.
unsigned char ubyte
Definition: pstypes.h:62
bool dc_maybe_stuff_ubyte(ubyte *i)
Tries to stuff an ubyte from the Command_string.
No token.
Definition: consoleparse.h:26
Integral with values between 0 and 255.
Definition: consoleparse.h:32
dc_token
Definition: consoleparse.h:25
SCP_vector< SCP_string > expected_tokens
Definition: consoleparse.h:73
Class thrown when an expected string was not found. Can/should contain all of the expected strings...
Definition: consoleparse.h:70
Floating point.
Definition: consoleparse.h:28
GLboolean GLboolean GLboolean b
Definition: Glext.h:5781
dc_token expected_type
Definition: consoleparse.h:52
void dc_stuff_uint(uint *i)
Stuffs an unsigned int to the given variable. Supports binary (0b), hexadecimal (0x), and octal (0o) formats.
errParse(const char *found_str, dc_token expected_dct)
Invalid/Unexpected token constructor.
Definition: consoleparse.h:59
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...
An overhauled/updated debug console to allow monitoring, testing, and general debugging of new featur...
void dc_required_string(char *pstr)
Searches for a specified required string, throwing an errParse if not found.
GLenum GLsizei len
Definition: Glext.h:6283
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...
GLsizei const GLchar ** strings
Definition: Glext.h:7179
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...
size_t len
The size of the destination container.
Definition: consoleparse.h:123
Integral.
Definition: consoleparse.h:29
uint dc_required_string_any(const uint n,...)
Searches for specified required strings.