diff options
Diffstat (limited to 'flang-rt/lib/runtime/edit-input.cpp')
-rw-r--r-- | flang-rt/lib/runtime/edit-input.cpp | 65 |
1 files changed, 39 insertions, 26 deletions
diff --git a/flang-rt/lib/runtime/edit-input.cpp b/flang-rt/lib/runtime/edit-input.cpp index 1355767..0c2a4cc 100644 --- a/flang-rt/lib/runtime/edit-input.cpp +++ b/flang-rt/lib/runtime/edit-input.cpp @@ -37,9 +37,7 @@ static RT_API_ATTRS bool CheckCompleteListDirectedField( if (edit.IsListDirected()) { std::size_t byteCount; if (auto ch{io.GetCurrentChar(byteCount)}) { - if (IsCharValueSeparator(edit, *ch)) { - return true; - } else { + if (!IsCharValueSeparator(edit, *ch)) { const auto &connection{io.GetConnectionState()}; io.GetIoErrorHandler().SignalError(IostatBadListDirectedInputSeparator, "invalid character (0x%x) after list-directed input value, " @@ -49,12 +47,9 @@ static RT_API_ATTRS bool CheckCompleteListDirectedField( static_cast<int>(connection.currentRecordNumber)); return false; } - } else { - return true; // end of record: ok } - } else { - return true; } + return true; } template <int LOG2_BASE> @@ -349,8 +344,8 @@ static RT_API_ATTRS ScannedRealInput ScanRealInput( } bool bzMode{(edit.modes.editingFlags & blankZero) != 0}; int exponent{0}; - if (!next || (!bzMode && *next == ' ') || - (!(edit.modes.editingFlags & decimalComma) && *next == ',')) { + const char32_t comma{GetSeparatorChar(edit)}; + if (!next || (!bzMode && *next == ' ') || *next == comma) { if (!edit.IsListDirected() && !io.GetConnectionState().IsAtEOF()) { // An empty/blank field means zero when not list-directed. // A fixed-width field containing only a sign is also zero; @@ -375,21 +370,37 @@ static RT_API_ATTRS ScannedRealInput ScanRealInput( Put(*next); } } - if (next && *next == '(') { // NaN(...) - Put('('); - int depth{1}; - while (true) { - next = io.NextInField(remaining, edit); - if (depth == 0) { - break; - } else if (!next) { - return {}; // error - } else if (*next == '(') { - ++depth; - } else if (*next == ')') { - --depth; + if (first == 'N' && (!next || *next == '(') && + remaining.value_or(1) > 0) { // NaN(...)? + std::size_t byteCount{0}; + if (!next) { // NextInField won't return '(' for list-directed + next = io.GetCurrentChar(byteCount); + } + if (next && *next == '(') { + int depth{1}; + while (true) { + if (*next >= 'a' && *next <= 'z') { + *next = *next - 'a' + 'A'; + } + Put(*next); + io.HandleRelativePosition(byteCount); + io.GotChar(byteCount); + if (remaining) { + *remaining -= byteCount; + } + if (depth == 0) { + break; // done + } + next = io.GetCurrentChar(byteCount); + if (!next || remaining.value_or(1) < 1) { + return {}; // error + } else if (*next == '(') { + ++depth; + } else if (*next == ')') { + --depth; + } } - Put(*next); + next = io.NextInField(remaining, edit); } } } else if (first == radixPointChar || (first >= '0' && first <= '9') || @@ -521,9 +532,11 @@ static RT_API_ATTRS ScannedRealInput ScanRealInput( io.SkipSpaces(remaining); next = io.NextInField(remaining, edit); } - if (!next) { // NextInField fails on separators like ')' + if (!next || *next == ')') { // NextInField fails on separators like ')' std::size_t byteCount{0}; - next = io.GetCurrentChar(byteCount); + if (!next) { + next = io.GetCurrentChar(byteCount); + } if (next && *next == ')') { io.HandleRelativePosition(byteCount); } @@ -532,7 +545,7 @@ static RT_API_ATTRS ScannedRealInput ScanRealInput( while (next && (*next == ' ' || *next == '\t')) { next = io.NextInField(remaining, edit); } - if (next && (*next != ',' || (edit.modes.editingFlags & decimalComma))) { + if (next && *next != comma) { return {}; // error: unused nonblank character in fixed-width field } } |