]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/Shell.c
ShellPkg: add API for determining operation type
[mirror_edk2.git] / ShellPkg / Application / Shell / Shell.c
index 4e791af84c471ea7e3d8a45a79ef87c4c59fb94e..ef757dec0fa724f87b490cd45fde513fed3a16d1 100644 (file)
@@ -1527,6 +1527,67 @@ ShellSubstituteAliases(
   return (EFI_SUCCESS);\r
 }\r
 \r
+/**\r
+  Takes the Argv[0] part of the command line and determine the meaning of it.\r
+**/\r
+SHELL_OPERATION_TYPES\r
+EFIAPI\r
+GetOperationType(\r
+  IN CONST CHAR16 *CmdName\r
+  )\r
+{\r
+        CHAR16* FileWithPath;\r
+  CONST CHAR16* TempLocation;\r
+  CONST CHAR16* TempLocation2;\r
+\r
+  FileWithPath = NULL;\r
+  //\r
+  // test for an internal command.\r
+  //\r
+  if (ShellCommandIsCommandOnList(CmdName)) {\r
+    return (INTERNAL_COMMAND);\r
+  }\r
+\r
+  //\r
+  // Test for file system change request.  anything ending with : and cant have spaces.\r
+  //\r
+  if (CmdName[(StrLen(CmdName)-1)] == L':') {\r
+    if (StrStr(CmdName, L" ") != NULL) {\r
+      return (UNKNOWN_INVALID);\r
+    }\r
+    return (FILE_SYS_CHANGE);\r
+  }\r
+\r
+  //\r
+  // Test for a file\r
+  //\r
+  if ((FileWithPath = ShellFindFilePathEx(CmdName, mExecutableExtensions)) != NULL) {\r
+    //\r
+    // See if that file has a script file extension\r
+    //\r
+    if (StrLen(FileWithPath) > 4) {\r
+      TempLocation = FileWithPath+StrLen(FileWithPath)-4;\r
+      TempLocation2 = mScriptExtension;\r
+      if (StringNoCaseCompare((VOID*)(&TempLocation), (VOID*)(&TempLocation2)) == 0) {\r
+        SHELL_FREE_NON_NULL(FileWithPath);\r
+        return (SCRIPT_FILE_NAME);\r
+      }\r
+    }\r
+\r
+    //\r
+    // Was a file, but not a script.  we treat this as an application.\r
+    //\r
+    SHELL_FREE_NON_NULL(FileWithPath);\r
+    return (EFI_APPLICATION);\r
+  }\r
+  \r
+  SHELL_FREE_NON_NULL(FileWithPath);\r
+  //\r
+  // No clue what this is... return invalid flag...\r
+  //\r
+  return (UNKNOWN_INVALID);\r
+}\r
+\r
 /**\r
   Function will process and run a command line.\r
 \r