]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Updating with new functions and adding "C" style entrypoint library with example...
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 16 Jun 2009 00:23:19 +0000 (00:23 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 16 Jun 2009 00:23:19 +0000 (00:23 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8564 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Include/Library/FileHandleLib.h
ShellPkg/Include/Library/ShellCEntryLib.h [new file with mode: 0644]
ShellPkg/Include/Library/ShellLib.h
ShellPkg/Include/Protocol/EfiShell.h
ShellPkg/Library/BaseFileHandleLib/BaseFileHandleLib.c
ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.c [new file with mode: 0644]
ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf [new file with mode: 0644]
ShellPkg/Library/UefiShellLib/UefiShellLib.c
ShellPkg/Library/UefiShellLib/UefiShellLib.inf
ShellPkg/ShellPkg.dec
ShellPkg/ShellPkg.dsc

index 3d2bbd1535d692417a172a4410df211e9369bd31..8547fd2e91f58b28e927d7bf2c27589b8aa6a6df 100644 (file)
@@ -12,13 +12,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
-#include <Uefi.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-\r
 /**\r
   This function will retrieve the information about the file for the handle \r
   specified and store it in allocated pool memory.\r
@@ -328,4 +321,75 @@ EFIAPI
 FileHandleGetSize (\r
   IN EFI_FILE_HANDLE            FileHandle,\r
   OUT UINT64                    *Size\r
+  );\r
+\r
+/**\r
+  Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the \r
+  directory 'stack'.\r
+\r
+  if Handle is NULL, return EFI_INVALID_PARAMETER\r
+\r
+  @param[in] Handle             Handle to the Directory or File to create path to.\r
+  @param[out] FullFileName      pointer to pointer to generated full file name.  It \r
+                                is the responsibility of the caller to free this memory\r
+                                with a call to FreePool().\r
+  @retval EFI_SUCCESS           the operation was sucessful and the FullFileName is valid.\r
+  @retval EFI_INVALID_PARAMETER Handle was NULL.\r
+  @retval EFI_INVALID_PARAMETER FullFileName was NULL.\r
+  @retval EFI_OUT_OF_MEMORY     a memory allocation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleGetFileName (\r
+  IN CONST EFI_FILE_HANDLE      Handle,\r
+  OUT CHAR16                    **FullFileName\r
+  );\r
+\r
+/**\r
+  Function to read a single line (up to but not including the \n) from a file.\r
+\r
+  @param[in]      Handle        FileHandle to read from\r
+  @param[in][out] Buffer        pointer to buffer to read into\r
+  @param[in][out] Size          pointer to number of bytes in buffer\r
+  @param[in[      Truncate      if TRUE then allows for truncation of the line to fit.\r
+                                if FALSE will reset the position to the begining of the \r
+                                line if the buffer is not large enough.\r
+\r
+  @retval EFI_SUCCESS           the operation was sucessful.  the line is stored in \r
+                                Buffer.  (Size was NOT updated)\r
+  @retval EFI_INVALID_PARAMETER Handle was NULL.\r
+  @retval EFI_INVALID_PARAMETER Buffer was NULL.\r
+  @retval EFI_INVALID_PARAMETER Size was NULL.\r
+  @retval EFI_BUFFER_TOO_SMALL  Size was not enough space to store the line.  \r
+                                Size was updated to minimum space required.\r
+  @sa FileHandleRead\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleReadLine(\r
+  IN EFI_FILE_HANDLE            Handle,\r
+  IN OUT VOID                   *Buffer,\r
+  IN OUT UINTN                  *Size,\r
+  IN BOOLEAN                    Truncate\r
+  );\r
+\r
+/**\r
+  function to write a line of unicode text to a file.\r
+\r
+  if Handle is NULL, ASSERT.\r
+  if Buffer is NULL, do nothing.  (return SUCCESS)\r
+\r
+  @param[in]     Handle         FileHandle to write to\r
+  @param[in]     Buffer         Buffer to write\r
+\r
+  @retval  EFI_SUCCESS          the data was written.\r
+  @retval  other                failure.\r
+\r
+  @sa FileHandleWrite\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleWriteLine(\r
+  IN EFI_FILE_HANDLE Handle,\r
+  IN CHAR16          *Buffer\r
   );
\ No newline at end of file
diff --git a/ShellPkg/Include/Library/ShellCEntryLib.h b/ShellPkg/Include/Library/ShellCEntryLib.h
new file mode 100644 (file)
index 0000000..762c95b
--- /dev/null
@@ -0,0 +1,32 @@
+/** @file\r
+  Provides application point extension for "C" style main funciton \r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+/**\r
+  Intermediate entry point for the application that will in turn call into the "C" \r
+  style main function.\r
+\r
+  this application must have a function like:\r
+  INT32 \r
+  EFIAPI \r
+  main(\r
+    UINTN Argc, \r
+    CHAR16 **Argv\r
+  );\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellCEntry(\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  );
\ No newline at end of file
index 1a9ef5ac59e96d10f4631ad18418e3242e0e84bc..f0998d8346118e41bc891fd7be7287b057553183 100644 (file)
@@ -749,4 +749,42 @@ EFIAPI
 ShellInitialize (\r
   );\r
 \r
+/**\r
+  Print at a specific location on the screen.\r
+\r
+  This function will move the cursor to a given screen location, print the specified string, \r
+  and return the cursor to the original locaiton.  \r
+  \r
+  If -1 is specified for either the Row or Col the current screen location for BOTH \r
+  will be used and the cursor's position will not be moved back to an original location.\r
+\r
+  if either Row or Col is out of range for the current console, then ASSERT\r
+  if Format is NULL, then ASSERT\r
+\r
+  In addition to the standard %-based flags as supported by UefiLib Print() this supports \r
+  the following additional flags:\r
+    %N       -   Set output attribute to normal\r
+    %H       -   Set output attribute to highlight\r
+    %E       -   Set output attribute to error\r
+    %B       -   Set output attribute to blue color\r
+    %V       -   Set output attribute to green color\r
+\r
+  Note: The background color is controlled by the shell command cls.\r
+\r
+  @param[in] Row        the row to print at\r
+  @param[in] Col        the column to print at\r
+  @param[in] Format     the format string\r
+\r
+  @return the number of characters printed to the screen\r
+**/\r
+\r
+UINTN\r
+EFIAPI\r
+ShellPrintEx(\r
+  IN INT32                Col OPTIONAL,\r
+  IN INT32                Row OPTIONAL,\r
+  IN CONST CHAR16         *Format,\r
+  ...\r
+  );\r
+\r
 #endif // __SHELL_LIB__
\ No newline at end of file
index 67306bbb76de40226972bffe065bde44ad596600..967bdc5ca88a71de0a008c729543d4292142f486 100644 (file)
@@ -501,7 +501,7 @@ typedef
 EFI_STATUS\r
 (EFIAPI *EFI_SHELL_GET_HELP_TEXT) (\r
   IN CONST CHAR16 *Command,\r
-  IN CONST CHAR16 *Sections,\r
+  IN CONST CHAR16 *Sections OPTIONAL,\r
   OUT CHAR16 **HelpText\r
   );\r
 \r
index 87b57724886281775a4c10be87ab43024ab9ac17..023210e8e0f0dc484a24b830d9f35e2d130d7a72 100644 (file)
@@ -14,11 +14,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <Uefi.h>\r
 \r
-#include <Library/ShellLib.h>\r
+#include <Protocol/SimpleFileSystem.h>\r
+\r
+#include <Guid/FileInfo.h>\r
+\r
 #include <Library/DebugLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
-\r
-#include <Protocol/SimpleFileSystem.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
 \r
 #define MAX_FILE_NAME_LEN 522 // (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for bytes)\r
 #define FIND_XXXXX_FILE_BUFFER_SIZE (SIZE_OF_EFI_FILE_INFO + MAX_FILE_NAME_LEN)\r
@@ -620,4 +623,297 @@ FileHandleGetSize (
   FreePool(FileInfo);\r
 \r
   return (EFI_SUCCESS);\r
-}
\ No newline at end of file
+}\r
+\r
+\r
+/**\r
+  Safely append (on the left) with automatic string resizing given length of Destination and \r
+  desired length of copy from Source.\r
+\r
+  append the first D characters of Source to the end of Destination, where D is \r
+  the lesser of Count and the StrLen() of Source. If appending those D characters \r
+  will fit within Destination (whose Size is given as CurrentSize) and \r
+  still leave room for a null terminator, then those characters are appended, \r
+  starting at the original terminating null of Destination, and a new terminating \r
+  null is appended.\r
+\r
+  If appending D characters onto Destination will result in a overflow of the size\r
+  given in CurrentSize the string will be grown such that the copy can be performed\r
+  and CurrentSize will be updated to the new size.\r
+\r
+  If Source is NULL, there is nothing to append, just return the current buffer in \r
+  Destination.\r
+\r
+  if Destination is NULL, then ASSERT()\r
+  if Destination's current length (including NULL terminator) is already more then \r
+  CurrentSize, then ASSERT()\r
+\r
+  @param[in][out] Destination   The String to append onto\r
+  @param[in][out] CurrentSize   on call the number of bytes in Destination.  On \r
+                                return possibly the new size (still in bytes).  if NULL\r
+                                then allocate whatever is needed.\r
+  @param[in]      Source        The String to append from\r
+  @param[in]      Count         Maximum number of characters to append.  if 0 then \r
+                                all are appended.\r
+\r
+  @return Destination           return the resultant string.\r
+**/\r
+CHAR16* \r
+EFIAPI\r
+StrnCatGrowLeft (\r
+  IN OUT CHAR16           **Destination,\r
+  IN OUT UINTN            *CurrentSize,\r
+  IN     CONST CHAR16     *Source,\r
+  IN     UINTN            Count\r
+  ){\r
+  UINTN DestinationStartSize;\r
+  UINTN NewSize;\r
+\r
+  //\r
+  // ASSERTs\r
+  //\r
+  ASSERT(Destination != NULL);\r
+\r
+  //\r
+  // If there's nothing to do then just return Destination\r
+  //\r
+  if (Source == NULL) {\r
+    return (*Destination);\r
+  }\r
+\r
+  //\r
+  // allow for NULL pointers address as Destination\r
+  //\r
+  if (*Destination != NULL) {\r
+    ASSERT(CurrentSize != 0);\r
+    DestinationStartSize = StrSize(*Destination);\r
+    ASSERT(DestinationStartSize <= *CurrentSize);\r
+  } else {\r
+    DestinationStartSize = 0;\r
+//    ASSERT(*CurrentSize == 0);\r
+  }\r
+\r
+  //\r
+  // Append all of Source?\r
+  //\r
+  if (Count == 0) {\r
+    Count = StrLen(Source);\r
+  }\r
+\r
+  //\r
+  // Test and grow if required\r
+  //\r
+  if (CurrentSize != NULL) {\r
+    NewSize = *CurrentSize;\r
+    while (NewSize < (DestinationStartSize + (Count*sizeof(CHAR16)))) {\r
+      NewSize += 2 * Count * sizeof(CHAR16);\r
+    }\r
+    *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);\r
+    *CurrentSize = NewSize;\r
+  } else {\r
+    *Destination = AllocateZeroPool((Count+1)*sizeof(CHAR16));\r
+  }\r
+\r
+  *Destination = CopyMem(*Destination+StrLen(Source), *Destination, StrSize(*Destination));\r
+  *Destination = CopyMem(*Destination, Source, StrLen(Source));\r
+  return (*Destination);\r
+}\r
+\r
+/**\r
+  Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the \r
+  directory 'stack'.\r
+\r
+  if Handle is NULL, return EFI_INVALID_PARAMETER\r
+\r
+  @param[in] Handle             Handle to the Directory or File to create path to.\r
+  @param[out] FullFileName      pointer to pointer to generated full file name.  It \r
+                                is the responsibility of the caller to free this memory\r
+                                with a call to FreePool().\r
+  @retval EFI_SUCCESS           the operation was sucessful and the FullFileName is valid.\r
+  @retval EFI_INVALID_PARAMETER Handle was NULL.\r
+  @retval EFI_INVALID_PARAMETER FullFileName was NULL.\r
+  @retval EFI_OUT_OF_RESOURCES  a memory allocation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleGetFileName (\r
+  IN CONST EFI_FILE_HANDLE      Handle,\r
+  OUT CHAR16                    **FullFileName\r
+  ){\r
+  EFI_STATUS      Status;\r
+  UINTN           Size;\r
+  EFI_FILE_HANDLE CurrentHandle;\r
+  EFI_FILE_HANDLE NextHigherHandle;\r
+  EFI_FILE_INFO   *FileInfo;\r
+\r
+  Size = 0;\r
+  *FullFileName = NULL;\r
+\r
+  //\r
+  // Check our parameters\r
+  //\r
+  if (FullFileName == NULL || Handle == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
+\r
+  Status = Handle->Open(Handle, &CurrentHandle, L".", EFI_FILE_MODE_READ, 0);\r
+  if (!EFI_ERROR(Status)) {\r
+    //\r
+    // Reverse out the current directory on the device\r
+    //\r
+    for (;;) {\r
+      FileInfo = FileHandleGetInfo(CurrentHandle);\r
+      if (FileInfo == NULL) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+        break;\r
+      } else {\r
+        //\r
+        // We got info... do we have a name? if yes preceed the current path with it...\r
+        //\r
+        if (StrLen (FileInfo->FileName) == 0) {\r
+          *FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);\r
+          FreePool(FileInfo);\r
+          break;\r
+        } else {\r
+          *FullFileName = StrnCatGrowLeft(FullFileName, &Size, FileInfo->FileName, 0);\r
+          *FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);\r
+          FreePool(FileInfo);\r
+        }\r
+      }\r
+      //\r
+      // Move to the parent directory\r
+      //\r
+      Status = CurrentHandle->Open (CurrentHandle, &NextHigherHandle, L"..", EFI_FILE_MODE_READ, 0);\r
+      if (EFI_ERROR (Status)) {\r
+        break;\r
+      }\r
+\r
+      FileHandleClose(CurrentHandle);\r
+      CurrentHandle = NextHigherHandle;\r
+    }\r
+  }\r
+\r
+  if (CurrentHandle != NULL) {\r
+    CurrentHandle->Close (CurrentHandle);\r
+  }\r
+\r
+  if (EFI_ERROR(Status) && *FullFileName != NULL) {\r
+    FreePool(FullFileName);\r
+  }\r
+\r
+  return (Status);\r
+}\r
+\r
+/**\r
+  Function to read a single line (up to but not including the \n) from a file.\r
+\r
+  @param[in]      Handle        FileHandle to read from\r
+  @param[in][out] Buffer        pointer to buffer to read into\r
+  @param[in][out] Size          pointer to number of bytes in buffer\r
+  @param[in[      Truncate      if TRUE then allows for truncation of the line to fit.\r
+                                if FALSE will reset the position to the begining of the \r
+                                line if the buffer is not large enough.\r
+\r
+  @retval EFI_SUCCESS           the operation was sucessful.  the line is stored in \r
+                                Buffer.\r
+  @retval EFI_INVALID_PARAMETER Handle was NULL.\r
+  @retval EFI_INVALID_PARAMETER Buffer was NULL.\r
+  @retval EFI_INVALID_PARAMETER Size was NULL.\r
+  @retval EFI_BUFFER_TOO_SMALL  Size was not enough space to store the line.  \r
+                                Size was updated to minimum space required.\r
+  @sa FileHandleRead\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleReadLine(\r
+  IN EFI_FILE_HANDLE            Handle,\r
+  IN OUT VOID                   *Buffer,\r
+  IN OUT UINTN                  *Size,\r
+  IN BOOLEAN                    Truncate\r
+  ){\r
+  EFI_STATUS  Status;\r
+  CHAR16      CharBuffer;\r
+  UINTN       CharSize;\r
+  UINTN       CountSoFar;\r
+  UINT64      Position;\r
+\r
+\r
+  if (Handle == NULL\r
+    ||Buffer == NULL\r
+    ||Size   == NULL\r
+    ){\r
+  return (EFI_INVALID_PARAMETER);\r
+  }\r
+  FileHandleGetPosition(Handle, &Position);\r
+\r
+  for (CountSoFar = 0;;CountSoFar++){\r
+    CharSize = sizeof(CharBuffer);\r
+    Status = FileHandleRead(Handle, &CharSize, &CharBuffer);\r
+    if (  EFI_ERROR(Status) \r
+       || CharSize == 0 \r
+       || CharBuffer == '\n'\r
+      ){\r
+      break;\r
+    }\r
+    //\r
+    // if we have space save it...\r
+    //\r
+    if ((CountSoFar+1)*sizeof(CHAR16) < *Size){\r
+      ((CHAR16*)Buffer)[CountSoFar] = CharBuffer;\r
+      ((CHAR16*)Buffer)[CountSoFar+1] = '\0';\r
+    }\r
+  }\r
+\r
+  //\r
+  // if we ran out of space tell when...\r
+  //\r
+  if ((CountSoFar+1)*sizeof(CHAR16) > *Size){\r
+    *Size = (CountSoFar+1)*sizeof(CHAR16);\r
+    if (Truncate == FALSE) {\r
+      FileHandleSetPosition(Handle, Position);\r
+    } else {\r
+      DEBUG((DEBUG_WARN, "The line was truncated in ReadLine"));\r
+    }\r
+    return (EFI_BUFFER_TOO_SMALL);\r
+  }\r
+  *Size = (CountSoFar+1)*sizeof(CHAR16);\r
+  return (Status);\r
+}\r
+\r
+/**\r
+  function to write a line of unicode text to a file.\r
+\r
+  if Handle is NULL, ASSERT.\r
+  if Buffer is NULL, do nothing.  (return SUCCESS)\r
+\r
+  @param[in]     Handle         FileHandle to write to\r
+  @param[in]     Buffer         Buffer to write\r
+\r
+  @retval  EFI_SUCCESS          the data was written.\r
+  @retval  other                failure.\r
+\r
+  @sa FileHandleWrite\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleWriteLine(\r
+  IN EFI_FILE_HANDLE Handle,\r
+  IN CHAR16          *Buffer\r
+  ){\r
+  EFI_STATUS Status;\r
+  UINTN      Size;\r
+\r
+  ASSERT(Handle != NULL);\r
+\r
+  if (Buffer == NULL) {\r
+    return (EFI_SUCCESS);\r
+  }\r
+\r
+  Size = StrLen(Buffer);\r
+  Status = FileHandleWrite(Handle, &Size, Buffer);\r
+  if (EFI_ERROR(Status)) {\r
+    return (Status);\r
+  }\r
+  Size = StrLen(L"\r\n");\r
+  return FileHandleWrite(Handle, &Size, L"\r\n");\r
+}\r
diff --git a/ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.c b/ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.c
new file mode 100644 (file)
index 0000000..0ce5271
--- /dev/null
@@ -0,0 +1,82 @@
+/** @file\r
+  Provides application point extension for "C" style main funciton \r
+\r
+Copyright (c) 2009, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Base.h>\r
+\r
+#include <Protocol/SimpleFileSystem.h>\r
+#include <Protocol/EfiShellInterface.h>\r
+#include <Protocol/EfiShellParameters.h>\r
+\r
+#include <Library/DebugLib.h>\r
+\r
+INT32 \r
+EFIAPI \r
+main(\r
+  UINTN Argc, \r
+  CHAR16 **Argv\r
+);\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ShellCEntryLib(\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  ){\r
+  INT32                         ReturnFromMain;\r
+  EFI_SHELL_PARAMETERS_PROTOCOL *EfiShellParametersProtocol;\r
+  EFI_SHELL_INTERFACE           *EfiShellInterface;\r
+  EFI_STATUS                    Status;\r
+\r
+  ReturnFromMain = -1;\r
+  EfiShellParametersProtocol = NULL;\r
+  EfiShellInterface = NULL;\r
+\r
+  Status = SystemTable->BootServices->OpenProtocol(ImageHandle, \r
+                             &gEfiShellParametersProtocolGuid,\r
+                             (VOID **)&EfiShellParametersProtocol,\r
+                             ImageHandle,\r
+                             NULL,\r
+                             EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                             );\r
+  if (!EFI_ERROR(Status)) {\r
+    //\r
+    // use shell 2.0 interface\r
+    //\r
+    ReturnFromMain = main(EfiShellInterface->Argc, EfiShellInterface->Argv);\r
+  } else {\r
+    //\r
+    // try to get shell 1.0 interface instead.\r
+    //\r
+    Status = SystemTable->BootServices->OpenProtocol(ImageHandle, \r
+                               &gEfiShellInterfaceGuid,\r
+                               (VOID **)&EfiShellInterface,\r
+                               ImageHandle,\r
+                               NULL,\r
+                               EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                               );\r
+    if (!EFI_ERROR(Status)) {\r
+      //\r
+      // use shell 1.0 interface\r
+      // \r
+      ReturnFromMain = main(EfiShellParametersProtocol->Argc, EfiShellParametersProtocol->Argv);\r
+    } else {\r
+      ASSERT(FALSE);\r
+    }\r
+  }\r
+  if (ReturnFromMain == 0) {\r
+    return (EFI_SUCCESS);\r
+  } else {\r
+    return (EFI_UNSUPPORTED);\r
+  }\r
+}\r
diff --git a/ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf b/ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
new file mode 100644 (file)
index 0000000..15a744f
--- /dev/null
@@ -0,0 +1,47 @@
+#/** @file\r
+# Provides interface to shell functionality for shell commands and applications.\r
+#\r
+# Copyright (c) 2006 - 2009, Intel Corporation.\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010006\r
+  BASE_NAME                      = UefiShellCEntryLib\r
+  FILE_GUID                      = 0e205c8a-8586-4dec-9f5c-4f9e394aefe8\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = ShellCEntryLib|UEFI_APPLICATION\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  UefiShellCEntryLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  ShellPkg/ShellPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiApplicationEntryPoint\r
+  DebugLib\r
+\r
+\r
+[Protocols]\r
+  gEfiShellParametersProtocolGuid                         # ALWAYS_CONSUMED\r
+  gEfiShellInterfaceGuid                                  # SOMETIMES_CONSUMED\r
+\r
+[Guids]\r
+\r
+[Pcd.common]\r
+\r
index 1ddff9a2a0130478a08370dc9cd05807f8b08abc..7ac7765b4b0dadd3ce386433fd46f67192023f58 100644 (file)
@@ -22,13 +22,16 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/DevicePathLib.h>\r
 #include <Library/PcdLib.h>\r
 #include <Library/FileHandleLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/UefiLib.h>\r
+\r
 #include <Protocol/EfiShellEnvironment2.h>\r
 #include <Protocol/EfiShellInterface.h>\r
 #include <Protocol/EfiShell.h>\r
 #include <Protocol/EfiShellParameters.h>\r
 #include <Protocol/SimpleFileSystem.h>\r
 \r
-#include "BaseShellLib.h"\r
+#include "UefiShellLib.h"\r
 \r
 #define MAX_FILE_NAME_LEN 522 // (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for bytes)\r
 #define FIND_XXXXX_FILE_BUFFER_SIZE (SIZE_OF_EFI_FILE_INFO + MAX_FILE_NAME_LEN)\r
@@ -237,7 +240,6 @@ ShellLibConstructor (
   mEfiShellInterface          = NULL;\r
   mEfiShellEnvironment2Handle = NULL;\r
 \r
-  ///@todo make a worker constructor so initialize function works\r
   //\r
   // verify that auto initialize is not set false\r
   // \r
@@ -455,7 +457,7 @@ ShellOpenFileByDevicePath(
   }\r
   Status = gBS->OpenProtocol(*DeviceHandle,\r
                              &gEfiSimpleFileSystemProtocolGuid,\r
-                             (VOID**) &EfiSimpleFileSystemProtocol,\r
+                             (VOID**)&EfiSimpleFileSystemProtocol,\r
                              gImageHandle,\r
                              NULL,\r
                              EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
@@ -569,6 +571,8 @@ ShellOpenFileByName(
 {\r
   EFI_HANDLE                    DeviceHandle;\r
   EFI_DEVICE_PATH_PROTOCOL      *FilePath;\r
+  EFI_STATUS                    Status;\r
+  EFI_FILE_INFO                 *FileInfo;\r
 \r
   //\r
   // ASSERT if FileName is NULL\r
@@ -579,11 +583,16 @@ ShellOpenFileByName(
     //\r
     // Use UEFI Shell 2.0 method\r
     //\r
-    return (mEfiShellProtocol->OpenFileByName(FileName,\r
-                                             FileHandle,\r
-                                             OpenMode));\r
-\r
-    ///@todo add the attributes\r
+    Status = mEfiShellProtocol->OpenFileByName(FileName,\r
+                                               FileHandle,\r
+                                               OpenMode);\r
+    if (!EFI_ERROR(Status)){\r
+      FileInfo = FileHandleGetInfo(*FileHandle);\r
+      ASSERT(FileInfo != NULL);\r
+      FileInfo->Attribute = Attributes;\r
+      Status = FileHandleSetInfo(*FileHandle, FileInfo);\r
+    }\r
+    return (Status);\r
   } \r
   //\r
   // Using EFI Shell version\r
@@ -1602,29 +1611,6 @@ InternalCommandLineParse (
       //\r
       // do nothing for NULL argv\r
       //\r
-    } else if (GetItemValue == TRUE) {\r
-      ASSERT(CurrentItemPackage != NULL);\r
-      //\r
-      // get the item VALUE for the previous flag\r
-      //\r
-      GetItemValue = FALSE;\r
-      CurrentItemPackage->Value = AllocateZeroPool(StrSize(Argv[LoopCounter]));\r
-      ASSERT(CurrentItemPackage->Value != NULL);\r
-      StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]);\r
-      InsertTailList(*CheckPackage, (LIST_ENTRY*)CurrentItemPackage);\r
-    } else if (InternalIsFlag(Argv[LoopCounter]) == FALSE) {\r
-      //\r
-      // add this one as a non-flag\r
-      //\r
-      CurrentItemPackage = AllocatePool(sizeof(SHELL_PARAM_PACKAGE));\r
-      ASSERT(CurrentItemPackage != NULL);\r
-      CurrentItemPackage->Name  = NULL;\r
-      CurrentItemPackage->Type  = TypePosition;\r
-      CurrentItemPackage->Value = AllocatePool(StrSize(Argv[LoopCounter]));\r
-      ASSERT(CurrentItemPackage->Value != NULL);\r
-      StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]);\r
-      CurrentItemPackage->OriginalPosition = Count++;\r
-      InsertTailList(*CheckPackage, (LIST_ENTRY*)CurrentItemPackage);\r
     } else if (InternalIsOnCheckList(Argv[LoopCounter], CheckList, &CurrentItemType) == TRUE) {\r
       //\r
       // this is a flag\r
@@ -1636,6 +1622,7 @@ InternalCommandLineParse (
       StrCpy(CurrentItemPackage->Name,  Argv[LoopCounter]);\r
       CurrentItemPackage->Type  = CurrentItemType;\r
       CurrentItemPackage->OriginalPosition = (UINTN)(-1);\r
+      CurrentItemPackage->Value = NULL;\r
 \r
       //\r
       // Does this flag require a value\r
@@ -1649,9 +1636,31 @@ InternalCommandLineParse (
         //\r
         // this item has no value expected; we are done\r
         //\r
-        CurrentItemPackage->Value = NULL;\r
-        InsertTailList(*CheckPackage, (LIST_ENTRY*)CurrentItemPackage);\r
+        InsertHeadList(*CheckPackage, (LIST_ENTRY*)CurrentItemPackage);\r
       }\r
+    } else if (GetItemValue == TRUE && InternalIsFlag(Argv[LoopCounter]) == FALSE) {\r
+      ASSERT(CurrentItemPackage != NULL);\r
+      //\r
+      // get the item VALUE for the previous flag\r
+      //\r
+      GetItemValue = FALSE;\r
+      CurrentItemPackage->Value = AllocateZeroPool(StrSize(Argv[LoopCounter]));\r
+      ASSERT(CurrentItemPackage->Value != NULL);\r
+      StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]);\r
+      InsertHeadList(*CheckPackage, (LIST_ENTRY*)CurrentItemPackage);\r
+    } else if (InternalIsFlag(Argv[LoopCounter]) == FALSE) {\r
+      //\r
+      // add this one as a non-flag\r
+      //\r
+      CurrentItemPackage = AllocatePool(sizeof(SHELL_PARAM_PACKAGE));\r
+      ASSERT(CurrentItemPackage != NULL);\r
+      CurrentItemPackage->Name  = NULL;\r
+      CurrentItemPackage->Type  = TypePosition;\r
+      CurrentItemPackage->Value = AllocatePool(StrSize(Argv[LoopCounter]));\r
+      ASSERT(CurrentItemPackage->Value != NULL);\r
+      StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]);\r
+      CurrentItemPackage->OriginalPosition = Count++;\r
+      InsertHeadList(*CheckPackage, (LIST_ENTRY*)CurrentItemPackage);\r
     } else if (ProblemParam) {\r
       //\r
       // this was a non-recognised flag... error!\r
@@ -1936,4 +1945,74 @@ ShellCommandLineGetRawValue (
     }\r
   }\r
   return (NULL);\r
+}\r
+\r
+/**\r
+  Print at a specific location on the screen.\r
+\r
+  This function will move the cursor to a given screen location, print the specified string, \r
+  and return the cursor to the original locaiton.  \r
+  \r
+  If -1 is specified for either the Row or Col the current screen location for BOTH \r
+  will be used and the cursor's position will not be moved back to an original location.\r
+\r
+  if either Row or Col is out of range for the current console, then ASSERT\r
+  if Format is NULL, then ASSERT\r
+\r
+  In addition to the standard %-based flags as supported by UefiLib Print() this supports \r
+  the following additional flags:\r
+    %N       -   Set output attribute to normal\r
+    %H       -   Set output attribute to highlight\r
+    %E       -   Set output attribute to error\r
+    %B       -   Set output attribute to blue color\r
+    %V       -   Set output attribute to green color\r
+\r
+  Note: The background color is controlled by the shell command cls.\r
+\r
+  @param[in] Row        the row to print at\r
+  @param[in] Col        the column to print at\r
+  @param[in] Format     the format string\r
+\r
+  @return the number of characters printed to the screen\r
+**/\r
+\r
+UINTN\r
+EFIAPI\r
+ShellPrintEx(\r
+  IN INT32                Col OPTIONAL,\r
+  IN INT32                Row OPTIONAL,\r
+  IN CONST CHAR16         *Format,\r
+  ...\r
+  ){\r
+  VA_LIST           Marker;\r
+  UINTN             BufferSize;\r
+  CHAR16            *Buffer;\r
+  UINTN             Return;\r
+  INT32             CurrentCol;\r
+  INT32             CurrentRow;\r
+  EFI_STATUS        Status;\r
+  \r
+  BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r
+  Buffer = AllocateZeroPool (BufferSize);\r
+  ASSERT (Buffer != NULL);\r
+\r
+  VA_START (Marker, Format);\r
+  Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);\r
+\r
+  if (Col != -1 && Row != -1) {\r
+    CurrentCol = gST->ConOut->Mode->CursorColumn;\r
+    CurrentRow = gST->ConOut->Mode->CursorRow;\r
+    Status = gST->ConOut->SetCursorPosition(gST->ConOut, Col, Row);\r
+    ASSERT_EFI_ERROR(Status);\r
+    Status = gST->ConOut->OutputString(gST->ConOut, Buffer);\r
+    ASSERT_EFI_ERROR(Status);\r
+    Status = gST->ConOut->SetCursorPosition(gST->ConOut, CurrentCol, CurrentRow);\r
+    ASSERT_EFI_ERROR(Status);\r
+  } else {\r
+    Status = gST->ConOut->OutputString(gST->ConOut, Buffer);\r
+    ASSERT_EFI_ERROR(Status);\r
+  }\r
+\r
+  FreePool(Buffer);\r
+  return (Return);\r
 }
