2 Main file for Help shell level 3 function.
4 Copyright (c) 2009 - 2013, 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
;
44 CONST COMMAND_LIST
*CommandList
;
45 CONST COMMAND_LIST
*Node
;
46 CHAR16
*CommandToGetHelpOn
;
47 CHAR16
*SectionToGetHelpOn
;
50 BOOLEAN PrintCommandText
;
52 PrintCommandText
= TRUE
;
54 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 PrintCommandText
= FALSE
;
113 ASSERT(SectionToGetHelpOn
== NULL
);
115 // Get the section name for the given command name
117 if (ShellCommandLineGetFlag(Package
, L
"-section")) {
118 StrnCatGrow(&SectionToGetHelpOn
, NULL
, ShellCommandLineGetValue(Package
, L
"-section"), 0);
119 } else if (ShellCommandLineGetFlag(Package
, L
"-usage")) {
120 StrnCatGrow(&SectionToGetHelpOn
, NULL
, L
"NAME,SYNOPSIS", 0);
121 } else if (ShellCommandLineGetFlag(Package
, L
"-verbose") || ShellCommandLineGetFlag(Package
, L
"-v")) {
124 // The output of help <command> will display NAME, SYNOPSIS, OPTIONS, DESCRIPTION, and EXAMPLES sections.
126 StrnCatGrow (&SectionToGetHelpOn
, NULL
, L
"NAME,SYNOPSIS,OPTIONS,DESCRIPTION,EXAMPLES", 0);
130 if (gUnicodeCollation
->StriColl(gUnicodeCollation
, CommandToGetHelpOn
, L
"special") == 0) {
132 // we need info on the special characters
134 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HELP_SC_HEADER
), gShellLevel3HiiHandle
);
135 HiiString
= HiiGetString(gShellLevel3HiiHandle
, STRING_TOKEN(STR_HELP_SC_DATA
), NULL
);
136 ShellPrintEx(-1, -1, L
"%s", HiiString
);
140 CommandList
= ShellCommandGetCommandList(TRUE
);
141 ASSERT(CommandList
!= NULL
);
142 for ( Node
= (COMMAND_LIST
*)GetFirstNode(&CommandList
->Link
)
143 ; CommandList
!= NULL
&& !IsListEmpty(&CommandList
->Link
) && !IsNull(&CommandList
->Link
, &Node
->Link
)
144 ; Node
= (COMMAND_LIST
*)GetNextNode(&CommandList
->Link
, &Node
->Link
)
147 // Checking execution break flag when print multiple command help information.
149 if (ShellGetExecutionBreakFlag ()) {
152 if ((gUnicodeCollation
->MetaiMatch(gUnicodeCollation
, Node
->CommandString
, CommandToGetHelpOn
)) ||
153 (gEfiShellProtocol
->GetAlias(CommandToGetHelpOn
, NULL
) != NULL
&& (gUnicodeCollation
->MetaiMatch(gUnicodeCollation
, Node
->CommandString
, (CHAR16
*)(gEfiShellProtocol
->GetAlias(CommandToGetHelpOn
, NULL
)))))) {
155 // We have a command to look for help on.
157 Status
= ShellPrintHelp(Node
->CommandString
, SectionToGetHelpOn
, PrintCommandText
);
158 if (Status
== EFI_DEVICE_ERROR
) {
159 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HELP_INV
), gShellLevel3HiiHandle
, Node
->CommandString
);
160 } else if (EFI_ERROR(Status
)) {
161 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HELP_NF
), gShellLevel3HiiHandle
, Node
->CommandString
);
168 // Search the .man file for Shell applications (Shell external commands).
171 Status
= ShellPrintHelp(CommandToGetHelpOn
, SectionToGetHelpOn
, FALSE
);
172 if (Status
== EFI_DEVICE_ERROR
) {
173 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HELP_INV
), gShellLevel3HiiHandle
, CommandToGetHelpOn
);
174 } else if (EFI_ERROR(Status
)) {
175 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HELP_NF
), gShellLevel3HiiHandle
, CommandToGetHelpOn
);
183 ShellStatus
= SHELL_NOT_FOUND
;
187 // free the command line package
189 ShellCommandLineFreeVarList (Package
);
193 if (CommandToGetHelpOn
!= NULL
&& StrCmp(CommandToGetHelpOn
, L
"*") == 0){
195 // If '*' then the command entered was 'Help' without qualifiers, This footer
196 // provides additional info on help switches
198 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HELP_FOOTER
), gShellLevel3HiiHandle
);
200 if (CommandToGetHelpOn
!= NULL
) {
201 FreePool(CommandToGetHelpOn
);
203 if (SectionToGetHelpOn
!= NULL
) {
204 FreePool(SectionToGetHelpOn
);
207 return (ShellStatus
);