]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
ShellPkg: Move UpdateMapping() out of Map command and added to UefiShellCommandLib...
[mirror_edk2.git] / ShellPkg / Library / UefiShellCommandLib / UefiShellCommandLib.c
index 9e7cd0e6e1464a1b9074f50a7528ad8431aef37a..18ae9f33844c5dcfa81141624f93c85875aae6e1 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   Provides interface to shell internal functions for shell commands.\r
 \r
-  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.\r
+  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
   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
 \r
 #include "UefiShellCommandLib.h"\r
 \r
-/// The tag for use in identifying UNICODE files.\r
-/// If the file is UNICODE, the first 16 bits of the file will equal this value.\r
-enum {\r
-  gUnicodeFileTag = 0xFEFF\r
-};\r
-\r
 // STATIC local variables\r
 STATIC SHELL_COMMAND_INTERNAL_LIST_ENTRY  mCommandList;\r
 STATIC SCRIPT_FILE_LIST                   mScriptList;\r
 STATIC ALIAS_LIST                         mAliasList;\r
 STATIC BOOLEAN                            mEchoState;\r
 STATIC BOOLEAN                            mExitRequested;\r
+STATIC UINT64                             mExitCode;\r
 STATIC BOOLEAN                            mExitScript;\r
 STATIC CHAR16                             *mProfileList;\r
 STATIC UINTN                              mProfileListSize;\r
@@ -34,10 +30,7 @@ STATIC UINTN                              mBlkMaxCount = 0;
 STATIC BUFFER_LIST                        mFileHandleList;\r
 \r
 // global variables required by library class.\r
-EFI_SHELL_PROTOCOL                *gEfiShellProtocol            = NULL;\r
-EFI_SHELL_PARAMETERS_PROTOCOL     *gEfiShellParametersProtocol  = NULL;\r
 EFI_UNICODE_COLLATION_PROTOCOL    *gUnicodeCollation            = NULL;\r
-EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *gDevPathToText               = NULL;\r
 SHELL_MAP_LIST                    gShellMapList;\r
 SHELL_MAP_LIST                    *gShellCurDir                 = NULL;\r
 \r
@@ -59,36 +52,12 @@ CommandInit(
   )\r
 {\r
   EFI_STATUS Status;\r
-  if (gEfiShellParametersProtocol == NULL) {\r
-    Status = gBS->OpenProtocol(gImageHandle,\r
-                               &gEfiShellParametersProtocolGuid,\r
-                               (VOID **)&gEfiShellParametersProtocol,\r
-                               gImageHandle,\r
-                               NULL,\r
-                               EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                              );\r
-    if (EFI_ERROR(Status)) {\r
-      return (EFI_DEVICE_ERROR);\r
-    }\r
-  }\r
-  if (gEfiShellProtocol == NULL) {\r
-    Status = gBS->LocateProtocol(&gEfiShellProtocolGuid, NULL, (VOID**)&gEfiShellProtocol);\r
-    if (EFI_ERROR(Status)) {\r
-      return (EFI_DEVICE_ERROR);\r
-    }\r
-  }\r
   if (gUnicodeCollation == NULL) {\r
     Status = gBS->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID**)&gUnicodeCollation);\r
     if (EFI_ERROR(Status)) {\r
       return (EFI_DEVICE_ERROR);\r
     }\r
   }\r
-  if (gDevPathToText == NULL) {\r
-    Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID**)&gDevPathToText);\r
-    if (EFI_ERROR(Status)) {\r
-      return (EFI_DEVICE_ERROR);\r
-    }\r
-  }\r
   return (EFI_SUCCESS);\r
 }\r
 \r
@@ -132,6 +101,37 @@ ShellCommandLibConstructor (
   return (RETURN_SUCCESS);\r
 }\r
 \r
