Now we allow spaces between the # and the directive.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@326 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2004-10-14 11:24:13 +00:00
parent a427a2050a
commit 71493c6b12
1 changed files with 445 additions and 423 deletions

View File

@ -173,8 +173,19 @@ void QCC_PR_NewLine (pbool incomment)
if (incomment) //no constants if in a comment.
{
}
else if (!strncmp(pr_file_p, "#define", 7))
else if (*pr_file_p == '#')
{
char *directive;
for (directive = pr_file_p+1; *directive; directive++)
{
if (*directive == '\r' || *directive == '\n')
QCC_PR_ParseError(ERR_UNKNOWNPUCTUATION, "Hanging # with no directive\n");
if (*directive > ' ')
break;
}
if (!strncmp(directive, "define", 6))
{
pr_file_p = directive;
QCC_PR_ConditionCompilation();
while(*pr_file_p != '\n' && *pr_file_p != '\0') //read on until the end of the line
{
@ -183,16 +194,16 @@ void QCC_PR_NewLine (pbool incomment)
if (!m)
pr_file_p++;
}
else if (!strncmp(pr_file_p, "#undef", 6))
else if (!strncmp(directive, "undef", 5))
{
pr_file_p+=6;
pr_file_p = directive+5;
while(*pr_file_p <= ' ')
pr_file_p++;
QCC_PR_SimpleGetToken ();
QCC_PR_UndefineName(pr_token);
// QCC_PR_ConditionCompilation();
// QCC_PR_ConditionCompilation();
while(*pr_file_p != '\n' && *pr_file_p != '\0') //read on until the end of the line
{
pr_file_p++;
@ -200,9 +211,9 @@ void QCC_PR_NewLine (pbool incomment)
if (!m)
pr_file_p++;
}
else if (!strncmp(pr_file_p, "#if", 3))
else if (!strncmp(directive, "if", 2))
{
pr_file_p+=3;
pr_file_p = directive+2;
if (!strncmp(pr_file_p, "def ", 4))
{
ifmode = 0;
@ -227,8 +238,8 @@ void QCC_PR_NewLine (pbool incomment)
{
pr_file_p++;
}
// pr_file_p++;
// pr_source_line++;
// pr_file_p++;
// pr_source_line++;
if (ifmode == 2)
{
@ -237,8 +248,8 @@ void QCC_PR_NewLine (pbool incomment)
}
else
{
// if (!STRCMP(pr_token, "COOP_MODE"))
// eval = false;
// if (!STRCMP(pr_token, "COOP_MODE"))
// eval = false;
if (QCC_PR_CheckCompConstDefined(pr_token))
eval = true;
@ -254,11 +265,16 @@ void QCC_PR_NewLine (pbool incomment)
{
while(*pr_file_p==' ' || *pr_file_p == '\t')
pr_file_p++;
if (!strncmp(pr_file_p, "#endif", 6))
if (*pr_file_p == '#')
{
pr_file_p++;
while(*pr_file_p==' ' || *pr_file_p == '\t')
pr_file_p++;
if (!strncmp(pr_file_p, "endif", 5))
level--;
if (!strncmp(pr_file_p, "#if", 3))
if (!strncmp(pr_file_p, "if", 2))
level++;
if (!strncmp(pr_file_p, "#else", 5) && level == 1)
if (!strncmp(pr_file_p, "else", 4) && level == 1)
{
ifs+=1;
while(*pr_file_p != '\n' && *pr_file_p != '\0') //read on until the end of the line
@ -267,6 +283,7 @@ void QCC_PR_NewLine (pbool incomment)
}
break;
}
}
while(*pr_file_p != '\n' && *pr_file_p != '\0') //read on until the end of the line
{
@ -279,7 +296,7 @@ void QCC_PR_NewLine (pbool incomment)
}
}
}
else if (!strncmp(pr_file_p, "#else", 5))
else if (!strncmp(directive, "else", 4))
{
ifs -= 1;
level = 1;
@ -292,15 +309,22 @@ void QCC_PR_NewLine (pbool incomment)
{
while(*pr_file_p==' ' || *pr_file_p == '\t')
pr_file_p++;
if (!strncmp(pr_file_p, "#endif", 6))
if (*pr_file_p == '#')
{
pr_file_p++;
while(*pr_file_p==' ' || *pr_file_p == '\t')
pr_file_p++;
if (!strncmp(pr_file_p, "endif", 5))
level--;
if (!strncmp(pr_file_p, "#if", 3))
if (!strncmp(pr_file_p, "if", 2))
level++;
if (!strncmp(pr_file_p, "#else", 5) && level == 1)
if (!strncmp(pr_file_p, "else", 4) && level == 1)
{
ifs+=1;
break;
}
}
while(*pr_file_p != '\n' && *pr_file_p != '\0') //read on until the end of the line
{
@ -312,7 +336,7 @@ void QCC_PR_NewLine (pbool incomment)
pr_source_line++;
}
}
else if (!strncmp(pr_file_p, "#endif", 6))
else if (!strncmp(directive, "endif", 5))
{
while(*pr_file_p != '\n' && *pr_file_p != '\0') //read on until the end of the line
{
@ -323,14 +347,14 @@ void QCC_PR_NewLine (pbool incomment)
else
ifs-=1;
}
else if (!strncmp(pr_file_p, "#eof", 4))
else if (!strncmp(directive, "eof", 3))
{
pr_file_p = NULL;
return;
}
else if (!strncmp(pr_file_p, "#error", 6))
else if (!strncmp(directive, "error", 5))
{
pr_file_p += 6;
pr_file_p = directive+5;
for (a = 0; a < 1023 && pr_file_p[a] != '\n' && pr_file_p[a] != '\0'; a++)
msg[a] = pr_file_p[a];
@ -343,9 +367,9 @@ void QCC_PR_NewLine (pbool incomment)
QCC_PR_ParseError(ERR_HASHERROR, "#Error: %s", msg);
}
else if (!strncmp(pr_file_p, "#warning", 8))
else if (!strncmp(directive, "warning", 7))
{
pr_file_p += 8;
pr_file_p = directive+7;
for (a = 0; a < 1023 && pr_file_p[a] != '\n' && pr_file_p[a] != '\0'; a++)
msg[a] = pr_file_p[a];
@ -358,9 +382,9 @@ void QCC_PR_NewLine (pbool incomment)
QCC_PR_ParseWarning(WARN_PRECOMPILERMESSAGE, "#warning: %s", msg);
}
else if (!strncmp(pr_file_p, "#message", 8))
else if (!strncmp(directive, "message", 7))
{
pr_file_p += 8;
pr_file_p = directive+7;
for (a = 0; a < 1023 && pr_file_p[a] != '\n' && pr_file_p[a] != '\0'; a++)
msg[a] = pr_file_p[a];
@ -373,9 +397,9 @@ void QCC_PR_NewLine (pbool incomment)
printf("#message: %s\n", msg);
}
else if (!strncmp(pr_file_p, "#copyright", 10))
else if (!strncmp(directive, "copyright", 9))
{
pr_file_p += 10;
pr_file_p = directive+9;
for (a = 0; a < 1023 && pr_file_p[a] != '\n' && pr_file_p[a] != '\0'; a++)
msg[a] = pr_file_p[a];
@ -390,10 +414,10 @@ void QCC_PR_NewLine (pbool incomment)
QCC_PR_ParseWarning(WARN_STRINGTOOLONG, "Copyright message is too long\n");
strncpy(QCC_copyright, msg, sizeof(QCC_copyright)-1);
}
else if (!strncmp(pr_file_p, "#pack", 5))
else if (!strncmp(directive, "pack", 4))
{
ifmode = 0;
pr_file_p+=5;
pr_file_p=directive+4;
if (!strncmp(pr_file_p, "id", 2))
pr_file_p+=3;
else
@ -420,9 +444,9 @@ void QCC_PR_NewLine (pbool incomment)
else
QCC_PR_ParseError(ERR_TOOMANYPACKFILES, "No more than 5 packs are allowed");
}
else if (!strncmp(pr_file_p, "#forcecrc", 9))
else if (!strncmp(directive, "forcecrc", 8))
{
pr_file_p+=9;
pr_file_p=directive+8;
ForcedCRC = QCC_PR_LexInteger();
@ -438,9 +462,9 @@ void QCC_PR_NewLine (pbool incomment)
pr_file_p++;
}
}
else if (!strncmp(pr_file_p, "#includelist", 12))
else if (!strncmp(directive, "includelist", 11))
{
pr_file_p+=12;
pr_file_p=directive+11;
while(*pr_file_p <= ' ')
pr_file_p++;
@ -483,9 +507,9 @@ void QCC_PR_NewLine (pbool incomment)
pr_file_p++;
}
}
else if (!strncmp(pr_file_p, "#include", 8))
else if (!strncmp(directive, "include", 7))
{
pr_file_p+=8;
pr_file_p=directive+7;
while(*pr_file_p <= ' ')
pr_file_p++;
@ -506,9 +530,9 @@ void QCC_PR_NewLine (pbool incomment)
pr_file_p++;
}
}
else if (!strncmp(pr_file_p, "#datafile", 9))
else if (!strncmp(directive, "datafile", 8))
{
pr_file_p+=9;
pr_file_p=directive+8;
while(*pr_file_p <= ' ')
pr_file_p++;
@ -529,13 +553,10 @@ void QCC_PR_NewLine (pbool incomment)
pr_file_p++;
}
}
else if (!strncmp(pr_file_p, "#output", 7))
else if (!strncmp(directive, "output", 6))
{
extern char destfile[1024];
if (pr_file_p[1] == 'p')
pr_file_p+=17;
else
pr_file_p+=7;
pr_file_p=directive+6;
while(*pr_file_p <= ' ')
pr_file_p++;
@ -556,9 +577,9 @@ void QCC_PR_NewLine (pbool incomment)
pr_file_p++;
}
}
else if (!strncmp(pr_file_p, "#pragma", 7))
else if (!strncmp(directive, "pragma", 6))
{
pr_file_p+=7;
pr_file_p=directive+6;
while(*pr_file_p <= ' ')
pr_file_p++;
@ -670,6 +691,7 @@ void QCC_PR_NewLine (pbool incomment)
else
QCC_PR_ParseWarning(WARN_BADPRAGMA, "Unknown pragma \'%s\'", qcc_token);
}
}
// if (pr_dumpasm)
// PR_PrintNextLine ();
@ -1376,7 +1398,7 @@ void QCC_PR_LexGrab (void)
// QCC_PR_ParseError ("hanging $");
if (*pr_file_p <= ' ')
QCC_PR_ParseError (ERR_BADFRAMEMACRO, "hanging $");
QCC_PR_LexName();
QCC_PR_SimpleGetToken();
if (!*pr_token)
QCC_PR_ParseError (ERR_BADFRAMEMACRO, "hanging $");