diff --git a/tools/qfcc/include/qfcc.h b/tools/qfcc/include/qfcc.h index 3b5537a16..e43ae4712 100644 --- a/tools/qfcc/include/qfcc.h +++ b/tools/qfcc/include/qfcc.h @@ -447,21 +447,6 @@ extern qboolean pr_dumpasm; extern def_t *pr_global_defs[MAX_REGS]; // to find def for a global // 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 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); 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))); extern jmp_buf pr_parse_abort; // longjump with this on parse error extern int pr_source_line; -extern char *pr_file_p; void *PR_Malloc (int size); diff --git a/tools/qfcc/source/pr_lex.c b/tools/qfcc/source/pr_lex.c index d6219d228..5d60f9aa9 100644 --- a/tools/qfcc/source/pr_lex.c +++ b/tools/qfcc/source/pr_lex.c @@ -46,7 +46,6 @@ int pr_bracelevel; char pr_token[2048]; int pr_token_len; -token_type_t pr_token_type; type_t *pr_immediate_type; eval_t pr_immediate; @@ -94,183 +93,6 @@ def_t *def_for_type[8] = { &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 diff --git a/tools/qfcc/source/qc-lex.l b/tools/qfcc/source/qc-lex.l index 22e20ba87..ef5eee7cc 100644 --- a/tools/qfcc/source/qc-lex.l +++ b/tools/qfcc/source/qc-lex.l @@ -121,22 +121,24 @@ m ([\-+]?) return INT_VAL; } -^#{s}+{DIGIT}+{s}+\"(\.|[^"])*\".*$ { +^#{s}+{DIGIT}+{s}+\"(\.|[^"\n])*\".*$ { char *p; + char *s; int line; - pr_file_p = yytext + 1; - line = strtol (pr_file_p, &p, 10); - pr_file_p = p; - while (isspace (*pr_file_p)) - pr_file_p++; - if (!*pr_file_p) + p = yytext + 1; + line = strtol (p, &s, 10); + p = s; + while (isspace (*p)) + p++; + if (!*p) error (0, "Unexpected end of file"); - PR_LexString (); // grab the filename - while (*pr_file_p && *pr_file_p != '\n') // ignore flags - pr_file_p++; + s = make_string (p); // grab the filename + while (*p && *p != '\n') // ignore flags + p++; pr_source_line = line - 1; - s_file = ReuseString (pr_immediate_string); + s_file = ReuseString (s); + free (s); } [+\-*/&|^%]= { @@ -192,7 +194,7 @@ m ([\-+]?) [^\r\n]* /* skip */ -<*>\r*\n { +<*>\r*\n { pr_source_line++; BEGIN (INITIAL); } @@ -359,13 +361,122 @@ clear_frame_macros (void) char * make_string (char *token) { - char *str; + char *str, *s; + int c; + int i; + int mask; + int boldnext; + int quote; - pr_file_p = token; - PR_LexString (); - str = malloc (pr_token_len + 1); + s = str = malloc (strlen (token) + 1); if (!str) 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; } diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y index bc70e2f5c..ddc782eca 100644 --- a/tools/qfcc/source/qc-parse.y +++ b/tools/qfcc/source/qc-parse.y @@ -52,7 +52,6 @@ yyerror (const char *s) int yylex (void); type_t *PR_FindType (type_t *new); -void PR_PrintType(type_t*); type_t *parse_params (def_t *parms); function_t *new_function (void); @@ -909,7 +908,6 @@ finish_function (function_t *f) void emit_function (function_t *f, expr_t *e) { - //PR_PrintType (f->def->type); //printf (" %s =\n", f->def->name); if (f->aux)