+/**\r
+  Frees list of file handles.\r
+\r
+  @param[in] List     The list to free.\r
+**/\r
+VOID\r
+EFIAPI\r
+FreeFileHandleList (\r
+  IN BUFFER_LIST *List\r
+  )\r
+{\r
+  BUFFER_LIST               *BufferListEntry;\r
+\r
+  if (List == NULL){\r
+    return;\r
+  }\r
+  //\r
+  // enumerate through the buffer list and free all memory\r
+  //\r
+  for ( BufferListEntry = ( BUFFER_LIST *)GetFirstNode(&List->Link)\r
+      ; !IsListEmpty (&List->Link)\r
+      ; BufferListEntry = (BUFFER_LIST *)GetFirstNode(&List->Link)\r
+     ){\r
+    RemoveEntryList(&BufferListEntry->Link);\r
+    ASSERT(BufferListEntry->Buffer != NULL);\r
+    SHELL_FREE_NON_NULL(((SHELL_COMMAND_FILE_HANDLE*)(BufferListEntry->Buffer))->Path);\r
+    SHELL_FREE_NON_NULL(BufferListEntry->Buffer);\r
+    SHELL_FREE_NON_NULL(BufferListEntry);\r
+  }\r
+}\r
+\r
 /**\r
   Destructor for the library.  free any resources.\r
 \r
@@ -148,7 +148,7 @@ ShellCommandLibDestructor (
   )\r
 {\r
   SHELL_COMMAND_INTERNAL_LIST_ENTRY *Node;\r
-  COMMAND_LIST                      *Node2;\r
+  ALIAS_LIST                        *Node2;\r
   SCRIPT_FILE_LIST                  *Node3;\r
   SHELL_MAP_LIST                    *MapNode;\r
   //\r
@@ -163,13 +163,14 @@ ShellCommandLibDestructor (
   }\r
 \r
   //\r
-  // enumerate through the init command list and free all memory\r
+  // enumerate through the alias list and free all memory\r
   //\r
   while (!IsListEmpty (&mAliasList.Link)) {\r
-    Node2 = (COMMAND_LIST *)GetFirstNode(&mAliasList.Link);\r
+    Node2 = (ALIAS_LIST *)GetFirstNode(&mAliasList.Link);\r
     RemoveEntryList(&Node2->Link);\r
     SHELL_FREE_NON_NULL(Node2->CommandString);\r
-    FreePool(Node2);\r
+    SHELL_FREE_NON_NULL(Node2->Alias);\r
+    SHELL_FREE_NON_NULL(Node2);\r
     DEBUG_CODE(Node2 = NULL;);\r
   }\r
 \r
@@ -200,17 +201,14 @@ ShellCommandLibDestructor (
     }\r
   }\r
   if (!IsListEmpty(&mFileHandleList.Link)){\r
-    FreeBufferList(&mFileHandleList);\r
+    FreeFileHandleList(&mFileHandleList);\r
   }\r
 \r
   if (mProfileList != NULL) {\r
     FreePool(mProfileList);\r
   }\r
 \r
-  gEfiShellProtocol            = NULL;\r
-  gEfiShellParametersProtocol  = NULL;\r
   gUnicodeCollation            = NULL;\r
-  gDevPathToText               = NULL;\r
   gShellCurDir                 = NULL;\r
 \r
   return (RETURN_SUCCESS);\r
@@ -354,6 +352,16 @@ ShellCommandRegisterCommandName (
   )\r
 {\r
   SHELL_COMMAND_INTERNAL_LIST_ENTRY *Node;\r
+  SHELL_COMMAND_INTERNAL_LIST_ENTRY *Command;\r
+  SHELL_COMMAND_INTERNAL_LIST_ENTRY *PrevCommand;\r
+  INTN LexicalMatchValue;\r
+\r
+  //\r
+  // Initialize local variables.\r
+  //\r
+  Command = NULL;\r
+  PrevCommand = NULL;\r
+  LexicalMatchValue = 0;\r
 \r
   //\r
   // ASSERTs for NULL parameters\r
@@ -412,9 +420,40 @@ ShellCommandRegisterCommandName (
   }\r
 \r
   //\r
-  // add the new struct to the list\r
+  // Insert a new entry on top of the list\r
+  //\r
+  InsertHeadList (&mCommandList.Link, &Node->Link);\r
+\r
   //\r
-  InsertTailList (&mCommandList.Link, &Node->Link);\r
+  // Move a new registered command to its sorted ordered location in the list\r
+  //\r
+  for (Command = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)GetFirstNode (&mCommandList.Link),\r
+        PrevCommand = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)GetFirstNode (&mCommandList.Link)\r
+        ; !IsNull (&mCommandList.Link, &Command->Link)\r
+        ; Command = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)GetNextNode (&mCommandList.Link, &Command->Link)) {\r
+\r
+    //\r
+    // Get Lexical Comparison Value between PrevCommand and Command list entry\r
+    //\r
+    LexicalMatchValue = gUnicodeCollation->StriColl (\r
+                                             gUnicodeCollation,\r
+                                             PrevCommand->CommandString,\r
+                                             Command->CommandString\r
+                                             );\r
+\r
+    //\r
+    // Swap PrevCommand and Command list entry if PrevCommand list entry\r
+    // is alphabetically greater than Command list entry\r
+    //\r
+    if (LexicalMatchValue > 0){\r
+      Command = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *) SwapListEntries (&PrevCommand->Link, &Command->Link);\r
+    } else if (LexicalMatchValue < 0) {\r
+      //\r
+      // PrevCommand entry is lexically lower than Command entry\r
+      //\r
+      break;\r
+    }\r
+  }\r
 \r
   return (RETURN_SUCCESS);\r
 }\r
@@ -446,12 +485,12 @@ ShellCommandGetProfileList (
   information will be returned. If Sections is NULL, then all help text information\r
   available will be returned.\r
 \r
-  @param[in]  CommandString         Pointer to the command name.  This is the name\r
-                                    found on the command line in the shell.\r
-  @param[in,out] RetVal             Pointer to the return vaule from the command handler.\r
+  @param[in]  CommandString          Pointer to the command name.  This is the name\r
+                                     found on the command line in the shell.\r
+  @param[in, out] RetVal             Pointer to the return vaule from the command handler.\r
 \r
-  @param[in,out]  CanAffectLE       indicates whether this command's return value\r
-                                    needs to be placed into LASTERROR environment variable.\r
+  @param[in, out]  CanAffectLE       indicates whether this command's return value\r
+                                     needs to be placed into LASTERROR environment variable.\r
 \r
   @retval RETURN_SUCCESS            The handler was run.\r
   @retval RETURN_NOT_FOUND          The CommandString did not match a registered\r
@@ -719,12 +758,14 @@ ShellCommandSetEchoState(
 /**\r
   Indicate that the current shell or script should exit.\r
 \r
-  @param[in] ScriptOnly   TRUE if only exiting a script, FALSE othrwise.\r
+  @param[in] ScriptOnly   TRUE if exiting a script; FALSE otherwise.\r
+  @param[in] ErrorCode    The 64 bit error code to return.\r
 **/\r
 VOID\r
 EFIAPI\r
 ShellCommandRegisterExit (\r
-  IN BOOLEAN ScriptOnly\r
+  IN BOOLEAN      ScriptOnly,\r
+  IN CONST UINT64 ErrorCode\r
   )\r
 {\r
   mExitRequested = (BOOLEAN)(!mExitRequested);\r
@@ -733,6 +774,7 @@ ShellCommandRegisterExit (
   } else {\r
     mExitScript    = FALSE;\r
   }\r
+  mExitCode = ErrorCode;\r
 }\r
 \r
 /**\r
@@ -750,6 +792,21 @@ ShellCommandGetExit (
   return (mExitRequested);\r
 }\r
 \r
+/**\r
+  Retrieve the Exit code.\r
+\r
+  If ShellCommandGetExit returns FALSE than the return from this is undefined.\r
+\r
+  @return the value passed into RegisterExit.\r
+**/\r
+UINT64\r
+EFIAPI\r
+ShellCommandGetExitCode (\r
+  VOID\r
+  )\r
+{\r
+  return (mExitCode);\r
+}\r
 /**\r
   Retrieve the Exit script indicator.\r
 \r
@@ -1142,36 +1199,114 @@ ShellCommandCreateInitialMappingsAndPaths(
   }\r
 \r
   return (EFI_SUCCESS);\r
-}\r
-\r
-/**\r
-  Function to make sure all directory delimeters are backslashes.\r
-\r
-  @param[in,out] Path     The path to modify.\r
-\r
-  @return Path.\r
-**/\r
-CHAR16*\r
-EFIAPI\r
-ShellCommandCleanPath (\r
-  IN OUT CHAR16 *Path\r
-  )\r
-{\r
-  CHAR16  *Path2;\r
-\r
-  for (Path2 = Path ; Path2 != NULL && *Path2 != CHAR_NULL ; Path2++) {\r
-    if (*Path2 == L'/') {\r
-      *Path2 = L'\\';\r
-    }\r
-  }\r
-\r
-  return (Path);\r
-}\r
-\r
-/**\r
-  Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*.\r
-\r
-  @param[in] Handle     The SHELL_FILE_HANDLE to convert.\r
+}
+
+/**
+  Add mappings for any devices without one.  Do not change any existing maps.
+
+  @retval EFI_SUCCESS   The operation was successful.
+**/
+EFI_STATUS
+EFIAPI
+ShellCommandUpdateMapping (
+  VOID
+  )
+{
+  EFI_STATUS                Status;
+  EFI_HANDLE                *HandleList;
+  UINTN                     Count;
+  EFI_DEVICE_PATH_PROTOCOL  **DevicePathList;
+  CHAR16                    *NewDefaultName;
+  CHAR16                    *NewConsistName;
+  EFI_DEVICE_PATH_PROTOCOL  **ConsistMappingTable;
+
+  HandleList  = NULL;
+  Status      = EFI_SUCCESS;
+
+  //
+  // remove mappings that represent removed devices.
+  //
+
+  //
+  // Find each handle with Simple File System
+  //
+  HandleList = GetHandleListByProtocol(&gEfiSimpleFileSystemProtocolGuid);
+  if (HandleList != NULL) {
+    //
+    // Do a count of the handles
+    //
+    for (Count = 0 ; HandleList[Count] != NULL ; Count++);
+
+    //
+    // Get all Device Paths
+    //
+    DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count);
+    ASSERT(DevicePathList != NULL);
+
+    for (Count = 0 ; HandleList[Count] != NULL ; Count++) {
+      DevicePathList[Count] = DevicePathFromHandle(HandleList[Count]);
+    }
+
+    //
+    // Sort all DevicePaths
+    //
+    PerformQuickSort(DevicePathList, Count, sizeof(EFI_DEVICE_PATH_PROTOCOL*), DevicePathCompare);
+
+    ShellCommandConsistMappingInitialize(&ConsistMappingTable);
+
+    //
+    // Assign new Mappings to remainders
+    //
+    for (Count = 0 ; HandleList[Count] != NULL && !EFI_ERROR(Status); Count++) {
+      //
+      // Skip ones that already have
+      //
+      if (gEfiShellProtocol->GetMapFromDevicePath(&DevicePathList[Count]) != NULL) {
+        continue;
+      }
+      //
+      // Get default name
+      //
+      NewDefaultName = ShellCommandCreateNewMappingName(MappingTypeFileSystem);
+      ASSERT(NewDefaultName != NULL);
+
+      //
+      // Call shell protocol SetMap function now...
+      //
+      Status = gEfiShellProtocol->SetMap(DevicePathList[Count], NewDefaultName);
+
+      if (!EFI_ERROR(Status)) {
+        //
+        // Now do consistent name
+        //
+        NewConsistName = ShellCommandConsistMappingGenMappingName(DevicePathList[Count], ConsistMappingTable);
+        if (NewConsistName != NULL) {
+          Status = gEfiShellProtocol->SetMap(DevicePathList[Count], NewConsistName);
+          FreePool(NewConsistName);
+        }
+      }
+
+      FreePool(NewDefaultName);
+    }
+    ShellCommandConsistMappingUnInitialize(ConsistMappingTable);
+    SHELL_FREE_NON_NULL(HandleList);
+    SHELL_FREE_NON_NULL(DevicePathList);
+
+    HandleList = NULL;
+  } else {
+    Count = (UINTN)-1;
+  }
+  //
+  // Do it all over again for gEfiBlockIoProtocolGuid
+  //
+
+  return (Status);
+}
+
+/**
+  Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*.
+
+  @param[in] Handle     The SHELL_FILE_HANDLE to convert.
 \r
   @return a EFI_FILE_PROTOCOL* representing the same file.\r
 **/\r
