mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-07 08:21:59 +00:00
more old-code cleanup. move PR_LexString into make_string
This commit is contained in:
parent
12d2338d1b
commit
718a64343b
4 changed files with 128 additions and 215 deletions
|
@ -447,21 +447,6 @@ extern qboolean pr_dumpasm;
|
||||||
extern def_t *pr_global_defs[MAX_REGS]; // to find def for a global
|
extern def_t *pr_global_defs[MAX_REGS]; // to find def for a global
|
||||||
// variable
|
// variable
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
tt_eof, // end of file reached
|
|
||||||
tt_name, // an alphanumeric name token
|
|
||||||
tt_punct, // code punctuation
|
|
||||||
tt_immediate, // string, float, vector
|
|
||||||
} token_type_t;
|
|
||||||
|
|
||||||
extern char pr_token[2048];
|
|
||||||
extern int pr_token_len;
|
|
||||||
extern token_type_t pr_token_type;
|
|
||||||
extern type_t *pr_immediate_type;
|
|
||||||
extern eval_t pr_immediate;
|
|
||||||
|
|
||||||
void PR_Lex (void);
|
|
||||||
void PR_LexString (void);
|
|
||||||
// reads the next token into pr_token and classifies its type
|
// reads the next token into pr_token and classifies its type
|
||||||
|
|
||||||
type_t *PR_ParseType (void);
|
type_t *PR_ParseType (void);
|
||||||
|
@ -470,14 +455,11 @@ def_t *PR_ParseImmediate (def_t *def);
|
||||||
def_t *PR_ReuseConstant (expr_t *expr, def_t *def);
|
def_t *PR_ReuseConstant (expr_t *expr, def_t *def);
|
||||||
type_t *PR_FindType (type_t *new);
|
type_t *PR_FindType (type_t *new);
|
||||||
|
|
||||||
qboolean PR_Check (token_type_t type, const char *string);
|
|
||||||
void PR_Expect (token_type_t type, const char *string);
|
|
||||||
void PR_ParseError (const char *error, ...)__attribute__((format(printf, 1,2)));
|
void PR_ParseError (const char *error, ...)__attribute__((format(printf, 1,2)));
|
||||||
|
|
||||||
|
|
||||||
extern jmp_buf pr_parse_abort; // longjump with this on parse error
|
extern jmp_buf pr_parse_abort; // longjump with this on parse error
|
||||||
extern int pr_source_line;
|
extern int pr_source_line;
|
||||||
extern char *pr_file_p;
|
|
||||||
|
|
||||||
void *PR_Malloc (int size);
|
void *PR_Malloc (int size);
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,6 @@ int pr_bracelevel;
|
||||||
|
|
||||||
char pr_token[2048];
|
char pr_token[2048];
|
||||||
int pr_token_len;
|
int pr_token_len;
|
||||||
token_type_t pr_token_type;
|
|
||||||
type_t *pr_immediate_type;
|
type_t *pr_immediate_type;
|
||||||
eval_t pr_immediate;
|
eval_t pr_immediate;
|
||||||
|
|
||||||
|
@ -94,183 +93,6 @@ def_t *def_for_type[8] = {
|
||||||
&def_entity, &def_field, &def_function, &def_pointer
|
&def_entity, &def_field, &def_function, &def_pointer
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
PR_LexString
|
|
||||||
|
|
||||||
Parse a quoted string
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
PR_LexString (void)
|
|
||||||
{
|
|
||||||
int c;
|
|
||||||
int i;
|
|
||||||
int mask;
|
|
||||||
int boldnext;
|
|
||||||
int quote;
|
|
||||||
|
|
||||||
pr_token_len = 0;
|
|
||||||
mask = 0x00;
|
|
||||||
boldnext = 0;
|
|
||||||
|
|
||||||
quote = *pr_file_p++;
|
|
||||||
do {
|
|
||||||
c = *pr_file_p++;
|
|
||||||
if (!c)
|
|
||||||
error (0, "EOF inside quote");
|
|
||||||
if (c == '\n')
|
|
||||||
error (0, "newline inside quote");
|
|
||||||
if (c == '\\') { // escape char
|
|
||||||
c = *pr_file_p++;
|
|
||||||
if (!c)
|
|
||||||
error (0, "EOF inside quote");
|
|
||||||
switch (c) {
|
|
||||||
case '\\':
|
|
||||||
c = '\\';
|
|
||||||
break;
|
|
||||||
case 'n':
|
|
||||||
c = '\n';
|
|
||||||
break;
|
|
||||||
case '"':
|
|
||||||
c = '\"';
|
|
||||||
break;
|
|
||||||
case '\'':
|
|
||||||
c = '\'';
|
|
||||||
break;
|
|
||||||
case '0':
|
|
||||||
case '1':
|
|
||||||
case '2':
|
|
||||||
case '3':
|
|
||||||
case '4':
|
|
||||||
case '5':
|
|
||||||
case '6':
|
|
||||||
case '7':
|
|
||||||
for (i = c = 0; i < 3
|
|
||||||
&& *pr_file_p >= '0'
|
|
||||||
&& *pr_file_p <= '7'; i++, pr_file_p++) {
|
|
||||||
c *= 8;
|
|
||||||
c += *pr_file_p - '0';
|
|
||||||
}
|
|
||||||
if (!*pr_file_p)
|
|
||||||
error (0, "EOF inside quote");
|
|
||||||
break;
|
|
||||||
case 'x':
|
|
||||||
c = 0;
|
|
||||||
while (*pr_file_p && isxdigit (*pr_file_p)) {
|
|
||||||
c *= 16;
|
|
||||||
if (*pr_file_p <= '9')
|
|
||||||
c += *pr_file_p - '0';
|
|
||||||
else if (*pr_file_p <= 'F')
|
|
||||||
c += *pr_file_p - 'A' + 10;
|
|
||||||
else
|
|
||||||
c += *pr_file_p - 'a' + 10;
|
|
||||||
pr_file_p++;
|
|
||||||
}
|
|
||||||
if (!*pr_file_p)
|
|
||||||
error (0, "EOF inside quote");
|
|
||||||
break;
|
|
||||||
case 'a':
|
|
||||||
c = '\a';
|
|
||||||
break;
|
|
||||||
case 'b':
|
|
||||||
c = '\b';
|
|
||||||
break;
|
|
||||||
case 'e':
|
|
||||||
c = '\033';
|
|
||||||
break;
|
|
||||||
case 'f':
|
|
||||||
c = '\f';
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
c = '\r';
|
|
||||||
break;
|
|
||||||
case 't':
|
|
||||||
c = '\t';
|
|
||||||
break;
|
|
||||||
case 'v':
|
|
||||||
c = '\v';
|
|
||||||
break;
|
|
||||||
case '^':
|
|
||||||
if (*pr_file_p == '\"')
|
|
||||||
error (0, "Unexpected end of string after \\^");
|
|
||||||
boldnext = 1;
|
|
||||||
continue;
|
|
||||||
case '<':
|
|
||||||
mask = 0x80;
|
|
||||||
continue;
|
|
||||||
case '>':
|
|
||||||
mask = 0x00;
|
|
||||||
continue;
|
|
||||||
default:
|
|
||||||
error (0, "Unknown escape char");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (c == quote) {
|
|
||||||
pr_token[pr_token_len] = 0;
|
|
||||||
pr_token_type = tt_immediate;
|
|
||||||
pr_immediate_type = &type_string;
|
|
||||||
strcpy (pr_immediate_string, pr_token);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (boldnext)
|
|
||||||
c = c ^ 0x80;
|
|
||||||
boldnext = 0;
|
|
||||||
c = c ^ mask;
|
|
||||||
pr_token[pr_token_len] = c;
|
|
||||||
pr_token_len++;
|
|
||||||
} while (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
PR_PrintType (type_t *type)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!type) {
|
|
||||||
printf ("(null)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (type->type) {
|
|
||||||
case ev_void:
|
|
||||||
printf ("void");
|
|
||||||
break;
|
|
||||||
case ev_string:
|
|
||||||
printf ("string");
|
|
||||||
break;
|
|
||||||
case ev_float:
|
|
||||||
printf ("float");
|
|
||||||
break;
|
|
||||||
case ev_vector:
|
|
||||||
printf ("vector");
|
|
||||||
break;
|
|
||||||
case ev_entity:
|
|
||||||
printf ("entity");
|
|
||||||
break;
|
|
||||||
case ev_field:
|
|
||||||
printf (".");
|
|
||||||
PR_PrintType (type->aux_type);
|
|
||||||
break;
|
|
||||||
case ev_func:
|
|
||||||
PR_PrintType (type->aux_type);
|
|
||||||
printf ("(");
|
|
||||||
for (i = 0; i < type->num_parms; i++) {
|
|
||||||
PR_PrintType (type->parm_types[i]);
|
|
||||||
if (i < type->num_parms - 1)
|
|
||||||
printf (",");
|
|
||||||
}
|
|
||||||
if (type->num_parms == -1)
|
|
||||||
printf ("...");
|
|
||||||
printf (")");
|
|
||||||
break;
|
|
||||||
case ev_pointer:
|
|
||||||
printf ("pointer to ");
|
|
||||||
PR_PrintType (type->aux_type);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
printf ("unknown type %d", type->type);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
PR_FindType
|
PR_FindType
|
||||||
|
|
||||||
|
|
|
@ -121,22 +121,24 @@ m ([\-+]?)
|
||||||
return INT_VAL;
|
return INT_VAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
^#{s}+{DIGIT}+{s}+\"(\.|[^"])*\".*$ {
|
^#{s}+{DIGIT}+{s}+\"(\.|[^"\n])*\".*$ {
|
||||||
char *p;
|
char *p;
|
||||||
|
char *s;
|
||||||
int line;
|
int line;
|
||||||
|
|
||||||
pr_file_p = yytext + 1;
|
p = yytext + 1;
|
||||||
line = strtol (pr_file_p, &p, 10);
|
line = strtol (p, &s, 10);
|
||||||
pr_file_p = p;
|
p = s;
|
||||||
while (isspace (*pr_file_p))
|
while (isspace (*p))
|
||||||
pr_file_p++;
|
p++;
|
||||||
if (!*pr_file_p)
|
if (!*p)
|
||||||
error (0, "Unexpected end of file");
|
error (0, "Unexpected end of file");
|
||||||
PR_LexString (); // grab the filename
|
s = make_string (p); // grab the filename
|
||||||
while (*pr_file_p && *pr_file_p != '\n') // ignore flags
|
while (*p && *p != '\n') // ignore flags
|
||||||
pr_file_p++;
|
p++;
|
||||||
pr_source_line = line - 1;
|
pr_source_line = line - 1;
|
||||||
s_file = ReuseString (pr_immediate_string);
|
s_file = ReuseString (s);
|
||||||
|
free (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
[+\-*/&|^%]= {
|
[+\-*/&|^%]= {
|
||||||
|
@ -359,13 +361,122 @@ clear_frame_macros (void)
|
||||||
char *
|
char *
|
||||||
make_string (char *token)
|
make_string (char *token)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str, *s;
|
||||||
|
int c;
|
||||||
|
int i;
|
||||||
|
int mask;
|
||||||
|
int boldnext;
|
||||||
|
int quote;
|
||||||
|
|
||||||
pr_file_p = token;
|
s = str = malloc (strlen (token) + 1);
|
||||||
PR_LexString ();
|
|
||||||
str = malloc (pr_token_len + 1);
|
|
||||||
if (!str)
|
if (!str)
|
||||||
Sys_Error ("make_string: Memory Allocation Failure\n");
|
Sys_Error ("make_string: Memory Allocation Failure\n");
|
||||||
memcpy (str, pr_token, pr_token_len + 1);
|
|
||||||
|
mask = 0x00;
|
||||||
|
boldnext = 0;
|
||||||
|
|
||||||
|
quote = *token++;
|
||||||
|
do {
|
||||||
|
c = *token++;
|
||||||
|
if (!c)
|
||||||
|
error (0, "EOF inside quote");
|
||||||
|
if (c == '\n')
|
||||||
|
error (0, "newline inside quote");
|
||||||
|
if (c == '\\') { // escape char
|
||||||
|
c = *token++;
|
||||||
|
if (!c)
|
||||||
|
error (0, "EOF inside quote");
|
||||||
|
switch (c) {
|
||||||
|
case '\\':
|
||||||
|
c = '\\';
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
c = '\n';
|
||||||
|
break;
|
||||||
|
case '"':
|
||||||
|
c = '\"';
|
||||||
|
break;
|
||||||
|
case '\'':
|
||||||
|
c = '\'';
|
||||||
|
break;
|
||||||
|
case '0':
|
||||||
|
case '1':
|
||||||
|
case '2':
|
||||||
|
case '3':
|
||||||
|
case '4':
|
||||||
|
case '5':
|
||||||
|
case '6':
|
||||||
|
case '7':
|
||||||
|
for (i = c = 0; i < 3
|
||||||
|
&& *token >= '0'
|
||||||
|
&& *token <= '7'; i++, token++) {
|
||||||
|
c *= 8;
|
||||||
|
c += *token - '0';
|
||||||
|
}
|
||||||
|
if (!*token)
|
||||||
|
error (0, "EOF inside quote");
|
||||||
|
break;
|
||||||
|
case 'x':
|
||||||
|
c = 0;
|
||||||
|
while (*token && isxdigit (*token)) {
|
||||||
|
c *= 16;
|
||||||
|
if (*token <= '9')
|
||||||
|
c += *token - '0';
|
||||||
|
else if (*token <= 'F')
|
||||||
|
c += *token - 'A' + 10;
|
||||||
|
else
|
||||||
|
c += *token - 'a' + 10;
|
||||||
|
token++;
|
||||||
|
}
|
||||||
|
if (!*token)
|
||||||
|
error (0, "EOF inside quote");
|
||||||
|
break;
|
||||||
|
case 'a':
|
||||||
|
c = '\a';
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
c = '\b';
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
c = '\033';
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
c = '\f';
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
c = '\r';
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
c = '\t';
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
|
c = '\v';
|
||||||
|
break;
|
||||||
|
case '^':
|
||||||
|
if (*token == '\"')
|
||||||
|
error (0, "Unexpected end of string after \\^");
|
||||||
|
boldnext = 1;
|
||||||
|
continue;
|
||||||
|
case '<':
|
||||||
|
mask = 0x80;
|
||||||
|
continue;
|
||||||
|
case '>':
|
||||||
|
mask = 0x00;
|
||||||
|
continue;
|
||||||
|
default:
|
||||||
|
error (0, "Unknown escape char");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (c == quote) {
|
||||||
|
*s++ = 0;
|
||||||
|
break;;
|
||||||
|
}
|
||||||
|
if (boldnext)
|
||||||
|
c = c ^ 0x80;
|
||||||
|
boldnext = 0;
|
||||||
|
c = c ^ mask;
|
||||||
|
*s++ = c;
|
||||||
|
} while (1);
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,6 @@ yyerror (const char *s)
|
||||||
|
|
||||||
int yylex (void);
|
int yylex (void);
|
||||||
type_t *PR_FindType (type_t *new);
|
type_t *PR_FindType (type_t *new);
|
||||||
void PR_PrintType(type_t*);
|
|
||||||
|
|
||||||
type_t *parse_params (def_t *parms);
|
type_t *parse_params (def_t *parms);
|
||||||
function_t *new_function (void);
|
function_t *new_function (void);
|
||||||
|
@ -909,7 +908,6 @@ finish_function (function_t *f)
|
||||||
void
|
void
|
||||||
emit_function (function_t *f, expr_t *e)
|
emit_function (function_t *f, expr_t *e)
|
||||||
{
|
{
|
||||||
//PR_PrintType (f->def->type);
|
|
||||||
//printf (" %s =\n", f->def->name);
|
//printf (" %s =\n", f->def->name);
|
||||||
|
|
||||||
if (f->aux)
|
if (f->aux)
|
||||||
|
|
Loading…
Reference in a new issue