mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Converted spaces to tabs *curses*
This commit is contained in:
parent
5840e987b1
commit
57b2da779f
|
@ -12,14 +12,14 @@
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
TOKEN_INT,
|
TOKEN_INT,
|
||||||
TOKEN_FLOAT,
|
TOKEN_FLOAT,
|
||||||
TOKEN_STRING
|
TOKEN_STRING
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int type;
|
int type;
|
||||||
const char *stored_string;
|
const char *stored_string;
|
||||||
} TOKEN;
|
} TOKEN;
|
||||||
|
|
||||||
|
@ -28,20 +28,20 @@ typedef struct
|
||||||
char string_storage[CONSOLE_MAX_STR_LENGTH+1];
|
char string_storage[CONSOLE_MAX_STR_LENGTH+1];
|
||||||
char *next_string;
|
char *next_string;
|
||||||
|
|
||||||
TOKEN tokens[MAX_TOKENS];
|
TOKEN tokens[MAX_TOKENS];
|
||||||
unsigned int num_tokens;
|
unsigned int num_tokens;
|
||||||
} LEXER_RESULT;
|
} LEXER_RESULT;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
STATE_START,
|
STATE_START,
|
||||||
STATE_INT,
|
STATE_INT,
|
||||||
STATE_FLOAT,
|
STATE_FLOAT,
|
||||||
STATE_POT_FLOAT,
|
STATE_POT_FLOAT,
|
||||||
STATE_POT_NEGATIVE,
|
STATE_POT_NEGATIVE,
|
||||||
STATE_STRING,
|
STATE_STRING,
|
||||||
STATE_QUOTED,
|
STATE_QUOTED,
|
||||||
STATE_ESCAPE
|
STATE_ESCAPE
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *store_string(LEXER_RESULT *res, const char *str, int len)
|
static const char *store_string(LEXER_RESULT *res, const char *str, int len)
|
||||||
|
@ -79,51 +79,51 @@ static const char *store_string(LEXER_RESULT *res, const char *str, int len)
|
||||||
|
|
||||||
static void save_token(LEXER_RESULT *res, int *index, const char **start, const char *end, int *state, int type)
|
static void save_token(LEXER_RESULT *res, int *index, const char **start, const char *end, int *state, int type)
|
||||||
{
|
{
|
||||||
/* printf("Saving token with length %d\n", end - *start); */
|
/* printf("Saving token with length %d\n", end - *start); */
|
||||||
TOKEN *tok = &res->tokens[*index];
|
TOKEN *tok = &res->tokens[*index];
|
||||||
tok->stored_string = store_string(res, *start, end - *start);
|
tok->stored_string = store_string(res, *start, end - *start);
|
||||||
tok->type = type;
|
tok->type = type;
|
||||||
++res->num_tokens;
|
++res->num_tokens;
|
||||||
|
|
||||||
*start = end + 1;
|
*start = end + 1;
|
||||||
*state = STATE_START;
|
*state = STATE_START;
|
||||||
++*index;
|
++*index;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int digit(char c)
|
static int digit(char c)
|
||||||
{
|
{
|
||||||
return '0' <= c && c <= '9';
|
return '0' <= c && c <= '9';
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lex(const char *line, LEXER_RESULT *res)
|
static int lex(const char *line, LEXER_RESULT *res)
|
||||||
{
|
{
|
||||||
int state = STATE_START, i = 0;
|
int state = STATE_START, i = 0;
|
||||||
int length_left = CONSOLE_MAX_STR_LENGTH;
|
int length_left = CONSOLE_MAX_STR_LENGTH;
|
||||||
const char *start, *c;
|
const char *start, *c;
|
||||||
res->num_tokens = 0;
|
res->num_tokens = 0;
|
||||||
|
|
||||||
mem_zero(res, sizeof(*res));
|
mem_zero(res, sizeof(*res));
|
||||||
res->next_string = res->string_storage;
|
res->next_string = res->string_storage;
|
||||||
|
|
||||||
for (c = start = line; *c != '\0' && res->num_tokens < MAX_TOKENS && length_left; ++c, --length_left)
|
for (c = start = line; *c != '\0' && res->num_tokens < MAX_TOKENS && length_left; ++c, --length_left)
|
||||||
{
|
{
|
||||||
/* printf("State: %d.. c: %c\n", state, *c); */
|
/* printf("State: %d.. c: %c\n", state, *c); */
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case STATE_START:
|
case STATE_START:
|
||||||
if (*c == ' ')
|
if (*c == ' ')
|
||||||
start = c + 1;
|
start = c + 1;
|
||||||
else if (digit(*c))
|
else if (digit(*c))
|
||||||
state = STATE_INT;
|
state = STATE_INT;
|
||||||
else if (*c == '-')
|
else if (*c == '-')
|
||||||
state = STATE_POT_NEGATIVE;
|
state = STATE_POT_NEGATIVE;
|
||||||
else if (*c == '.')
|
else if (*c == '.')
|
||||||
state = STATE_POT_FLOAT;
|
state = STATE_POT_FLOAT;
|
||||||
else if (*c == '"')
|
else if (*c == '"')
|
||||||
state = STATE_QUOTED;
|
state = STATE_QUOTED;
|
||||||
else
|
else
|
||||||
state = STATE_STRING;
|
state = STATE_STRING;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATE_POT_NEGATIVE:
|
case STATE_POT_NEGATIVE:
|
||||||
if (digit(*c))
|
if (digit(*c))
|
||||||
|
@ -131,82 +131,82 @@ static int lex(const char *line, LEXER_RESULT *res)
|
||||||
else if (*c == '.')
|
else if (*c == '.')
|
||||||
state = STATE_POT_FLOAT;
|
state = STATE_POT_FLOAT;
|
||||||
else if (*c == ' ')
|
else if (*c == ' ')
|
||||||
save_token(res, &i, &start, c, &state, TOKEN_STRING);
|
save_token(res, &i, &start, c, &state, TOKEN_STRING);
|
||||||
else
|
else
|
||||||
state = STATE_STRING;
|
state = STATE_STRING;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATE_INT:
|
case STATE_INT:
|
||||||
if (digit(*c))
|
if (digit(*c))
|
||||||
;
|
;
|
||||||
else if (*c == '.')
|
else if (*c == '.')
|
||||||
state = STATE_FLOAT;
|
state = STATE_FLOAT;
|
||||||
else if (*c == ' ')
|
else if (*c == ' ')
|
||||||
save_token(res, &i, &start, c, &state, TOKEN_INT);
|
save_token(res, &i, &start, c, &state, TOKEN_INT);
|
||||||
else
|
else
|
||||||
state = STATE_STRING;
|
state = STATE_STRING;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATE_FLOAT:
|
case STATE_FLOAT:
|
||||||
if (digit(*c))
|
if (digit(*c))
|
||||||
;
|
;
|
||||||
else if (*c == ' ')
|
else if (*c == ' ')
|
||||||
save_token(res, &i, &start, c, &state, TOKEN_FLOAT);
|
save_token(res, &i, &start, c, &state, TOKEN_FLOAT);
|
||||||
else
|
else
|
||||||
state = STATE_STRING;
|
state = STATE_STRING;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATE_POT_FLOAT:
|
case STATE_POT_FLOAT:
|
||||||
if (digit(*c))
|
if (digit(*c))
|
||||||
state = STATE_FLOAT;
|
state = STATE_FLOAT;
|
||||||
else if (*c == ' ')
|
else if (*c == ' ')
|
||||||
save_token(res, &i, &start, c, &state, TOKEN_STRING);
|
save_token(res, &i, &start, c, &state, TOKEN_STRING);
|
||||||
else
|
else
|
||||||
state = STATE_STRING;
|
state = STATE_STRING;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATE_STRING:
|
case STATE_STRING:
|
||||||
if (*c == ' ')
|
if (*c == ' ')
|
||||||
save_token(res, &i, &start, c, &state, TOKEN_STRING);
|
save_token(res, &i, &start, c, &state, TOKEN_STRING);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATE_QUOTED:
|
case STATE_QUOTED:
|
||||||
if (*c == '"')
|
if (*c == '"')
|
||||||
{
|
{
|
||||||
++start;
|
++start;
|
||||||
save_token(res, &i, &start, c, &state, TOKEN_STRING);
|
save_token(res, &i, &start, c, &state, TOKEN_STRING);
|
||||||
}
|
}
|
||||||
else if (*c == '\\')
|
else if (*c == '\\')
|
||||||
state = STATE_ESCAPE;
|
state = STATE_ESCAPE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATE_ESCAPE:
|
case STATE_ESCAPE:
|
||||||
if (*c != ' ')
|
if (*c != ' ')
|
||||||
state = STATE_QUOTED;
|
state = STATE_QUOTED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case STATE_INT:
|
case STATE_INT:
|
||||||
save_token(res, &i, &start, c, &state, TOKEN_INT);
|
save_token(res, &i, &start, c, &state, TOKEN_INT);
|
||||||
break;
|
break;
|
||||||
case STATE_FLOAT:
|
case STATE_FLOAT:
|
||||||
save_token(res, &i, &start, c, &state, TOKEN_FLOAT);
|
save_token(res, &i, &start, c, &state, TOKEN_FLOAT);
|
||||||
break;
|
break;
|
||||||
case STATE_STRING:
|
case STATE_STRING:
|
||||||
case STATE_QUOTED:
|
case STATE_QUOTED:
|
||||||
case STATE_POT_FLOAT:
|
case STATE_POT_FLOAT:
|
||||||
case STATE_POT_NEGATIVE:
|
case STATE_POT_NEGATIVE:
|
||||||
save_token(res, &i, &start, c, &state, TOKEN_STRING);
|
save_token(res, &i, &start, c, &state, TOKEN_STRING);
|
||||||
break;
|
break;
|
||||||
case STATE_ESCAPE:
|
case STATE_ESCAPE:
|
||||||
dbg_msg("console/lexer", "Misplaced escape character");
|
dbg_msg("console/lexer", "Misplaced escape character");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -432,11 +432,11 @@ void console_init()
|
||||||
{
|
{
|
||||||
MACRO_REGISTER_COMMAND("echo", "s", echo_command, 0x0);
|
MACRO_REGISTER_COMMAND("echo", "s", echo_command, 0x0);
|
||||||
|
|
||||||
#define MACRO_CONFIG_INT(name,def,min,max) { static INT_VARIABLE_DATA data = { &config_get_ ## name, &config_set_ ## name }; MACRO_REGISTER_COMMAND(#name, "?i", int_variable_command, &data) }
|
#define MACRO_CONFIG_INT(name,def,min,max) { static INT_VARIABLE_DATA data = { &config_get_ ## name, &config_set_ ## name }; MACRO_REGISTER_COMMAND(#name, "?i", int_variable_command, &data) }
|
||||||
#define MACRO_CONFIG_STR(name,len,def) { static STR_VARIABLE_DATA data = { &config_get_ ## name, &config_set_ ## name }; MACRO_REGISTER_COMMAND(#name, "?s", str_variable_command, &data) }
|
#define MACRO_CONFIG_STR(name,len,def) { static STR_VARIABLE_DATA data = { &config_get_ ## name, &config_set_ ## name }; MACRO_REGISTER_COMMAND(#name, "?s", str_variable_command, &data) }
|
||||||
|
|
||||||
#include "e_config_variables.h"
|
#include "e_config_variables.h"
|
||||||
|
|
||||||
#undef MACRO_CONFIG_INT
|
#undef MACRO_CONFIG_INT
|
||||||
#undef MACRO_CONFIG_STR
|
#undef MACRO_CONFIG_STR
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue