public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Lokesh B V <lokesh.bv@arm.com>
To: edk2-devel@lists.01.org
Subject: [edk2-test][PATCH v2] SctPkg/Tools: Fix incorrect line ending detection by GenBin tool
Date: Wed, 28 Nov 2018 15:00:02 +0530	[thread overview]
Message-ID: <1543397402-19411-5-git-send-email-lokesh.bv@arm.com> (raw)
In-Reply-To: <1543397402-19411-1-git-send-email-lokesh.bv@arm.com>

Some windows editors uses "\r\n" for line feed. While processing uefi
sct testcase info file, the GenBin tool logic to skip line feed doesn't
consider the presence of carraige return(\r) in line feed. So this results
in incorrect format error.

Fixed this issue by changing logic of Trim and Getline functions used
in GenBin source code.

Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Lokesh B V <lokesh.bv@arm.com>
---
Changes since v1:
* Adopted changes suggested by Supreeth.
* modified Copyright content

 uefi-sct/SctPkg/Tools/Source/GenBin/GenBin.c | 58 +++++++++++++---------------
 1 file changed, 26 insertions(+), 32 deletions(-)

diff --git a/uefi-sct/SctPkg/Tools/Source/GenBin/GenBin.c b/uefi-sct/SctPkg/Tools/Source/GenBin/GenBin.c
index 61bb35b..6d8e844 100644
--- a/uefi-sct/SctPkg/Tools/Source/GenBin/GenBin.c
+++ b/uefi-sct/SctPkg/Tools/Source/GenBin/GenBin.c
@@ -2,6 +2,7 @@
 
   Copyright 2006 - 2010 Unified EFI, Inc.<BR>
   Copyright (c) 2010 Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2018 ARM Ltd. All rights reserved.<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -32,6 +33,7 @@ Abstract:
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 
 //
 // Definitions
@@ -49,7 +51,7 @@ PrintUsage (
   void
   );
 
-void
+char *
 Trim (
   char        *String
   );
@@ -159,50 +161,42 @@ PrintUsage (
 }
 
 
-void
+char *
 Trim (
   char        *String
   )
 {
-  int   Index1;
-  int   Index2;
   int   Length;
+  char  *end;
 
   Length = strlen (String);
 
-  //
-  // Remove the space characters from the beginning of this string
-  //
-  for (Index1 = 0; Index1 < Length; Index1++) {
-    if ((String[Index1] != ' ' ) &&
-        (String[Index1] != '\t') &&
-        (String[Index1] != '\n')) {
-      break;
-    }
-  }
-
-  for (Index2 = Index1; Index2 < Length; Index2++) {
-    String[Index2 - Index1] = String[Index2];
+  if (!Length) {
+    return String;
   }
 
-  Length = Length - Index1;
+  end = String + Length - 1;
 
   //
   // Remove the space characters from the end of this string
   //
-  for (Index1 = 0; Index1 < Length; Index1++) {
-    if ((String[Length - 1 - Index1] != ' ' ) &&
-        (String[Length - 1 - Index1] != '\t') &&
-        (String[Length - 1 - Index1] != '\n')) {
-      break;
-    }
+  while (end >= String && isspace (*end)) {
+    end--;
   }
 
-  String[Length - Index1] = '\0';
+  *(end + 1) = '\0';
+
+  //
+  // Remove the space characters from the beginning of this string
+  //
+  while (*String && isspace (*String)) {
+    String++;
+  }
 
   //
   // Done
   //
+  return String;
 }
 
 
@@ -227,20 +221,20 @@ GetLine (
       return -1;
     }
 
-    (*LineNo)++;
-
     //
     // Remove the beginning and ending space characters
     //
-    Trim (String);
+    String = Trim (Result);
 
     //
-    // Ignore the empty line and comment line
+    // Skip the empty line and comment line
     //
-    if ((String[0] != '\0') &&
-        (String[0] != '#' )) {
-      break;
+    if ((String[0] == '\0') ||
+        (String[0] == '#' )) {
+      continue;
     }
+
+    (*LineNo)++;
   }
 
   //
-- 
2.7.4



  parent reply	other threads:[~2018-11-28  9:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-28  9:29 [edk2-test][PATCH] Framework/Include: allow usage with EFI version 2.7 Lokesh B V
2018-11-28  9:29 ` [edk2-test][PATCH] SctPkg/UEFI: Fix invalid GUID value format error Lokesh B V
     [not found]   ` <f59c45a7de154bd3706c54b73a48aa975dbfbf96.camel@arm.com>
2018-11-28 22:28     ` Supreeth Venkatesh
2018-11-28 22:29   ` Supreeth Venkatesh
2018-11-28  9:30 ` [edk2-test][PATCH v2] SctPkg/build: Add support for GenBin tool build Lokesh B V
2018-11-28 22:30   ` Supreeth Venkatesh
2018-11-28  9:30 ` [edk2-test][PATCH] Add *.o and *.d pattern to .gitignore Lokesh B V
2018-11-28 22:29   ` Supreeth Venkatesh
2018-11-28  9:30 ` Lokesh B V [this message]
2018-11-28 22:29   ` [edk2-test][PATCH v2] SctPkg/Tools: Fix incorrect line ending detection by GenBin tool Supreeth Venkatesh
2019-03-29  8:31   ` Jin, Eric
2019-03-29 14:11     ` Supreeth Venkatesh
2019-03-29 14:28     ` Minnow Ware
2019-03-29 14:34       ` Supreeth Venkatesh
2018-11-28 22:30 ` [edk2-test][PATCH] Framework/Include: allow usage with EFI version 2.7 Supreeth Venkatesh

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-list 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=1543397402-19411-5-git-send-email-lokesh.bv@arm.com \
    --to=devel@edk2.groups.io \
    /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