Merge pull request #2098 from bbbradsmith/split2092-grc65-fix
grc65 fix flawed text parsing
This commit is contained in:
@@ -850,14 +850,25 @@ static char *filterInput (FILE *F, char *tbl)
|
|||||||
/* loads file into buffer filtering it out */
|
/* loads file into buffer filtering it out */
|
||||||
int a, prevchar = -1, i = 0, bracket = 0, quote = 1;
|
int a, prevchar = -1, i = 0, bracket = 0, quote = 1;
|
||||||
|
|
||||||
for (;;) {
|
a = getc(F);
|
||||||
a = getc(F);
|
while (1) {
|
||||||
if ((a == '\n') || (a == '\015')) a = ' ';
|
if (i >= BLOODY_BIG_BUFFER) {
|
||||||
if (a == ',' && quote) a = ' ';
|
AbEnd ("File too large for internal parsing buffer (%d bytes)",BLOODY_BIG_BUFFER);
|
||||||
if (a == '\042') quote =! quote;
|
}
|
||||||
|
if (((a == '\n') || (a == '\015')) ||
|
||||||
|
(a == ',' && quote)) {
|
||||||
|
a = ' ';
|
||||||
|
}
|
||||||
|
if (a == '\042') {
|
||||||
|
quote =! quote;
|
||||||
|
}
|
||||||
if (quote) {
|
if (quote) {
|
||||||
if ((a == '{') || (a == '(')) bracket++;
|
if ((a == '{') || (a == '(')) {
|
||||||
if ((a == '}') || (a == ')')) bracket--;
|
bracket++;
|
||||||
|
}
|
||||||
|
if ((a == '}') || (a == ')')) {
|
||||||
|
bracket--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (a == EOF) {
|
if (a == EOF) {
|
||||||
tbl[i] = '\0';
|
tbl[i] = '\0';
|
||||||
@@ -873,13 +884,18 @@ static char *filterInput (FILE *F, char *tbl)
|
|||||||
if (a == ';' && quote) {
|
if (a == ';' && quote) {
|
||||||
do {
|
do {
|
||||||
a = getc (F);
|
a = getc (F);
|
||||||
} while (a != '\n');
|
} while (a != '\n' && a != EOF);
|
||||||
fseek (F, -1, SEEK_CUR);
|
/* Don't discard this newline/EOF, continue to next loop.
|
||||||
|
** A previous implementation used fseek(F,-1,SEEK_CUR),
|
||||||
|
** which is invalid for text mode files, and was unreliable across platforms.
|
||||||
|
*/
|
||||||
|
continue;
|
||||||
} else {
|
} else {
|
||||||
tbl[i++] = a;
|
tbl[i++] = a;
|
||||||
prevchar = a;
|
prevchar = a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
a = getc(F);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bracket != 0) AbEnd ("There are unclosed brackets!");
|
if (bracket != 0) AbEnd ("There are unclosed brackets!");
|
||||||
|
|||||||
Reference in New Issue
Block a user