Avoid use of goto in nextLine

This commit is contained in:
Rangi42
2025-02-27 14:28:17 -05:00
parent 2cdbb145da
commit 00d0ae840d

View File

@@ -34,28 +34,31 @@ static char const *delim = " \f\n\r\t\v"; // Whitespace according to the C and P
static int static int
nextLine(std::vector<char> &lineBuf, uint32_t &lineNo, FileStackNode const &where, FILE *file) { nextLine(std::vector<char> &lineBuf, uint32_t &lineNo, FileStackNode const &where, FILE *file) {
retry: int firstChar;
++lineNo; for (;;) {
int firstChar = getc(file); ++lineNo;
lineBuf.clear(); firstChar = getc(file);
lineBuf.clear();
switch (firstChar) { switch (firstChar) {
case EOF: case EOF:
return EOF; return EOF;
case ';': case ';':
// Discard comment line // Discard comment line
// TODO: if `;!FILE [...]` on the first line (`lineNo`), return it // TODO: if `;!FILE [...]` on the first line (`lineNo`), return it
do { do {
firstChar = getc(file); firstChar = getc(file);
} while (firstChar != EOF && firstChar != '\r' && firstChar != '\n'); } while (firstChar != EOF && firstChar != '\r' && firstChar != '\n');
[[fallthrough]]; [[fallthrough]];
case '\r': case '\r':
if (firstChar == '\r' && getc(file) != '\n') { if (firstChar == '\r' && getc(file) != '\n') {
consumeLF(where, lineNo, file); consumeLF(where, lineNo, file);
}
[[fallthrough]];
case '\n':
continue;
} }
[[fallthrough]]; break;
case '\n':
goto retry;
} }
for (;;) { for (;;) {