mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-11-27 22:22:17 +00:00
Merge branch 'master' into ast-and-ir
This commit is contained in:
commit
206952b920
14 changed files with 152 additions and 158 deletions
3
.gitattributes
vendored
Normal file
3
.gitattributes
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
#dissalow trailing whitespace
|
||||
*.c whitespace=-trailing-space
|
||||
*.h whitespace=-trailing-space
|
2
gmqcc.h
2
gmqcc.h
|
@ -271,8 +271,6 @@ uint32_t util_crc32(const char *, int, register const short);
|
|||
#define VECTOR_MAKE(T,N) \
|
||||
VECTOR_TYPE(T,N); \
|
||||
VECTOR_CORE(T,N)
|
||||
/* Builds a vector add function pointer for inside structures */
|
||||
#define VECTOR_IMPL(T,N) int (*N##_add)(T)
|
||||
|
||||
//===================================================================
|
||||
//=========================== code.c ================================
|
||||
|
|
45
lex.c
45
lex.c
|
@ -48,7 +48,7 @@ void lex_init(const char *file, lex_file **set) {
|
|||
lex->size = lex->length; /* copy, this is never changed */
|
||||
fseek(lex->file, 0, SEEK_SET);
|
||||
lex->last = 0;
|
||||
lex->line = 0;
|
||||
lex->line = 1;
|
||||
|
||||
memset(lex->peek, 0, sizeof(lex->peek));
|
||||
*set = lex;
|
||||
|
@ -77,14 +77,25 @@ static inline void lex_clear(lex_file *file) {
|
|||
* it's own internal state for this.
|
||||
*/
|
||||
static int lex_inget(lex_file *file) {
|
||||
char get;
|
||||
file->length --;
|
||||
if (file->last > 0)
|
||||
return file->peek[--file->last];
|
||||
return fgetc(file->file);
|
||||
|
||||
if (file->last > 0) {
|
||||
if ((get = file->peek[--file->last]) == '\n')
|
||||
file->line ++;
|
||||
return get;
|
||||
}
|
||||
if ((get = fgetc(file->file)) == '\n')
|
||||
file->line++;
|
||||
|
||||
return get;
|
||||
}
|
||||
static void lex_unget(int ch, lex_file *file) {
|
||||
if (file->last < sizeof(file->peek))
|
||||
if (file->last < sizeof(file->peek)) {
|
||||
if (ch == '\n')
|
||||
file->line --;
|
||||
file->peek[file->last++] = ch;
|
||||
}
|
||||
file->length ++;
|
||||
}
|
||||
|
||||
|
@ -139,22 +150,10 @@ static int lex_digraph(lex_file *file, int first) {
|
|||
|
||||
static int lex_getch(lex_file *file) {
|
||||
int ch = lex_inget(file);
|
||||
|
||||
static int str = 0;
|
||||
switch (ch) {
|
||||
case '?' :
|
||||
if (ch == '?')
|
||||
return lex_trigraph(file);
|
||||
case '<' :
|
||||
case ':' :
|
||||
case '%' :
|
||||
case '"' : str = !str; if (str) { file->line ++; }
|
||||
if (ch == '<' || ch == ':' || ch == '%')
|
||||
return lex_digraph(file, ch);
|
||||
|
||||
case '\n':
|
||||
if (!str)
|
||||
file->line++;
|
||||
}
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
@ -283,13 +282,7 @@ int lex_token(lex_file *file) {
|
|||
if (ch > 0 && (ch == '_' || isalpha(ch))) {
|
||||
lex_clear(file);
|
||||
|
||||
/*
|
||||
* Yes this is dirty, but there is no other _sane_ easy
|
||||
* way to do it, this is what I call defensive programming
|
||||
* if something breaks, add more defense :-)
|
||||
*/
|
||||
while (ch > 0 && ch != ' ' && ch != '(' &&
|
||||
ch != '\n' && ch != ';' && ch != ')') {
|
||||
while (ch > 0 && (ch == '_' || isalpha(ch))) {
|
||||
lex_addch(ch, file);
|
||||
ch = lex_getsource(file);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue