Skip to content

Commit 00d0ae8

Browse files
committed
Avoid use of goto in nextLine
1 parent 2cdbb14 commit 00d0ae8

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

Diff for: src/link/sdas_obj.cpp

+23-20
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,31 @@ static char const *delim = " \f\n\r\t\v"; // Whitespace according to the C and P
3434

3535
static int
3636
nextLine(std::vector<char> &lineBuf, uint32_t &lineNo, FileStackNode const &where, FILE *file) {
37-
retry:
38-
++lineNo;
39-
int firstChar = getc(file);
40-
lineBuf.clear();
37+
int firstChar;
38+
for (;;) {
39+
++lineNo;
40+
firstChar = getc(file);
41+
lineBuf.clear();
4142

42-
switch (firstChar) {
43-
case EOF:
44-
return EOF;
45-
case ';':
46-
// Discard comment line
47-
// TODO: if `;!FILE [...]` on the first line (`lineNo`), return it
48-
do {
49-
firstChar = getc(file);
50-
} while (firstChar != EOF && firstChar != '\r' && firstChar != '\n');
51-
[[fallthrough]];
52-
case '\r':
53-
if (firstChar == '\r' && getc(file) != '\n') {
54-
consumeLF(where, lineNo, file);
43+
switch (firstChar) {
44+
case EOF:
45+
return EOF;
46+
case ';':
47+
// Discard comment line
48+
// TODO: if `;!FILE [...]` on the first line (`lineNo`), return it
49+
do {
50+
firstChar = getc(file);
51+
} while (firstChar != EOF && firstChar != '\r' && firstChar != '\n');
52+
[[fallthrough]];
53+
case '\r':
54+
if (firstChar == '\r' && getc(file) != '\n') {
55+
consumeLF(where, lineNo, file);
56+
}
57+
[[fallthrough]];
58+
case '\n':
59+
continue;
5560
}
56-
[[fallthrough]];
57-
case '\n':
58-
goto retry;
61+
break;
5962
}
6063

6164
for (;;) {

0 commit comments

Comments
 (0)