]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c
udk2010.up2.shell initial release.
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / TimeDate.c
1 /** @file
2 Main file for time, timezone, and date shell level 2 and shell level 3 functions.
3
4 Copyright (c) 2009 - 2010, 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
9
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.
12
13 **/
14
15 #include "UefiShellLevel2CommandsLib.h"
16
17 INT16
18 EFIAPI
19 AbsVal(
20 INT16 v
21 )
22 {
23 if (v>0) {
24 return (v);
25 }
26 return ((INT16)(-v));
27 }
28
29 BOOLEAN
30 EFIAPI
31 InternalIsTimeLikeString (
32 IN CONST CHAR16 *String,
33 IN CONST CHAR16 Char,
34 IN CONST UINTN Min,
35 IN CONST UINTN Max,
36 IN CONST BOOLEAN MinusOk
37 )
38 {
39 UINTN Count;
40 Count = 0;
41
42 if (MinusOk) {
43 //
44 // A single minus is ok.
45 //
46 if (*String == L'-') {
47 String++;
48 }
49 }
50
51 //
52 // the first char must be numeric.
53 //
54 if (!ShellIsDecimalDigitCharacter(*String)) {
55 return (FALSE);
56 }
57 //
58 // loop through the characters and use the lib function
59 //
60 for ( ; String != NULL && *String != CHAR_NULL ; String++){
61 if (*String == Char) {
62 Count++;
63 if (Count > Max) {
64 return (FALSE);
65 }
66 continue;
67 }
68 if (!ShellIsDecimalDigitCharacter(*String)) {
69 return (FALSE);
70 }
71 }
72 if (Count < Min) {
73 return (FALSE);
74 }
75 return (TRUE);
76 }
77
78 SHELL_STATUS
79 EFIAPI
80 CheckAndSetDate (
81 IN CONST CHAR16 *DateString
82 )
83 {
84 EFI_TIME TheTime;
85 EFI_STATUS Status;
86 CONST CHAR16 *Walker;
87
88 if (!InternalIsTimeLikeString(DateString, L'/', 2, 2, FALSE)) {
89 return (SHELL_INVALID_PARAMETER);
90 }
91
92 Status = gRT->GetTime(&TheTime, NULL);
93 ASSERT_EFI_ERROR(Status);
94
95 Walker = DateString;
96
97 TheTime.Month = 0xFF;
98 TheTime.Day = 0xFF;
99 TheTime.Year = 0xFFFF;
100
101 TheTime.Month = (UINT8)StrDecimalToUintn (Walker);
102 Walker = StrStr(Walker, L"/");
103 if (Walker != NULL && *Walker == L'/') {
104 Walker = Walker + 1;
105 }
106 if (Walker != NULL && Walker[0] != CHAR_NULL) {
107 TheTime.Day = (UINT8)StrDecimalToUintn (Walker);
108 Walker = StrStr(Walker, L"/");
109 if (Walker != NULL && *Walker == L'/') {
110 Walker = Walker + 1;
111 }
112 if (Walker != NULL && Walker[0] != CHAR_NULL) {
113 TheTime.Year = (UINT16)StrDecimalToUintn (Walker);
114 }
115 }
116
117 if (TheTime.Year < 100) {
118 if (TheTime.Year >= 98) {
119 TheTime.Year = (UINT16)(1900 + TheTime.Year);
120 } else {
121 TheTime.Year = (UINT16)(2000 + TheTime.Year);
122 }
123 }
124
125 Status = gRT->SetTime(&TheTime);
126
127 if (!EFI_ERROR(Status)){
128 return (SHELL_SUCCESS);
129 }
130 return (SHELL_INVALID_PARAMETER);
131 }
132
133 /**
134 Function for 'date' command.
135
136 @param[in] ImageHandle Handle to the Image (NULL if Internal).
137 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
138 **/
139 SHELL_STATUS
140 EFIAPI
141 ShellCommandRunDate (
142 IN EFI_HANDLE ImageHandle,
143 IN EFI_SYSTEM_TABLE *SystemTable
144 )
145 {
146 EFI_STATUS Status;
147 LIST_ENTRY *Package;
148 EFI_TIME TheTime;
149 CHAR16 *ProblemParam;
150 SHELL_STATUS ShellStatus;
151
152 ShellStatus = SHELL_SUCCESS;
153 ProblemParam = NULL;
154
155 //
156 // initialize the shell lib (we must be in non-auto-init...)
157 //
158 Status = ShellInitialize();
159 ASSERT_EFI_ERROR(Status);
160
161 //
162 // parse the command line
163 //
164 Status = ShellCommandLineParse (SfoParamList, &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;
170 } else {
171 ASSERT(FALSE);
172 }
173 } else {
174 //
175 // check for "-?"
176 //
177 if (ShellCommandLineGetFlag(Package, L"-?")) {
178 ASSERT(FALSE);
179 } else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
180 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
181 ShellStatus = SHELL_INVALID_PARAMETER;
182 } else {
183 //
184 // If there are 0 value parameters, then print the current date
185 // else If there are any value paramerers, then print error
186 //
187 if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
188 //
189 // get the current date
190 //
191 Status = gRT->GetTime(&TheTime, NULL);
192 ASSERT_EFI_ERROR(Status);
193
194 //
195 // ShellPrintEx the date in SFO or regular format
196 //
197 if (ShellCommandLineGetFlag(Package, L"-sfo")) {
198 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DATE_SFO_FORMAT), gShellLevel2HiiHandle, TheTime.Month, TheTime.Day, TheTime.Year);
199 } else {
200 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DATE_FORMAT), gShellLevel2HiiHandle, TheTime.Month, TheTime.Day, TheTime.Year);
201 }
202 } else {
203 if (PcdGet8(PcdShellSupportLevel) == 2) {
204 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
205 ShellStatus = SHELL_INVALID_PARAMETER;
206 } else {
207 //
208 // perform level 3 operation here.
209 //
210 ShellStatus = CheckAndSetDate(ShellCommandLineGetRawValue(Package, 1));
211 if (ShellStatus != SHELL_SUCCESS) {
212 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));
213 ShellStatus = SHELL_INVALID_PARAMETER;
214 }
215 }
216 }
217 }
218 }
219 //
220 // free the command line package
221 //
222 ShellCommandLineFreeVarList (Package);
223
224 //
225 // return the status
226 //
227 return (ShellStatus);
228 }
229
230 //
231 // Note "-tz" is invalid for this (non-interactive) version of 'time'.
232 //
233 STATIC CONST SHELL_PARAM_ITEM TimeParamList2[] = {
234 {L"-d", TypeValue},
235 {NULL, TypeMax}
236 };
237
238 STATIC CONST SHELL_PARAM_ITEM TimeParamList3[] = {
239 {L"-d", TypeValue},
240 {L"-tz", TypeValue},
241 {NULL, TypeMax}
242 };
243
244 SHELL_STATUS
245 EFIAPI
246 CheckAndSetTime (
247 IN CONST CHAR16 *TimeString,
248 IN CONST INT16 Tz,
249 IN CONST UINT8 Daylight
250 )
251 {
252 EFI_TIME TheTime;
253 EFI_STATUS Status;
254 CONST CHAR16 *Walker;
255
256 if (TimeString != NULL && !InternalIsTimeLikeString(TimeString, L':', 1, 2, FALSE)) {
257 return (SHELL_INVALID_PARAMETER);
258 }
259
260 Status = gRT->GetTime(&TheTime, NULL);
261 ASSERT_EFI_ERROR(Status);
262
263 if (TimeString != NULL) {
264 Walker = TimeString;
265 TheTime.Hour = 0xFF;
266 TheTime.Minute = 0xFF;
267
268 TheTime.Hour = (UINT8)StrDecimalToUintn (Walker);
269 Walker = StrStr(Walker, L":");
270 if (Walker != NULL && *Walker == L':') {
271 Walker = Walker + 1;
272 }
273 if (Walker != NULL && Walker[0] != CHAR_NULL) {
274 TheTime.Minute = (UINT8)StrDecimalToUintn (Walker);
275 Walker = StrStr(Walker, L":");
276 if (Walker != NULL && *Walker == L':') {
277 Walker = Walker + 1;
278 }
279 if (Walker != NULL && Walker[0] != CHAR_NULL) {
280 TheTime.Second = (UINT8)StrDecimalToUintn (Walker);
281 }
282 }
283 }
284
285 if ((Tz >= -1440 && Tz <= 1440)||(Tz == 2047)) {
286 TheTime.TimeZone = Tz;
287 }
288 if (Daylight <= 3 && Daylight != 2) {
289 TheTime.Daylight = Daylight;
290 }
291 Status = gRT->SetTime(&TheTime);
292
293 if (!EFI_ERROR(Status)){
294 return (SHELL_SUCCESS);
295 }
296
297 return (SHELL_INVALID_PARAMETER);
298 }
299
300 /**
301 Function for 'time' command.
302
303 @param[in] ImageHandle Handle to the Image (NULL if Internal).
304 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
305 **/
306 SHELL_STATUS
307 EFIAPI
308 ShellCommandRunTime (
309 IN EFI_HANDLE ImageHandle,
310 IN EFI_SYSTEM_TABLE *SystemTable
311 )
312 {
313 EFI_STATUS Status;
314 LIST_ENTRY *Package;
315 CHAR16 *Message;
316 EFI_TIME TheTime;
317 CHAR16 *ProblemParam;
318 SHELL_STATUS ShellStatus;
319 INT16 Tz;
320 UINT8 Daylight;
321 CONST CHAR16 *TempLocation;
322 UINTN TzMinutes;
323
324 ShellStatus = SHELL_SUCCESS;
325 ProblemParam = NULL;
326
327 //
328 // Initialize variables
329 //
330 Message = NULL;
331
332 //
333 // initialize the shell lib (we must be in non-auto-init...)
334 //
335 Status = ShellInitialize();
336 ASSERT_EFI_ERROR(Status);
337
338 //
339 // parse the command line
340 //
341 if (PcdGet8(PcdShellSupportLevel) == 2) {
342 Status = ShellCommandLineParseEx (TimeParamList2, &Package, &ProblemParam, TRUE, TRUE);
343 } else {
344 ASSERT(PcdGet8(PcdShellSupportLevel) == 3);
345 Status = ShellCommandLineParseEx (TimeParamList3, &Package, &ProblemParam, TRUE, TRUE);
346 }
347 if (EFI_ERROR(Status)) {
348 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
349 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
350 FreePool(ProblemParam);
351 ShellStatus = SHELL_INVALID_PARAMETER;
352 } else {
353 ASSERT(FALSE);
354 }
355 } else {
356 //
357 // check for "-?"
358 //
359 Status = gRT->GetTime(&TheTime, NULL);
360 ASSERT_EFI_ERROR(Status);
361 if (ShellCommandLineGetFlag(Package, L"-?")) {
362 ASSERT(FALSE);
363 } else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
364 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
365 ShellStatus = SHELL_INVALID_PARAMETER;
366 } else {
367 //
368 // If there are no parameters, then print the current time
369 //
370 if (ShellCommandLineGetRawValue(Package, 1) == NULL
371 && !ShellCommandLineGetFlag(Package, L"-d")
372 && !ShellCommandLineGetFlag(Package, L"-tz")) {
373 //
374 // ShellPrintEx the current time
375 //
376 if (TheTime.TimeZone == 2047) {
377 TzMinutes = 0;
378 } else {
379 TzMinutes = AbsVal(TheTime.TimeZone) % 60;
380 }
381
382 ShellPrintHiiEx (
383 -1,
384 -1,
385 NULL,
386 STRING_TOKEN (STR_TIME_FORMAT),
387 gShellLevel2HiiHandle,
388 TheTime.Hour,
389 TheTime.Minute,
390 TheTime.Second,
391 TheTime.TimeZone==2047?L" ":(TheTime.TimeZone > 0?L"-":L"+"),
392 TheTime.TimeZone==2047?0:AbsVal(TheTime.TimeZone) / 60,
393 TzMinutes
394 );
395 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF), gShellLevel2HiiHandle);
396 } else if (ShellCommandLineGetFlag(Package, L"-d") && ShellCommandLineGetValue(Package, L"-d") == NULL) {
397 if (TheTime.TimeZone == 2047) {
398 TzMinutes = 0;
399 } else {
400 TzMinutes = AbsVal(TheTime.TimeZone) % 60;
401 }
402
403 ShellPrintHiiEx (
404 -1,
405 -1,
406 NULL,
407 STRING_TOKEN (STR_TIME_FORMAT),
408 gShellLevel2HiiHandle,
409 TheTime.Hour,
410 TheTime.Minute,
411 TheTime.Second,
412 TheTime.TimeZone==2047?L" ":(TheTime.TimeZone > 0?L"-":L"+"),
413 TheTime.TimeZone==2047?0:AbsVal(TheTime.TimeZone) / 60,
414 TzMinutes
415 );
416 switch (TheTime.Daylight) {
417 case 0:
418 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DSTNA), gShellLevel2HiiHandle);
419 break;
420 case EFI_TIME_ADJUST_DAYLIGHT:
421 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DSTST), gShellLevel2HiiHandle);
422 break;
423 case EFI_TIME_IN_DAYLIGHT:
424 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DSTDT), gShellLevel2HiiHandle);
425 break;
426 default:
427 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_ERROR), gShellLevel2HiiHandle, L"gRT->GetTime", L"TheTime.Daylight", TheTime.Daylight);
428 }
429 } else {
430 if (PcdGet8(PcdShellSupportLevel) == 2) {
431 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
432 ShellStatus = SHELL_INVALID_PARAMETER;
433 } else {
434 //
435 // perform level 3 operation here.
436 //
437 if ((TempLocation = ShellCommandLineGetValue(Package, L"-tz")) != NULL) {
438 if (TempLocation[0] == L'-') {
439 Tz = (INT16)(0 - StrDecimalToUintn(++TempLocation));
440 } else {
441 Tz = (INT16)StrDecimalToUintn(TempLocation);
442 }
443 if (!(Tz >= -1440 && Tz <= 1440) && Tz != 2047) {
444 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"-d");
445 ShellStatus = SHELL_INVALID_PARAMETER;
446 }
447 } else {
448 //
449 // intentionally out of bounds value will prevent changing it...
450 //
451 Tz = 1441;
452 }
453 TempLocation = ShellCommandLineGetValue(Package, L"-d");
454 if (TempLocation != NULL) {
455 Daylight = (UINT8)StrDecimalToUintn(TempLocation);
456 if (Daylight != 0 && Daylight != 1 && Daylight != 3) {
457 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"-d");
458 ShellStatus = SHELL_INVALID_PARAMETER;
459 }
460 } else {
461 //
462 // invalid = will not use
463 //
464 Daylight = 0xFF;
465 }
466 if (ShellStatus == SHELL_SUCCESS) {
467 ShellStatus = CheckAndSetTime(ShellCommandLineGetRawValue(Package, 1), Tz, Daylight);
468 if (ShellStatus != SHELL_SUCCESS) {
469 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));
470 ShellStatus = SHELL_INVALID_PARAMETER;
471 }
472 }
473 }
474 }
475 }
476 }
477
478 //
479 // free the command line package
480 //
481 ShellCommandLineFreeVarList (Package);
482
483 //
484 // return the status
485 //
486 return (ShellStatus);
487 }
488
489 typedef struct {
490 INT16 TimeZone;
491 EFI_STRING_ID StringId;
492 } TIME_ZONE_ITEM;
493
494 STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList2[] = {
495 {L"-l", TypeFlag},
496 {L"-f", TypeFlag},
497 {NULL, TypeMax}
498 };
499 STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList3[] = {
500 {L"-l", TypeFlag},
501 {L"-f", TypeFlag},
502 {L"-s", TypeValue},
503 {NULL, TypeMax}
504 };
505
506 STATIC CONST TIME_ZONE_ITEM TimeZoneList[] = {
507 {720, STRING_TOKEN (STR_TIMEZONE_M12)},
508 {660, STRING_TOKEN (STR_TIMEZONE_M11)},
509 {600, STRING_TOKEN (STR_TIMEZONE_M10)},
510 {540, STRING_TOKEN (STR_TIMEZONE_M9)},
511 {480, STRING_TOKEN (STR_TIMEZONE_M8)},
512 {420, STRING_TOKEN (STR_TIMEZONE_M7)},
513 {360, STRING_TOKEN (STR_TIMEZONE_M6)},
514 {300, STRING_TOKEN (STR_TIMEZONE_M5)},
515 {270, STRING_TOKEN (STR_TIMEZONE_M430)},
516 {240, STRING_TOKEN (STR_TIMEZONE_M4)},
517 {210, STRING_TOKEN (STR_TIMEZONE_M330)},
518 {180, STRING_TOKEN (STR_TIMEZONE_M3)},
519 {120, STRING_TOKEN (STR_TIMEZONE_M2)},
520 {60 , STRING_TOKEN (STR_TIMEZONE_M1)},
521 {0 , STRING_TOKEN (STR_TIMEZONE_0)},
522 {-60 , STRING_TOKEN (STR_TIMEZONE_P1)},
523 {-120 , STRING_TOKEN (STR_TIMEZONE_P2)},
524 {-180 , STRING_TOKEN (STR_TIMEZONE_P3)},
525 {-210 , STRING_TOKEN (STR_TIMEZONE_P330)},
526 {-240 , STRING_TOKEN (STR_TIMEZONE_P4)},
527 {-270 , STRING_TOKEN (STR_TIMEZONE_P430)},
528 {-300 , STRING_TOKEN (STR_TIMEZONE_P5)},
529 {-330 , STRING_TOKEN (STR_TIMEZONE_P530)},
530 {-345 , STRING_TOKEN (STR_TIMEZONE_P545)},
531 {-360 , STRING_TOKEN (STR_TIMEZONE_P6)},
532 {-390 , STRING_TOKEN (STR_TIMEZONE_P630)},
533 {-420 , STRING_TOKEN (STR_TIMEZONE_P7)},
534 {-480 , STRING_TOKEN (STR_TIMEZONE_P8)},
535 {-540 , STRING_TOKEN (STR_TIMEZONE_P9)},
536 {-570 , STRING_TOKEN (STR_TIMEZONE_P930)},
537 {-600 , STRING_TOKEN (STR_TIMEZONE_P10)},
538 {-660 , STRING_TOKEN (STR_TIMEZONE_P11)},
539 {-720 , STRING_TOKEN (STR_TIMEZONE_P12)},
540 {-780 , STRING_TOKEN (STR_TIMEZONE_P13)},
541 {-840 , STRING_TOKEN (STR_TIMEZONE_P14)}
542 };
543
544 SHELL_STATUS
545 EFIAPI
546 CheckAndSetTimeZone (
547 IN CONST CHAR16 *TimeZoneString
548 )
549 {
550 EFI_TIME TheTime;
551 EFI_STATUS Status;
552 CONST CHAR16 *Walker;
553 UINTN LoopVar;
554
555 if (TimeZoneString == NULL) {
556 return (SHELL_INVALID_PARAMETER);
557 }
558
559 if (TimeZoneString != NULL && !InternalIsTimeLikeString(TimeZoneString, L':', 1, 1, TRUE)) {
560 return (SHELL_INVALID_PARAMETER);
561 }
562
563 Status = gRT->GetTime(&TheTime, NULL);
564 ASSERT_EFI_ERROR(Status);
565
566 Walker = TimeZoneString;
567 if (*Walker == L'-') {
568 TheTime.TimeZone = (INT16)((StrDecimalToUintn (++Walker)) * 60);
569 } else {
570 TheTime.TimeZone = (INT16)((StrDecimalToUintn (Walker)) * -60);
571 }
572 Walker = StrStr(Walker, L":");
573 if (Walker != NULL && *Walker == L':') {
574 Walker = Walker + 1;
575 }
576 if (Walker != NULL && Walker[0] != CHAR_NULL) {
577 if (TheTime.TimeZone < 0) {
578 TheTime.TimeZone = (INT16)(TheTime.TimeZone - (UINT8)StrDecimalToUintn (Walker));
579 } else {
580 TheTime.TimeZone = (INT16)(TheTime.TimeZone + (UINT8)StrDecimalToUintn (Walker));
581 }
582 }
583
584 Status = EFI_INVALID_PARAMETER;
585
586 for ( LoopVar = 0
587 ; LoopVar < sizeof(TimeZoneList) / sizeof(TimeZoneList[0])
588 ; LoopVar++
589 ){
590 if (TheTime.TimeZone == TimeZoneList[LoopVar].TimeZone) {
591 Status = gRT->SetTime(&TheTime);
592 break;
593 }
594 }
595
596 if (!EFI_ERROR(Status)){
597 return (SHELL_SUCCESS);
598 }
599 return (SHELL_INVALID_PARAMETER);
600 }
601
602
603 /**
604 Function for 'timezone' command.
605
606 @param[in] ImageHandle Handle to the Image (NULL if Internal).
607 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
608 **/
609 SHELL_STATUS
610 EFIAPI
611 ShellCommandRunTimeZone (
612 IN EFI_HANDLE ImageHandle,
613 IN EFI_SYSTEM_TABLE *SystemTable
614 )
615 {
616 //
617 // non interactive
618 //
619 EFI_STATUS Status;
620 LIST_ENTRY *Package;
621 CHAR16 *ProblemParam;
622 SHELL_STATUS ShellStatus;
623 UINT8 LoopVar;
624 EFI_TIME TheTime;
625 BOOLEAN Found;
626 UINTN TzMinutes;
627
628 ShellStatus = SHELL_SUCCESS;
629 ProblemParam = NULL;
630
631 //
632 // initialize the shell lib (we must be in non-auto-init...)
633 //
634 Status = ShellInitialize();
635 ASSERT_EFI_ERROR(Status);
636
637 //
638 // parse the command line
639 //
640 if (PcdGet8(PcdShellSupportLevel) == 2) {
641 Status = ShellCommandLineParse (TimeZoneParamList2, &Package, &ProblemParam, FALSE);
642 } else {
643 ASSERT(PcdGet8(PcdShellSupportLevel) == 3);
644 Status = ShellCommandLineParseEx (TimeZoneParamList3, &Package, &ProblemParam, FALSE, TRUE);
645 }
646 if (EFI_ERROR(Status)) {
647 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
648 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
649 FreePool(ProblemParam);
650 ShellStatus = SHELL_INVALID_PARAMETER;
651 } else {
652 ASSERT(FALSE);
653 }
654 } else {
655 //
656 // check for "-?"
657 //
658 if (ShellCommandLineGetCount(Package) > 1) {
659 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
660 ShellStatus = SHELL_INVALID_PARAMETER;
661 } else if (ShellCommandLineGetFlag(Package, L"-?")) {
662 ASSERT(FALSE);
663 } else if (ShellCommandLineGetFlag(Package, L"-s")) {
664 if ((ShellCommandLineGetFlag(Package, L"-l")) || (ShellCommandLineGetFlag(Package, L"-f"))) {
665 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"-l or -f");
666 ShellStatus = SHELL_INVALID_PARAMETER;
667 } else {
668 ASSERT(PcdGet8(PcdShellSupportLevel) == 3);
669 if (ShellCommandLineGetValue(Package, L"-s") == NULL) {
670 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellLevel2HiiHandle, L"-s");
671 ShellStatus = SHELL_INVALID_PARAMETER;
672 } else {
673 //
674 // Set the time zone
675 //
676 ShellStatus = CheckAndSetTimeZone(ShellCommandLineGetValue(Package, L"-s"));
677 if (ShellStatus != SHELL_SUCCESS) {
678 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ShellCommandLineGetValue(Package, L"-s"));
679 ShellStatus = SHELL_INVALID_PARAMETER;
680 }
681 }
682 }
683 } else if (ShellCommandLineGetFlag(Package, L"-l")) {
684 //
685 // Print a list of all time zones
686 //
687 for ( LoopVar = 0
688 ; LoopVar < sizeof(TimeZoneList) / sizeof(TimeZoneList[0])
689 ; LoopVar++
690 ){
691 ShellPrintHiiEx (-1, -1, NULL, TimeZoneList[LoopVar].StringId, gShellLevel2HiiHandle);
692 }
693 } else {
694 //
695 // Get Current Time Zone Info
696 //
697 Status = gRT->GetTime(&TheTime, NULL);
698 ASSERT_EFI_ERROR(Status);
699
700 if (TheTime.TimeZone != 2047) {
701 Found = FALSE;
702 for ( LoopVar = 0
703 ; LoopVar < sizeof(TimeZoneList) / sizeof(TimeZoneList[0])
704 ; LoopVar++
705 ){
706 if (TheTime.TimeZone == TimeZoneList[LoopVar].TimeZone) {
707 if (ShellCommandLineGetFlag(Package, L"-f")) {
708 //
709 // Print all info about current time zone
710 //
711 ShellPrintHiiEx (-1, -1, NULL, TimeZoneList[LoopVar].StringId, gShellLevel2HiiHandle);
712 } else {
713 //
714 // Print basic info only
715 //
716 if (TheTime.TimeZone == 2047) {
717 TzMinutes = 0;
718 } else {
719 TzMinutes = AbsVal(TheTime.TimeZone) % 60;
720 }
721
722 ShellPrintHiiEx (
723 -1,
724 -1,
725 NULL,
726 STRING_TOKEN(STR_TIMEZONE_SIMPLE),
727 gShellLevel2HiiHandle,
728 TheTime.TimeZone==2047?0:(TheTime.TimeZone > 0?L"-":L"+"),
729 TheTime.TimeZone==2047?0:AbsVal(TheTime.TimeZone) / 60,
730 TzMinutes);
731 }
732 Found = TRUE;
733 break;
734 }
735 }
736 if (!Found) {
737 //
738 // Print basic info only
739 //
740 if (TheTime.TimeZone == 2047) {
741 TzMinutes = 0;
742 } else {
743 TzMinutes = AbsVal(TheTime.TimeZone) % 60;
744 }
745 ShellPrintHiiEx (
746 -1,
747 -1,
748 NULL,
749 STRING_TOKEN(STR_TIMEZONE_SIMPLE),
750 gShellLevel2HiiHandle,
751 TheTime.TimeZone==2047?0:(TheTime.TimeZone > 0?L"-":L"+"),
752 TheTime.TimeZone==2047?0:AbsVal(TheTime.TimeZone) / 60,
753 TzMinutes);
754 if (ShellCommandLineGetFlag(Package, L"-f")) {
755 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN(STR_TIMEZONE_NI), gShellLevel2HiiHandle);
756 }
757 }
758 } else {
759 //
760 // TimeZone was 2047 (unknown) from GetTime()
761 //
762 }
763 }
764 }
765
766 //
767 // free the command line package
768 //
769 ShellCommandLineFreeVarList (Package);
770
771 return (ShellStatus);
772 }