2 Main file for Parse shell level 2 function.
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
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 ASSERT(ColumnPointer
!= NULL
);
95 TempSpot
= StrStr(ColumnPointer
, L
",");
96 if (TempSpot
!= NULL
) {
97 *TempSpot
= CHAR_NULL
;
99 while (ColumnPointer
!= NULL
&& *ColumnPointer
!= CHAR_NULL
&& ColumnPointer
[0] == L
' '){
102 if (ColumnPointer
!= NULL
&& *ColumnPointer
!= CHAR_NULL
&& ColumnPointer
[0] == L
'\"'){
105 if (ColumnPointer
!= NULL
&& *ColumnPointer
!= CHAR_NULL
&& ColumnPointer
[StrLen(ColumnPointer
)-1] == L
'\"'){
106 ColumnPointer
[StrLen(ColumnPointer
)-1] = CHAR_NULL
;
109 ShellPrintEx(-1, -1, L
"%s\r\n", ColumnPointer
);
112 SHELL_FREE_NON_NULL(TempLine
);
116 return (ShellStatus
);
119 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
126 Function for 'parse' command.
128 @param[in] ImageHandle Handle to the Image (NULL if Internal).
129 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
133 ShellCommandRunParse (
134 IN EFI_HANDLE ImageHandle
,
135 IN EFI_SYSTEM_TABLE
*SystemTable
140 CHAR16
*ProblemParam
;
141 CONST CHAR16
*FileName
;
142 CONST CHAR16
*TableName
;
143 CONST CHAR16
*ColumnString
;
144 SHELL_STATUS ShellStatus
;
145 UINTN ShellCommandInstance
;
146 UINTN TableNameInstance
;
148 ShellStatus
= SHELL_SUCCESS
;
152 // initialize the shell lib (we must be in non-auto-init...)
154 Status
= ShellInitialize();
155 ASSERT_EFI_ERROR(Status
);
158 // parse the command line
160 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
161 if (EFI_ERROR(Status
)) {
162 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
163 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
164 FreePool(ProblemParam
);
165 ShellStatus
= SHELL_INVALID_PARAMETER
;
170 if (ShellCommandLineGetCount(Package
) < 4) {
171 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
);
172 ShellStatus
= SHELL_INVALID_PARAMETER
;
173 } else if (ShellCommandLineGetCount(Package
) > 4) {
174 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
175 ShellStatus
= SHELL_INVALID_PARAMETER
;
177 FileName
= ShellCommandLineGetRawValue(Package
, 1);
178 TableName
= ShellCommandLineGetRawValue(Package
, 2);
179 ColumnString
= ShellCommandLineGetRawValue(Package
, 3);
181 if (ShellCommandLineGetValue(Package
, L
"-i") == NULL
) {
182 TableNameInstance
= (UINTN
)-1;
184 TableNameInstance
= ShellStrToUintn(ShellCommandLineGetValue(Package
, L
"-i"));
186 if (ShellCommandLineGetValue(Package
, L
"-s") == NULL
) {
187 ShellCommandInstance
= 1;
189 ShellCommandInstance
= ShellStrToUintn(ShellCommandLineGetValue(Package
, L
"-s"));
192 ShellStatus
= PerformParsing(FileName
, TableName
, ShellStrToUintn(ColumnString
), TableNameInstance
, ShellCommandInstance
);
197 // free the command line package
199 ShellCommandLineFreeVarList (Package
);
201 return (ShellStatus
);