2 Main file for time, timezone, and date shell level 2 and shell level 3 functions.
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 Determine if String is a valid representation for a time or date.
20 @param[in] String The pointer to the string to test.
21 @param[in] Char The delimeter character.
22 @param[in] Min The minimum value allowed.
23 @param[in] Max The maximum value allowed.
24 @param[in] MinusOk Whether negative numbers are permitted.
26 @retval TRUE String is a valid representation.
27 @retval FALSE String is invalid.
31 InternalIsTimeLikeString (
32 IN CONST CHAR16
*String
,
36 IN CONST BOOLEAN MinusOk
44 // A single minus is ok.
46 if (*String
== L
'-') {
52 // the first char must be numeric.
54 if (!ShellIsDecimalDigitCharacter(*String
)) {
58 // loop through the characters and use the lib function
60 for ( ; String
!= NULL
&& *String
!= CHAR_NULL
; String
++){
61 if (*String
== Char
) {
68 if (!ShellIsDecimalDigitCharacter(*String
)) {
79 Verify that the DateString is valid and if so set that as the current
82 @param[in] DateString The pointer to a string representation of the date.
84 @retval SHELL_INVALID_PARAMETER DateString was NULL.
85 @retval SHELL_INVALID_PARAMETER DateString was mis-formatted.
86 @retval SHELL_SUCCESS The operation was successful.
91 IN CONST CHAR16
*DateString
96 CHAR16
*DateStringCopy
;
100 if (!InternalIsTimeLikeString(DateString
, L
'/', 2, 2, FALSE
)) {
101 return (SHELL_INVALID_PARAMETER
);
104 Status
= gRT
->GetTime(&TheTime
, NULL
);
105 if (EFI_ERROR(Status
)) {
106 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"gRT->GetTime", Status
);
107 return (SHELL_DEVICE_ERROR
);
110 DateStringCopy
= NULL
;
111 DateStringCopy
= StrnCatGrow(&DateStringCopy
, NULL
, DateString
, 0);
112 if (DateStringCopy
== NULL
) {
113 return (SHELL_OUT_OF_RESOURCES
);
115 Walker
= DateStringCopy
;
117 TheTime
.Month
= 0xFF;
119 TheTime
.Year
= 0xFFFF;
121 Walker1
= StrStr(Walker
, L
"/");
122 if (Walker1
!= NULL
&& *Walker1
== L
'/') {
123 *Walker1
= CHAR_NULL
;
126 TheTime
.Month
= (UINT8
)ShellStrToUintn (Walker
);
127 if (Walker1
!= NULL
) {
128 Walker
= Walker1
+ 1;
130 Walker1
= Walker
!=NULL
?StrStr(Walker
, L
"/"):NULL
;
131 if (Walker1
!= NULL
&& *Walker1
== L
'/') {
132 *Walker1
= CHAR_NULL
;
134 if (Walker
!= NULL
&& Walker
[0] != CHAR_NULL
) {
135 TheTime
.Day
= (UINT8
)ShellStrToUintn (Walker
);
136 if (Walker1
!= NULL
) {
137 Walker
= Walker1
+ 1;
139 Walker1
= Walker
!=NULL
?StrStr(Walker
, L
"/"):NULL
;
140 if (Walker1
!= NULL
&& *Walker1
== L
'/') {
141 *Walker1
= CHAR_NULL
;
143 if (Walker
!= NULL
&& Walker
[0] != CHAR_NULL
) {
144 TheTime
.Year
= (UINT16
)ShellStrToUintn (Walker
);
148 if (TheTime
.Year
< 100) {
149 if (TheTime
.Year
>= 98) {
150 TheTime
.Year
= (UINT16
)(1900 + TheTime
.Year
);
152 TheTime
.Year
= (UINT16
)(2000 + TheTime
.Year
);
156 Status
= gRT
->SetTime(&TheTime
);
158 if (!EFI_ERROR(Status
)){
159 return (SHELL_SUCCESS
);
161 return (SHELL_INVALID_PARAMETER
);
165 Function for 'date' command.
167 @param[in] ImageHandle Handle to the Image (NULL if Internal).
168 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
172 ShellCommandRunDate (
173 IN EFI_HANDLE ImageHandle
,
174 IN EFI_SYSTEM_TABLE
*SystemTable
180 CHAR16
*ProblemParam
;
181 SHELL_STATUS ShellStatus
;
183 ShellStatus
= SHELL_SUCCESS
;
187 // initialize the shell lib (we must be in non-auto-init...)
189 Status
= ShellInitialize();
190 ASSERT_EFI_ERROR(Status
);
193 // parse the command line
195 Status
= ShellCommandLineParse (SfoParamList
, &Package
, &ProblemParam
, TRUE
);
196 if (EFI_ERROR(Status
)) {
197 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
198 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
199 FreePool(ProblemParam
);
200 ShellStatus
= SHELL_INVALID_PARAMETER
;
208 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
210 } else if (ShellCommandLineGetRawValue(Package
, 2) != NULL
) {
211 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
212 ShellStatus
= SHELL_INVALID_PARAMETER
;
215 // If there are 0 value parameters, then print the current date
216 // else If there are any value paramerers, then print error
218 if (ShellCommandLineGetRawValue(Package
, 1) == NULL
) {
220 // get the current date
222 Status
= gRT
->GetTime(&TheTime
, NULL
);
223 ASSERT_EFI_ERROR(Status
);
226 // ShellPrintEx the date in SFO or regular format
228 if (ShellCommandLineGetFlag(Package
, L
"-sfo")) {
229 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DATE_SFO_FORMAT
), gShellLevel2HiiHandle
, TheTime
.Month
, TheTime
.Day
, TheTime
.Year
);
231 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DATE_FORMAT
), gShellLevel2HiiHandle
, TheTime
.Month
, TheTime
.Day
, TheTime
.Year
);
234 if (PcdGet8(PcdShellSupportLevel
) == 2) {
235 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
236 ShellStatus
= SHELL_INVALID_PARAMETER
;
239 // perform level 3 operation here.
241 ShellStatus
= CheckAndSetDate(ShellCommandLineGetRawValue(Package
, 1));
242 if (ShellStatus
!= SHELL_SUCCESS
) {
243 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ShellCommandLineGetRawValue(Package
, 1));
244 ShellStatus
= SHELL_INVALID_PARAMETER
;
251 // free the command line package
253 ShellCommandLineFreeVarList (Package
);
258 return (ShellStatus
);
262 // Note "-tz" is invalid for this (non-interactive) version of 'time'.
264 STATIC CONST SHELL_PARAM_ITEM TimeParamList2
[] = {
269 STATIC CONST SHELL_PARAM_ITEM TimeParamList3
[] = {
276 Verify that the TimeString is valid and if so set that as the current
279 @param[in] TimeString The pointer to a string representation of the time.
280 @param[in] Tz The value to set for TimeZone.
281 @param[in] Daylight The value to set for Daylight.
283 @retval SHELL_INVALID_PARAMETER TimeString was NULL.
284 @retval SHELL_INVALID_PARAMETER TimeString was mis-formatted.
285 @retval SHELL_SUCCESS The operation was successful.
290 IN CONST CHAR16
*TimeString
,
292 IN CONST UINT8 Daylight
297 CHAR16
*TimeStringCopy
;
301 if (TimeString
!= NULL
&& !InternalIsTimeLikeString(TimeString
, L
':', 1, 2, FALSE
)) {
302 return (SHELL_INVALID_PARAMETER
);
304 if (Daylight
!= 0xFF &&((Daylight
& (EFI_TIME_IN_DAYLIGHT
|EFI_TIME_ADJUST_DAYLIGHT
)) != Daylight
)) {
305 return (SHELL_INVALID_PARAMETER
);
308 Status
= gRT
->GetTime(&TheTime
, NULL
);
309 ASSERT_EFI_ERROR(Status
);
311 if (TimeString
!= NULL
) {
312 TimeStringCopy
= NULL
;
313 TimeStringCopy
= StrnCatGrow(&TimeStringCopy
, NULL
, TimeString
, 0);
314 Walker1
= TimeStringCopy
;
316 TheTime
.Minute
= 0xFF;
318 Walker2
= Walker1
!=NULL
?StrStr(Walker1
, L
":"):NULL
;
319 if (Walker2
!= NULL
&& *Walker2
== L
':') {
320 *Walker2
= CHAR_NULL
;
322 TheTime
.Hour
= (UINT8
)ShellStrToUintn (Walker1
);
323 if (Walker2
!= NULL
) {
324 Walker1
= Walker2
+ 1;
326 Walker2
= Walker1
!=NULL
?StrStr(Walker1
, L
":"):NULL
;
327 if (Walker2
!= NULL
&& *Walker2
== L
':') {
328 *Walker2
= CHAR_NULL
;
330 if (Walker1
!= NULL
&& Walker1
[0] != CHAR_NULL
) {
331 TheTime
.Minute
= (UINT8
)ShellStrToUintn (Walker1
);
332 if (Walker2
!= NULL
) {
333 Walker1
= Walker2
+ 1;
335 if (Walker1
!= NULL
&& Walker1
[0] != CHAR_NULL
) {
336 TheTime
.Second
= (UINT8
)ShellStrToUintn (Walker1
);
339 SHELL_FREE_NON_NULL(TimeStringCopy
);
343 if ((Tz
>= -1440 && Tz
<= 1440)||(Tz
== 0x7FF)) {
344 TheTime
.TimeZone
= Tz
;
347 if (Daylight
!= 0xFF) {
348 TheTime
.Daylight
= Daylight
;
351 Status
= gRT
->SetTime(&TheTime
);
353 if (!EFI_ERROR(Status
)){
354 return (SHELL_SUCCESS
);
357 return (SHELL_INVALID_PARAMETER
);
361 Function for 'time' command.
363 @param[in] ImageHandle Handle to the Image (NULL if Internal).
364 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
368 ShellCommandRunTime (
369 IN EFI_HANDLE ImageHandle
,
370 IN EFI_SYSTEM_TABLE
*SystemTable
377 CHAR16
*ProblemParam
;
378 SHELL_STATUS ShellStatus
;
381 CONST CHAR16
*TempLocation
;
384 ShellStatus
= SHELL_SUCCESS
;
388 // Initialize variables
393 // initialize the shell lib (we must be in non-auto-init...)
395 Status
= ShellInitialize();
396 ASSERT_EFI_ERROR(Status
);
399 // parse the command line
401 if (PcdGet8(PcdShellSupportLevel
) == 2) {
402 Status
= ShellCommandLineParseEx (TimeParamList2
, &Package
, &ProblemParam
, TRUE
, TRUE
);
404 ASSERT(PcdGet8(PcdShellSupportLevel
) == 3);
405 Status
= ShellCommandLineParseEx (TimeParamList3
, &Package
, &ProblemParam
, TRUE
, TRUE
);
407 if (EFI_ERROR(Status
)) {
408 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
409 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
410 FreePool(ProblemParam
);
411 ShellStatus
= SHELL_INVALID_PARAMETER
;
419 Status
= gRT
->GetTime(&TheTime
, NULL
);
420 ASSERT_EFI_ERROR(Status
);
421 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
423 } else if (ShellCommandLineGetRawValue(Package
, 2) != NULL
) {
424 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
425 ShellStatus
= SHELL_INVALID_PARAMETER
;
428 // If there are no parameters, then print the current time
430 if (ShellCommandLineGetRawValue(Package
, 1) == NULL
431 && !ShellCommandLineGetFlag(Package
, L
"-d")
432 && !ShellCommandLineGetFlag(Package
, L
"-tz")) {
434 // ShellPrintEx the current time
436 if (TheTime
.TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) {
439 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
446 STRING_TOKEN (STR_TIME_FORMAT
),
447 gShellLevel2HiiHandle
,
451 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?L
" ":(TheTime
.TimeZone
> 0?L
"-":L
"+"),
452 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?0:(ABS(TheTime
.TimeZone
)) / 60,
455 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_CRLF
), gShellLevel2HiiHandle
);
456 } else if (ShellCommandLineGetFlag(Package
, L
"-d") && ShellCommandLineGetValue(Package
, L
"-d") == NULL
) {
457 if (TheTime
.TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) {
460 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
467 STRING_TOKEN (STR_TIME_FORMAT
),
468 gShellLevel2HiiHandle
,
472 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?L
" ":(TheTime
.TimeZone
> 0?L
"-":L
"+"),
473 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?0:(ABS(TheTime
.TimeZone
)) / 60,
476 switch (TheTime
.Daylight
) {
478 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST0
), gShellLevel2HiiHandle
);
480 case EFI_TIME_ADJUST_DAYLIGHT
:
481 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST1
), gShellLevel2HiiHandle
);
483 case EFI_TIME_IN_DAYLIGHT
:
484 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST2
), gShellLevel2HiiHandle
);
486 case EFI_TIME_IN_DAYLIGHT
|EFI_TIME_ADJUST_DAYLIGHT
:
487 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST3
), gShellLevel2HiiHandle
);
490 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_ERROR
), gShellLevel2HiiHandle
, L
"gRT->GetTime", L
"TheTime.Daylight", TheTime
.Daylight
);
493 if (PcdGet8(PcdShellSupportLevel
) == 2) {
494 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
495 ShellStatus
= SHELL_INVALID_PARAMETER
;
498 // perform level 3 operation here.
500 if ((TempLocation
= ShellCommandLineGetValue(Package
, L
"-tz")) != NULL
) {
501 if (TempLocation
[0] == L
'-') {
502 Tz
= (INT16
)(0 - ShellStrToUintn(++TempLocation
));
504 Tz
= (INT16
)ShellStrToUintn(TempLocation
);
506 if (!(Tz
>= -1440 && Tz
<= 1440) && Tz
!= EFI_UNSPECIFIED_TIMEZONE
) {
507 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellLevel2HiiHandle
, L
"-tz");
508 ShellStatus
= SHELL_INVALID_PARAMETER
;
512 // intentionally out of bounds value will prevent changing it...
516 TempLocation
= ShellCommandLineGetValue(Package
, L
"-d");
517 if (TempLocation
!= NULL
) {
518 Daylight
= (UINT8
)ShellStrToUintn(TempLocation
);
519 if (Daylight
!= 0 && Daylight
!= 1 && Daylight
!= 3) {
520 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellLevel2HiiHandle
, L
"-d");
521 ShellStatus
= SHELL_INVALID_PARAMETER
;
525 // invalid = will not use
529 if (ShellStatus
== SHELL_SUCCESS
) {
530 ShellStatus
= CheckAndSetTime(ShellCommandLineGetRawValue(Package
, 1), Tz
, Daylight
);
531 if (ShellStatus
!= SHELL_SUCCESS
) {
532 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ShellCommandLineGetRawValue(Package
, 1));
533 ShellStatus
= SHELL_INVALID_PARAMETER
;
542 // free the command line package
544 ShellCommandLineFreeVarList (Package
);
549 return (ShellStatus
);
554 EFI_STRING_ID StringId
;
557 STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList2
[] = {
562 STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList3
[] = {
569 STATIC CONST TIME_ZONE_ITEM TimeZoneList
[] = {
570 {720, STRING_TOKEN (STR_TIMEZONE_M12
)},
571 {660, STRING_TOKEN (STR_TIMEZONE_M11
)},
572 {600, STRING_TOKEN (STR_TIMEZONE_M10
)},
573 {540, STRING_TOKEN (STR_TIMEZONE_M9
)},
574 {480, STRING_TOKEN (STR_TIMEZONE_M8
)},
575 {420, STRING_TOKEN (STR_TIMEZONE_M7
)},
576 {360, STRING_TOKEN (STR_TIMEZONE_M6
)},
577 {300, STRING_TOKEN (STR_TIMEZONE_M5
)},
578 {270, STRING_TOKEN (STR_TIMEZONE_M430
)},
579 {240, STRING_TOKEN (STR_TIMEZONE_M4
)},
580 {210, STRING_TOKEN (STR_TIMEZONE_M330
)},
581 {180, STRING_TOKEN (STR_TIMEZONE_M3
)},
582 {120, STRING_TOKEN (STR_TIMEZONE_M2
)},
583 {60 , STRING_TOKEN (STR_TIMEZONE_M1
)},
584 {0 , STRING_TOKEN (STR_TIMEZONE_0
)},
585 {-60 , STRING_TOKEN (STR_TIMEZONE_P1
)},
586 {-120 , STRING_TOKEN (STR_TIMEZONE_P2
)},
587 {-180 , STRING_TOKEN (STR_TIMEZONE_P3
)},
588 {-210 , STRING_TOKEN (STR_TIMEZONE_P330
)},
589 {-240 , STRING_TOKEN (STR_TIMEZONE_P4
)},
590 {-270 , STRING_TOKEN (STR_TIMEZONE_P430
)},
591 {-300 , STRING_TOKEN (STR_TIMEZONE_P5
)},
592 {-330 , STRING_TOKEN (STR_TIMEZONE_P530
)},
593 {-345 , STRING_TOKEN (STR_TIMEZONE_P545
)},
594 {-360 , STRING_TOKEN (STR_TIMEZONE_P6
)},
595 {-390 , STRING_TOKEN (STR_TIMEZONE_P630
)},
596 {-420 , STRING_TOKEN (STR_TIMEZONE_P7
)},
597 {-480 , STRING_TOKEN (STR_TIMEZONE_P8
)},
598 {-540 , STRING_TOKEN (STR_TIMEZONE_P9
)},
599 {-570 , STRING_TOKEN (STR_TIMEZONE_P930
)},
600 {-600 , STRING_TOKEN (STR_TIMEZONE_P10
)},
601 {-660 , STRING_TOKEN (STR_TIMEZONE_P11
)},
602 {-720 , STRING_TOKEN (STR_TIMEZONE_P12
)},
603 {-780 , STRING_TOKEN (STR_TIMEZONE_P13
)},
604 {-840 , STRING_TOKEN (STR_TIMEZONE_P14
)}
608 Verify that the TimeZoneString is valid and if so set that as the current
611 @param[in] TimeZoneString The pointer to a string representation of the timezone.
613 @retval SHELL_INVALID_PARAMETER TimeZoneString was NULL.
614 @retval SHELL_INVALID_PARAMETER TimeZoneString was mis-formatted.
615 @retval SHELL_SUCCESS The operation was successful.
619 CheckAndSetTimeZone (
620 IN CONST CHAR16
*TimeZoneString
625 CHAR16
*TimeZoneCopy
;
630 if (TimeZoneString
== NULL
) {
631 return (SHELL_INVALID_PARAMETER
);
634 if (TimeZoneString
!= NULL
&& !InternalIsTimeLikeString(TimeZoneString
, L
':', 1, 1, TRUE
)) {
635 return (SHELL_INVALID_PARAMETER
);
638 Status
= gRT
->GetTime(&TheTime
, NULL
);
639 ASSERT_EFI_ERROR(Status
);
642 TimeZoneCopy
= StrnCatGrow(&TimeZoneCopy
, NULL
, TimeZoneString
, 0);
643 Walker
= TimeZoneCopy
;
644 Walker2
= StrStr(Walker
, L
":");
645 if (Walker2
!= NULL
&& *Walker2
== L
':') {
646 *Walker2
= CHAR_NULL
;
648 if (*Walker
== L
'-') {
649 TheTime
.TimeZone
= (INT16
)((ShellStrToUintn (++Walker
)) * 60);
651 TheTime
.TimeZone
= (INT16
)((ShellStrToUintn (Walker
)) * -60);
653 if (Walker2
!= NULL
) {
654 Walker
= Walker2
+ 1;
656 if (Walker
!= NULL
&& Walker
[0] != CHAR_NULL
) {
657 if (TheTime
.TimeZone
< 0) {
658 TheTime
.TimeZone
= (INT16
)(TheTime
.TimeZone
- (UINT8
)ShellStrToUintn (Walker
));
660 TheTime
.TimeZone
= (INT16
)(TheTime
.TimeZone
+ (UINT8
)ShellStrToUintn (Walker
));
664 Status
= EFI_INVALID_PARAMETER
;
667 ; LoopVar
< sizeof(TimeZoneList
) / sizeof(TimeZoneList
[0])
670 if (TheTime
.TimeZone
== TimeZoneList
[LoopVar
].TimeZone
) {
671 Status
= gRT
->SetTime(&TheTime
);
676 FreePool(TimeZoneCopy
);
678 if (!EFI_ERROR(Status
)){
679 return (SHELL_SUCCESS
);
681 return (SHELL_INVALID_PARAMETER
);
686 Function for 'timezone' command.
688 @param[in] ImageHandle Handle to the Image (NULL if Internal).
689 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
693 ShellCommandRunTimeZone (
694 IN EFI_HANDLE ImageHandle
,
695 IN EFI_SYSTEM_TABLE
*SystemTable
703 CHAR16
*ProblemParam
;
704 SHELL_STATUS ShellStatus
;
710 ShellStatus
= SHELL_SUCCESS
;
714 // initialize the shell lib (we must be in non-auto-init...)
716 Status
= ShellInitialize();
717 ASSERT_EFI_ERROR(Status
);
720 // parse the command line
722 if (PcdGet8(PcdShellSupportLevel
) == 2) {
723 Status
= ShellCommandLineParse (TimeZoneParamList2
, &Package
, &ProblemParam
, FALSE
);
725 ASSERT(PcdGet8(PcdShellSupportLevel
) == 3);
726 Status
= ShellCommandLineParseEx (TimeZoneParamList3
, &Package
, &ProblemParam
, FALSE
, TRUE
);
728 if (EFI_ERROR(Status
)) {
729 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
730 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
731 FreePool(ProblemParam
);
732 ShellStatus
= SHELL_INVALID_PARAMETER
;
740 if (ShellCommandLineGetCount(Package
) > 1) {
741 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
742 ShellStatus
= SHELL_INVALID_PARAMETER
;
743 } else if (ShellCommandLineGetFlag(Package
, L
"-?")) {
745 } else if (ShellCommandLineGetFlag(Package
, L
"-s")) {
746 if ((ShellCommandLineGetFlag(Package
, L
"-l")) || (ShellCommandLineGetFlag(Package
, L
"-f"))) {
747 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"-l or -f");
748 ShellStatus
= SHELL_INVALID_PARAMETER
;
750 ASSERT(PcdGet8(PcdShellSupportLevel
) == 3);
751 if (ShellCommandLineGetValue(Package
, L
"-s") == NULL
) {
752 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellLevel2HiiHandle
, L
"-s");
753 ShellStatus
= SHELL_INVALID_PARAMETER
;
758 ShellStatus
= CheckAndSetTimeZone(ShellCommandLineGetValue(Package
, L
"-s"));
759 if (ShellStatus
!= SHELL_SUCCESS
) {
760 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ShellCommandLineGetValue(Package
, L
"-s"));
761 ShellStatus
= SHELL_INVALID_PARAMETER
;
765 } else if (ShellCommandLineGetFlag(Package
, L
"-l")) {
767 // Print a list of all time zones
770 ; LoopVar
< sizeof(TimeZoneList
) / sizeof(TimeZoneList
[0])
773 ShellPrintHiiEx (-1, -1, NULL
, TimeZoneList
[LoopVar
].StringId
, gShellLevel2HiiHandle
);
777 // Get Current Time Zone Info
779 Status
= gRT
->GetTime(&TheTime
, NULL
);
780 ASSERT_EFI_ERROR(Status
);
782 if (TheTime
.TimeZone
!= EFI_UNSPECIFIED_TIMEZONE
) {
785 ; LoopVar
< sizeof(TimeZoneList
) / sizeof(TimeZoneList
[0])
788 if (TheTime
.TimeZone
== TimeZoneList
[LoopVar
].TimeZone
) {
789 if (ShellCommandLineGetFlag(Package
, L
"-f")) {
791 // Print all info about current time zone
793 ShellPrintHiiEx (-1, -1, NULL
, TimeZoneList
[LoopVar
].StringId
, gShellLevel2HiiHandle
);
796 // Print basic info only
798 if (TheTime
.TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) {
801 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
808 STRING_TOKEN(STR_TIMEZONE_SIMPLE
),
809 gShellLevel2HiiHandle
,
810 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?0:(TheTime
.TimeZone
> 0?L
"-":L
"+"),
811 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?0:(ABS(TheTime
.TimeZone
)) / 60,
820 // Print basic info only
822 if (TheTime
.TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) {
825 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
831 STRING_TOKEN(STR_TIMEZONE_SIMPLE
),
832 gShellLevel2HiiHandle
,
833 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?0:(TheTime
.TimeZone
> 0?L
"-":L
"+"),
834 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?0:(ABS(TheTime
.TimeZone
)) / 60,
836 if (ShellCommandLineGetFlag(Package
, L
"-f")) {
837 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN(STR_TIMEZONE_NI
), gShellLevel2HiiHandle
);
842 // TimeZone was EFI_UNSPECIFIED_TIMEZONE (unknown) from GetTime()
849 // free the command line package
851 ShellCommandLineFreeVarList (Package
);
853 return (ShellStatus
);