diff options
Diffstat (limited to 'Source/cmFortranParserImpl.cxx')
-rw-r--r-- | Source/cmFortranParserImpl.cxx | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/Source/cmFortranParserImpl.cxx b/Source/cmFortranParserImpl.cxx index 71edf9f..639b3f0 100644 --- a/Source/cmFortranParserImpl.cxx +++ b/Source/cmFortranParserImpl.cxx @@ -119,8 +119,19 @@ int cmFortranParser_Input(cmFortranParser* parser, char* buffer, // Read from the file on top of the stack. If the stack is empty, // the end of the translation unit has been reached. if (!parser->FileStack.empty()) { - FILE* file = parser->FileStack.top().File; - return (int)fread(buffer, 1, bufferSize, file); + cmFortranFile& ff = parser->FileStack.top(); + FILE* file = ff.File; + size_t n = fread(buffer, 1, bufferSize, file); + if (n > 0) { + ff.LastCharWasNewline = buffer[n - 1] == '\n'; + } else if (!ff.LastCharWasNewline) { + // The file ended without a newline. Inject one so + // that the file always ends in an end-of-statement. + buffer[0] = '\n'; + n = 1; + ff.LastCharWasNewline = true; + } + return (int)n; } return 0; } @@ -164,11 +175,9 @@ int cmFortranParser_GetOldStartcond(cmFortranParser* parser) return parser->OldStartcond; } -void cmFortranParser_Error(cmFortranParser* /*unused*/, const char* /*unused*/) +void cmFortranParser_Error(cmFortranParser* parser, const char* msg) { - // If there is a parser error just ignore it. The source will not - // compile and the user will edit it. Then dependencies will have - // to be regenerated anyway. + parser->Error = msg ? msg : "unknown error"; } void cmFortranParser_RuleUse(cmFortranParser* parser, const char* name) |