diff options
author | Mike Frysinger <vapier@gentoo.org> | 2021-10-31 22:35:41 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2021-10-31 22:35:41 -0400 |
commit | f0982318065617e92c28e23ee382981c2a898ca2 (patch) | |
tree | 881d3c412ba2b7a6d4eab15cd000042c1d58cd86 | |
parent | fc3579da2ea6b2db27ac3003f818abd7786b9b30 (diff) | |
download | gdb-f0982318065617e92c28e23ee382981c2a898ca2.zip gdb-f0982318065617e92c28e23ee382981c2a898ca2.tar.gz gdb-f0982318065617e92c28e23ee382981c2a898ca2.tar.bz2 |
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).
-rw-r--r-- | sim/ppc/table.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/sim/ppc/table.c b/sim/ppc/table.c index 3c7e446..6399bda 100644 --- a/sim/ppc/table.c +++ b/sim/ppc/table.c @@ -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 |