// Positions in a record file (sequential or direct, not stream)
std::int64_t currentRecordNumber{1}; // 1 is first
std::int64_t positionInRecord{0}; // offset in current record
- std::int64_t furthestPositionInRecord{0}; // max(positionInRecord)
+ std::int64_t furthestPositionInRecord{0}; // max(position+bytes)
bool nonAdvancing{false}; // ADVANCE='NO'
// Set at end of non-advancing I/O data transfer
while (true) {
std::optional<int> repeat;
bool unlimited{false};
- CharType ch{Capitalize(GetNextChar(context))};
+ CharType ch{GetNextChar(context)};
while (ch == ',' || ch == ':') {
// Skip commas, and don't complain if they're missing; the format
// validator does that.
if (stop && ch == ':') {
return 0;
}
- ch = Capitalize(GetNextChar(context));
+ ch = GetNextChar(context);
}
if (ch == '-' || ch == '+' || (ch >= '0' && ch <= '9')) {
repeat = GetIntField(context, ch);
return 0;
}
}
+ ch = Capitalize(ch);
if (ch == '(') {
if (height_ >= maxHeight_) {
context.SignalError(IostatErrorInFormat,
}
}
+static void CloseAllExternalUnits(const char *why) {
+ Fortran::runtime::io::IoErrorHandler handler{why};
+ Fortran::runtime::io::ExternalFileUnit::CloseAll(handler);
+}
+
[[noreturn]] void RTNAME(StopStatement)(
int code, bool isErrorStop, bool quiet) {
+ CloseAllExternalUnits("STOP statement");
if (!quiet) {
if (code != EXIT_SUCCESS) {
std::fprintf(stderr, "Fortran %s: code %d\n",
[[noreturn]] void RTNAME(StopStatementText)(
const char *code, bool isErrorStop, bool quiet) {
+ CloseAllExternalUnits("STOP statement");
if (!quiet) {
std::fprintf(
stderr, "Fortran %s: %s\n", isErrorStop ? "ERROR STOP" : "STOP", code);
[[noreturn]] void RTNAME(FailImageStatement)() {
Fortran::runtime::NotifyOtherImagesOfFailImageStatement();
+ CloseAllExternalUnits("FAIL IMAGE statement");
std::exit(EXIT_FAILURE);
}
[[noreturn]] void RTNAME(ProgramEndStatement)() {
- Fortran::runtime::io::IoErrorHandler handler{"END statement"};
- Fortran::runtime::io::ExternalFileUnit::CloseAll(handler);
+ CloseAllExternalUnits("END statement");
std::exit(EXIT_SUCCESS);
}
}
return false;
}
WriteFrame(frameOffsetInFile_, recordOffsetInFrame_ + furthestAfter, handler);
+ if (positionInRecord > furthestPositionInRecord) {
+ std::memset(Frame() + furthestPositionInRecord, ' ',
+ positionInRecord - furthestPositionInRecord);
+ }
std::memcpy(Frame() + positionInRecord, data, bytes);
positionInRecord += bytes;
furthestPositionInRecord = furthestAfter;
' ', *recordLength - furthestPositionInRecord);
}
} else {
- positionInRecord = furthestPositionInRecord + 1;
+ positionInRecord = furthestPositionInRecord;
ok &= Emit("\n", 1, handler); // TODO: Windows CR+LF
frameOffsetInFile_ += recordOffsetInFrame_ + furthestPositionInRecord;
recordOffsetInFrame_ = 0;