\ No newline at end of file
index 5ed4259479607ab4082e9dae4dd6dfa000e3fec2..c2f26cd526110ec76f250661c42865df988f57aa 100644 (file)
@@ -43,6 +43,8 @@
   BaseMemoryLib\r
   DebugLib\r
   FileHandleLib\r
+  PrintLib\r
+  UefiLib\r
 \r
 [Protocols]\r
   gEfiSimpleFileSystemProtocolGuid              # ALWAYS_CONSUMED\r
@@ -61,3 +63,4 @@
 \r
 [Pcd.common]\r
   gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize  # ALWAYS_CONSUMED\r
+  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize # ALWAYS_CONSUMED\r
index 65b62a0827335e0fca6a78378e8dc97d69d13dd4..7e0b1a07c5d11c1156841f64d30a726c1e41a605 100644 (file)
@@ -36,6 +36,9 @@
   ##                 used by Shell and ShellLib\r
   ##\r
   FileHandleLib|Include/Library/FileHandleLib.h\r
+  \r
+  ## Allows for a shell application to have a C style entry point\r
+  ShellCEntryLib|Include/Library/ShellCEntryLib.h\r
 \r
 \r
 [Guids.common]\r
@@ -48,7 +51,7 @@
   gEfiShellEnvironment2Guid       = {0x47c7b221, 0xc42a, 0x11d2, {0x8e, 0x57, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}\r
   gEfiShellInterfaceGuid          = {0x47c7b223, 0xc42a, 0x11d2, {0x8e, 0x57, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}\r
 \r
-[PcdsFixedAtBuild,PcdsPatchableInModule,PcdsDynamic]\r
+[PcdsFixedAtBuild]\r
   ## This flag is used to control initialization of the shell library\r
-  ## This should be FALSE for compiling the shell application itself onlty.\r
+  ## This should be FALSE for compiling the shell application itself only.\r
   gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|TRUE|BOOLEAN|0x00000005
\ No newline at end of file
index ed7d46d9cad42d0a7ffef18c42030f2370d786b2..70e6fbc1a20dff2e0bc453fe487a189b33d3028b 100644 (file)
   BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf\r
   PrintLib|MdeModulePkg/Library/DxePrintLibPrint2Protocol/DxePrintLibPrint2Protocol.inf\r
   UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
+  UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf\r
+  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf\r
   \r
   ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf\r
   FileHandleLib|ShellPkg/Library/BaseFileHandleLib/BaseFileHandleLib.inf\r
-\r
+  ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf\r
 [PcdsFixedAtBuild.common]\r
 \r
 [Components.common]\r
   ShellPkg/Application/ShellExecTestApp/SA.inf\r
-  ShellPkg/Application/ShellLibTestApp/SA3.inf
\ No newline at end of file
+  ShellPkg/Application/ShellLibTestApp/SA3.inf\r
+  ShellPkg/Library/BaseFileHandleLib/BaseFileHandleLib.inf\r
+  ShellPkg/Library/UefiShellLib/UefiShellLib.inf\r
+  ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf\r
+  ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf\r
+  ShellPkg/Application/ShellCTestApp/ShellCTestApp.inf
\ No newline at end of file