[edk2] [PATCH v5] MdeModulePkg/RegularExpressionDxe:disable wraning to pass gcc4.8 build

2018-10-10 Thread Dongao Guo
There are three warnings reported by GCC 4.8 and the later GCC release
are workaround with them.
And all the three warnings are invalid,so I just disable warnings rather
than fix them at now.

Following is the analysis from Laszlo Ersek.
(1)

> MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regcomp.c: In
> function 'compile_length_tree':
> MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regcomp.c:1516:7:
> warning: 'len' may be used uninitialized in this function
> [-Wmaybe-uninitialized]
>int len;
>^

I think this is an invalid warning; the type of the controlling expression
(node->type) is enum GimmickType, and the case labels cover all values of
the enum. An assert(0) could be added, I guess, but again, upstream
Oniguruma would be justified to reject the idea.

(2)

> MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regparse.c: In
> function 'parse_callout_args.isra.10.constprop.30':
> MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regparse.c:6753:25:
> warning: 'rl' may be used uninitialized in this function
> [-Wmaybe-uninitialized]
>   vals[n].l = rl;
>   ^

This warning is invalid, given:

  6749if (cn > 0) {
  6750  long rl;
  6751  r = parse_long(enc, buf, bufend, 1, LONG_MAX, );
  6752  if (r == ONIG_NORMAL) {
  6753vals[n].l = rl;

Because parse_long() only returns ONIG_NORMAL after it sets (*rl).

(3)

> MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regparse.c: In
> function 'parse_callout_of_name.constprop.29':
> MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regparse.c:6861:38:
> warning: 'tag_end' may be used uninitialized in this function
> [-Wmaybe-uninitialized]
>  if (! is_allowed_callout_tag_name(enc, tag_start, tag_end))

This warning is also invalid, given:

  6852if (c == '[') {
  6853  if (PEND) return ONIGERR_END_PATTERN_IN_GROUP;
  6854  tag_start = p;
  6855  while (! PEND) {
  6856if (PEND) return ONIGERR_END_PATTERN_IN_GROUP;
  6857tag_end = p;
  6858PFETCH_S(c);
  6859if (c == ']') break;
  6860  }
  6861  if (! is_allowed_callout_tag_name(enc, tag_start, tag_end))
  6862return ONIGERR_INVALID_CALLOUT_TAG_NAME;
  6863

To see that, first we should note:
 #define PEND (p < end ?  0 : 1)

therefore PEND doesn't change if neither "p" nor "end" change.

Second, when we reach line 6855 (the "while") for the very first time,
(!PEND) is certainly true (i.e., PEND is false), because otherwise we
would have bailed at line 6853. Therefore we reach line 6857, and assign
"tag_end". Regardless of whether we iterate zero or more *additional*
times around the loop, "tag_end" will have been set, whenever we reach
line 6861.

Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dongao Guo 
---
 MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf | 3 +++
 1 file changed, 3 insertions(+)

diff --git 
a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf 
b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
index 16e91bd..07bc02e 100644
--- a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
+++ b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
@@ -109,3 +109,6 @@
 
   # Oniguruma: error: variable 'fp' set but not used
   GCC:*_*_*_CC_FLAGS = -Wno-error=unused-but-set-variable
+
+  # Oniguruma: tag_end in parse_callout_of_name
+  GCC:*_*_*_CC_FLAGS = -Wno-error=maybe-uninitialized
-- 
2.6.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v4] MdeModulePkg/RegularExpressionDxe:disable wraning to pass gcc4.8 build

2018-10-09 Thread Dongao Guo
There are three warnings reported by GCC 4.8 and the later GCC release
are workaround with them.
And all the three warnings are invalid,so I just disable warnings rather
than fix them at now.

Following is the analysis from Laszlo Ersek.
(1)

> MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regcomp.c: In
> function 'compile_length_tree':
> MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regcomp.c:1516:7:
> warning: 'len' may be used uninitialized in this function
> [-Wmaybe-uninitialized]
>int len;
>^

I think this is an invalid warning; the type of the controlling expression
(node->type) is enum GimmickType, and the case labels cover all values of
the enum. An assert(0) could be added, I guess, but again, upstream
Oniguruma would be justified to reject the idea.

(2)

> MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regparse.c: In
> function 'parse_callout_args.isra.10.constprop.30':
> MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regparse.c:6753:25:
> warning: 'rl' may be used uninitialized in this function
> [-Wmaybe-uninitialized]
>   vals[n].l = rl;
>   ^

This warning is invalid, given:

  6749if (cn > 0) {
  6750  long rl;
  6751  r = parse_long(enc, buf, bufend, 1, LONG_MAX, );
  6752  if (r == ONIG_NORMAL) {
  6753vals[n].l = rl;

Because parse_long() only returns ONIG_NORMAL after it sets (*rl).

(3)

> MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regparse.c: In
> function 'parse_callout_of_name.constprop.29':
> MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regparse.c:6861:38:
> warning: 'tag_end' may be used uninitialized in this function
> [-Wmaybe-uninitialized]
>  if (! is_allowed_callout_tag_name(enc, tag_start, tag_end))

This warning is also invalid, given:

  6852if (c == '[') {
  6853  if (PEND) return ONIGERR_END_PATTERN_IN_GROUP;
  6854  tag_start = p;
  6855  while (! PEND) {
  6856if (PEND) return ONIGERR_END_PATTERN_IN_GROUP;
  6857tag_end = p;
  6858PFETCH_S(c);
  6859if (c == ']') break;
  6860  }
  6861  if (! is_allowed_callout_tag_name(enc, tag_start, tag_end))
  6862return ONIGERR_INVALID_CALLOUT_TAG_NAME;
  6863

To see that, first we should note:

therefore PEND doesn't change if neither "p" nor "end" change.

Second, when we reach line 6855 (the "while") for the very first time,
(!PEND) is certainly true (i.e., PEND is false), because otherwise we
would have bailed at line 6853. Therefore we reach line 6857, and assign
"tag_end". Regardless of whether we iterate zero or more *additional*
times around the loop, "tag_end" will have been set, whenever we reach
line 6861.

Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dongao Guo 
---
 MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf | 3 +++
 1 file changed, 3 insertions(+)

diff --git 
a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf 
b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
index 16e91bd..07bc02e 100644
--- a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
+++ b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
@@ -109,3 +109,6 @@
 
   # Oniguruma: error: variable 'fp' set but not used
   GCC:*_*_*_CC_FLAGS = -Wno-error=unused-but-set-variable
+
+  # Oniguruma: tag_end in parse_callout_of_name
+  GCC:*_*_*_CC_FLAGS = -Wno-error=maybe-uninitialized
-- 
2.6.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] MdeModulePkg/RegularExpressionDxe:omit unused variable

2018-10-08 Thread Dongao Guo


comment unused variable to avoid warning,and modify inf build option.

Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dongao Guo 
---
 .../RegularExpressionDxe/Oniguruma/regexec.c   | 28 +++---
 .../RegularExpressionDxe/RegularExpressionDxe.inf  |  3 ---
 2 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regexec.c 
b/MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regexec.c
index 7b0fda0..26e7a31 100644
--- a/MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regexec.c
+++ b/MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regexec.c
@@ -5603,11 +5603,11 @@ onig_builtin_monitor(OnigCalloutArgs* args, void* 
user_data)
   int r;
   int num;
   size_t tag_len;
-  const UChar* start;
-  const UChar* right;
-  const UChar* current;
-  const UChar* string;
-  const UChar* strend;
+ // const UChar* start;
+ // const UChar* right;
+ // const UChar* current;
+ // const UChar* string;
+ // const UChar* strend;
   const UChar* tag_start;
   const UChar* tag_end;
   regex_t* reg;
@@ -5615,9 +5615,9 @@ onig_builtin_monitor(OnigCalloutArgs* args, void* 
user_data)
   OnigType type;
   OnigValue val;
   char buf[20];
-  FILE* fp;
+ // FILE* fp;
 
-  fp = OutFp;
+ // fp = OutFp;
 
   r = onig_get_arg_by_callout_args(args, 0, , );
   if (r != ONIG_NORMAL) return r;
@@ -5633,11 +5633,11 @@ onig_builtin_monitor(OnigCalloutArgs* args, void* 
user_data)
   }
 
   num   = onig_get_callout_num_by_callout_args(args);
-  start = onig_get_start_by_callout_args(args);
-  right = onig_get_right_range_by_callout_args(args);
-  current   = onig_get_current_by_callout_args(args);
-  string= onig_get_string_by_callout_args(args);
-  strend= onig_get_string_end_by_callout_args(args);
+ // start = onig_get_start_by_callout_args(args);
+ // right = onig_get_right_range_by_callout_args(args);
+ // current   = onig_get_current_by_callout_args(args);
+ // string= onig_get_string_by_callout_args(args);
+ // strend= onig_get_string_end_by_callout_args(args);
   reg   = onig_get_regex_by_callout_args(args);
   tag_start = onig_get_callout_tag_start(reg, num);
   tag_end   = onig_get_callout_tag_end(reg, num);
@@ -5653,7 +5653,7 @@ onig_builtin_monitor(OnigCalloutArgs* args, void* 
user_data)
 for (i = 0; i < tag_len; i++) buf[i] = tag_start[i];
 buf[tag_len] = '\0';
   }
-
+/*
   fprintf(fp, "ONIG-MONITOR: %-4s %s at: %d [%d - %d] len: %d\n",
   buf,
   in == ONIG_CALLOUT_IN_PROGRESS ? "=>" : "<=",
@@ -5662,7 +5662,7 @@ onig_builtin_monitor(OnigCalloutArgs* args, void* 
user_data)
   (int )(right   - string),
   (int )(strend  - string));
   //fflush(fp);
-
+*/
   return ONIG_CALLOUT_SUCCESS;
 }
 
diff --git 
a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf 
b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
index 16e91bd..98fb8db 100644
--- a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
+++ b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
@@ -106,6 +106,3 @@
 
   # Oniguruma: signed and unsigned mismatch/cast
   MSFT:*_*_*_CC_FLAGS = /wd4018 /wd4245 /wd4389
-
-  # Oniguruma: error: variable 'fp' set but not used
-  GCC:*_*_*_CC_FLAGS = -Wno-error=unused-but-set-variable
-- 
1.9.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v3] MdeModulePkg/RegularExpressionDxe:disable wraning to pass gcc4.8 build

