Skip to content

Commit b49dbb8

Browse files
committed
Merge branch 'albert-github-feature/bug_pre_stderr'
2 parents e3a54a2 + 08dd2ed commit b49dbb8

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

src/pre.l

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4053,17 +4053,39 @@ void Preprocessor::processFile(const QCString &fileName,const std::string &input
40534053
{
40544054
std::lock_guard<std::mutex> lock(g_debugMutex);
40554055
Debug::print(Debug::Preprocessor,0,"Preprocessor output of %s (size: %zu bytes):\n",qPrint(fileName),output.size());
4056-
int line=1;
4057-
Debug::print(Debug::Preprocessor,0,"---------\n");
4058-
if (!Debug::isFlagSet(Debug::NoLineNo)) Debug::print(Debug::Preprocessor,0,"00001 ");
4059-
size_t pos=0;
4060-
while (pos<output.size())
4056+
std::string contents;
4057+
if (Debug::isFlagSet(Debug::NoLineNo))
40614058
{
4062-
putchar(output[pos]);
4063-
if (output[pos]=='\n' && !Debug::isFlagSet(Debug::NoLineNo)) Debug::print(Debug::Preprocessor,0,"%05d ",++line);
4064-
pos++;
4059+
contents=output;
40654060
}
4066-
Debug::print(Debug::Preprocessor,0,"\n---------\n");
4061+
else // need to add line numbers
4062+
{
4063+
int line=1;
4064+
bool startOfLine = true;
4065+
size_t content_size = output.size() +
4066+
output.size()*6/40; // assuming 40 chars per line on average
4067+
// and 6 chars extra for the line number
4068+
contents.reserve(content_size);
4069+
size_t pos=0;
4070+
while (pos<output.size())
4071+
{
4072+
if (startOfLine)
4073+
{
4074+
char lineNrStr[10];
4075+
snprintf(lineNrStr,10,"%05d ",line++);
4076+
contents+=lineNrStr;
4077+
}
4078+
contents += output[pos];
4079+
startOfLine = output[pos]=='\n';
4080+
pos++;
4081+
}
4082+
}
4083+
char end[2]={0,0};
4084+
if (!contents.empty() && contents[contents.length()-1]!='\n')
4085+
{
4086+
end[0]='\n';
4087+
}
4088+
Debug::print(Debug::Preprocessor,0,"---------\n%s%s---------\n",contents.c_str(),end);
40674089
if (yyextra->contextDefines.size()>0)
40684090
{
40694091
Debug::print(Debug::Preprocessor,0,"Macros accessible in this file (%s):\n", qPrint(fileName));

0 commit comments

Comments
 (0)