preprocessor: Better warning when illegal character found
This commit is contained in:
parent
2018c25d20
commit
1cd9496039
|
@ -40,6 +40,8 @@ void Preprocessor::preprocess(std::istream &istr, std::map<std::string, std::str
|
|||
{
|
||||
// Get filedata from stream..
|
||||
bool ignoreSpace = true;
|
||||
|
||||
int lineno = 1;
|
||||
|
||||
std::ostringstream code;
|
||||
for (char ch = (char)istr.get(); istr.good(); ch = (char)istr.get())
|
||||
|
@ -47,14 +49,15 @@ void Preprocessor::preprocess(std::istream &istr, std::map<std::string, std::str
|
|||
if ( ch < 0 )
|
||||
{
|
||||
// Bad content..
|
||||
errout << "[" << filename << "] Bad character found: " << int((unsigned char)ch) << std::endl;
|
||||
errout << "[" << filename << ":" << lineno << "] Bad character found: " << int((unsigned char)ch) << std::endl;
|
||||
result.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ch == '\n' )
|
||||
++lineno;
|
||||
|
||||
// Replace assorted special chars with spaces..
|
||||
if ( ch < 0 )
|
||||
ch = ' ';
|
||||
if ( (ch != '\n') && (isspace(ch) || iscntrl(ch)) )
|
||||
ch = ' ';
|
||||
|
||||
|
@ -72,7 +75,8 @@ void Preprocessor::preprocess(std::istream &istr, std::map<std::string, std::str
|
|||
{
|
||||
while (istr.good() && ch!='\n')
|
||||
ch = (char)istr.get();
|
||||
code << "\n";
|
||||
code << "\n";
|
||||
++lineno;
|
||||
}
|
||||
|
||||
else if ( chNext == '*' )
|
||||
|
@ -82,13 +86,18 @@ void Preprocessor::preprocess(std::istream &istr, std::map<std::string, std::str
|
|||
{
|
||||
chPrev = ch;
|
||||
ch = (char)istr.get();
|
||||
if (ch == '\n')
|
||||
code << "\n";
|
||||
if (ch == '\n')
|
||||
{
|
||||
code << "\n";
|
||||
++lineno;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
{
|
||||
if ( chNext == '\n' )
|
||||
++lineno;
|
||||
code << std::string(1,ch) << std::string(1,chNext);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue