1
0
Fork 0

src/Scripting/NasalSys.cxx: show source line if we get error while parsing Nasal.

Helps track down errors in Nalsa embedded inside XML - line numbers are from
start of Nasal, not start of XML file.
This commit is contained in:
Julian Smith 2021-06-06 12:44:03 +01:00
parent 97a25b79ea
commit 31c7fc8565

View file

@ -1580,6 +1580,28 @@ naRef FGNasalSys::parse(naContext ctx, const char* filename,
" in "<< filename <<", line " << errLine;
errors = errorMessageStream.str();
SG_LOG(SG_NASAL, SG_ALERT, errors);
// Show the line, in case <filename> isn't a real file, e.g. nasal code
// is in an .xml file.
const char* line_begin = buf;
const char* line_end = nullptr;
int line_num = 1;
for(;;) {
line_end = strchr(line_begin, '\n');
if (!line_end) {
line_end = line_begin + strlen(line_begin);
break;
}
if (line_num == errLine) break;
line_begin = line_end + 1;
line_num += 1;
}
if (line_num == errLine) {
SG_LOG(SG_NASAL, SG_ALERT, std::string(line_begin, line_end) << "\n");
}
else {
SG_LOG(SG_NASAL, SG_ALERT, "[Could not find line " << errLine << " - only " << line_num << " lines.");
}
return naNil();
}