Recursion bad... handle C++ style comments

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2369 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Brian Macy
1999-05-09 02:35:00 +00:00
parent c00dee5597
commit 631cefffd4

View File

@@ -1478,46 +1478,59 @@ bool wxReallocateResourceBuffer()
static bool wxEatWhiteSpace(FILE *fd) static bool wxEatWhiteSpace(FILE *fd)
{ {
int ch = getc(fd); int ch = 0;
if ((ch != ' ') && (ch != '/') && (ch != ' ') && (ch != 10) && (ch != 13) && (ch != 9))
while ((ch = getc(fd)) != EOF)
{ {
ungetc(ch, fd); switch (ch)
{
case ' ':
case 0x0a:
case 0x0d:
case 0x09:
break;
case '/':
{
int prev_ch = ch;
ch = getc(fd);
if (ch == EOF)
{
ungetc(prev_ch, fd);
return TRUE; return TRUE;
} }
// Eat whitespace
while (ch == ' ' || ch == 10 || ch == 13 || ch == 9)
ch = getc(fd);
// Check for comment
if (ch == '/')
{
ch = getc(fd);
if (ch == '*') if (ch == '*')
{ {
bool finished = FALSE; // Eat C comment
while (!finished) prev_ch = 0;
while ((ch = getc(fd)) != EOF)
{ {
ch = getc(fd); if (ch == '/' && prev_ch == '*')
if (ch == EOF) break;
return FALSE; prev_ch = ch;
if (ch == '*') }
}
else if (ch == '/')
{ {
int newCh = getc(fd); // Eat C++ comment
if (newCh == '/') static char buffer[255];
finished = TRUE; fgets(buffer, 255, fd);
}
else else
{ {
ungetc(newCh, fd); ungetc(prev_ch, fd);
}
}
}
}
else // False alarm
return FALSE;
}
else
ungetc(ch, fd); ungetc(ch, fd);
return wxEatWhiteSpace(fd); return TRUE;
}
}
break;
default:
ungetc(ch, fd);
return TRUE;
}
}
return FALSE;
} }
bool wxGetResourceToken(FILE *fd) bool wxGetResourceToken(FILE *fd)
@@ -2545,49 +2558,53 @@ static int ungetc_string()
bool wxEatWhiteSpaceString(char *s) bool wxEatWhiteSpaceString(char *s)
{ {
int ch = getc_string(s); int ch = 0;
if (ch == EOF)
return TRUE;
if ((ch != ' ') && (ch != '/') && (ch != ' ') && (ch != 10) && (ch != 13) && (ch != 9)) while ((ch = getc_string(s)) != EOF)
{
switch (ch)
{
case ' ':
case 0x0a:
case 0x0d:
case 0x09:
break;
case '/':
{
int prev_ch = ch;
ch = getc_string(s);
if (ch == EOF)
{ {
ungetc_string(); ungetc_string();
return TRUE; return TRUE;
} }
// Eat whitespace
while (ch == ' ' || ch == 10 || ch == 13 || ch == 9)
ch = getc_string(s);
// Check for comment
if (ch == '/')
{
ch = getc_string(s);
if (ch == '*') if (ch == '*')
{ {
bool finished = FALSE; // Eat C comment
while (!finished) prev_ch = 0;
while ((ch = getc_string(s)) != EOF)
{ {
ch = getc_string(s); if (ch == '/' && prev_ch == '*')
if (ch == EOF) break;
return FALSE; prev_ch = ch;
if (ch == '*') }
{ }
int newCh = getc_string(s);
if (newCh == '/')
finished = TRUE;
else else
{ {
ungetc_string(); ungetc_string();
}
}
}
}
else // False alarm
return FALSE;
}
else if (ch != EOF)
ungetc_string(); ungetc_string();
return wxEatWhiteSpaceString(s); return TRUE;
}
}
break;
default:
ungetc_string();
return TRUE;
}
}
return FALSE;
} }
bool wxGetResourceTokenString(char *s) bool wxGetResourceTokenString(char *s)