Yay for escape characters.

This commit is contained in:
Brian Koropoff 2002-08-22 22:43:47 +00:00
parent 06e6c92da8
commit 0715464bb1
4 changed files with 36 additions and 7 deletions

View file

@ -1,8 +1,8 @@
function "sensitivity" {
if ($argc == 1) {
echo $0 is $in_mouse_amp
return
}
in_mouse_amp $1
if ($argc == 1) {
echo "\"", $0, "\" is \"", $in_mouse_amp, "\""
return
}
in_mouse_amp $1
}
export sensitivity

View file

@ -29,6 +29,8 @@
$Id$
*/
inline qboolean GIB_Escaped (const char *str, int i);
char GIB_Parse_Match_Brace (const char *str, unsigned int *i);
char GIB_Parse_Match_Backtick (const char *str, unsigned int *i);
char GIB_Parse_Match_Index (const char *str, unsigned int *i);

View file

@ -47,6 +47,7 @@ static const char rcsid[] =
#include "QF/gib_builtin.h"
#include "QF/gib_function.h"
#include "QF/gib_vars.h"
#include "QF/gib_parse.h"
// Interpreter structure and prototypes
@ -62,6 +63,17 @@ cbuf_interpreter_t gib_interp = {
GIB_Buffer_Destruct,
};
inline qboolean
GIB_Escaped (const char *str, int i)
{
int n, c;
if (!i)
return 0;
for (n = i - 1, c = 0; n >= 0 && str[n] == '\\'; n--, c++);
return c & 1;
}
/*
GIB_Parse_Match_Dquote
@ -77,7 +89,7 @@ GIB_Parse_Match_Dquote (const char *str, unsigned int *i)
for ((*i)++; str[*i]; (*i)++) {
if (str[*i] == '\n')
return '\"'; // Newlines should never occur inside quotes, EVER
else if (str[*i] == '\"')
else if (str[*i] == '\"' && !GIB_Escaped (str, *i))
return 0;
}
return '\"';

View file

@ -250,8 +250,21 @@ GIB_Process_Embedded (struct dstring_s *token)
return 0;
}
void
GIB_Process_Escapes (dstring_t *token)
{
int i;
for (i = 0; token->str[i]; i++) {
if (token->str[i] == '\\') {
dstring_snip (token, i, 1);
if (token->str[i] == 'n')
token->str[i] = '\n';
}
}
}
int
GIB_Process_Token (struct dstring_s *token, char delim)
GIB_Process_Token (dstring_t *token, char delim)
{
if (delim != '{' && delim != '\"') {
if (GIB_Process_Embedded (token))
@ -263,5 +276,7 @@ GIB_Process_Token (struct dstring_s *token, char delim)
if (delim == '(')
if (GIB_Process_Math (token))
return -1;
if (delim == '\"')
GIB_Process_Escapes (token);
return 0;
}