2018-09-28 Thread Dongao Guo
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dongao Guo 
---
 MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf | 3 +++
 1 file changed, 3 insertions(+)

diff --git 
a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf 
b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
index 16e91bd..07bc02e 100644
--- a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
+++ b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
@@ -109,3 +109,6 @@
 
   # Oniguruma: error: variable 'fp' set but not used
   GCC:*_*_*_CC_FLAGS = -Wno-error=unused-but-set-variable
+
+  # Oniguruma: tag_end in parse_callout_of_name
+  GCC:*_*_*_CC_FLAGS = -Wno-error=maybe-uninitialized
-- 
2.6.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH V2] MdeModulePkg/RegularExpressionDxe:disable wraning to pass gcc4.8 build

2018-09-28 Thread Dongao Guo
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
---
 MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf | 3 +++
 1 file changed, 3 insertions(+)

diff --git 
a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf 
b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
index 16e91bd..07bc02e 100644
--- a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
+++ b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
@@ -109,3 +109,6 @@
 
   # Oniguruma: error: variable 'fp' set but not used
   GCC:*_*_*_CC_FLAGS = -Wno-error=unused-but-set-variable
+
+  # Oniguruma: tag_end in parse_callout_of_name
+  GCC:*_*_*_CC_FLAGS = -Wno-error=maybe-uninitialized
-- 
2.6.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] MdeModulePkg:disable wraning to pass gcc4.8 build

