2 Main file for Parse shell level 2 function.
4 Copyright (c) 2009 - 2012, 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
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.
15 #include "UefiShellLevel2CommandsLib.h"
18 Do the actual parsing of the file. the file should be SFO output from a
19 shell command or a similar format.
21 @param[in] FileName The filename to open.
22 @param[in] TableName The name of the table to find.
23 @param[in] ColumnIndex The column number to get.
24 @param[in] TableNameInstance Which instance of the table to get (row).
25 @param[in] ShellCommandInstance Which instance of the command to get.
27 @retval SHELL_NOT_FOUND The requested instance was not found.
28 @retval SHELL_SUCCESS The operation was successful.
33 IN CONST CHAR16
*FileName
,
34 IN CONST CHAR16
*TableName
,
35 IN CONST UINTN ColumnIndex
,
36 IN CONST UINTN TableNameInstance
,
37 IN CONST UINTN ShellCommandInstance
40 SHELL_FILE_HANDLE FileHandle
;
46 CHAR16
*ColumnPointer
;
47 SHELL_STATUS ShellStatus
;
50 ASSERT(FileName
!= NULL
);
51 ASSERT(TableName
!= NULL
);
53 ShellStatus
= SHELL_SUCCESS
;
55 Status
= ShellOpenFileByName(FileName
, &FileHandle
, EFI_FILE_MODE_READ
, 0);
56 if (EFI_ERROR(Status
)) {
57 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL
), gShellLevel2HiiHandle
, FileName
);
58 ShellStatus
= SHELL_NOT_FOUND
;
60 for (LoopVariable
= 0 ; LoopVariable
< ShellCommandInstance
&& !ShellFileHandleEof(FileHandle
);) {
61 TempLine
= ShellFileHandleReturnLine(FileHandle
, &Ascii
);
62 if (TempLine
== NULL
) {
65 if (StrStr(TempLine
, L
"ShellCommand, \"") == TempLine
) {
68 SHELL_FREE_NON_NULL(TempLine
);
70 if (LoopVariable
== ShellCommandInstance
) {
73 TempLine
= ShellFileHandleReturnLine(FileHandle
, &Ascii
);
75 || *TempLine
== CHAR_NULL
76 || StrStr(TempLine
, L
"ShellCommand, \"") == TempLine
78 SHELL_FREE_NON_NULL(TempLine
);
81 if (StrStr(TempLine
, TableName
) == TempLine
) {
84 if ( LoopVariable
== TableNameInstance
85 || (TableNameInstance
== (UINTN
)-1 && StrStr(TempLine
, TableName
) == TempLine
)
87 for (ColumnLoop
= 1, ColumnPointer
= TempLine
; ColumnLoop
< ColumnIndex
&& ColumnPointer
!= NULL
&& *ColumnPointer
!= CHAR_NULL
; ColumnLoop
++) {
88 ColumnPointer
= StrStr(ColumnPointer
, L
",");
89 if (ColumnPointer
!= NULL
&& *ColumnPointer
!= CHAR_NULL
){
93 if (ColumnLoop
== ColumnIndex
) {
94 if (ColumnPointer
== NULL
) {
95 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellLevel2HiiHandle
, L
"Column Index");
96 ShellStatus
= SHELL_INVALID_PARAMETER
;
98 TempSpot
= StrStr(ColumnPointer
, L
",");
99 if (TempSpot
!= NULL
) {
100 *TempSpot
= CHAR_NULL
;
102 while (ColumnPointer
!= NULL
&& *ColumnPointer
!= CHAR_NULL
&& ColumnPointer
[0] == L
' '){
105 if (ColumnPointer
!= NULL
&& *ColumnPointer
!= CHAR_NULL
&& ColumnPointer
[0] == L
'\"'){
108 if (ColumnPointer
!= NULL
&& *ColumnPointer
!= CHAR_NULL
&& ColumnPointer
[StrLen(ColumnPointer
)-1] == L
'\"'){
109 ColumnPointer
[StrLen(ColumnPointer
)-1] = CHAR_NULL
;
112 ShellPrintEx(-1, -1, L
"%s\r\n", ColumnPointer
);
116 SHELL_FREE_NON_NULL(TempLine
);
120 return (ShellStatus
);
123 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
130 Function for 'parse' command.
132 @param[in] ImageHandle Handle to the Image (NULL if Internal).
133 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
137 ShellCommandRunParse (
138 IN EFI_HANDLE ImageHandle
,
139 IN EFI_SYSTEM_TABLE
*SystemTable
144 CHAR16
*ProblemParam
;
145 CONST CHAR16
*FileName
;
146 CONST CHAR16
*TableName
;
147 CONST CHAR16
*ColumnString
;
148 SHELL_STATUS ShellStatus
;
149 UINTN ShellCommandInstance
;
150 UINTN TableNameInstance
;
152 ShellStatus
= SHELL_SUCCESS
;
156 // initialize the shell lib (we must be in non-auto-init...)
158 Status
= ShellInitialize();
159 ASSERT_EFI_ERROR(Status
);
162 // parse the command line
164 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
165 if (EFI_ERROR(Status
)) {
166 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
167 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
168 FreePool(ProblemParam
);
169 ShellStatus
= SHELL_INVALID_PARAMETER
;
174 if (ShellCommandLineGetCount(Package
) < 4) {
175 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
);
176 ShellStatus
= SHELL_INVALID_PARAMETER
;
177 } else if (ShellCommandLineGetCount(Package
) > 4) {
178 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
179 ShellStatus
= SHELL_INVALID_PARAMETER
;
181 FileName
= ShellCommandLineGetRawValue(Package
, 1);
182 TableName
= ShellCommandLineGetRawValue(Package
, 2);
183 ColumnString
= ShellCommandLineGetRawValue(Package
, 3);
185 if (ShellCommandLineGetValue(Package
, L
"-i") == NULL
) {
186 TableNameInstance
= (UINTN
)-1;
188 TableNameInstance
= ShellStrToUintn(ShellCommandLineGetValue(Package
, L
"-i"));
190 if (ShellCommandLineGetValue(Package
, L
"-s") == NULL
) {
191 ShellCommandInstance
= 1;
193 ShellCommandInstance
= ShellStrToUintn(ShellCommandLineGetValue(Package
, L
"-s"));
196 ShellStatus
= PerformParsing(FileName
, TableName
, ShellStrToUintn(ColumnString
), TableNameInstance
, ShellCommandInstance
);
201 // free the command line package
203 ShellCommandLineFreeVarList (Package
);
205 return (ShellStatus
);