Source code of Windows XP (NT5)
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.

241 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1998 Intel Corporation
  3. Module Name:
  4. cmddisp.c
  5. Abstract:
  6. Shell Environment internal command management
  7. Revision History
  8. --*/
  9. #include "shelle.h"
  10. #define COMMAND_SIGNATURE EFI_SIGNATURE_32('c','m','d','s')
  11. typedef struct {
  12. UINTN Signature;
  13. LIST_ENTRY Link;
  14. SHELLENV_INTERNAL_COMMAND Dispatch;
  15. CHAR16 *Cmd;
  16. CHAR16 *CmdFormat;
  17. CHAR16 *CmdHelpLine;
  18. VOID *CmdVerboseHelp;
  19. } COMMAND;
  20. /*
  21. * Internal prototype
  22. */
  23. EFI_STATUS
  24. SEnvHelp (
  25. IN EFI_HANDLE ImageHandle,
  26. IN EFI_SYSTEM_TABLE *SystemTable
  27. );
  28. /*
  29. *
  30. */
  31. struct {
  32. SHELLENV_INTERNAL_COMMAND Dispatch;
  33. CHAR16 *Cmd;
  34. CHAR16 *CmdFormat;
  35. CHAR16 *CmdHelpLine;
  36. VOID *CmdVerboseHelp;
  37. } SEnvInternalCommands[] = {
  38. SEnvHelp, L"?", NULL, NULL, NULL,
  39. SEnvLoadDefaults, L"_load_defaults", NULL, NULL, NULL,
  40. SEnvHelp, L"help", L"help [-b] [internal command]", L"Displays this help", NULL,
  41. SEnvCmdProt, L"guid", L"guid [-b] [sname]", L"Dump known guid ids", NULL,
  42. SEnvCmdSet, L"set", L"set [-bdv] [sname] [value]", L"Set/get environment variable", NULL,
  43. SEnvCmdAlias, L"alias", L"alias [-bdv] [sname] [value]" , L"Set/get alias settings", NULL,
  44. SEnvCmdDH, L"dh", L"dh [-b] [-p prot_id] | [handle]",L"Dump handle info", NULL,
  45. SEnvCmdMap, L"map", L"map [-bdvr] [sname[:]] [handle]",L"Map shortname to device path", NULL,
  46. SEnvCmdMount, L"mount", L"mount BlkDevice [sname[:]]", L"Mount a filesytem on a block device", NULL,
  47. SEnvCmdCd, L"cd", L"cd [path]", L"Updates the current directory",NULL,
  48. SEnvCmdEcho, L"echo", L"echo [[-on | -off] | [text]", L"Echo text to stdout or toggle script echo",NULL,
  49. SEnvCmdIf, L"if", L"if [not] condition then", L"Script-only: IF THEN construct",NULL,
  50. SEnvCmdEndif, L"endif", L"endif", L"Script-only: Delimiter for IF THEN construct",NULL,
  51. SEnvCmdGoto, L"goto", L"goto label", L"Script-only: Jump to label location in script",NULL,
  52. SEnvCmdFor, L"for", L"for var in <set>", L"Script-only: Loop construct", NULL,
  53. SEnvCmdEndfor, L"endfor", L"endfor", L"Script-only: Delimiter for loop construct", NULL,
  54. SEnvCmdPause, L"pause", L"pause", L"Script-only: Prompt to quit or continue", NULL,
  55. SEnvExit, L"exit", NULL, NULL, NULL,
  56. NULL
  57. } ;
  58. /*
  59. * SEnvCmds - a list of all internal commands
  60. */
  61. LIST_ENTRY SEnvCmds;
  62. /*
  63. *
  64. */
  65. VOID
  66. SEnvInitCommandTable (
  67. VOID
  68. )
  69. {
  70. UINTN Index;
  71. /*
  72. * Add all of our internal commands to the command dispatch table
  73. */
  74. InitializeListHead (&SEnvCmds);
  75. for (Index=0; SEnvInternalCommands[Index].Dispatch; Index += 1) {
  76. SEnvAddCommand (
  77. SEnvInternalCommands[Index].Dispatch,
  78. SEnvInternalCommands[Index].Cmd,
  79. SEnvInternalCommands[Index].CmdFormat,
  80. SEnvInternalCommands[Index].CmdHelpLine,
  81. SEnvInternalCommands[Index].CmdVerboseHelp
  82. );
  83. }
  84. }
  85. EFI_STATUS
  86. SEnvAddCommand (
  87. IN SHELLENV_INTERNAL_COMMAND Handler,
  88. IN CHAR16 *CmdStr,
  89. IN CHAR16 *CmdFormat,
  90. IN CHAR16 *CmdHelpLine,
  91. IN CHAR16 *CmdVerboseHelp
  92. )
  93. {
  94. COMMAND *Cmd;
  95. Cmd = AllocateZeroPool (sizeof(COMMAND));
  96. if (Cmd) {
  97. AcquireLock (&SEnvLock);
  98. Cmd->Signature = COMMAND_SIGNATURE;
  99. Cmd->Dispatch = Handler;
  100. Cmd->Cmd = CmdStr;
  101. Cmd->CmdFormat = CmdFormat;
  102. Cmd->CmdHelpLine = CmdHelpLine;
  103. Cmd->CmdVerboseHelp = CmdVerboseHelp;
  104. InsertTailList (&SEnvCmds, &Cmd->Link);
  105. ReleaseLock (&SEnvLock);
  106. }
  107. return Cmd ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES;
  108. }
  109. SHELLENV_INTERNAL_COMMAND
  110. SEnvGetCmdDispath(
  111. IN CHAR16 *CmdName
  112. )
  113. {
  114. LIST_ENTRY *Link;
  115. COMMAND *Command;
  116. SHELLENV_INTERNAL_COMMAND Dispatch;
  117. Dispatch = NULL;
  118. AcquireLock (&SEnvLock);
  119. for (Link=SEnvCmds.Flink; Link != &SEnvCmds; Link = Link->Flink) {
  120. Command = CR(Link, COMMAND, Link, COMMAND_SIGNATURE);
  121. if (StriCmp (Command->Cmd, CmdName) == 0) {
  122. Dispatch = Command->Dispatch;
  123. break;
  124. }
  125. }
  126. ReleaseLock (&SEnvLock);
  127. return Dispatch;
  128. }
  129. EFI_STATUS
  130. SEnvHelp (
  131. IN EFI_HANDLE ImageHandle,
  132. IN EFI_SYSTEM_TABLE *SystemTable
  133. )
  134. {
  135. LIST_ENTRY *Link;
  136. COMMAND *Command;
  137. UINTN SynLen, Len;
  138. UINTN Index;
  139. CHAR16 *p;
  140. BOOLEAN PageBreaks;
  141. UINTN TempColumn;
  142. UINTN ScreenCount;
  143. UINTN ScreenSize;
  144. CHAR16 ReturnStr[1];
  145. /*
  146. * Intialize application
  147. */
  148. InitializeShellApplication (ImageHandle, SystemTable);
  149. PageBreaks = FALSE;
  150. for (Index = 1; Index < SI->Argc; Index += 1) {
  151. p = SI->Argv[Index];
  152. if (*p == '-') {
  153. switch (p[1]) {
  154. case 'b' :
  155. case 'B' :
  156. PageBreaks = TRUE;
  157. ST->ConOut->QueryMode (ST->ConOut, ST->ConOut->Mode->Mode, &TempColumn, &ScreenSize);
  158. ScreenCount = 0;
  159. break;
  160. default:
  161. Print (L"%EDH: Unkown flag %s\n", p);
  162. return EFI_INVALID_PARAMETER;
  163. }
  164. }
  165. }
  166. AcquireLock (&SEnvLock);
  167. SynLen = 0;
  168. for (Link=SEnvCmds.Flink; Link != &SEnvCmds; Link = Link->Flink) {
  169. Command = CR(Link, COMMAND, Link, COMMAND_SIGNATURE);
  170. if (Command->CmdFormat && Command->CmdHelpLine) {
  171. Len = StrLen(Command->CmdFormat);
  172. if (Len > SynLen) {
  173. SynLen = Len;
  174. }
  175. }
  176. }
  177. for (Link=SEnvCmds.Flink; Link != &SEnvCmds; Link = Link->Flink) {
  178. Command = CR(Link, COMMAND, Link, COMMAND_SIGNATURE);
  179. if (Command->CmdFormat && Command->CmdHelpLine) {
  180. Print (L"%-.*hs - %s\n", SynLen, Command->CmdFormat, Command->CmdHelpLine);
  181. if (PageBreaks) {
  182. ScreenCount++;
  183. if (ScreenCount > ScreenSize - 4) {
  184. ScreenCount = 0;
  185. Print (L"\nPress Return to contiue :");
  186. Input (L"", ReturnStr, sizeof(ReturnStr)/sizeof(CHAR16));
  187. Print (L"\n\n");
  188. }
  189. }
  190. }
  191. }
  192. ReleaseLock (&SEnvLock);
  193. return EFI_SUCCESS;
  194. }