Show additional lines for config errors.

Refs #5825
This commit is contained in:
Gunnar Beutner 2014-03-21 15:51:55 +01:00
parent 0b90444dd8
commit c286c25183
1 changed files with 17 additions and 13 deletions

View File

@ -51,6 +51,8 @@ DebugInfo icinga::DebugInfoRange(const DebugInfo& start, const DebugInfo& end)
return result; return result;
} }
#define EXTRA_LINES 2
void icinga::ShowCodeFragment(std::ostream& out, const DebugInfo& di) void icinga::ShowCodeFragment(std::ostream& out, const DebugInfo& di)
{ {
if (di.Path.IsEmpty()) if (di.Path.IsEmpty())
@ -62,18 +64,19 @@ void icinga::ShowCodeFragment(std::ostream& out, const DebugInfo& di)
int lineno = 1; int lineno = 1;
char line[1024]; char line[1024];
while (ifs.good() && lineno <= di.LastLine) { while (ifs.good() && lineno <= di.LastLine + EXTRA_LINES) {
ifs.getline(line, sizeof(line)); ifs.getline(line, sizeof(line));
for (int i = 0; line[i]; i++) for (int i = 0; line[i]; i++)
if (line[i] == '\t') if (line[i] == '\t')
line[i] = ' '; line[i] = ' ';
if (lineno >= di.FirstLine && lineno <= di.LastLine) { if (lineno >= di.FirstLine - EXTRA_LINES && lineno <= di.LastLine + EXTRA_LINES) {
String pathInfo = di.Path + "(" + Convert::ToString(lineno) + "): "; String pathInfo = di.Path + "(" + Convert::ToString(lineno) + "): ";
out << pathInfo; out << pathInfo;
out << line << "\n"; out << line << "\n";
if (lineno >= di.FirstLine && lineno <= di.LastLine) {
int start, end; int start, end;
start = 0; start = 0;
@ -91,6 +94,7 @@ void icinga::ShowCodeFragment(std::ostream& out, const DebugInfo& di)
out << "\n"; out << "\n";
} }
}
lineno++; lineno++;
} }