2 Main file for Help shell level 3 function.
4 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved. <BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "UefiShellLevel3CommandsLib.h"
17 #include <Library/ShellLib.h>
19 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
20 {L
"-usage", TypeFlag
},
21 {L
"-section", TypeMaxValue
},
22 {L
"-verbose", TypeFlag
},
28 Function for 'help' command.
30 @param[in] ImageHandle Handle to the Image (NULL if Internal).
31 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
36 IN EFI_HANDLE ImageHandle
,
37 IN EFI_SYSTEM_TABLE
*SystemTable
43 SHELL_STATUS ShellStatus
;
45 CONST COMMAND_LIST
*CommandList
;
46 CONST COMMAND_LIST
*Node
;
47 CHAR16
*CommandToGetHelpOn
;
48 CHAR16
*SectionToGetHelpOn
;
53 ShellStatus
= SHELL_SUCCESS
;
55 CommandToGetHelpOn
= NULL
;
56 SectionToGetHelpOn
= NULL
;
60 // initialize the shell lib (we must be in non-auto-init...)
62 Status
= ShellInitialize();
63 ASSERT_EFI_ERROR(Status
);
65 Status
= CommandInit();
66 ASSERT_EFI_ERROR(Status
);
69 // parse the command line
71 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
72 if (EFI_ERROR(Status
)) {
73 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
74 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel3HiiHandle
, ProblemParam
);
75 FreePool(ProblemParam
);
76 ShellStatus
= SHELL_INVALID_PARAMETER
;
82 // Check for conflicting parameters.
84 if (ShellCommandLineGetFlag(Package
, L
"-usage")
85 &&ShellCommandLineGetFlag(Package
, L
"-section")
86 &&(ShellCommandLineGetFlag(Package
, L
"-verbose") || ShellCommandLineGetFlag(Package
, L
"-v"))
88 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CON
), gShellLevel3HiiHandle
);
89 ShellStatus
= SHELL_INVALID_PARAMETER
;
90 } else if (ShellCommandLineGetRawValue(Package
, 2) != NULL
) {
91 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel3HiiHandle
);
92 ShellStatus
= SHELL_INVALID_PARAMETER
;
95 // Get the command name we are getting help on
97 ASSERT(CommandToGetHelpOn
== NULL
);
98 StrnCatGrow(&CommandToGetHelpOn
, NULL
, ShellCommandLineGetRawValue(Package
, 1), 0);
99 if (CommandToGetHelpOn
== NULL
&& ShellCommandLineGetFlag(Package
, L
"-?")) {
101 // If we dont have a command and we got a simple -?
102 // we are looking for help on help command.
104 StrnCatGrow(&CommandToGetHelpOn
, NULL
, L
"help", 0);
107 if (CommandToGetHelpOn
== NULL
) {
108 StrnCatGrow(&CommandToGetHelpOn
, NULL
, L
"*", 0);
109 ASSERT(SectionToGetHelpOn
== NULL
);
110 StrnCatGrow(&SectionToGetHelpOn
, NULL
, L
"NAME", 0);
112 ASSERT(SectionToGetHelpOn
== NULL
);
114 // Get the section name for the given command name
116 if (ShellCommandLineGetFlag(Package
, L
"-section")) {
117 StrnCatGrow(&SectionToGetHelpOn
, NULL
, ShellCommandLineGetValue(Package
, L
"-section"), 0);
118 } else if (ShellCommandLineGetFlag(Package
, L
"-usage")) {
119 StrnCatGrow(&SectionToGetHelpOn
, NULL
, L
"NAME,SYNOPSIS", 0);
120 } else if (ShellCommandLineGetFlag(Package
, L
"-verbose") || ShellCommandLineGetFlag(Package
, L
"-v")) {
122 StrnCatGrow(&SectionToGetHelpOn
, NULL
, L
"NAME", 0);
126 if (gUnicodeCollation
->StriColl(gUnicodeCollation
, CommandToGetHelpOn
, L
"special") == 0) {
128 // we need info on the special characters
130 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HELP_SC_HEADER
), gShellLevel3HiiHandle
);
131 HiiString
= HiiGetString(gShellLevel3HiiHandle
, STRING_TOKEN(STR_HELP_SC_DATA
), NULL
);
132 ShellPrintEx(-1, -1, L
"%s", HiiString
);
136 CommandList
= ShellCommandGetCommandList(TRUE
);
137 ASSERT(CommandList
!= NULL
);
138 for ( Node
= (COMMAND_LIST
*)GetFirstNode(&CommandList
->Link
)
139 ; CommandList
!= NULL
&& !IsListEmpty(&CommandList
->Link
) && !IsNull(&CommandList
->Link
, &Node
->Link
)
140 ; Node
= (COMMAND_LIST
*)GetNextNode(&CommandList
->Link
, &Node
->Link
)
142 if ((gUnicodeCollation
->MetaiMatch(gUnicodeCollation
, Node
->CommandString
, CommandToGetHelpOn
)) ||
143 (gEfiShellProtocol
->GetAlias(CommandToGetHelpOn
, NULL
) != NULL
&& (gUnicodeCollation
->MetaiMatch(gUnicodeCollation
, Node
->CommandString
, (CHAR16
*)(gEfiShellProtocol
->GetAlias(CommandToGetHelpOn
, NULL
)))))) {
145 // We have a command to look for help on.
147 Status
= gEfiShellProtocol
->GetHelpText(Node
->CommandString
, SectionToGetHelpOn
, &OutText
);
148 if (EFI_ERROR(Status
) || OutText
== NULL
) {
149 if (Status
== EFI_DEVICE_ERROR
) {
150 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HELP_INV
), gShellLevel3HiiHandle
, Node
->CommandString
);
152 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HELP_NF
), gShellLevel3HiiHandle
, Node
->CommandString
);
154 ShellStatus
= SHELL_NOT_FOUND
;
156 while (OutText
[StrLen(OutText
)-1] == L
'\r' || OutText
[StrLen(OutText
)-1] == L
'\n' || OutText
[StrLen(OutText
)-1] == L
' ') {
157 OutText
[StrLen(OutText
)-1] = CHAR_NULL
;
159 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HELP_COMMAND
), gShellLevel3HiiHandle
, Node
->CommandString
, OutText
);
168 if (!Found
&& ShellStatus
== SHELL_SUCCESS
) {
169 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HELP_NF
), gShellLevel3HiiHandle
, CommandToGetHelpOn
);
170 ShellStatus
= SHELL_NOT_FOUND
;
174 // free the command line package
176 ShellCommandLineFreeVarList (Package
);
179 if (CommandToGetHelpOn
!= NULL
) {
180 FreePool(CommandToGetHelpOn
);
182 if (SectionToGetHelpOn
!= NULL
) {
183 FreePool(SectionToGetHelpOn
);
186 return (ShellStatus
);