@@ -1328,157 +1463,6 @@ ShellFileHandleEof(
   return (RetVal);\r
 }\r
 \r
-/**\r
-  Function to read a single line from a SHELL_FILE_HANDLE. The \n is not included in the returned\r
-  buffer.  The returned buffer must be callee freed.\r
-\r
-  If the position upon start is 0, then the Ascii Boolean will be set.  This should be\r
-  maintained and not changed for all operations with the same file.\r
-\r
-  @param[in]      Handle        SHELL_FILE_HANDLE to read from.\r
-  @param[in,out]  Ascii         Boolean value for indicating whether the file is\r
-                                Ascii (TRUE) or UCS2 (FALSE).\r
-\r
-  @return                       The line of text from the file.\r
-\r
-  @sa ShellFileHandleReadLine\r
-**/\r
-CHAR16*\r
-EFIAPI\r
-ShellFileHandleReturnLine(\r
-  IN SHELL_FILE_HANDLE            Handle,\r
-  IN OUT BOOLEAN                *Ascii\r
-  )\r
-{\r
-  CHAR16          *RetVal;\r
-  UINTN           Size;\r
-  EFI_STATUS      Status;\r
-\r
-  Size = 0;\r
-  RetVal = NULL;\r
-\r
-  Status = ShellFileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii);\r
-  if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    RetVal = AllocateZeroPool(Size);\r
-    Status = ShellFileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii);\r
-  }\r
-  ASSERT_EFI_ERROR(Status);\r
-  if (EFI_ERROR(Status) && (RetVal != NULL)) {\r
-    FreePool(RetVal);\r
-    RetVal = NULL;\r
-  }\r
-  return (RetVal);\r
-}\r
-\r
-/**\r
-  Function to read a single line (up to but not including the \n) from a SHELL_FILE_HANDLE.\r
-\r
-  If the position upon start is 0, then the Ascii Boolean will be set.  This should be\r
-  maintained and not changed for all operations with the same file.\r
-\r
-  @param[in]      Handle        SHELL_FILE_HANDLE to read from.\r
-  @param[in,out]  Buffer        The pointer to buffer to read into.\r
-  @param[in,out]  Size          The pointer to number of bytes in Buffer.\r
-  @param[in]      Truncate      If the buffer is large enough, this has no effect.\r
-                                If the buffer is is too small and Truncate is TRUE,\r
-                                the line will be truncated.\r
-                                If the buffer is is too small and Truncate is FALSE,\r
-                                then no read will occur.\r
-\r
-  @param[in,out]  Ascii         Boolean value for indicating whether the file is\r
-                                Ascii (TRUE) or UCS2 (FALSE).\r
-\r
-  @retval EFI_SUCCESS           The operation was successful.  The line is stored in\r
-                                Buffer.\r
-  @retval EFI_INVALID_PARAMETER Handle was NULL.\r
-  @retval EFI_INVALID_PARAMETER Size was NULL.\r
-  @retval EFI_BUFFER_TOO_SMALL  Size was not large enough to store the line.\r
-                                Size was updated to the minimum space required.\r
-  @sa ShellFileHandleRead\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-ShellFileHandleReadLine(\r
-  IN SHELL_FILE_HANDLE          Handle,\r
-  IN OUT CHAR16                 *Buffer,\r
-  IN OUT UINTN                  *Size,\r
-  IN BOOLEAN                    Truncate,\r
-  IN OUT BOOLEAN                *Ascii\r
-  )\r
-{\r
-  EFI_STATUS  Status;\r
-  CHAR16      CharBuffer;\r
-  UINTN       CharSize;\r
-  UINTN       CountSoFar;\r
-  UINT64      OriginalFilePosition;\r
-\r
-\r
-  if (Handle == NULL\r
-    ||Size   == NULL\r
-   ){\r
-    return (EFI_INVALID_PARAMETER);\r
-  }\r
-  if (Buffer == NULL) {\r
-    ASSERT(*Size == 0);\r
-  } else {\r
-    *Buffer = CHAR_NULL;\r
-  }\r
-  gEfiShellProtocol->GetFilePosition(Handle, &OriginalFilePosition);\r
-  if (OriginalFilePosition == 0) {\r
-    CharSize = sizeof(CHAR16);\r
-    Status = gEfiShellProtocol->ReadFile(Handle, &CharSize, &CharBuffer);\r
-    ASSERT_EFI_ERROR(Status);\r
-    if (CharBuffer == gUnicodeFileTag) {\r
-      *Ascii = FALSE;\r
-    } else {\r
-      *Ascii = TRUE;\r
-      gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition);\r
-    }\r
-  }\r
-\r
-  for (CountSoFar = 0;;CountSoFar++){\r
-    CharBuffer = 0;\r
-    if (*Ascii) {\r
-      CharSize = sizeof(CHAR8);\r
-    } else {\r
-      CharSize = sizeof(CHAR16);\r
-    }\r
-    Status = gEfiShellProtocol->ReadFile(Handle, &CharSize, &CharBuffer);\r
-    if (  EFI_ERROR(Status)\r
-       || CharSize == 0\r
-       || (CharBuffer == L'\n' && !(*Ascii))\r
-       || (CharBuffer ==  '\n' && *Ascii)\r
-     ){\r
-      break;\r
-    }\r
-    //\r
-    // if we have space save it...\r
-    //\r
-    if ((CountSoFar+1)*sizeof(CHAR16) < *Size){\r
-      ASSERT(Buffer != NULL);\r
-      ((CHAR16*)Buffer)[CountSoFar] = CharBuffer;\r
-      ((CHAR16*)Buffer)[CountSoFar+1] = CHAR_NULL;\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) {\r
-      gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition);\r
-    } else {\r
-      DEBUG((DEBUG_WARN, "The line was truncated in ShellFileHandleReadLine"));\r
-    }\r
-    return (EFI_BUFFER_TOO_SMALL);\r
-  }\r
-  while(Buffer[StrLen(Buffer)-1] == L'\r') {\r
-    Buffer[StrLen(Buffer)-1] = CHAR_NULL;\r
-  }\r
-\r
-  return (Status);\r
-}\r
 /**\r
   Frees any BUFFER_LIST defined type.\r
 \r
@@ -1511,37 +1495,3 @@ FreeBufferList (
   }\r
 }\r
 \r
-/**\r
-  Chops off last directory or file entry in a path leaving the trailing slash\r
-\r
-  @param[in,out] PathToReturn The path to modify.\r
-\r
-  @retval FALSE     No directory was found to chop off.\r
-  @retval TRUE      A directory was chopped off.\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-ChopLastSlash(\r
-  IN OUT CHAR16 *PathToReturn\r
-  )\r
-{\r
-  CHAR16        *Walker;\r
-  CHAR16        *LastSlash;\r
-  //\r
-  // get directory name from path... ('chop' off extra)\r
-  //\r
-  for ( Walker = PathToReturn, LastSlash = NULL\r
-      ; Walker != NULL && *Walker != CHAR_NULL\r
-      ; Walker++\r
-     ){\r
-    if (*Walker == L'\\' && *(Walker + 1) != CHAR_NULL) {\r
-      LastSlash = Walker+1;\r
-    }\r
-  }\r
-  if (LastSlash != NULL) {\r
-    *LastSlash = CHAR_NULL;\r
-    return (TRUE);\r
-  }\r
-  return (FALSE);\r
-}\r
-\r