+++ /dev/null
-// @file\r
-// MergeCmd command-line interface to the classes that combine\r
-// multiple MSA files into a single MSA file.\r
-//\r
-// Copyright (c) 2006, Intel Corporation All rights reserved.\r
-//\r
-// This program and the accompanying materials are licensed and made\r
-// available under the terms and conditions of the BSD License which\r
-// accompanies this distribution. The full text of the license may \r
-// be found at 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
-// This program is the command line interface to the CombineMsa class, which\r
-// will take the following arguments:\r
-//\r
-// Input:\r
-// -t Target The MSA file that will be created\r
-// -u UiName The UiName for the merged MSA OPTIONAL\r
-// If not provided, the UiName will come from the\r
-// first leaf MSA file\r
-// -p Package The SPD file that the new MSA file will be added to. OPTIONAL\r
-// leaf.msa The path and filename of the MSA files to be merged into the Target.\r
-//\r
-// Output:\r
-// Target.msa\r
-//\r
-// Modifies - OPTIONAL\r
-// Package.spd\r
-//\r
-\r
-package org.tianocore.Merge;\r
-\r
-import java.io.*;\r
-import java.util.*;\r
-\r
-// import org.tianocore.Merge.CombineMsa;\r
-\r
-public class MergeCmd {\r
-\r
- private static int DEBUG = 1;\r
- \r
- private static final String copyright = "Copyright (c) 2006, Intel Corporation All rights reserved.";\r
- \r
- private static final String version = "Version 0.1";\r
- \r
- private int VERBOSE = 0;\r
-\r
- private String targetFile = null;\r
-\r
- private ArrayList<String> leafFiles = new ArrayList<String>();\r
-\r
- private String spdFile = null;\r
-\r
- private String uiName = null;\r
- \r
- private String fileBasename = null;\r
-\r
- private final int ESUCCESS = 0;\r
-\r
- private final int EFAILURE = 1;\r
-\r
- private final static int FOUND = 1;\r
-\r
- private final static int NOTFOUND = 0;\r
-\r
- private int result = ESUCCESS;\r
-\r
- public int MergeCmdLine(String[] args) {\r
- result = parseCmdLine(args);\r
- if (result == ESUCCESS) {\r
- if ((DEBUG > 7) || (VERBOSE > 5)) {\r
- System.out.println("Parse Succeeded!");\r
- System.out.println("CWD: " + System.getProperty("user.dir"));\r
- System.out.println("Merge Module Name: " + targetFile);\r
- System.out.println("Found Leaf Module: " + leafFiles.size());\r
- if (spdFile != null)\r
- System.out.println("Package Name: " + spdFile);\r
- if (uiName != null)\r
- System.out.println("User Interface Name: " + uiName);\r
- }\r
- CombineMsa newMsa = new CombineMsa();\r
- result = newMsa.combineMsaFiles(targetFile, leafFiles, uiName, spdFile, fileBasename, VERBOSE);\r
- }\r
- return result;\r
- }\r
-\r
- private int parseCmdLine(String[] args) {\r
-\r
- if (args.length == NOTFOUND) {\r
- outputUsage();\r
- System.exit(EFAILURE);\r
- }\r
-\r
- for (int i = 0; i < args.length; i++) {\r
- if (args[i].toLowerCase().contains("-t")) {\r
- i++;\r
- targetFile = args[i];\r
- targetFile.replace(" ", "_");\r
- if (!targetFile.toLowerCase().contains(".msa"))\r
- targetFile = targetFile + ".msa";\r
-\r
-\r
- } else if (args[i].toLowerCase().contains("-p")) {\r
- i++;\r
- spdFile = args[i];\r
- if (!spdFile.toLowerCase().contains(".spd"))\r
- spdFile = spdFile + ".spd";\r
- spdFile = spdFile.replace("\\", "/").trim();\r
- if (testFile(spdFile) == NOTFOUND) {\r
- System.out.println("WARNING: The Package file: " + spdFile + " does NOT exist!");\r
- System.out.print("Do you want to continue anyway [y|N]? ");\r
- String inputLine = null;\r
- try {\r
- BufferedReader inputString = new BufferedReader(new InputStreamReader(System.in));\r
- inputLine = inputString.readLine();\r
- if ((inputLine.length() == 0) || (!inputLine.toLowerCase().contains("y"))) {\r
- System.out.println("Merge Aborted at user request!");\r
- System.exit(EFAILURE);\r
- } else {\r
- spdFile = null;\r
- System.out\r
- .println("Continuing with the Merge. Don't forget to add the new MSA file to a Package.");\r
- }\r
- } catch (IOException e) {\r
- System.out.println("IOException: " + e);\r
- }\r
- }\r
- } else if (args[i].toLowerCase().contains("-u")) {\r
- i++;\r
- uiName = args[i];\r
- } else if (args[i].toLowerCase().contains("-o")) {\r
- i++;\r
- fileBasename = args[i];\r
- } else if (args[i].toLowerCase().contains("-v")) {\r
- VERBOSE++;\r
- } else if ((args[i].toLowerCase().contains("-h")) || (args[i].toLowerCase().contains("-?"))\r
- || (args[i].toLowerCase().contains("/h")) || (args[i].toLowerCase().contains("--help"))) {\r
- outputUsage();\r
- System.exit(EFAILURE);\r
- } else {\r
- if (args[i].startsWith("-")) {\r
- System.out.println("Invalid Argument: " + args[i]);\r
- outputUsage();\r
- System.out.println("Merge Aborted!");\r
- System.exit(EFAILURE);\r
- }\r
- String leafFile = args[i];\r
- if (!leafFile.toLowerCase().contains(".msa"))\r
- leafFile = leafFile + ".msa";\r
-\r
- if (testFile(leafFile) == NOTFOUND) {\r
- System.out.println("ERROR: The Leaf MSA File: " + leafFile + " was NOT FOUND!");\r
- System.out.println("Merge Aborted!");\r
- System.exit(EFAILURE);\r
- } else {\r
- if (DEBUG > 9)\r
- System.out.println("Found Leaf Module: " + leafFile);\r
- leafFiles.add(leafFile);\r
- }\r
- }\r
- }\r
- if (testFile(targetFile) == FOUND) {\r
- System.out.println("WARNING: The targetfile: " + targetFile + "Already Exists!");\r
- System.out.print("Do you want to over write it [y|N]? ");\r
- String inputLine = null;\r
- try {\r
- BufferedReader inputString = new BufferedReader(new InputStreamReader(System.in));\r
- inputLine = inputString.readLine();\r
- if ((inputLine.length() == 0) || (!inputLine.toLowerCase().contains("y"))) {\r
- System.out.println("Please correct the options, then try again.");\r
- System.out.println("Merge Aborted at user request!");\r
- System.exit(EFAILURE);\r
- }\r
- } catch (IOException e) {\r
- System.out.println("IOException: " + e);\r
- }\r
-\r
- }\r
- return ESUCCESS;\r
- }\r
-\r
- private static int testFile(String Filename) {\r
- File tFile = new File(Filename);\r
- if (DEBUG > 8)\r
- System.out.println("File is located: " + tFile.getPath());\r
- if (tFile.exists())\r
- return FOUND;\r
- else\r
- return NOTFOUND;\r
- }\r
-\r
- private static void outputUsage() {\r
- \r
- \r
- System.out.println("Merge, " + version);\r
- System.out.println(copyright);\r
- System.out.println("Usage:");\r
- System.out.println(" merge [-v] -t target [-u UiName] [-p PackageFile] dir1" + File.separator + "leaf1 ... dirN" + File.separator + "leafN [-h | -? | --help]");\r
- System.out.println(" where:");\r
- System.out.println(" -h | -? | --help OPTIONAL - This Help Text");\r
- System.out.println(" -t Target REQUIRED - The Name of the new Merge Module MSA file");\r
- System.out.println(" -p Package OPTIONAL - The Name of the Package (SPD) file to add the target");\r
- System.out.println(" -u UiName OPTIONAL - The User Interface Name for the Target Module");\r
- System.out.println(" -v OPTIONAL - Verbose, print information messages.");\r
- System.out.println(" -o OutputFileBasename OPTIONAL - Set the Output Filename for this module to Basename");\r
- System.out.println(" dir1" + File.separator + "leaf1 ... dirN" + File.separator + "leafN REQUIRED The path to two or more MSA files that will be merged");\r
- System.out.println("");\r
- }\r
-}\r