sim: ppc: handle \r in igen inputs [PR sim/28476]

Make sure we consume & ignore \r bytes in inputs in case the file
encodings are from a non-LF systems (e.g. Windows).
This commit is contained in:
Mike Frysinger 2021-10-31 22:35:41 -04:00
parent fc3579da2e
commit f098231806

View File

@ -208,7 +208,7 @@ table_entry_read(table *root)
/* break the line into its colon delimitered fields */
for (field = 0; field < file->nr_fields-1; field++) {
entry->fields[field] = file->pos;
while(*file->pos && *file->pos != ':' && *file->pos != '\n')
while(*file->pos && *file->pos != ':' && *file->pos != '\n' && *file->pos != '\r')
file->pos++;
if (*file->pos == ':') {
*file->pos = '\0';
@ -219,7 +219,11 @@ table_entry_read(table *root)
/* any trailing stuff not the last field */
ASSERT(field == file->nr_fields-1);
entry->fields[field] = file->pos;
while (*file->pos && *file->pos != '\n') {
while (*file->pos && *file->pos != '\n' && *file->pos != '\r') {
file->pos++;
}
if (*file->pos == '\r') {
*file->pos = '\0';
file->pos++;
}
if (*file->pos == '\n') {
@ -243,7 +247,7 @@ table_entry_read(table *root)
file->pos++;
for (field = 0; field < file->nr_model_fields-1; field++) {
model->fields[field] = file->pos;
while(*file->pos && *file->pos != ':' && *file->pos != '\n')
while(*file->pos && *file->pos != ':' && *file->pos != '\n' && *file->pos != '\r')
file->pos++;
if (*file->pos == ':') {
*file->pos = '\0';
@ -254,7 +258,11 @@ table_entry_read(table *root)
/* any trailing stuff not the last field */
ASSERT(field == file->nr_model_fields-1);
model->fields[field] = file->pos;
while (*file->pos && *file->pos != '\n') {
while (*file->pos && *file->pos != '\n' && *file->pos != '\r') {
file->pos++;
}
if (*file->pos == '\r') {
*file->pos = '\0';
file->pos++;
}
if (*file->pos == '\n') {
@ -274,13 +282,13 @@ table_entry_read(table *root)
do {
do {
file->pos++;
} while (*file->pos != '\0' && *file->pos != '\n');
if (*file->pos == '\n') {
} while (*file->pos != '\0' && *file->pos != '\n' && *file->pos != '\r');
if (*file->pos == '\n' || *file->pos == '\r') {
char *save_pos = ++file->pos;
int extra_lines = 0;
file->line_nr++;
/* Allow tab indented to have blank lines */
while (*save_pos == '\n') {
while (*save_pos == '\n' || *save_pos == '\r') {
save_pos++;
extra_lines++;
}
@ -290,7 +298,7 @@ table_entry_read(table *root)
}
}
} while (*file->pos != '\0' && *file->pos == '\t');
if (file->pos[-1] == '\n')
if (file->pos[-1] == '\n' || file->pos[-1] == '\r')
file->pos[-1] = '\0';
}
else