]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c
ShellPkg: Rewrite’s Help.c to call the ShellPrintHelp function.
[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 CHAR16 *OutText;
45 CONST COMMAND_LIST *CommandList;
46 CONST COMMAND_LIST *Node;
47 CHAR16 *CommandToGetHelpOn;
48 CHAR16 *SectionToGetHelpOn;
49 CHAR16 *HiiString;
50 BOOLEAN Found;
51 BOOLEAN PrintCommandText;
52
53 PrintCommandText = TRUE;
54 ProblemParam = NULL;
55 ShellStatus = SHELL_SUCCESS;
56 OutText = NULL;
57 CommandToGetHelpOn = NULL;
58 SectionToGetHelpOn = NULL;
59 Found = FALSE;
60
61 //
62 // initialize the shell lib (we must be in non-auto-init...)
63 //
64 Status = ShellInitialize();
65 ASSERT_EFI_ERROR(Status);
66
67 Status = CommandInit();
68 ASSERT_EFI_ERROR(Status);
69
70 //
71 // parse the command line
72 //
73 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
74 if (EFI_ERROR(Status)) {
75 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
76 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
77 FreePool(ProblemParam);
78 ShellStatus = SHELL_INVALID_PARAMETER;
79 } else {
80 ASSERT(FALSE);
81 }
82 } else {
83 //
84 // Check for conflicting parameters.
85 //
86 if (ShellCommandLineGetFlag(Package, L"-usage")
87 &&ShellCommandLineGetFlag(Package, L"-section")
88 &&(ShellCommandLineGetFlag(Package, L"-verbose") || ShellCommandLineGetFlag(Package, L"-v"))
89 ){
90 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellLevel3HiiHandle);
91 ShellStatus = SHELL_INVALID_PARAMETER;
92 } else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
93 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);
94 ShellStatus = SHELL_INVALID_PARAMETER;
95 } else {
96 //
97 // Get the command name we are getting help on
98 //
99 ASSERT(CommandToGetHelpOn == NULL);
100 StrnCatGrow(&CommandToGetHelpOn, NULL, ShellCommandLineGetRawValue(Package, 1), 0);
101 if (CommandToGetHelpOn == NULL && ShellCommandLineGetFlag(Package, L"-?")) {
102 //
103 // If we dont have a command and we got a simple -?
104 // we are looking for help on help command.
105 //
106 StrnCatGrow(&CommandToGetHelpOn, NULL, L"help", 0);
107 }
108
109 if (CommandToGetHelpOn == NULL) {
110 StrnCatGrow(&CommandToGetHelpOn, NULL, L"*", 0);
111 ASSERT(SectionToGetHelpOn == NULL);
112 StrnCatGrow(&SectionToGetHelpOn, NULL, L"NAME", 0);
113 } else {
114 PrintCommandText = FALSE;
115 ASSERT(SectionToGetHelpOn == NULL);
116 //
117 // Get the section name for the given command name
118 //
119 if (ShellCommandLineGetFlag(Package, L"-section")) {
120 StrnCatGrow(&SectionToGetHelpOn, NULL, ShellCommandLineGetValue(Package, L"-section"), 0);
121 } else if (ShellCommandLineGetFlag(Package, L"-usage")) {
122 StrnCatGrow(&SectionToGetHelpOn, NULL, L"NAME,SYNOPSIS", 0);
123 } else if (ShellCommandLineGetFlag(Package, L"-verbose") || ShellCommandLineGetFlag(Package, L"-v")) {
124 } else {
125 //
126 // The output of help <command> will display NAME, SYNOPSIS, OPTIONS, DESCRIPTION, and EXAMPLES sections.
127 //
128 StrnCatGrow (&SectionToGetHelpOn, NULL, L"NAME,SYNOPSIS,OPTIONS,DESCRIPTION,EXAMPLES", 0);
129 }
130 }
131
132 if (gUnicodeCollation->StriColl(gUnicodeCollation, CommandToGetHelpOn, L"special") == 0) {
133 //
134 // we need info on the special characters
135 //
136 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_SC_HEADER), gShellLevel3HiiHandle);
137 HiiString = HiiGetString(gShellLevel3HiiHandle, STRING_TOKEN(STR_HELP_SC_DATA), NULL);
138 ShellPrintEx(-1, -1, L"%s", HiiString);
139 FreePool(HiiString);
140 Found = TRUE;
141 } else {
142 CommandList = ShellCommandGetCommandList(TRUE);
143 ASSERT(CommandList != NULL);
144 for ( Node = (COMMAND_LIST*)GetFirstNode(&CommandList->Link)
145 ; CommandList != NULL && !IsListEmpty(&CommandList->Link) && !IsNull(&CommandList->Link, &Node->Link)
146 ; Node = (COMMAND_LIST*)GetNextNode(&CommandList->Link, &Node->Link)
147 ){
148 //
149 // Checking execution break flag when print multiple command help information.
150 //
151 if (ShellGetExecutionBreakFlag ()) {
152 break;
153 }
154 if ((gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, CommandToGetHelpOn)) ||
155 (gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL) != NULL && (gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, (CHAR16*)(gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL)))))) {
156 //
157 // We have a command to look for help on.
158 //
159 Status = ShellPrintHelp(Node->CommandString, SectionToGetHelpOn, PrintCommandText);
160 if (Status == EFI_DEVICE_ERROR) {
161 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_INV), gShellLevel3HiiHandle, Node->CommandString);
162 } else if (EFI_ERROR(Status)) {
163 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, Node->CommandString);
164 } else {
165 Found = TRUE;
166 }
167 }
168 }
169 //
170 // Search the .man file for Shell applications (Shell external commands).
171 //
172 if (!Found) {
173 Status = ShellPrintHelp(CommandToGetHelpOn, SectionToGetHelpOn, FALSE);
174 if (Status == EFI_DEVICE_ERROR) {
175 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_INV), gShellLevel3HiiHandle, CommandToGetHelpOn);
176 } else if (EFI_ERROR(Status)) {
177 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, CommandToGetHelpOn);
178 } else {
179 Found = TRUE;
180 }
181 }
182 }
183
184 if (!Found) {
185 ShellStatus = SHELL_NOT_FOUND;
186 }
187
188 //
189 // free the command line package
190 //
191 ShellCommandLineFreeVarList (Package);
192 }
193 }
194
195 if (CommandToGetHelpOn != NULL && StrCmp(CommandToGetHelpOn, L"*") == 0){
196 //
197 // If '*' then the command entered was 'Help' without qualifiers, This footer
198 // provides additional info on help switches
199 //
200 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_FOOTER), gShellLevel3HiiHandle);
201 }
202 if (CommandToGetHelpOn != NULL) {
203 FreePool(CommandToGetHelpOn);
204 }
205 if (SectionToGetHelpOn != NULL) {
206 FreePool(SectionToGetHelpOn);
207 }
208
209 return (ShellStatus);
210 }
211