2018-09-28 Thread Dongao Guo
Change-Id: I782962e4994a8edf14beb7ede8b1aabe233dc3a8
Contributed-under: TianoCore Contribution Agreement 1.1
---
 MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf | 3 +++
 1 file changed, 3 insertions(+)

diff --git 
a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf 
b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
index 16e91bd..07bc02e 100644
--- a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
+++ b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
@@ -109,3 +109,6 @@
 
   # Oniguruma: error: variable 'fp' set but not used
   GCC:*_*_*_CC_FLAGS = -Wno-error=unused-but-set-variable
+
+  # Oniguruma: tag_end in parse_callout_of_name
+  GCC:*_*_*_CC_FLAGS = -Wno-error=maybe-uninitialized
-- 
2.6.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] MdeModulePkg/RegularExpressionDxe: modify inf to pass vs 2012 build

2018-09-26 Thread Dongao Guo
add /wd4703 for passing VS 2012 build.This equals /wd4701 in VS2015.

Cc: Liming Gao 
Change-Id: I06ff88b11246491ccc83b2231d4070c2acd7331a
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dongao Guo 
---
 MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf 
b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
index 7490a03..16e91bd 100644
--- a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
+++ b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
@@ -84,7 +84,7 @@
   INTEL:*_*_*_CC_FLAGS = /Oi-
 
   # Oniguruma: potentially uninitialized local variable used
-  MSFT:*_*_*_CC_FLAGS = /wd4701
+  MSFT:*_*_*_CC_FLAGS = /wd4701 /wd4703
 
   # Oniguruma: intrinsic function not declared
   MSFT:*_*_*_CC_FLAGS = /wd4164
-- 
2.6.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch v3] Formalize source files to follow DOS format

2018-06-08 Thread Dongao Guo
From: Liming Gao 

V3:
support exclude dir and file by name while traversing the directory.
remove close in with statement.

V2:
add version,description,copyright.
add flag -v,-q,--append-extensions,--override-extensions,--debug.
-q will omit default output,-v and --debug are not implemented.
add default file extensions.
support input of file path.
support muliple input path.
simplify comment.
change 'pattern'.encode() to b'pattern',I think this will be better.
change naming of variable and function to keep the same with BinToPcd.py

V1:
FormatDosFiles.py is added to clean up dos source files. It bases on
the rules defined in EDKII C Coding Standards Specification.
5.1.2 Do not use tab characters
5.1.6 Only use CRLF (Carriage Return Line Feed) line endings.
5.1.7 All files must end with CRLF
No trailing white space in one line. (To be added in spec)

The source files in edk2 project with the below postfix are dos format.
.h .c .nasm .nasmb .asm .S .inf .dec .dsc .fdf .uni .asl .aslc .vfr .idf
.txt .bat .py

The package maintainer can use this script to clean up all files in his
package. The prefer way is to create one patch per one package.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao 
Signed-off-by: Dongao Guo 

---
 BaseTools/Scripts/FormatDosFiles.py | 95 +
 1 file changed, 95 insertions(+)
 create mode 100644 BaseTools/Scripts/FormatDosFiles.py

