1 | /** @file
|
---|
2 | Main file for Help shell level 3 function.
|
---|
3 |
|
---|
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
|
---|
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 |
|
---|
52 | ProblemParam = NULL;
|
---|
53 | ShellStatus = SHELL_SUCCESS;
|
---|
54 | OutText = NULL;
|
---|
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 | ASSERT(SectionToGetHelpOn == NULL);
|
---|
113 | //
|
---|
114 | // Get the section name for the given command name
|
---|
115 | //
|
---|
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")) {
|
---|
121 | } else {
|
---|
122 | StrnCatGrow(&SectionToGetHelpOn, NULL, L"NAME", 0);
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | if (gUnicodeCollation->StriColl(gUnicodeCollation, CommandToGetHelpOn, L"special") == 0) {
|
---|
127 | //
|
---|
128 | // we need info on the special characters
|
---|
129 | //
|
---|
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);
|
---|
133 | FreePool(HiiString);
|
---|
134 | Found = TRUE;
|
---|
135 | } else {
|
---|
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)
|
---|
141 | ){
|
---|
142 | if ((gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, CommandToGetHelpOn)) ||
|
---|
143 | (gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL) != NULL && (gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, (CHAR16*)(gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL)))))) {
|
---|
144 | //
|
---|
145 | // We have a command to look for help on.
|
---|
146 | //
|
---|
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);
|
---|
151 | } else {
|
---|
152 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, Node->CommandString);
|
---|
153 | }
|
---|
154 | ShellStatus = SHELL_NOT_FOUND;
|
---|
155 | } else {
|
---|
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;
|
---|
158 | }
|
---|
159 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_COMMAND), gShellLevel3HiiHandle, Node->CommandString, OutText);
|
---|
160 | FreePool(OutText);
|
---|
161 | OutText = NULL;
|
---|
162 | Found = TRUE;
|
---|
163 | }
|
---|
164 | }
|
---|
165 | }
|
---|
166 | }
|
---|
167 |
|
---|
168 | if (!Found && ShellStatus == SHELL_SUCCESS) {
|
---|
169 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, CommandToGetHelpOn);
|
---|
170 | ShellStatus = SHELL_NOT_FOUND;
|
---|
171 | }
|
---|
172 |
|
---|
173 | //
|
---|
174 | // free the command line package
|
---|
175 | //
|
---|
176 | ShellCommandLineFreeVarList (Package);
|
---|
177 | }
|
---|
178 | }
|
---|
179 | if (CommandToGetHelpOn != NULL) {
|
---|
180 | FreePool(CommandToGetHelpOn);
|
---|
181 | }
|
---|
182 | if (SectionToGetHelpOn != NULL) {
|
---|
183 | FreePool(SectionToGetHelpOn);
|
---|
184 | }
|
---|
185 |
|
---|
186 | return (ShellStatus);
|
---|
187 | }
|
---|
188 |
|
---|