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.

171 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 1999 Intel Corporation
  3. Module Name:
  4. goto.c
  5. Abstract:
  6. Shell Environment batch goto command
  7. Revision History
  8. --*/
  9. #include "shelle.h"
  10. /*
  11. * Statics
  12. */
  13. STATIC CHAR16 *TargetLabel;
  14. /*/////////////////////////////////////////////////////////////////////
  15. Function Name:
  16. SEnvCmdGoto
  17. Description:
  18. Transfers execution of batch file to location following a label (:labelname).
  19. */
  20. EFI_STATUS
  21. SEnvCmdGoto(
  22. IN EFI_HANDLE ImageHandle,
  23. IN EFI_SYSTEM_TABLE *SystemTable
  24. )
  25. {
  26. CHAR16 **Argv;
  27. UINTN Argc = 0;
  28. EFI_STATUS Status = EFI_SUCCESS;
  29. InitializeShellApplication (ImageHandle, SystemTable);
  30. Argv = SI->Argv;
  31. Argc = SI->Argc;
  32. if ( !SEnvBatchIsActive() ) {
  33. Print( L"Error: GOTO command only supported in script files\n" );
  34. Status = EFI_UNSUPPORTED;
  35. goto Done;
  36. }
  37. if ( Argc > 2 ) {
  38. Status = EFI_INVALID_PARAMETER;
  39. goto Done;
  40. }
  41. TargetLabel = StrDuplicate( Argv[1] );
  42. if ( !TargetLabel ) {
  43. Status = EFI_OUT_OF_RESOURCES;
  44. goto Done;
  45. }
  46. SEnvBatchSetGotoActive();
  47. Done:
  48. return Status;
  49. }
  50. /*/////////////////////////////////////////////////////////////////////
  51. Function Name:
  52. SEnvCheckForGotoTarget
  53. Description:
  54. Check to see if we have found the target label of a GOTO command.
  55. */
  56. EFI_STATUS
  57. SEnvCheckForGotoTarget(
  58. IN CHAR16 *Candidate,
  59. IN UINT64 GotoFilePos,
  60. IN UINT64 FilePosition,
  61. OUT UINTN *GotoTargetStatus
  62. )
  63. {
  64. EFI_STATUS Status = EFI_SUCCESS;
  65. if ( !Candidate ) {
  66. Status = EFI_INVALID_PARAMETER;
  67. goto Done;
  68. }
  69. /*
  70. * See if we found the label (strip the leading ':' off the candidate)
  71. * or if we have searched the whole file without finding it.
  72. */
  73. if ( StriCmp( &Candidate[1], TargetLabel ) == 0 ) {
  74. *GotoTargetStatus = GOTO_TARGET_FOUND;
  75. goto Done;
  76. } else if ( GotoFilePos == FilePosition ) {
  77. *GotoTargetStatus = GOTO_TARGET_DOESNT_EXIST;
  78. goto Done;
  79. } else {
  80. *GotoTargetStatus = GOTO_TARGET_NOT_FOUND;
  81. goto Done;
  82. }
  83. Done:
  84. return Status;
  85. }
  86. /*/////////////////////////////////////////////////////////////////////
  87. Function Name:
  88. SEnvPrintLabelNotFound
  89. Description:
  90. Print an error message when a label referenced by a GOTO is not
  91. found in the script file..
  92. */
  93. VOID
  94. SEnvPrintLabelNotFound(
  95. VOID
  96. )
  97. {
  98. Print( L"GOTO target label \":%s\" not found\n", TargetLabel );
  99. return;
  100. }
  101. /*/////////////////////////////////////////////////////////////////////
  102. Function Name:
  103. SEnvInitTargetLabel
  104. Description:
  105. Initialize the target label for the GOTO command.
  106. */
  107. VOID
  108. SEnvInitTargetLabel(
  109. VOID
  110. )
  111. {
  112. TargetLabel = NULL;
  113. return;
  114. }
  115. /*/////////////////////////////////////////////////////////////////////
  116. Function Name:
  117. SEnvFreeTargetLabel
  118. Description:
  119. Free the target label saved from the GOTO command.
  120. */
  121. VOID
  122. SEnvFreeTargetLabel(
  123. VOID
  124. )
  125. {
  126. if ( TargetLabel ) {
  127. FreePool( TargetLabel );
  128. TargetLabel = NULL;
  129. }
  130. return;
  131. }