Re: [edk2] [edk2-test][PATCH v2] SctPkg/Tools: Fix incorrect line ending detection by GenBin tool
Thanks Kilian. There was no issue. This patch was sent in error. However, I will look into this feedback - "The GenBin.c should be extended by a manual BIN2TXT translation." Supreeth From: Minnow Ware Sent: Friday, March 29, 2019 9:29 AM To: Jin, Eric ; Supreeth Venkatesh ; edk2-devel@lists.01.org Cc: Jin, Eric Subject: RE: [edk2] [edk2-test][PATCH v2] SctPkg/Tools: Fix incorrect line ending detection by GenBin tool Hi Supreeth, theoretically the standard C implementation of fopen(char *filename, char *mode) "can" support BINARY and TEXT mode. This is specified here http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf, "7.19.2 Streams" In praxis only Windows-/DOS platforms supports a BINARY ( w/ "b") and a TEXT mode (w/o "b"). This is valid for all C-library implementations on that platforms. In textmode all "\r\n"-sequences in the file are automatically (by the C Library) translated to "\n" only, when reading the file to the buffer. And on write operations each "\n" is transformed to "\r\n". On UNIX-systems with or without "b"-inary flag do not affect the data read/written. Since the profile file is opened correctly in text mode (Line 107 https://github.com/tianocore/edk2-test/blob/master/uefi-sct/SctPkg/Tools/Source/GenBin/GenBin.c), the issue tells me, you are running on a UNIX system, dealing with Windows text files. The GenBin.c should be extended by a manual BIN2TXT translation. Best Regrads, Kilian https://github.com/MinnowWare From: Jin, Eric<mailto:eric@intel.com> Sent: Friday, March 29, 2019 09:31 AM To: Supreeth Venkatesh<mailto:supreeth.venkat...@arm.com>; edk2-devel@lists.01.org<mailto:edk2-devel@lists.01.org> Cc: Jin, Eric<mailto:eric....@intel.com> Subject: Re: [edk2] [edk2-test][PATCH v2] SctPkg/Tools: Fix incorrect line ending detection by GenBin tool Hi Supreeth, This patch can't be applied to the lasted code base SHA-1: 33022e. One patch from may already fix the issue. Please check again. Best Regards Eric -Original Message- From: edk2-devel mailto:edk2-devel-boun...@lists.01.org>> On Behalf Of Supreeth Venkatesh Sent: Friday, March 29, 2019 7:08 AM To: supreeth.venkat...@arm.com<mailto:supreeth.venkat...@arm.com>; edk2-devel@lists.01.org<mailto:edk2-devel@lists.01.org> Subject: [edk2] [edk2-test][PATCH v2] SctPkg/Tools: Fix incorrect line ending detection by GenBin tool From: Lokesh B V mailto:lokesh...@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 mailto:supreeth.venkat...@arm.com>> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Lokesh B V mailto:lokesh...@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. Copyright (c) 2010 Intel Corporation. All rights reserved. + Copyright (c) 2018 ARM Ltd. All rights reserved. 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 #include #include +#include // // 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] != ' '
Re: [edk2] [edk2-test][PATCH v2] SctPkg/Tools: Fix incorrect line ending detection by GenBin tool
Hi Supreeth, theoretically the standard C implementation of fopen(char *filename, char *mode) “can” support BINARY and TEXT mode. This is specified here http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf, “7.19.2 Streams” In praxis only Windows-/DOS platforms supports a BINARY ( w/ “b”) and a TEXT mode (w/o “b”). This is valid for all C-library implementations on that platforms. In textmode all "\r\n"-sequences in the file are automatically (by the C Library) translated to “\n” only, when reading the file to the buffer. And on write operations each “\n” is transformed to “\r\n”. On UNIX-systems with or without “b”-inary flag do not affect the data read/written. Since the profile file is opened correctly in text mode (Line 107 https://github.com/tianocore/edk2-test/blob/master/uefi-sct/SctPkg/Tools/Source/GenBin/GenBin.c), the issue tells me, you are running on a UNIX system, dealing with Windows text files. The GenBin.c should be extended by a manual BIN2TXT translation. Best Regrads, Kilian https://github.com/MinnowWare From: Jin, Eric<mailto:eric@intel.com> Sent: Friday, March 29, 2019 09:31 AM To: Supreeth Venkatesh<mailto:supreeth.venkat...@arm.com>; edk2-devel@lists.01.org<mailto:edk2-devel@lists.01.org> Cc: Jin, Eric<mailto:eric....@intel.com> Subject: Re: [edk2] [edk2-test][PATCH v2] SctPkg/Tools: Fix incorrect line ending detection by GenBin tool Hi Supreeth, This patch can't be applied to the lasted code base SHA-1: 33022e. One patch from may already fix the issue. Please check again. Best Regards Eric -Original Message- From: edk2-devel On Behalf Of Supreeth Venkatesh Sent: Friday, March 29, 2019 7:08 AM To: supreeth.venkat...@arm.com; edk2-devel@lists.01.org Subject: [edk2] [edk2-test][PATCH v2] SctPkg/Tools: Fix incorrect line ending detection by GenBin tool From: Lokesh B V 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 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Lokesh B V --- 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. Copyright (c) 2010 Intel Corporation. All rights reserved. + Copyright (c) 2018 ARM Ltd. All rights reserved. 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 #include #include +#include // // 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
Re: [edk2] [edk2-test][PATCH v2] SctPkg/Tools: Fix incorrect line ending detection by GenBin tool
Sorry. This was sent in error. I was testing my new Desktop with git send-email. Please ignore. Supreeth -Original Message- From: Jin, Eric Sent: Friday, March 29, 2019 3:32 AM To: Supreeth Venkatesh ; edk2-devel@lists.01.org Cc: Jin, Eric Subject: RE: [edk2] [edk2-test][PATCH v2] SctPkg/Tools: Fix incorrect line ending detection by GenBin tool Hi Supreeth, This patch can't be applied to the lasted code base SHA-1: 33022e. One patch from may already fix the issue. Please check again. Best Regards Eric -Original Message- From: edk2-devel On Behalf Of Supreeth Venkatesh Sent: Friday, March 29, 2019 7:08 AM To: supreeth.venkat...@arm.com; edk2-devel@lists.01.org Subject: [edk2] [edk2-test][PATCH v2] SctPkg/Tools: Fix incorrect line ending detection by GenBin tool From: Lokesh B V 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 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Lokesh B V --- 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. Copyright (c) 2010 Intel Corporation. All rights reserved. + Copyright (c) 2018 ARM Ltd. All rights reserved. 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 #include #include +#include // // 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 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [edk2-test][PATCH v2] SctPkg/Tools: Fix incorrect line ending detection by GenBin tool
Hi Supreeth, This patch can't be applied to the lasted code base SHA-1: 33022e. One patch from may already fix the issue. Please check again. Best Regards Eric -Original Message- From: edk2-devel On Behalf Of Supreeth Venkatesh Sent: Friday, March 29, 2019 7:08 AM To: supreeth.venkat...@arm.com; edk2-devel@lists.01.org Subject: [edk2] [edk2-test][PATCH v2] SctPkg/Tools: Fix incorrect line ending detection by GenBin tool From: Lokesh B V 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 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Lokesh B V --- 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. Copyright (c) 2010 Intel Corporation. All rights reserved. + Copyright (c) 2018 ARM Ltd. All rights reserved. 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 #include #include +#include // // 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 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [edk2-test][PATCH v2] SctPkg/Tools: Fix incorrect line ending detection by GenBin tool
From: Lokesh B V 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 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Lokesh B V --- 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. Copyright (c) 2010 Intel Corporation. All rights reserved. + Copyright (c) 2018 ARM Ltd. All rights reserved. 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 #include #include +#include // // 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 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [edk2-test][PATCH v2] SctPkg/Tools: Fix incorrect line ending detection by GenBin tool
On Wed, 2018-11-28 at 15:00 +0530, Lokesh B V wrote: > 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 Changed to "consider the presence of carriage return(\r)" > results > in incorrect format error. > > Fixed this issue by changing logic of Trim and Getline functions used > in GenBin source code. > > Cc: Supreeth Venkatesh > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Lokesh B V Reviewed-by: Supreeth Venkatesh Pushed with additional changes inline below. > --- > 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. >Copyright (c) 2010 Intel Corporation. All rights reserved. > + Copyright (c) 2018 ARM Ltd. All rights reserved. > >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 > #include > #include > +#include > > // > // 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)++; As LineNo is being used only for printing where the issue is, we should increment line number as soon as fgets yields successful output. Changed this and committed. >} > >// ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [edk2-test][PATCH v2] SctPkg/Tools: Fix incorrect line ending detection by GenBin tool
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 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Lokesh B V --- 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. Copyright (c) 2010 Intel Corporation. All rights reserved. + Copyright (c) 2018 ARM Ltd. All rights reserved. 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 #include #include +#include // // 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 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel