summaryrefslogtreecommitdiff
path: root/ShellPkg
diff options
context:
space:
mode:
authorJaben Carsey <jaben.carsey@intel.com>2013-12-12 18:42:18 +0000
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2013-12-12 18:42:18 +0000
commitad2bc85412dcc566dae32cd4b18da356ace1ea3d (patch)
tree5956034b87e344b378c2a738466e6aa9577f1050 /ShellPkg
parent321a8d494f19277f764b4a9128b898d10b6db01a (diff)
downloadedk2-ad2bc85412dcc566dae32cd4b18da356ace1ea3d.zip
edk2-ad2bc85412dcc566dae32cd4b18da356ace1ea3d.tar.gz
edk2-ad2bc85412dcc566dae32cd4b18da356ace1ea3d.tar.bz2
ShellPkg: refactor out leading and trailing space trimming
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14972 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg')
-rw-r--r--ShellPkg/Application/Shell/Shell.c60
1 files changed, 34 insertions, 26 deletions
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c
index 25c519c..7af8153 100644
--- a/ShellPkg/Application/Shell/Shell.c
+++ b/ShellPkg/Application/Shell/Shell.c
@@ -71,6 +71,36 @@ STATIC CONST CHAR16 mExecutableExtensions[] = L".NSH;.EFI";
STATIC CONST CHAR16 mStartupScript[] = L"startup.nsh";
/**
+ Cleans off leading and trailing spaces and tabs
+
+ @param[in] String pointer to the string to trim them off
+**/
+EFI_STATUS
+EFIAPI
+TrimSpaces(
+ IN CHAR16 **String
+ )
+{
+ ASSERT(String != NULL);
+ ASSERT(*String!= NULL);
+ //
+ // Remove any spaces and tabs at the beginning of the (*String).
+ //
+ while (((*String)[0] == L' ') || ((*String)[0] == L'\t')) {
+ CopyMem((*String), (*String)+1, StrSize((*String)) - sizeof((*String)[0]));
+ }
+
+ //
+ // Remove any spaces at the end of the (*String).
+ //
+ while ((*String)[StrLen((*String))-1] == L' ') {
+ (*String)[StrLen((*String))-1] = CHAR_NULL;
+ }
+
+ return (EFI_SUCCESS);
+}
+
+/**
Find a command line contains a split operation
@param[in] CmdLine The command line to parse.
@@ -1460,12 +1490,7 @@ RunCommand(
return (EFI_OUT_OF_RESOURCES);
}
- //
- // Remove any spaces and tabs at the beginning of the string.
- //
- while ((CleanOriginal[0] == L' ') || (CleanOriginal[0] == L'\t')) {
- CopyMem(CleanOriginal, CleanOriginal+1, StrSize(CleanOriginal) - sizeof(CleanOriginal[0]));
- }
+ TrimSpaces(&CleanOriginal);
//
// Handle case that passed in command line is just 1 or more " " characters.
@@ -1478,13 +1503,6 @@ RunCommand(
return (EFI_SUCCESS);
}
- //
- // Remove any spaces at the end of the string.
- //
- while (CleanOriginal[StrLen(CleanOriginal)-1] == L' ') {
- CleanOriginal[StrLen(CleanOriginal)-1] = CHAR_NULL;
- }
-
CommandName = NULL;
if (StrStr(CleanOriginal, L" ") == NULL){
StrnCatGrow(&CommandName, NULL, CleanOriginal, 0);
@@ -1530,12 +1548,7 @@ RunCommand(
return (EFI_OUT_OF_RESOURCES);
}
- while (PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] == L' ') {
- PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] = CHAR_NULL;
- }
- while (PostVariableCmdLine[0] == L' ') {
- CopyMem(PostVariableCmdLine, PostVariableCmdLine+1, StrSize(PostVariableCmdLine) - sizeof(PostVariableCmdLine[0]));
- }
+ TrimSpaces(&PostVariableCmdLine);
//
// We dont do normal processing with a split command line (output from one command input to another)
@@ -1583,13 +1596,8 @@ RunCommand(
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle);
}
} else {
- while (PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] == L' ') {
- PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] = CHAR_NULL;
- }
- while (PostVariableCmdLine[0] == L' ') {
- CopyMem(PostVariableCmdLine, PostVariableCmdLine+1, StrSize(PostVariableCmdLine) - sizeof(PostVariableCmdLine[0]));
- }
-
+ TrimSpaces(&PostVariableCmdLine);
+
//
// get the argc and argv updated for internal commands
//