Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 1999 Intel Corporation
  3. Module Name:
  4. time.c
  5. Abstract:
  6. Revision History
  7. --*/
  8. #include "shell.h"
  9. EFI_STATUS
  10. InitializeTime (
  11. IN EFI_HANDLE ImageHandle,
  12. IN EFI_SYSTEM_TABLE *SystemTable
  13. );
  14. EFI_DRIVER_ENTRY_POINT(InitializeTime)
  15. EFI_STATUS
  16. InitializeTime (
  17. IN EFI_HANDLE ImageHandle,
  18. IN EFI_SYSTEM_TABLE *SystemTable
  19. )
  20. /*+++
  21. time [hh:mm:ss]
  22. --*/
  23. {
  24. EFI_STATUS Status;
  25. EFI_TIME Time;
  26. CHAR16 *TimeString;
  27. UINT32 i;
  28. InstallInternalShellCommand (
  29. ImageHandle, SystemTable, InitializeTime,
  30. L"time", /* command */
  31. L"time [hh:mm:ss]", /* command syntax */
  32. L"Get or set time", /* 1 line descriptor */
  33. NULL /* command help page */
  34. );
  35. InitializeShellApplication (ImageHandle, SystemTable);
  36. if (SI->Argc > 2) {
  37. Print(L"time [hh:mm:ss]\n");
  38. return EFI_SUCCESS;
  39. }
  40. if (SI->Argc == 1) {
  41. Status = RT->GetTime(&Time,NULL);
  42. if (!EFI_ERROR(Status)) {
  43. Print(L"%02d:%02d:%02d\n",Time.Hour,Time.Minute,Time.Second);
  44. }
  45. return EFI_SUCCESS;
  46. }
  47. if (StrCmp(SI->Argv[1],L"/?") == 0) {
  48. Print(L"time [hh:mm:ss]\n");
  49. return EFI_SUCCESS;
  50. }
  51. if (StrCmp(SI->Argv[1],L"/h") == 0) {
  52. Print(L"time [hh:mm:ss]\n");
  53. return EFI_SUCCESS;
  54. }
  55. Status = RT->GetTime(&Time,NULL);
  56. if (EFI_ERROR(Status)) {
  57. Print(L"error : RTC not functional\n");
  58. return Status;
  59. }
  60. TimeString = SI->Argv[1];
  61. Time.Hour = (UINT8)Atoi(TimeString);
  62. if ((INT8)Time.Hour<0 || Time.Hour>23) {
  63. Print(L"error : invalid hour\n");
  64. return EFI_INVALID_PARAMETER;
  65. }
  66. for(i=0;i<StrLen(TimeString) && TimeString[i]!=':';i++);
  67. if (TimeString[i]==':') {
  68. i++;
  69. Time.Minute = (UINT8)Atoi(&(TimeString[i]));
  70. if ((INT8)Time.Minute<0 || Time.Minute>59) {
  71. Print(L"error : invalid minutes\n");
  72. return EFI_INVALID_PARAMETER;
  73. }
  74. for(;i<StrLen(TimeString) && TimeString[i]!=':';i++);
  75. if (TimeString[i]==':') {
  76. i++;
  77. Time.Second = (UINT8)Atoi(&(TimeString[i]));
  78. } else {
  79. Time.Second = 0;
  80. }
  81. if ((INT8)Time.Second<0 || Time.Second>59) {
  82. Print(L"error : invalid seconds\n");
  83. return EFI_INVALID_PARAMETER;
  84. }
  85. Status = RT->SetTime(&Time);
  86. if (EFI_ERROR(Status)) {
  87. Print(L"error : RTC not functional\n");
  88. return Status;
  89. }
  90. return EFI_SUCCESS;
  91. }
  92. Print(L"error : invalid time format\n");
  93. return EFI_INVALID_PARAMETER;
  94. }