]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c
ShellPkg: Fixed build error 'variable set but not used'
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel3CommandsLib / Help.c
1 /** @file
2 Main file for Help shell level 3 function.
3
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
9
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.
12
13 **/
14
15 #include "UefiShellLevel3CommandsLib.h"
16
17 #include <Library/ShellLib.h>
18
19 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
20 {L"-usage", TypeFlag},
21 {L"-section", TypeMaxValue},
22 {L"-verbose", TypeFlag},
23 {L"-v", TypeFlag},
24 {NULL, TypeMax}
25 };
26
27 /**
28 Function for 'help' command.
29
30 @param[in] ImageHandle Handle to the Image (NULL if Internal).
31 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
32 **/
33 SHELL_STATUS
34 EFIAPI
35 ShellCommandRunHelp (
36 IN EFI_HANDLE ImageHandle,
37 IN EFI_SYSTEM_TABLE *SystemTable
38 )
39 {
40 EFI_STATUS Status;
41 LIST_ENTRY *Package;
42 CHAR16 *ProblemParam;
43 SHELL_STATUS ShellStatus;
44 CONST COMMAND_LIST *CommandList;
45 CONST COMMAND_LIST *Node;
46 CHAR16 *CommandToGetHelpOn;
47 CHAR16 *SectionToGetHelpOn;
48 CHAR16 *HiiString;
49 BOOLEAN Found;
50 BOOLEAN PrintCommandText;
51
52 PrintCommandText = TRUE;
53 ProblemParam = NULL;
54 ShellStatus = SHELL_SUCCESS;
55 CommandToGetHelpOn = NULL;
56 SectionToGetHelpOn = NULL;
57 Found = FALSE;
58
59 //
60 // initialize the shell lib (we must be in non-auto-init...)
61 //
62 Status = ShellInitialize();
63 ASSERT_EFI_ERROR(Status);
64
65 Status = CommandInit();
66 ASSERT_EFI_ERROR(Status);
67
68 //
69 // parse the command line
70 //
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;
77 } else {
78 ASSERT(FALSE);
79 }
80 } else {
81 //
82 // Check for conflicting parameters.
83 //
84 if (ShellCommandLineGetFlag(Package, L"-usage")
85 &&ShellCommandLineGetFlag(Package, L"-section")
86 &&(ShellCommandLineGetFlag(Package, L"-verbose") || ShellCommandLineGetFlag(Package, L"-v"))
87 ){
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;
93 } else {
94 //
95 // Get the command name we are getting help on
96 //
97 ASSERT(CommandToGetHelpOn == NULL);
98 StrnCatGrow(&CommandToGetHelpOn, NULL, ShellCommandLineGetRawValue(Package, 1), 0);
99 if (CommandToGetHelpOn == NULL && ShellCommandLineGetFlag(Package, L"-?")) {
100 //
101 // If we dont have a command and we got a simple -?
102 // we are looking for help on help command.
103 //
104 StrnCatGrow(&CommandToGetHelpOn, NULL, L"help", 0);
105 }
106
107 if (CommandToGetHelpOn == NULL) {
108 StrnCatGrow(&CommandToGetHelpOn, NULL, L"*", 0);
109 ASSERT(SectionToGetHelpOn == NULL);
110 StrnCatGrow(&SectionToGetHelpOn, NULL, L"NAME", 0);
111 } else {
112 PrintCommandText = FALSE;
113 ASSERT(SectionToGetHelpOn == NULL);
114 //
115 // Get the section name for the given command name
116 //
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")) {
122 } else {
123 //
124 // The output of help <command> will display NAME, SYNOPSIS, OPTIONS, DESCRIPTION, and EXAMPLES sections.
125 //
126 StrnCatGrow (&SectionToGetHelpOn, NULL, L"NAME,SYNOPSIS,OPTIONS,DESCRIPTION,EXAMPLES", 0);
127 }
128 }
129
130 if (gUnicodeCollation->StriColl(gUnicodeCollation, CommandToGetHelpOn, L"special") == 0) {
131 //
132 // we need info on the special characters
133 //
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);
137 FreePool(HiiString);
138 Found = TRUE;
139 } else {
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)
145 ){
146 //
147 // Checking execution break flag when print multiple command help information.
148 //
149 if (ShellGetExecutionBreakFlag ()) {
150 break;
151 }
152 if ((gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, CommandToGetHelpOn)) ||
153 (gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL) != NULL && (gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, (CHAR16*)(gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL)))))) {
154 //
155 // We have a command to look for help on.
156 //
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);
162 } else {
163 Found = TRUE;
164 }
165 }
166 }
167 //
168 // Search the .man file for Shell applications (Shell external commands).
169 //
170 if (!Found) {
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);
176 } else {
177 Found = TRUE;
178 }
179 }
180 }
181
182 if (!Found) {
183 ShellStatus = SHELL_NOT_FOUND;
184 }
185
186 //
187 // free the command line package
188 //
189 ShellCommandLineFreeVarList (Package);
190 }
191 }
192
193 if (CommandToGetHelpOn != NULL && StrCmp(CommandToGetHelpOn, L"*") == 0){
194 //
195 // If '*' then the command entered was 'Help' without qualifiers, This footer
196 // provides additional info on help switches
197 //
198 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_FOOTER), gShellLevel3HiiHandle);
199 }
200 if (CommandToGetHelpOn != NULL) {
201 FreePool(CommandToGetHelpOn);
202 }
203 if (SectionToGetHelpOn != NULL) {
204 FreePool(SectionToGetHelpOn);
205 }
206
207 return (ShellStatus);
208 }
209