|
@ -60,6 +60,9 @@ ORCA_FORCE_NO_INLINE |
|
|
Conf_read_result conf_read_line(FILE* file, char* buf, Usz bufsize, |
|
|
Conf_read_result conf_read_line(FILE* file, char* buf, Usz bufsize, |
|
|
char** out_left, Usz* out_leftsize, |
|
|
char** out_left, Usz* out_leftsize, |
|
|
char** out_right, Usz* out_rightsize) { |
|
|
char** out_right, Usz* out_rightsize) { |
|
|
|
|
|
// a0 and a1 are the start and end positions of the left side of an "foo=bar"
|
|
|
|
|
|
// pair. b0 and b1 are the positions right side. Leading and trailing spaces
|
|
|
|
|
|
// will be removed.
|
|
|
Usz len, a0, a1, b0, b1; |
|
|
Usz len, a0, a1, b0, b1; |
|
|
char* s; |
|
|
char* s; |
|
|
if (bufsize < 2) |
|
|
if (bufsize < 2) |
|
@ -77,8 +80,8 @@ Conf_read_result conf_read_line(FILE* file, char* buf, Usz bufsize, |
|
|
len = strlen(buf); |
|
|
len = strlen(buf); |
|
|
if (len == bufsize - 1 && buf[len - 1] != '\n' && !feof(file)) |
|
|
if (len == bufsize - 1 && buf[len - 1] != '\n' && !feof(file)) |
|
|
goto insufficient_buffer; |
|
|
goto insufficient_buffer; |
|
|
a0 = 0; // start of left
|
|
|
a0 = 0; |
|
|
for (;;) { |
|
|
for (;;) { // scan for first non-space in " foo=bar"
|
|
|
if (a0 == len) |
|
|
if (a0 == len) |
|
|
goto ignore; |
|
|
goto ignore; |
|
|
char c = s[a0]; |
|
|
char c = s[a0]; |
|
@ -90,13 +93,13 @@ Conf_read_result conf_read_line(FILE* file, char* buf, Usz bufsize, |
|
|
break; |
|
|
break; |
|
|
a0++; |
|
|
a0++; |
|
|
} |
|
|
} |
|
|
a1 = a0; // end of left
|
|
|
a1 = a0; |
|
|
for (;;) { |
|
|
for (;;) { // scan for '='
|
|
|
a1++; |
|
|
a1++; |
|
|
if (a1 == len) |
|
|
if (a1 == len) |
|
|
goto ignore; |
|
|
goto ignore; |
|
|
char c = s[a1]; |
|
|
char c = s[a1]; |
|
|
Usz x = a1; |
|
|
Usz x = a1; // don't include any whitespace preceeding the '='
|
|
|
while (isspace(c)) { |
|
|
while (isspace(c)) { |
|
|
x++; |
|
|
x++; |
|
|
if (x == len) |
|
|
if (x == len) |
|
@ -109,7 +112,7 @@ Conf_read_result conf_read_line(FILE* file, char* buf, Usz bufsize, |
|
|
} |
|
|
} |
|
|
a1 = x; |
|
|
a1 = x; |
|
|
} |
|
|
} |
|
|
for (;;) { |
|
|
for (;;) { // scan for first non-whitespace after '='
|
|
|
b0++; |
|
|
b0++; |
|
|
if (b0 == len) |
|
|
if (b0 == len) |
|
|
goto ignore; |
|
|
goto ignore; |
|
@ -117,13 +120,13 @@ Conf_read_result conf_read_line(FILE* file, char* buf, Usz bufsize, |
|
|
if (!isspace(c)) |
|
|
if (!isspace(c)) |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
b1 = b0; // end of right
|
|
|
b1 = b0; |
|
|
for (;;) { |
|
|
for (;;) { // scan for end of useful stuff for right-side value
|
|
|
b1++; |
|
|
b1++; |
|
|
if (b1 == len) |
|
|
if (b1 == len) |
|
|
goto ok; |
|
|
goto ok; |
|
|
char c = s[b1]; |
|
|
char c = s[b1]; |
|
|
Usz x = b1; |
|
|
Usz x = b1; // don't include any whitespace preceeding the EOL
|
|
|
while (isspace(c)) { |
|
|
while (isspace(c)) { |
|
|
x++; |
|
|
x++; |
|
|
if (x == len) |
|
|
if (x == len) |
|
|