diff --git a/BaseTools/Scripts/FormatDosFiles.py 
b/BaseTools/Scripts/FormatDosFiles.py
new file mode 100644
index 000..4c75876
--- /dev/null
+++ b/BaseTools/Scripts/FormatDosFiles.py
@@ -0,0 +1,95 @@
+# @file FormatDosFiles.py
+# This script format the source files to follow dos style.
+# It supports Python2.x and Python3.x both.
+#
+#  Copyright (c) 2018, Intel Corporation. All rights reserved.
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD 
License
+#  which accompanies this distribution.  The full text of the license may be 
found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+#
+
+#
+# Import Modules
+#
+import argparse
+import os
+import os.path
+import re
+import sys
+import copy
+
+__prog__= 'FormatDosFiles'
+__version__ = '%s Version %s' % (__prog__, '0.12 ')
+__copyright__   = 'Copyright (c) 2018 3, Intel Corporation. All rights 
reserved.'
+__description__ = 'Convert source files to meet the EDKII C Coding Standards 
Specification.\n'
+DEFAULT_EXT_LIST = ['.h', '.c', '.nasm', '.nasmb', '.asm', '.S', '.inf', 
'.dec', '.dsc', '.fdf', '.uni', '.asl', '.aslc', '.vfr', '.idf', '.txt', 
'.bat', '.py']
+
+#For working in python2 and python3 environment, re pattern should use binary 
string, which is bytes type in python3.
+#Because in python3,read from file in binary mode will return bytes type,and 
in python3 bytes type can not be mixed with str type.
+def FormatFile(FilePath, Args):
+with open(FilePath, 'rb') as Fd:
+Content = Fd.read()
+# Convert the line endings to CRLF
+Content = re.sub(br'([^\r])\n', br'\1\r\n', Content)
+Content = re.sub(br'^\n', br'\r\n', Content, flags=re.MULTILINE)
+# Add a new empty line if the file is not end with one
+Content = re.sub(br'([^\r\n])$', br'\1\r\n', Content)
+# Remove trailing white spaces
+Content = re.sub(br'[ \t]+(\r\n)', br'\1', Content, flags=re.MULTILINE)
+# Replace '\t' with two spaces
+Content = re.sub(b'\t', b'  ', Content)
+with open(FilePath, 'wb') as Fd:
+Fd.write(Content)
+if not Args.Quiet:
+print(FilePath)
+
+def FormatFilesInDir(DirPath, ExtList, Args):
+
+FileList = []
+for DirPath, DirNames, FileNames in os.walk(DirPath):
+if Args.Exclude:
+DirNames[:] = [d for d in DirNames if d not in Args.Exclude]
+FileNames[:] = [f for f in FileNames if f not in Args.Exclude]
+for FileName in [f for f in FileNames if any(f.endswith(ext) for ext 
in ExtList)]:
+FileList.append(os.path.join(DirPath, FileName))
+for File in FileList:
+FormatFile(File, Args)
+
+if __name__ == "__main__":
+parser = argparse.ArgumentParser(prog=__prog__,description=__description__ 
+ __copyright__, conflict_handler = 'resolve')
+
+parser.add_argument('Path', nargs='+',
+help='the path for files to be converted.It could be 
directory or file path.')
+parser.add_argument('--version', action='version', version=__version__)
+parser.add_argument('--append-extensions', dest='AppendExt', nargs='+',
+help='append file extensions filter to default 
extensions. (Example: .txt .c .h)')
+parser.add_argument('--overri

[edk2] [PATCH v2] Formalize source files to follow DOS format

2018-05-29 Thread Dongao Guo
From: Liming Gao 

V2:
add version,description,copyright.
add flag -v,-q,--append-extensions,--override-extensions,--debug.
-q will omit default output,-v and --debug are not implemented.
add default file extensions.
support input of file path.
support muliple input path.
simplify comment.
change 'pattern'.encode() to b'pattern',I think this will be better.
change naming of variable and function to keep the same with BinToPcd.py

V1:
FormatDosFiles.py is added to clean up dos source files. It bases on
the rules defined in EDKII C Coding Standards Specification.
5.1.2 Do not use tab characters
5.1.6 Only use CRLF (Carriage Return Line Feed) line endings.
5.1.7 All files must end with CRLF
No trailing white space in one line. (To be added in spec)

The source files in edk2 project with the below postfix are dos format.
.h .c .nasm .nasmb .asm .S .inf .dec .dsc .fdf .uni .asl .aslc .vfr .idf
.txt .bat .py

The package maintainer can use this script to clean up all files in his
package. The prefer way is to create one patch per one package.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao 
Signed-off-by: Dongao Guo 

---
 BaseTools/Scripts/FormatDosFiles.py | 94 +
 1 file changed, 94 insertions(+)
 create mode 100644 BaseTools/Scripts/FormatDosFiles.py

diff --git a/BaseTools/Scripts/FormatDosFiles.py 
b/BaseTools/Scripts/FormatDosFiles.py
new file mode 100644
index 000..fa969ed
--- /dev/null
+++ b/BaseTools/Scripts/FormatDosFiles.py
@@ -0,0 +1,94 @@
+# @file FormatDosFiles.py
+# This script format the source files to follow dos style.
+# It supports Python2.x and Python3.x both.
+#
+#  Copyright (c) 2018, Intel Corporation. All rights reserved.
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD 
License
+#  which accompanies this distribution.  The full text of the license may be 
found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+#
+
+#
+# Import Modules
+#
+import argparse
+import os
+import os.path
+import re
+import sys
+import copy
+
+__prog__= 'FormatDosFiles'
+__version__ = '%s Version %s' % (__prog__, '0.12 ')
+__copyright__   = 'Copyright (c) 2018 3, Intel Corporation. All rights 
reserved.'
+__description__ = 'Convert source files to meet the EDKII C Coding Standards 
Specification.\n'
+DEFAULT_EXT_LIST = ['.h', '.c', '.nasm', '.nasmb', '.asm', '.S', '.inf', 
'.dec', '.dsc', '.fdf', '.uni', '.asl', '.aslc', '.vfr', '.idf', '.txt', 
'.bat', '.py']
+
+#For working in python2 and python3 environment, re pattern should use binary 
string, which is bytes type in python3.
+#Because in python3,read from file in binary mode will return bytes type,and 
in python3 bytes type can not be mixed with str type.
+def FormatFile(FilePath, Args):
+with open(FilePath, 'rb') as Fd:
+Content = Fd.read()
+Fd.close()
+# Convert the line endings to CRLF
+Content = re.sub(br'([^\r])\n', br'\1\r\n', Content)
+Content = re.sub(br'^\n', br'\r\n', Content, flags=re.MULTILINE)
+# Add a new empty line if the file is not end with one
+Content = re.sub(br'([^\r\n])$', br'\1\r\n', Content)
+# Remove trailing white spaces
+Content = re.sub(br'[ \t]+(\r\n)', br'\1', Content, flags=re.MULTILINE)
+# Replace '\t' with two spaces
+Content = re.sub(b'\t', b'  ', Content)
+with open(FilePath, 'wb') as Fd:
+Fd.write(Content)
+Fd.close()
+if not Args.Quiet:
+print(FilePath)
+
+def FormatFilesInDir(DirPath, ExtList, Args):
+
+FileList = []
+for DirPath, DirNames, FileNames in os.walk(DirPath):
+for FileName in [f for f in FileNames if any(f.endswith(ext) for ext 
in ExtList)]:
+FileList.append(os.path.join(DirPath, FileName))
+for File in FileList:
+FormatFile(File, Args)
+
+if __name__ == "__main__":
+parser = argparse.ArgumentParser(prog=__prog__,description=__description__ 
+ __copyright__, conflict_handler = 'resolve')
+
+parser.add_argument('Path', nargs='+',
+help='the path for files to be converted.It could be 
directory or file path.')
+parser.add_argument('--version', action='version', version=__version__)
+parser.add_argument('--append-extensions', dest='AppendExt', nargs='+',
+help='append file extensions filter to default 
extensions. (Example: .txt .c .h)')
+parser.add_argument('--override-extensions', dest='OverrideExt', nargs='+',
+help='override file extensions filter on default 
extensions. (Example: .txt .c .h)')
+parser.add_argument('-v', '--verbose', dest='Verbose'