diff options
author | Jaben Carsey <jaben.carsey@intel.com> | 2013-12-13 21:58:51 +0000 |
---|---|---|
committer | jcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524> | 2013-12-13 21:58:51 +0000 |
commit | 5a5eb8069cc91e0334f3dfec17da672ac326fa55 (patch) | |
tree | 6b62bbbb4d75eafbac09a8fa2ffdace48f54f6bd /ShellPkg/Application/Shell/Shell.c | |
parent | ceecdc62ab73e5b726630345865a512c780c134e (diff) | |
download | edk2-platforms-5a5eb8069cc91e0334f3dfec17da672ac326fa55.tar.xz |
ShellPkg: Refactor updating command line for help use
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@14985 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg/Application/Shell/Shell.c')
-rw-r--r-- | ShellPkg/Application/Shell/Shell.c | 78 |
1 files changed, 55 insertions, 23 deletions
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c index 0cf09ec76b..6822f52e81 100644 --- a/ShellPkg/Application/Shell/Shell.c +++ b/ShellPkg/Application/Shell/Shell.c @@ -1656,6 +1656,57 @@ ChangeMappedDrive( }
/**
+ 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 @@ RunCommand( 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 @@ RunCommand( 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);
}
//
|