From 00d10d92b06ee93413a68f93c04a3af5e3693862 Mon Sep 17 00:00:00 2001 From: niruiyu Date: Wed, 16 Feb 2011 08:42:11 +0000 Subject: [PATCH] Fix shell timezone bugs git-svn-id: https://svn.code.sf.net/p/efi-shell/code/trunk/Shell@47 98faeb64-521c-4ab6-bae1-df9f193a316f --- time/time.c | 54 +++++------ tzone/TZoneStrings.uni | Bin 22740 -> 22848 bytes tzone/tzone.c | 202 ++++++++++++++++++++--------------------- 3 files changed, 119 insertions(+), 137 deletions(-) diff --git a/time/time.c b/time/time.c index bd9c35d..00dd586 100644 --- a/time/time.c +++ b/time/time.c @@ -1,6 +1,6 @@ /*++ -Copyright (c) 2005 - 2007, Intel Corporation +Copyright (c) 2005 - 2011, Intel Corporation All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -96,8 +96,7 @@ Routine Description: UINTN Offset; UINTN Data; EFI_HII_HANDLE HiiHandle; - INTN nValue; - UINTN uValueSize; + INT16 nValue; CHAR16 wchSign; SHELL_VAR_CHECK_CODE RetCode; @@ -188,38 +187,27 @@ Routine Description: Status = RT->GetTime (&Time, NULL); if (!EFI_ERROR (Status)) { - Status = RT->GetVariable ( - L"TimeZone", - &gEfiGenericVariableGuid, - NULL, - &uValueSize, - &nValue - ); - if (!EFI_ERROR (Status) || EFI_NOT_FOUND == Status) { - if (EFI_NOT_FOUND == Status) { - nValue = 0; - } - - if (nValue < 0) { - nValue = -nValue; - wchSign = L'-'; - } - - PrintToken ( - STRING_TOKEN (STR_TIME_THREE_VARS), - HiiHandle, - (UINTN) Time.Hour, - (UINTN) Time.Minute, - (UINTN) Time.Second, - wchSign, - nValue / 100, - nValue % 100 - ); - Status = EFI_SUCCESS; - goto Done; + if (Time.TimeZone < 0) { + nValue = -Time.TimeZone; + } else { + nValue = Time.TimeZone; + wchSign = L'-'; } - } + PrintToken ( + STRING_TOKEN (STR_TIME_THREE_VARS), + HiiHandle, + (UINTN) Time.Hour, + (UINTN) Time.Minute, + (UINTN) Time.Second, + wchSign, + nValue / 60, + nValue % 60 + ); + Status = EFI_SUCCESS; + goto Done; + } + PrintToken (STRING_TOKEN (STR_TIME_CLOCK_NOT_FUNC), HiiHandle, L"time"); goto Done; } diff --git a/tzone/TZoneStrings.uni b/tzone/TZoneStrings.uni index 87b1f6a5bc32c5ef3b2850a5c7f2b2631f0e04aa..b019b85f9610ad75eaf778f833ab32fd34f8ff8a 100644 GIT binary patch delta 527 zcmXYu%`XFC5XR@tA_!HB2DLO4RYJRMxAm2vS(_$RG{VhSLgL^fO>svqd|S1{$+F zFn|xTDm46-b^HuCO(g}uPgNcFv_{r`2(dmb*^~V2@+$e*LB}!6iSSXkfm+#*q~JYcU|^&;#0XQd2=pN`JC9?MaNLZJk2)gw||Icd4z|&6m-ZgJgLl3O(;5ERHf14 zD!@Et2rq44>}2MxHF=mGoJLzq6c4I3p7@`i;7y2A*EJqNBFIKAdz_Y?vl-YkwTSMz zXHxIA1`aE4`9APN0JrT1uGLTS_1LQ6p17O4t&T~)zG-{ocoZZ;Tu4VYu&-&C-|fs9 zL5p*rIEZJ?E1{*vn~w!QxKP6AY0dJFFxeg3#15NE+O!F$Vr_-OZh#IGFheH-Bg8Xw z;`EI|{BYZjTg8oC3y`Gp5-h_4I4G{bBCHZ6NGD;P;tDC9VuJDsyp>zAw!J=;bkBDF E0Up4LPidD_cBUyJWn=|%npe8zpR=NZl!kB!lZI$&Y-li$h-j!DXo%)$ zh_H?tnj9TkgywRHrUvJT>is^x?fpIXe9!yxT;oB0y_f434qHr$OByzv2HqT1q8O(~ znlzzr^sL!5DMeIJ419A+a%z!2EA*Y-Q&in{6qOt@t}BZs>E^pDC6gr~EakpWSwkye z;JAN_rh?x;x7ba#t+u05&(>d#E^v(eOr49c*wtt^NsjS~YOw>F|_AG=@HS zGMlXEcvr<%a-I9FxXYID<$K}cG`LtK&}kEadFfBGGj)l7LmMqvp^KKGB02@t_^F;$|TPmoH8#D}<%)hng&vHARS%kzXR#BBSt9nZgp5 zl!&+uZ;Qs$YSt``6=m@&2=Tm9!t!_xa~?Zw&%hI@%Q0$i-c%;KWgJcg&GuwD`VVbx BghBuS diff --git a/tzone/tzone.c b/tzone/tzone.c index 7f5002b..30cc513 100644 --- a/tzone/tzone.c +++ b/tzone/tzone.c @@ -1,6 +1,6 @@ /*++ -Copyright (c) 2005 - 2007, Intel Corporation +Copyright (c) 2005 - 2011, Intel Corporation All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -70,7 +70,7 @@ SHELL_VAR_CHECK_ITEM TzoneCheckList[] = { }; struct tagMap { - INTN m_nValue; + INT16 m_nValue; // Timezone value in EFI_TIME structure.( = UTC - local time). UINTN m_uToken; }; @@ -83,12 +83,12 @@ InitializeTZone ( BOOLEAN TZoneArgtoValue ( IN CHAR16 *wszValue, - OUT INTN *pnValue + OUT INT16 *pnValue ); EFI_STATUS TZoneSetValue ( - IN INTN nValue + IN INT16 nValue ); EFI_STATUS @@ -102,136 +102,136 @@ EFI_BOOTSHELL_CODE( struct tagMap gTZMap[] = { { - -1200, - STRING_TOKEN(STR_TZONE_GMT_N1200) + 720, + STRING_TOKEN(STR_TZONE_GMT_N720) }, { - -1100, - STRING_TOKEN(STR_TZONE_GMT_N1100) + 660, + STRING_TOKEN(STR_TZONE_GMT_N660) }, { - -1000, - STRING_TOKEN(STR_TZONE_GMT_N1000) + 600, + STRING_TOKEN(STR_TZONE_GMT_N600) }, { - -900, - STRING_TOKEN(STR_TZONE_GMT_N0900) + 540, + STRING_TOKEN(STR_TZONE_GMT_N540) }, { - -800, - STRING_TOKEN(STR_TZONE_GMT_N0800) + 480, + STRING_TOKEN(STR_TZONE_GMT_N480) }, { - -700, - STRING_TOKEN(STR_TZONE_GMT_N0700) + 420, + STRING_TOKEN(STR_TZONE_GMT_N420) }, { - -600, - STRING_TOKEN(STR_TZONE_GMT_N0600) + 360, + STRING_TOKEN(STR_TZONE_GMT_N360) }, { - -500, - STRING_TOKEN(STR_TZONE_GMT_N0500) + 300, + STRING_TOKEN(STR_TZONE_GMT_N300) }, { - -400, - STRING_TOKEN(STR_TZONE_GMT_N0400) + 240, + STRING_TOKEN(STR_TZONE_GMT_N240) }, { - -330, - STRING_TOKEN(STR_TZONE_GMT_N0330) + 210, + STRING_TOKEN(STR_TZONE_GMT_N210) }, { - -300, - STRING_TOKEN(STR_TZONE_GMT_N0300) + 180, + STRING_TOKEN(STR_TZONE_GMT_N180) }, { - -200, - STRING_TOKEN(STR_TZONE_GMT_N0200) + 120, + STRING_TOKEN(STR_TZONE_GMT_N120) }, { - -100, - STRING_TOKEN(STR_TZONE_GMT_N0100) + 60, + STRING_TOKEN(STR_TZONE_GMT_N060) }, { 0, - STRING_TOKEN(STR_TZONE_GMT_0000) + STRING_TOKEN(STR_TZONE_GMT_000) }, { - 100, - STRING_TOKEN(STR_TZONE_GMT_P0100) + -60, + STRING_TOKEN(STR_TZONE_GMT_P060) }, { - 200, - STRING_TOKEN(STR_TZONE_GMT_P0200) + -120, + STRING_TOKEN(STR_TZONE_GMT_P120) }, { - 300, - STRING_TOKEN(STR_TZONE_GMT_P0300) + -180, + STRING_TOKEN(STR_TZONE_GMT_P180) }, { - 330, - STRING_TOKEN(STR_TZONE_GMT_P0330) + -210, + STRING_TOKEN(STR_TZONE_GMT_P210) }, { - 400, - STRING_TOKEN(STR_TZONE_GMT_P0400) + -240, + STRING_TOKEN(STR_TZONE_GMT_P240) }, { - 430, - STRING_TOKEN(STR_TZONE_GMT_P0430) + -270, + STRING_TOKEN(STR_TZONE_GMT_P270) }, { - 500, - STRING_TOKEN(STR_TZONE_GMT_P0500) + -300, + STRING_TOKEN(STR_TZONE_GMT_P300) }, { - 530, - STRING_TOKEN(STR_TZONE_GMT_P0530) + -330, + STRING_TOKEN(STR_TZONE_GMT_P330) }, { - 545, - STRING_TOKEN(STR_TZONE_GMT_P0545) + -345, + STRING_TOKEN(STR_TZONE_GMT_P345) }, { - 600, - STRING_TOKEN(STR_TZONE_GMT_P0600) + -360, + STRING_TOKEN(STR_TZONE_GMT_P360) }, { - 630, - STRING_TOKEN(STR_TZONE_GMT_P0630) + -390, + STRING_TOKEN(STR_TZONE_GMT_P390) }, { - 700, - STRING_TOKEN(STR_TZONE_GMT_P0700) + -420, + STRING_TOKEN(STR_TZONE_GMT_P420) }, { - 800, - STRING_TOKEN(STR_TZONE_GMT_P0800) + -480, + STRING_TOKEN(STR_TZONE_GMT_P480) }, { - 900, - STRING_TOKEN(STR_TZONE_GMT_P0900) + -540, + STRING_TOKEN(STR_TZONE_GMT_P540) }, { - 930, - STRING_TOKEN(STR_TZONE_GMT_P0930) + -570, + STRING_TOKEN(STR_TZONE_GMT_P570) }, { - 1000, - STRING_TOKEN(STR_TZONE_GMT_P1000) + -600, + STRING_TOKEN(STR_TZONE_GMT_P600) }, { - 1100, - STRING_TOKEN(STR_TZONE_GMT_P1100) + -660, + STRING_TOKEN(STR_TZONE_GMT_P660) }, { - 1200, - STRING_TOKEN(STR_TZONE_GMT_P1200) + -720, + STRING_TOKEN(STR_TZONE_GMT_P720) }, { - 1300, - STRING_TOKEN(STR_TZONE_GMT_P1300) + -780, + STRING_TOKEN(STR_TZONE_GMT_P780) } }; @@ -257,12 +257,13 @@ InitializeTZone ( BOOLEAN bFullInfo; BOOLEAN bList; BOOLEAN bSet; - INTN nValue; + INT16 nValue; UINTN uValueSize; SHELL_VAR_CHECK_CODE RetCode; CHAR16 *Useful; SHELL_VAR_CHECK_PACKAGE ChkPck; SHELL_ARG_LIST *Item; + EFI_TIME Time; bFullInfo = FALSE; bList = FALSE; @@ -270,6 +271,7 @@ InitializeTZone ( nValue = 0; uValueSize = sizeof (INTN); ZeroMem (&ChkPck, sizeof (SHELL_VAR_CHECK_PACKAGE)); + ZeroMem (&Time, sizeof (EFI_TIME)); // // We are now being installed as an internal command driver, initialize // as an nshell app and run @@ -378,10 +380,10 @@ InitializeTZone ( } if (nValue >= 0) { - PrintToken (STRING_TOKEN (STR_TZONE_INVALID_VALUE), hHiiHandle, L"timezone", L"+", nValue / 100, nValue % 100); + PrintToken (STRING_TOKEN (STR_TZONE_INVALID_VALUE), hHiiHandle, L"timezone", L"-", nValue / 60, nValue % 60); } else { nValue = -nValue; - PrintToken (STRING_TOKEN (STR_TZONE_INVALID_VALUE), hHiiHandle, L"timezone", L"-", nValue / 100, nValue % 100); + PrintToken (STRING_TOKEN (STR_TZONE_INVALID_VALUE), hHiiHandle, L"timezone", L"+", nValue / 60, nValue % 60); } Status = EFI_INVALID_PARAMETER; @@ -390,26 +392,13 @@ InitializeTZone ( Status = TZoneList (&hHiiHandle); goto Done; } else { - Status = RT->GetVariable ( - L"TimeZone", - &gEfiGenericVariableGuid, - NULL, - &uValueSize, - &nValue - ); + Status = RT->GetTime(&Time, NULL); if (EFI_ERROR (Status)) { - if (EFI_NOT_FOUND == Status) { - if (bFullInfo) { - PrintToken (STRING_TOKEN (STR_TZONE_GMT_0000), hHiiHandle); - } else { - PrintToken (STRING_TOKEN (STR_TZONE_GMT_FMT), hHiiHandle, L"+", 0, 0); - } - - Status = EFI_SUCCESS; - } - + PrintToken (STRING_TOKEN (STR_GET_TIME_ERROR), hHiiHandle); goto Done; } + nValue = Time.TimeZone; + // // end of if (EFI_ERROR(Status)) // @@ -422,10 +411,10 @@ InitializeTZone ( } } else { if (nValue >= 0) { - PrintToken (STRING_TOKEN (STR_TZONE_GMT_FMT), hHiiHandle, L"+", nValue / 100, nValue % 100); + PrintToken (STRING_TOKEN (STR_TZONE_GMT_FMT), hHiiHandle, L"-", nValue / 60, nValue % 60); } else { nValue = -nValue; - PrintToken (STRING_TOKEN (STR_TZONE_GMT_FMT), hHiiHandle, L"-", nValue / 100, nValue % 100); + PrintToken (STRING_TOKEN (STR_TZONE_GMT_FMT), hHiiHandle, L"+", nValue / 60, nValue % 60); } } } @@ -439,14 +428,14 @@ InitializeTZone ( BOOLEAN TZoneArgtoValue ( IN CHAR16 *wszValue, - OUT INTN *pnValue + OUT INT16 *pnValue ) { UINTN uPos; CHAR16 *pwchBreak; BOOLEAN bDigitFound; BOOLEAN bSignGot; - INTN nSign; + INT16 nSign; UINTN uDigitStart; uPos = 0; @@ -485,7 +474,7 @@ TZoneArgtoValue ( } wszValue[uPos] = 0; - *pnValue = Atoi (wszValue + uDigitStart); + *pnValue = (UINT16) Atoi (wszValue + uDigitStart); wszValue[uPos] = L':'; if (NULL != pwchBreak) { @@ -531,25 +520,30 @@ TZoneArgtoValue ( return FALSE; } - *pnValue *= 100; - *pnValue = *pnValue + Atoi (pwchBreak); + *pnValue *= 60; + *pnValue = *pnValue + (UINT16) Atoi (pwchBreak); *pnValue = *pnValue * nSign; + *pnValue = - (*pnValue); return TRUE; } EFI_STATUS TZoneSetValue ( - IN INTN nValue + IN INT16 nValue ) { - return RT->SetVariable ( - L"TimeZone", - &gEfiGenericVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, - sizeof (INTN), - &nValue - ); + EFI_TIME Time; + EFI_STATUS Status; + + Status = RT->GetTime (&Time, NULL); + if (EFI_ERROR (Status)) { + return Status; + } + + Time.TimeZone = nValue; + + return RT->SetTime(&Time); } EFI_STATUS