X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=lexer.c;h=6c8ccd9db127c82c11996ccf82a08037e196c840;hb=d8b3faa8711d172ee66f8c6e30f154dc7de4646d;hp=7642d261b89b4b3b9eae3e8fa6c4c1ec0751b96e;hpb=fa14ca93d2b60f722d55c24214fde7ac84581ad0;p=xonotic%2Fgmqcc.git diff --git a/lexer.c b/lexer.c index 7642d26..6c8ccd9 100644 --- a/lexer.c +++ b/lexer.c @@ -25,6 +25,7 @@ #include "gmqcc.h" #include "lexer.h" + /* * List of Keywords */ @@ -179,8 +180,8 @@ static void lex_token_new(lex_file *lex) lex_file* lex_open(const char *file) { - lex_file *lex; - FILE *in = fs_file_open(file, "rb"); + lex_file *lex; + fs_file_t *in = fs_file_open(file, "rb"); if (!in) { lexerror(NULL, "open failed: '%s'\n", file); @@ -273,11 +274,11 @@ static int lex_fgetc(lex_file *lex) } if (lex->open_string) { if (lex->open_string_pos >= lex->open_string_length) - return EOF; + return FS_FILE_EOF; lex->column++; return lex->open_string[lex->open_string_pos++]; } - return EOF; + return FS_FILE_EOF; } /* Get or put-back data @@ -493,7 +494,7 @@ static bool lex_try_pragma(lex_file *lex) goto unroll; lex->line = line; - while (ch != '\n' && ch != EOF) + while (ch != '\n' && ch != FS_FILE_EOF) ch = lex_getch(lex); vec_free(command); vec_free(param); @@ -573,7 +574,7 @@ static int lex_skipwhite(lex_file *lex, bool hadwhite) do { ch = lex_getch(lex); - while (ch != EOF && util_isspace(ch)) { + while (ch != FS_FILE_EOF && util_isspace(ch)) { if (ch == '\n') { if (lex_try_pragma(lex)) continue; @@ -613,7 +614,7 @@ static int lex_skipwhite(lex_file *lex, bool hadwhite) lex_tokench(lex, ' '); } - while (ch != EOF && ch != '\n') { + while (ch != FS_FILE_EOF && ch != '\n') { if (lex->flags.preprocessing) lex_tokench(lex, ' '); /* ch); */ ch = lex_getch(lex); @@ -638,7 +639,7 @@ static int lex_skipwhite(lex_file *lex, bool hadwhite) lex_tokench(lex, ' '); } - while (ch != EOF) + while (ch != FS_FILE_EOF) { ch = lex_getch(lex); if (ch == '*') { @@ -671,7 +672,7 @@ static int lex_skipwhite(lex_file *lex, bool hadwhite) ch = '/'; break; } - } while (ch != EOF && util_isspace(ch)); + } while (ch != FS_FILE_EOF && util_isspace(ch)); if (haswhite) { lex_endtoken(lex); @@ -687,7 +688,7 @@ static bool GMQCC_WARN lex_finish_ident(lex_file *lex) int ch; ch = lex_getch(lex); - while (ch != EOF && isident(ch)) + while (ch != FS_FILE_EOF && isident(ch)) { lex_tokench(lex, ch); ch = lex_getch(lex); @@ -707,7 +708,7 @@ static int lex_parse_frame(lex_file *lex) lex_token_new(lex); ch = lex_getch(lex); - while (ch != EOF && ch != '\n' && util_isspace(ch)) + while (ch != FS_FILE_EOF && ch != '\n' && util_isspace(ch)) ch = lex_getch(lex); if (ch == '\n') @@ -761,14 +762,14 @@ static bool lex_finish_frames(lex_file *lex) static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote) { - uchar_t chr; + utf8ch_t chr = 0; int ch = 0; int nextch; bool hex; char u8buf[8]; /* way more than enough */ int u8len, uc; - while (ch != EOF) + while (ch != FS_FILE_EOF) { ch = lex_getch(lex); if (ch == quote) @@ -777,18 +778,18 @@ static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote) if (lex->flags.preprocessing && ch == '\\') { lex_tokench(lex, ch); ch = lex_getch(lex); - if (ch == EOF) { + if (ch == FS_FILE_EOF) { lexerror(lex, "unexpected end of file"); - lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */ + lex_ungetch(lex, FS_FILE_EOF); /* next token to be TOKEN_EOF */ return (lex->tok.ttype = TOKEN_ERROR); } lex_tokench(lex, ch); } else if (ch == '\\') { ch = lex_getch(lex); - if (ch == EOF) { + if (ch == FS_FILE_EOF) { lexerror(lex, "unexpected end of file"); - lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */ + lex_ungetch(lex, FS_FILE_EOF); /* next token to be TOKEN_EOF */ return (lex->tok.ttype = TOKEN_ERROR); } @@ -879,7 +880,7 @@ static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote) } } if (OPTS_FLAG(UTF8) && chr >= 128) { - u8len = u8_fromchar(chr, u8buf, sizeof(u8buf)); + u8len = utf8_from(u8buf, chr); if (!u8len) ch = 0; else { @@ -887,7 +888,8 @@ static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote) lex->column += u8len; for (uc = 0; uc < u8len; ++uc) lex_tokench(lex, u8buf[uc]); - /* the last character will be inserted with the tokench() call + /* + * the last character will be inserted with the tokench() call * below the switch */ ch = u8buf[uc]; @@ -910,7 +912,7 @@ static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote) lex_tokench(lex, ch); } lexerror(lex, "unexpected end of file within string constant"); - lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */ + lex_ungetch(lex, FS_FILE_EOF); /* next token to be TOKEN_EOF */ return (lex->tok.ttype = TOKEN_ERROR); } @@ -1031,7 +1033,7 @@ int lex_do(lex_file *lex) if (lex->eof) return (lex->tok.ttype = TOKEN_FATAL); - if (ch == EOF) { + if (ch == FS_FILE_EOF) { lex->eof = true; return (lex->tok.ttype = TOKEN_EOF); } @@ -1068,7 +1070,7 @@ int lex_do(lex_file *lex) if (!strcmp(v, "framevalue")) { ch = lex_getch(lex); - while (ch != EOF && util_isspace(ch) && ch != '\n') + while (ch != FS_FILE_EOF && util_isspace(ch) && ch != '\n') ch = lex_getch(lex); if (!util_isdigit(ch)) { @@ -1148,7 +1150,7 @@ int lex_do(lex_file *lex) vec_free(lex->frames); /* skip line (fteqcc does it too) */ ch = lex_getch(lex); - while (ch != EOF && ch != '\n') + while (ch != FS_FILE_EOF && ch != '\n') ch = lex_getch(lex); return lex_do(lex); } @@ -1162,7 +1164,7 @@ int lex_do(lex_file *lex) { /* skip line */ ch = lex_getch(lex); - while (ch != EOF && ch != '\n') + while (ch != FS_FILE_EOF && ch != '\n') ch = lex_getch(lex); return lex_do(lex); } @@ -1472,14 +1474,10 @@ int lex_do(lex_file *lex) lex_endtoken(lex); lex->tok.ttype = TOKEN_CHARCONST; - /* It's a vector if we can successfully scan 3 floats */ -#ifdef _MSC_VER - if (sscanf_s(lex->tok.value, " %f %f %f ", - &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3) -#else - if (sscanf(lex->tok.value, " %f %f %f ", + + /* It's a vector if we can successfully scan 3 floats */ + if (util_sscanf(lex->tok.value, " %f %f %f ", &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3) -#endif { lex->tok.ttype = TOKEN_VECTORCONST; @@ -1487,9 +1485,9 @@ int lex_do(lex_file *lex) else { if (!lex->flags.preprocessing && strlen(lex->tok.value) > 1) { - uchar_t u8char; + utf8ch_t u8char; /* check for a valid utf8 character */ - if (!OPTS_FLAG(UTF8) || !u8_analyze(lex->tok.value, NULL, NULL, &u8char, 8)) { + if (!OPTS_FLAG(UTF8) || !utf8_to(&u8char, (const unsigned char *)lex->tok.value, 8)) { if (lexwarn(lex, WARN_MULTIBYTE_CHARACTER, ( OPTS_FLAG(UTF8) ? "invalid multibyte character sequence `%s`" : "multibyte character: `%s`" ),