]>
Commit | Line | Data |
---|---|---|
a405b86d | 1 | /** @file\r |
2 | Main file for Help shell level 3 function.\r | |
3 | \r | |
345cd235 | 4 | Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved. <BR>\r |
a405b86d | 5 | This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "UefiShellLevel3CommandsLib.h"\r | |
16 | \r | |
17 | #include <Library/ShellLib.h>\r | |
18 | \r | |
19 | STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r | |
20 | {L"-usage", TypeFlag},\r | |
345cd235 | 21 | {L"-section", TypeMaxValue},\r |
a405b86d | 22 | {L"-verbose", TypeFlag},\r |
23 | {L"-v", TypeFlag},\r | |
24 | {NULL, TypeMax}\r | |
25 | };\r | |
26 | \r | |
27 | /**\r | |
28 | Function for 'help' command.\r | |
29 | \r | |
30 | @param[in] ImageHandle Handle to the Image (NULL if Internal).\r | |
31 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r | |
32 | **/\r | |
33 | SHELL_STATUS\r | |
34 | EFIAPI\r | |
35 | ShellCommandRunHelp (\r | |
36 | IN EFI_HANDLE ImageHandle,\r | |
37 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
38 | )\r | |
39 | {\r | |
40 | EFI_STATUS Status;\r | |
41 | LIST_ENTRY *Package;\r | |
42 | CHAR16 *ProblemParam;\r | |
43 | SHELL_STATUS ShellStatus;\r | |
44 | CHAR16 *OutText;\r | |
45 | CONST COMMAND_LIST *CommandList;\r | |
46 | CONST COMMAND_LIST *Node;\r | |
47 | CHAR16 *CommandToGetHelpOn;\r | |
48 | CHAR16 *SectionToGetHelpOn;\r | |
49 | CHAR16 *HiiString;\r | |
50 | BOOLEAN Found;\r | |
d51088b7 | 51 | BOOLEAN HelpPage;\r |
a405b86d | 52 | \r |
d51088b7 | 53 | HelpPage = FALSE;\r |
a405b86d | 54 | ProblemParam = NULL;\r |
55 | ShellStatus = SHELL_SUCCESS;\r | |
56 | OutText = NULL;\r | |
57 | CommandToGetHelpOn = NULL;\r | |
58 | SectionToGetHelpOn = NULL;\r | |
59 | Found = FALSE;\r | |
60 | \r | |
61 | //\r | |
62 | // initialize the shell lib (we must be in non-auto-init...)\r | |
63 | //\r | |
64 | Status = ShellInitialize();\r | |
65 | ASSERT_EFI_ERROR(Status);\r | |
66 | \r | |
67 | Status = CommandInit();\r | |
68 | ASSERT_EFI_ERROR(Status);\r | |
69 | \r | |
70 | //\r | |
71 | // parse the command line\r | |
72 | //\r | |
73 | Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r | |
74 | if (EFI_ERROR(Status)) {\r | |
75 | if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r | |
76 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);\r | |
77 | FreePool(ProblemParam);\r | |
78 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
79 | } else {\r | |
80 | ASSERT(FALSE);\r | |
81 | }\r | |
82 | } else {\r | |
83 | //\r | |
84 | // Check for conflicting parameters.\r | |
85 | //\r | |
86 | if (ShellCommandLineGetFlag(Package, L"-usage")\r | |
87 | &&ShellCommandLineGetFlag(Package, L"-section")\r | |
88 | &&(ShellCommandLineGetFlag(Package, L"-verbose") || ShellCommandLineGetFlag(Package, L"-v"))\r | |
89 | ){\r | |
90 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellLevel3HiiHandle);\r | |
91 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
92 | } else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {\r | |
93 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);\r | |
94 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
95 | } else {\r | |
96 | //\r | |
97 | // Get the command name we are getting help on\r | |
98 | //\r | |
99 | ASSERT(CommandToGetHelpOn == NULL);\r | |
100 | StrnCatGrow(&CommandToGetHelpOn, NULL, ShellCommandLineGetRawValue(Package, 1), 0);\r | |
101 | if (CommandToGetHelpOn == NULL && ShellCommandLineGetFlag(Package, L"-?")) {\r | |
102 | //\r | |
103 | // If we dont have a command and we got a simple -?\r | |
104 | // we are looking for help on help command.\r | |
105 | //\r | |
106 | StrnCatGrow(&CommandToGetHelpOn, NULL, L"help", 0);\r | |
107 | }\r | |
108 | \r | |
109 | if (CommandToGetHelpOn == NULL) {\r | |
110 | StrnCatGrow(&CommandToGetHelpOn, NULL, L"*", 0);\r | |
111 | ASSERT(SectionToGetHelpOn == NULL);\r | |
112 | StrnCatGrow(&SectionToGetHelpOn, NULL, L"NAME", 0);\r | |
113 | } else {\r | |
d51088b7 | 114 | HelpPage = TRUE;\r |
a405b86d | 115 | ASSERT(SectionToGetHelpOn == NULL);\r |
116 | //\r | |
117 | // Get the section name for the given command name\r | |
118 | //\r | |
119 | if (ShellCommandLineGetFlag(Package, L"-section")) {\r | |
120 | StrnCatGrow(&SectionToGetHelpOn, NULL, ShellCommandLineGetValue(Package, L"-section"), 0);\r | |
121 | } else if (ShellCommandLineGetFlag(Package, L"-usage")) {\r | |
122 | StrnCatGrow(&SectionToGetHelpOn, NULL, L"NAME,SYNOPSIS", 0);\r | |
123 | } else if (ShellCommandLineGetFlag(Package, L"-verbose") || ShellCommandLineGetFlag(Package, L"-v")) {\r | |
124 | } else {\r | |
d51088b7 | 125 | //\r |
126 | // The output of help <command> will display NAME, SYNOPSIS, OPTIONS, DESCRIPTION, and EXAMPLES sections.\r | |
127 | //\r | |
128 | StrnCatGrow (&SectionToGetHelpOn, NULL, L"NAME,SYNOPSIS,OPTIONS,DESCRIPTION,EXAMPLES", 0);\r | |
a405b86d | 129 | }\r |
130 | }\r | |
131 | \r | |
132 | if (gUnicodeCollation->StriColl(gUnicodeCollation, CommandToGetHelpOn, L"special") == 0) {\r | |
133 | //\r | |
134 | // we need info on the special characters\r | |
135 | //\r | |
136 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_SC_HEADER), gShellLevel3HiiHandle);\r | |
137 | HiiString = HiiGetString(gShellLevel3HiiHandle, STRING_TOKEN(STR_HELP_SC_DATA), NULL);\r | |
138 | ShellPrintEx(-1, -1, L"%s", HiiString);\r | |
139 | FreePool(HiiString);\r | |
140 | Found = TRUE;\r | |
141 | } else {\r | |
345cd235 | 142 | CommandList = ShellCommandGetCommandList(TRUE);\r |
a405b86d | 143 | ASSERT(CommandList != NULL);\r |
144 | for ( Node = (COMMAND_LIST*)GetFirstNode(&CommandList->Link)\r | |
145 | ; CommandList != NULL && !IsListEmpty(&CommandList->Link) && !IsNull(&CommandList->Link, &Node->Link)\r | |
146 | ; Node = (COMMAND_LIST*)GetNextNode(&CommandList->Link, &Node->Link)\r | |
147 | ){\r | |
d51088b7 | 148 | //\r |
149 | // Checking execution break flag when print multiple command help information.\r | |
150 | //\r | |
151 | if (ShellGetExecutionBreakFlag ()) {\r | |
152 | break;\r | |
153 | } \r | |
345cd235 | 154 | if ((gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, CommandToGetHelpOn)) ||\r |
155 | (gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL) != NULL && (gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, (CHAR16*)(gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL)))))) {\r | |
a405b86d | 156 | //\r |
157 | // We have a command to look for help on.\r | |
158 | //\r | |
159 | Status = gEfiShellProtocol->GetHelpText(Node->CommandString, SectionToGetHelpOn, &OutText);\r | |
160 | if (EFI_ERROR(Status) || OutText == NULL) {\r | |
345cd235 | 161 | if (Status == EFI_DEVICE_ERROR) {\r |
162 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_INV), gShellLevel3HiiHandle, Node->CommandString);\r | |
163 | } else {\r | |
164 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, Node->CommandString);\r | |
165 | }\r | |
a405b86d | 166 | ShellStatus = SHELL_NOT_FOUND;\r |
167 | } else {\r | |
eafd681e | 168 | if (HelpPage) {\r |
d51088b7 | 169 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_PAGE_COMMAND), gShellLevel3HiiHandle, OutText);\r |
170 | } else {\r | |
171 | while (OutText[StrLen(OutText)-1] == L'\r' || OutText[StrLen(OutText)-1] == L'\n' || OutText[StrLen(OutText)-1] == L' ') {\r | |
172 | OutText[StrLen(OutText)-1] = CHAR_NULL;\r | |
173 | }\r | |
174 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_COMMAND), gShellLevel3HiiHandle, Node->CommandString, OutText);\r | |
a405b86d | 175 | }\r |
a405b86d | 176 | FreePool(OutText);\r |
177 | OutText = NULL;\r | |
178 | Found = TRUE;\r | |
179 | }\r | |
180 | }\r | |
181 | }\r | |
d51088b7 | 182 | //\r |
183 | // Search the .man file for Shell applications (Shell external commands).\r | |
184 | //\r | |
185 | if (!Found) {\r | |
186 | Status = gEfiShellProtocol->GetHelpText (CommandToGetHelpOn, SectionToGetHelpOn, &OutText);\r | |
187 | if (EFI_ERROR(Status) || OutText == NULL) {\r | |
188 | if (Status == EFI_DEVICE_ERROR) {\r | |
189 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_HELP_INV), gShellLevel3HiiHandle, CommandToGetHelpOn);\r | |
190 | } else {\r | |
191 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, CommandToGetHelpOn);\r | |
192 | }\r | |
193 | ShellStatus = SHELL_NOT_FOUND;\r | |
194 | } else {\r | |
195 | while (OutText[StrLen (OutText) - 1] == L'\r' || OutText[StrLen (OutText) - 1] == L'\n' || OutText[StrLen (OutText) - 1] == L' ') {\r | |
196 | OutText[StrLen (OutText)-1] = CHAR_NULL;\r | |
197 | }\r | |
198 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_HELP_COMMAND), gShellLevel3HiiHandle, CommandToGetHelpOn, OutText);\r | |
199 | if (OutText != NULL) {\r | |
200 | FreePool (OutText);\r | |
201 | OutText = NULL;\r | |
202 | }\r | |
203 | Found = TRUE;\r | |
204 | }\r | |
205 | }\r | |
a405b86d | 206 | }\r |
207 | \r | |
208 | if (!Found && ShellStatus == SHELL_SUCCESS) {\r | |
209 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, CommandToGetHelpOn);\r | |
210 | ShellStatus = SHELL_NOT_FOUND;\r | |
211 | }\r | |
212 | \r | |
213 | //\r | |
214 | // free the command line package\r | |
215 | //\r | |
216 | ShellCommandLineFreeVarList (Package);\r | |
217 | }\r | |
218 | }\r | |
219 | if (CommandToGetHelpOn != NULL) {\r | |
220 | FreePool(CommandToGetHelpOn);\r | |
221 | }\r | |
222 | if (SectionToGetHelpOn != NULL) {\r | |
223 | FreePool(SectionToGetHelpOn);\r | |
224 | }\r | |
225 | \r | |
226 | return (ShellStatus);\r | |
227 | }\r | |
228 | \r |