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