public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/2] sim: ppc: handle \r in igen inputs [PR sim/28476]
Date: Sun, 31 Oct 2021 22:38:09 -0400	[thread overview]
Message-ID: <20211101023809.15374-2-vapier@gentoo.org> (raw)
In-Reply-To: <20211101023809.15374-1-vapier@gentoo.org>

Make sure we consume & ignore \r bytes in inputs in case the file
encodings are from a non-LF systems (e.g. Windows).
---
 sim/ppc/table.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/sim/ppc/table.c b/sim/ppc/table.c
index 3c7e4464beb5..6399bdaddcb1 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
-- 
2.33.0


      reply	other threads:[~2021-11-01  2:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-01  2:38 [PATCH 1/2] sim: ppc: constify strings in igen tooling Mike Frysinger
2021-11-01  2:38 ` Mike Frysinger [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211101023809.15374-2-vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).