]> git.proxmox.com Git - mirror_edk2.git/commitdiff
k8 fixes and moving prompting for responses into this file.
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 3 Feb 2010 15:37:54 +0000 (15:37 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 3 Feb 2010 15:37:54 +0000 (15:37 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9922 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellLib/UefiShellLib.c
ShellPkg/Library/UefiShellLib/UefiShellLib.inf

index 5271d19490eedd50ff7694d3a0650e873ed4e2ec..fcb7e430ed6ec260217cc4d468fab3030a789396 100644 (file)
@@ -197,6 +197,7 @@ ShellLibConstructorWorker (
       mEfiShellInterface = NULL;\r
     }\r
   }\r
+\r
   //\r
   // only success getting 2 of either the old or new, but no 1/2 and 1/2\r
   //\r
@@ -247,7 +248,6 @@ ShellLibConstructor (
   IN EFI_SYSTEM_TABLE  *SystemTable\r
   ) {\r
 \r
-\r
   mEfiShellEnvironment2       = NULL;\r
   mEfiShellProtocol           = NULL;\r
   mEfiShellParametersProtocol = NULL;\r
@@ -1278,6 +1278,10 @@ InternalShellConvertFileListType (
     // allocate a new EFI_SHELL_FILE_INFO object\r
     //\r
     NewInfo               = AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
+    ASSERT(NewInfo != NULL);\r
+    if (NewInfo == NULL) {\r
+      break;\r
+    }\r
 \r
     //\r
     // copy the simple items\r
@@ -1498,6 +1502,10 @@ ShellFindFilePath (
     Size = StrSize(Path);\r
     Size += StrSize(FileName);\r
     TestPath = AllocateZeroPool(Size);\r
+    ASSERT(TestPath != NULL);\r
+    if (TestPath == NULL) {\r
+      return (NULL);\r
+    }\r
     StrCpy(TestPath, Path);\r
     StrCat(TestPath, FileName);\r
     Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);\r
@@ -1567,6 +1575,7 @@ ShellFindFilePathEx (
   CONST CHAR16      *ExtensionWalker;\r
   UINTN             Size;\r
   CHAR16            *TempChar;\r
+  CHAR16            *TempChar2;\r
 \r
   ASSERT(FileName != NULL);\r
   if (FileExtension == NULL) {\r
@@ -1579,7 +1588,11 @@ ShellFindFilePathEx (
   Size =  StrSize(FileName);\r
   Size += StrSize(FileExtension);\r
   TestPath = AllocateZeroPool(Size);\r
-  for (ExtensionWalker = FileExtension ;  ; ExtensionWalker = StrStr(ExtensionWalker, L";") + 1 ){\r
+  ASSERT(TestPath != NULL);\r
+  if (TestPath == NULL) {\r
+    return (NULL);\r
+  }\r
+  for (ExtensionWalker = FileExtension, TempChar2 = (CHAR16*)FileExtension;  TempChar2 != NULL ; ExtensionWalker = TempChar2 + 1 ){\r
     StrCpy(TestPath, FileName);\r
     if (ExtensionWalker != NULL) {\r
       StrCat(TestPath, ExtensionWalker);\r
@@ -1592,12 +1605,7 @@ ShellFindFilePathEx (
     if (RetVal != NULL) {\r
       break;\r
     }\r
-    //\r
-    // Must be after first loop...\r
-    //\r
-    if (StrStr(ExtensionWalker, L";") == NULL) {\r
-      break;\r
-    }\r
+    TempChar2 = StrStr(ExtensionWalker, L";");\r
   }\r
   FreePool(TestPath);\r
   return (RetVal);\r
@@ -2804,13 +2812,185 @@ StrnCatGrow (
       NewSize += 2 * Count * sizeof(CHAR16);\r
     }\r
     *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);\r
+    ASSERT(*Destination != NULL);\r
     *CurrentSize = NewSize;\r
   } else {\r
     *Destination = AllocateZeroPool((Count+1)*sizeof(CHAR16));\r
+    ASSERT(*Destination != NULL);\r
   }\r
 \r
   //\r
   // Now use standard StrnCat on a big enough buffer\r
   //\r
+  if (*Destination == NULL) {\r
+    return (NULL);\r
+  }\r
   return StrnCat(*Destination, Source, Count);\r
 }\r
+\r
+/**\r
+  Prompt the user and return the resultant answer to the requestor.\r
+\r
+  This function will display the requested question on the shell prompt and then\r
+  wait for an apropriate answer to be input from the console.\r
+\r
+  if the SHELL_PROMPT_REQUEST_TYPE is SHELL_PROMPT_REQUEST_TYPE_YESNO, SHELL_PROMPT_REQUEST_TYPE_QUIT_CONTINUE\r
+  or SHELL_PROMPT_REQUEST_TYPE_YESNOCANCEL then *Response is of type SHELL_PROMPT_RESPONSE.\r
+\r
+  if the SHELL_PROMPT_REQUEST_TYPE is SHELL_PROMPT_REQUEST_TYPE_FREEFORM then *Response is of type\r
+  CHAR16*.\r
+\r
+  In either case *Response must be callee freed if Response was not NULL;\r
+\r
+  @param Type                     What type of question is asked.  This is used to filter the input\r
+                                  to prevent invalid answers to question.\r
+  @param Prompt                   Pointer to string prompt to use to request input.\r
+  @param Response                 Pointer to Response which will be populated upon return.\r
+\r
+  @retval EFI_SUCCESS             The operation was sucessful.\r
+  @retval EFI_UNSUPPORTED         The operation is not supported as requested.\r
+  @retval EFI_INVALID_PARAMETER   A parameter was invalid.\r
+  @return other                   The operation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellPromptForResponse (\r
+  IN SHELL_PROMPT_REQUEST_TYPE   Type,\r
+  IN CHAR16         *Prompt OPTIONAL,\r
+  IN OUT VOID       **Response OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS        Status;\r
+  EFI_INPUT_KEY     Key;\r
+  UINTN             EventIndex;\r
+  SHELL_PROMPT_RESPONSE          *Resp;\r
+\r
+  Status = EFI_SUCCESS;\r
+  Resp = (SHELL_PROMPT_RESPONSE*)AllocatePool(sizeof(SHELL_PROMPT_RESPONSE));\r
+\r
+  switch(Type) {\r
+    case SHELL_PROMPT_REQUEST_TYPE_QUIT_CONTINUE:\r
+      if (Prompt != NULL) {\r
+        ShellPrintEx(-1, -1, L"%s", Prompt);\r
+      }\r
+      //\r
+      // wait for valid response\r
+      //\r
+      gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
+      Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
+      ASSERT_EFI_ERROR(Status);\r
+      ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
+      if (Key.UnicodeChar == L'Q' || Key.UnicodeChar ==L'q') {\r
+        *Resp = SHELL_PROMPT_RESPONSE_QUIT;\r
+      } else {\r
+        *Resp = SHELL_PROMPT_RESPONSE_CONTINUE;\r
+      }\r
+      break;\r
+    case SHELL_PROMPT_REQUEST_TYPE_YES_NO_ALL_CANCEL:\r
+       if (Prompt != NULL) {\r
+        ShellPrintEx(-1, -1, L"%s", Prompt);\r
+      }\r
+      //\r
+      // wait for valid response\r
+      //\r
+      *Resp = SHELL_PROMPT_RESPONSE_MAX;\r
+      while (*Resp == SHELL_PROMPT_RESPONSE_MAX) {\r
+        gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
+        Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
+        ASSERT_EFI_ERROR(Status);\r
+        ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
+        switch (Key.UnicodeChar) {\r
+          case L'Y':\r
+          case L'y':\r
+            *Resp = SHELL_PROMPT_RESPONSE_YES;\r
+            break;\r
+          case L'N':\r
+          case L'n':\r
+            *Resp = SHELL_PROMPT_RESPONSE_NO;\r
+            break;\r
+          case L'A':\r
+          case L'a':\r
+            *Resp = SHELL_PROMPT_RESPONSE_ALL;\r
+            break;\r
+          case L'C':\r
+          case L'c':\r
+            *Resp = SHELL_PROMPT_RESPONSE_CANCEL;\r
+            break;\r
+        }\r
+      }\r
+      break;\r
+    case SHELL_PROMPT_REQUEST_TYPE_ENTER_TO_COMTINUE:\r
+    case SHELL_PROMPT_REQUEST_TYPE_ANYKEY_TO_COMTINUE:\r
+      if (Prompt != NULL) {\r
+        ShellPrintEx(-1, -1, L"%s", Prompt);\r
+      }\r
+      //\r
+      // wait for valid response\r
+      //\r
+      *Resp = SHELL_PROMPT_RESPONSE_MAX;\r
+      while (*Resp == SHELL_PROMPT_RESPONSE_MAX) {\r
+        gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
+        if (Type == SHELL_PROMPT_REQUEST_TYPE_ENTER_TO_COMTINUE) {\r
+          Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
+          ASSERT_EFI_ERROR(Status);\r
+          ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
+          if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
+            *Resp = SHELL_PROMPT_RESPONSE_CONTINUE;\r
+            break;\r
+          }\r
+        }\r
+        if (Type == SHELL_PROMPT_REQUEST_TYPE_ANYKEY_TO_COMTINUE) {\r
+          *Resp = SHELL_PROMPT_RESPONSE_CONTINUE;\r
+          break;\r
+        }\r
+      }\r
+      break;\r
+    ///@todo add more request types here!\r
+    default:\r
+      Status = EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Response != NULL) {\r
+    *Response = Resp;\r
+  } else {\r
+    FreePool(Resp);\r
+  }\r
+\r
+  return (Status);\r
+}\r
+\r
+/**\r
+  Prompt the user and return the resultant answer to the requestor.\r
+\r
+  This function is the same as ShellPromptForResponse, except that the prompt is\r
+  automatically pulled from HII.\r
+\r
+  @param Type     What type of question is asked.  This is used to filter the input\r
+                  to prevent invalid answers to question.\r
+  @param Prompt   Pointer to string prompt to use to request input.\r
+  @param Response Pointer to Response which will be populated upon return.\r
+\r
+  @retval EFI_SUCCESS the operation was sucessful.\r
+  @return other       the operation failed.\r
+\r
+  @sa ShellPromptForResponse\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellPromptForResponseHii (\r
+  IN SHELL_PROMPT_REQUEST_TYPE         Type,\r
+  IN CONST EFI_STRING_ID  HiiFormatStringId,\r
+  IN CONST EFI_HANDLE     HiiFormatHandle,\r
+  IN OUT VOID             **Response\r
+  )\r
+{\r
+  CHAR16      *Prompt;\r
+  EFI_STATUS  Status;\r
+\r
+  Prompt = HiiGetString(HiiFormatHandle, HiiFormatStringId, NULL);\r
+  Status = ShellPromptForResponse(Type, Prompt, Response);\r
+  FreePool(Prompt);\r
+  return (Status);\r
+}\r
+\r
+\r
index 4c4bf4a0618ff5d698d95ac3b781e1f4e8e1390e..5aefe008933b829423d57144b0d1ac47e4343966 100644 (file)
@@ -1,7 +1,7 @@
 #/** @file\r
 # Provides interface to shell functionality for shell commands and applications.\r
 #\r
-# Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved. <BR>\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved. <BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r