Revision: 14985
          http://sourceforge.net/p/edk2/code/14985
Author:   jcarsey
Date:     2013-12-13 21:58:51 +0000 (Fri, 13 Dec 2013)
Log Message:
-----------
ShellPkg: Refactor updating command line for help use

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <[email protected]>
Reviewed-by: Erik Bjorge <[email protected]>

Modified Paths:
--------------
    trunk/edk2/ShellPkg/Application/Shell/Shell.c

Modified: trunk/edk2/ShellPkg/Application/Shell/Shell.c
===================================================================
--- trunk/edk2/ShellPkg/Application/Shell/Shell.c       2013-12-13 19:22:39 UTC 
(rev 14984)
+++ trunk/edk2/ShellPkg/Application/Shell/Shell.c       2013-12-13 21:58:51 UTC 
(rev 14985)
@@ -1656,6 +1656,57 @@
 }
 
 /**
+  Reprocess the command line to direct all -? to the help command.
+
+  if found, will add "help" as argv[0], and move the rest later.
+
+  @param[in,out] Argc  The pointer to argc to update 
+  @param[in,out] Argv  The pointer to argv to update (this is a pointer to an 
array of string pointers)
+**/
+EFI_STATUS
+EFIAPI
+DoHelpUpdateArgcArgv(
+  IN OUT UINTN *Argc,
+  IN OUT CHAR16 ***Argv
+  )
+{
+  UINTN Count;
+  UINTN Count2;
+  //
+  // Check each parameter
+  //
+  for (Count = 0 ; Count < (*Argc) ; Count++) {
+    //
+    // if it's "-?" or if the first parameter is "?"
+    //
+    if (StrStr((*Argv)[Count], L"-?") == (*Argv)[Count] 
+    ||  ((*Argv)[0][0] == L'?' && (*Argv)[0][1] == CHAR_NULL)
+      ) {
+      //
+      // We need to redo the arguments since a parameter was -?
+      // move them all down 1 to the end, then up one then replace the first 
with help
+      //
+      FreePool((*Argv)[Count]);
+      (*Argv)[Count] = NULL;
+      for (Count2 = Count ; (Count2 + 1) < (*Argc) ; Count2++) {
+        (*Argv)[Count2] = (*Argv)[Count2+1];
+      }
+      (*Argv)[Count2] = NULL;
+      for (Count2 = (*Argc) -1 ; Count2 > 0 ; Count2--) {
+        (*Argv)[Count2] = (*Argv)[Count2-1];
+      }
+      (*Argv)[0] = NULL;
+      (*Argv)[0] = StrnCatGrow(&(*Argv)[0], NULL, L"help", 0);
+      if ((*Argv)[0] == NULL) {
+        return (EFI_OUT_OF_RESOURCES);
+      }
+      break;
+    }
+  }
+  return (EFI_SUCCESS);
+}
+
+/**
   Function will process and run a command line.
 
   This will determine if the command line represents an internal shell 
@@ -1688,8 +1739,6 @@
   SHELL_FILE_HANDLE         OriginalStdOut;
   SHELL_FILE_HANDLE         OriginalStdErr;
   SYSTEM_TABLE_INFO         OriginalSystemTableInfo;
-  UINTN                     Count;
-  UINTN                     Count2;
   CHAR16                    *CleanOriginal;
 
   ASSERT(CmdLine != NULL);
@@ -1770,27 +1819,10 @@
       Status = UpdateArgcArgv(ShellInfoObject.NewShellParametersProtocol, 
CleanOriginal, &Argv, &Argc);
       ASSERT_EFI_ERROR(Status);
 
-      for (Count = 0 ; Count < 
ShellInfoObject.NewShellParametersProtocol->Argc ; Count++) {
-        if (StrStr(ShellInfoObject.NewShellParametersProtocol->Argv[Count], 
L"-?") == ShellInfoObject.NewShellParametersProtocol->Argv[Count]
-        ||  (ShellInfoObject.NewShellParametersProtocol->Argv[0][0] == L'?' && 
ShellInfoObject.NewShellParametersProtocol->Argv[0][1] == CHAR_NULL)
-          ) {
-          //
-          // We need to redo the arguments since a parameter was -?
-          // move them all down 1 to the end, then up one then replace the 
first with help
-          //
-          FreePool(ShellInfoObject.NewShellParametersProtocol->Argv[Count]);
-          ShellInfoObject.NewShellParametersProtocol->Argv[Count] = NULL;
-          for (Count2 = Count ; (Count2 + 1) < 
ShellInfoObject.NewShellParametersProtocol->Argc ; Count2++) {
-            ShellInfoObject.NewShellParametersProtocol->Argv[Count2] = 
ShellInfoObject.NewShellParametersProtocol->Argv[Count2+1];
-          }
-          ShellInfoObject.NewShellParametersProtocol->Argv[Count2] = NULL;
-          for (Count2 = ShellInfoObject.NewShellParametersProtocol->Argc -1 ; 
Count2 > 0 ; Count2--) {
-            ShellInfoObject.NewShellParametersProtocol->Argv[Count2] = 
ShellInfoObject.NewShellParametersProtocol->Argv[Count2-1];
-          }
-          ShellInfoObject.NewShellParametersProtocol->Argv[0] = NULL;
-          ShellInfoObject.NewShellParametersProtocol->Argv[0] = 
StrnCatGrow(&ShellInfoObject.NewShellParametersProtocol->Argv[0], NULL, 
L"help", 0);
-          break;
-        }
+      if (StrStr(CleanOriginal, L"?") != NULL) {
+        Status = DoHelpUpdateArgcArgv(
+          &ShellInfoObject.NewShellParametersProtocol->Argc,
+          &ShellInfoObject.NewShellParametersProtocol->Argv);
       }
 
       //

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to