mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +00:00
Avoid use of goto in nextLine
This commit is contained in:
@@ -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 (;;) {
|
||||||
|
|||||||
Reference in New Issue
Block a user