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))
{
ungetc(ch, fd);
return TRUE;
}
// Eat whitespace while ((ch = getc(fd)) != EOF)
while (ch == ' ' || ch == 10 || ch == 13 || ch == 9)
ch = getc(fd);
// Check for comment
if (ch == '/')
{
ch = getc(fd);
if (ch == '*')
{
bool finished = FALSE;
while (!finished)
{ {
ch = getc(fd); switch (ch)
if (ch == EOF) {
return FALSE; case ' ':
if (ch == '*') case 0x0a:
{ case 0x0d:
int newCh = getc(fd); case 0x09:
if (newCh == '/') break;
finished = TRUE; case '/':
else {
{ int prev_ch = ch;
ungetc(newCh, fd); ch = getc(fd);
} if (ch == EOF)
} {
ungetc(prev_ch, fd);
return TRUE;
}
if (ch == '*')
{
// Eat C comment
prev_ch = 0;
while ((ch = getc(fd)) != EOF)
{
if (ch == '/' && prev_ch == '*')
break;
prev_ch = ch;
}
}
else if (ch == '/')
{
// Eat C++ comment
static char buffer[255];
fgets(buffer, 255, fd);
}
else
{
ungetc(prev_ch, fd);
ungetc(ch, fd);
return TRUE;
}
}
break;
default:
ungetc(ch, fd);
return TRUE;
}
} }
} return FALSE;
else // False alarm
return FALSE;
}
else
ungetc(ch, fd);
return wxEatWhiteSpace(fd);
} }
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)
{
ungetc_string();
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 == '*')
{
bool finished = FALSE;
while (!finished)
{ {
ch = getc_string(s); switch (ch)
if (ch == EOF) {
return FALSE; case ' ':
if (ch == '*') case 0x0a:
{ case 0x0d:
int newCh = getc_string(s); case 0x09:
if (newCh == '/') break;
finished = TRUE; case '/':
else {
{ int prev_ch = ch;
ch = getc_string(s);
if (ch == EOF)
{
ungetc_string();
return TRUE;
}
if (ch == '*')
{
// Eat C comment
prev_ch = 0;
while ((ch = getc_string(s)) != EOF)
{
if (ch == '/' && prev_ch == '*')
break;
prev_ch = ch;
}
}
else
{
ungetc_string();
ungetc_string();
return TRUE;
}
}
break;
default:
ungetc_string(); ungetc_string();
} return TRUE;
}
}
} }
} return FALSE;
else // False alarm
return FALSE;
}
else if (ch != EOF)
ungetc_string();
return wxEatWhiteSpaceString(s);
} }
bool wxGetResourceTokenString(char *s) bool wxGetResourceTokenString(char *s)