/// <summary> /// Processes the command line arguments. /// </summary> private static bool ProcessCommandLine2(List <string> tokens) { try { List <string> designFiles = new List <string>(); string identifierFile = null; string outputDir = null; bool generateIds = false; uint startId = 1; string stackRootDir = null; string ansicRootDir = null; bool generateMultiFile = false; bool useXmlInitializers = false; for (int ii = 1; ii < tokens.Count; ii++) { if (tokens[ii] == "-d2") { if (ii >= tokens.Count - 1) { throw new ArgumentException("Incorrect number of parameters specified with the -d2 option."); } designFiles.Add(tokens[++ii]); continue; } if (tokens[ii] == "-c" || tokens[ii] == "-cg") { if (ii >= tokens.Count - 1) { throw new ArgumentException("Incorrect number of parameters specified with the -c or -cg option."); } generateIds = tokens[ii] == "-cg"; identifierFile = tokens[++ii]; continue; } if (tokens[ii] == "-o") { if (ii >= tokens.Count - 1) { throw new ArgumentException("Incorrect number of parameters specified with the -o option."); } outputDir = tokens[++ii]; continue; } if (tokens[ii] == "-o2") { if (ii >= tokens.Count - 1) { throw new ArgumentException("Incorrect number of parameters specified with the -o option."); } outputDir = tokens[++ii]; generateMultiFile = true; continue; } if (tokens[ii] == "-id") { startId = Convert.ToUInt32(tokens[++ii]); continue; } if (tokens[ii] == "-ansic") { if (ii >= tokens.Count - 1) { throw new ArgumentException("Incorrect number of parameters specified with the -stack option."); } ansicRootDir = tokens[++ii]; continue; } if (tokens[ii] == "-useXmlInitializers") { useXmlInitializers = true; continue; } if (tokens[ii] == "-stack") { if (ii >= tokens.Count - 1) { throw new ArgumentException("Incorrect number of parameters specified with the -stack option."); } stackRootDir = tokens[++ii]; continue; } } ModelGenerator2 generator = new ModelGenerator2(); for (int ii = 0; ii < designFiles.Count; ii++) { if (String.IsNullOrEmpty(designFiles[ii])) { throw new ArgumentException("No design file specified."); } if (!new FileInfo(designFiles[ii]).Exists) { throw new ArgumentException("The design file does not exist: " + designFiles[ii]); } } if (String.IsNullOrEmpty(identifierFile)) { throw new ArgumentException("No identifier file specified."); } if (!new FileInfo(identifierFile).Exists) { if (!generateIds) { throw new ArgumentException("The identifier file does not exist: " + identifierFile); } File.Create(identifierFile).Close(); } generator.ValidateAndUpdateIds(designFiles, identifierFile, startId); if (!String.IsNullOrEmpty(stackRootDir)) { if (!new DirectoryInfo(stackRootDir).Exists) { throw new ArgumentException("The directory does not exist: " + stackRootDir); } StackGenerator.GenerateDotNet(stackRootDir); } if (!String.IsNullOrEmpty(ansicRootDir)) { if (!new DirectoryInfo(ansicRootDir).Exists) { throw new ArgumentException("The directory does not exist: " + stackRootDir); } StackGenerator.GenerateAnsiC(ansicRootDir); generator.GenerateIdentifiersAndNamesForAnsiC(ansicRootDir); } if (!String.IsNullOrEmpty(outputDir)) { if (generateMultiFile) { generator.GenerateMultipleFiles(outputDir, useXmlInitializers); } else { generator.GenerateInternalSingleFile(outputDir, useXmlInitializers); } } } catch (Exception e) { if (Environment.CommandLine.Contains(consoleOutputCommandLineArgument)) { System.Console.Error.WriteLine(e.Message); System.Console.Error.WriteLine(e.StackTrace); } else { new ExceptionDlg(e).ShowDialog(); } return(true); } return(true); }
/// <summary> /// Processes the command line arguments. /// </summary> private static bool ProcessCommandLine2(List <string> tokens) { try { List <string> designFiles = new List <string>(); string identifierFile = null; string outputDir = null; bool generateIds = false; uint startId = 1; string stackRootDir = null; string ansicRootDir = null; bool generateMultiFile = false; bool useXmlInitializers = false; string[] excludeCategories = null; bool updateHeaders = false; string inputDirectory = "."; string filePattern = "*.xml"; var licenseType = HeaderUpdateTool.LicenseType.MITXML; bool silent = false; for (int ii = 1; ii < tokens.Count; ii++) { if (tokens[ii] == "-input") { if (ii >= tokens.Count - 1) { throw new ArgumentException("Incorrect number of parameters specified with the -input option."); } inputDirectory = tokens[++ii]; continue; } if (tokens[ii] == "-pattern") { if (ii >= tokens.Count - 1) { throw new ArgumentException("Incorrect number of parameters specified with the -pattern option."); } filePattern = tokens[++ii]; continue; } if (tokens[ii] == "-silent") { silent = true; continue; } if (tokens[ii] == "-license") { if (ii >= tokens.Count - 1) { throw new ArgumentException("Incorrect number of parameters specified with the -license option."); } updateHeaders = true; licenseType = (HeaderUpdateTool.LicenseType)Enum.Parse(typeof(HeaderUpdateTool.LicenseType), tokens[++ii]); continue; } if (tokens[ii] == "-d2") { if (ii >= tokens.Count - 1) { throw new ArgumentException("Incorrect number of parameters specified with the -d2 option."); } designFiles.Add(tokens[++ii]); continue; } if (tokens[ii] == "-d2") { if (ii >= tokens.Count - 1) { throw new ArgumentException("Incorrect number of parameters specified with the -d2 option."); } designFiles.Add(tokens[++ii]); continue; } if (tokens[ii] == "-d2") { if (ii >= tokens.Count - 1) { throw new ArgumentException("Incorrect number of parameters specified with the -d2 option."); } designFiles.Add(tokens[++ii]); continue; } if (tokens[ii] == "-c" || tokens[ii] == "-cg") { if (ii >= tokens.Count - 1) { throw new ArgumentException("Incorrect number of parameters specified with the -c or -cg option."); } generateIds = tokens[ii] == "-cg"; identifierFile = tokens[++ii]; continue; } if (tokens[ii] == "-o") { if (ii >= tokens.Count - 1) { throw new ArgumentException("Incorrect number of parameters specified with the -o option."); } outputDir = tokens[++ii]; continue; } if (tokens[ii] == "-o2") { if (ii >= tokens.Count - 1) { throw new ArgumentException("Incorrect number of parameters specified with the -o option."); } outputDir = tokens[++ii]; generateMultiFile = true; continue; } if (tokens[ii] == "-id") { startId = Convert.ToUInt32(tokens[++ii]); continue; } if (tokens[ii] == "-ansic") { if (ii >= tokens.Count - 1) { throw new ArgumentException("Incorrect number of parameters specified with the -ansic option."); } ansicRootDir = tokens[++ii]; continue; } if (tokens[ii] == "-useXmlInitializers") { useXmlInitializers = true; continue; } if (tokens[ii] == "-stack") { if (ii >= tokens.Count - 1) { throw new ArgumentException("Incorrect number of parameters specified with the -stack option."); } stackRootDir = tokens[++ii]; continue; } if (tokens[ii] == "-exclude") { if (ii >= tokens.Count - 1) { throw new ArgumentException("Incorrect number of parameters specified with the -exclude option."); } excludeCategories = tokens[++ii].Split(','); continue; } } if (updateHeaders) { HeaderUpdateTool.ProcessDirectory(inputDirectory, filePattern, licenseType, silent); return(true); } ModelGenerator2 generator = new ModelGenerator2(); for (int ii = 0; ii < designFiles.Count; ii++) { if (String.IsNullOrEmpty(designFiles[ii])) { throw new ArgumentException("No design file specified."); } if (!new FileInfo(designFiles[ii]).Exists) { throw new ArgumentException("The design file does not exist: " + designFiles[ii]); } } if (String.IsNullOrEmpty(identifierFile)) { throw new ArgumentException("No identifier file specified."); } if (!new FileInfo(identifierFile).Exists) { if (!generateIds) { throw new ArgumentException("The identifier file does not exist: " + identifierFile); } File.Create(identifierFile).Close(); } generator.ValidateAndUpdateIds(designFiles, identifierFile, startId); if (!String.IsNullOrEmpty(stackRootDir)) { if (!new DirectoryInfo(stackRootDir).Exists) { throw new ArgumentException("The directory does not exist: " + stackRootDir); } StackGenerator.GenerateDotNet(stackRootDir); } if (!String.IsNullOrEmpty(ansicRootDir)) { if (!new DirectoryInfo(ansicRootDir).Exists) { throw new ArgumentException("The directory does not exist: " + ansicRootDir); } StackGenerator.GenerateAnsiC(ansicRootDir); generator.GenerateIdentifiersAndNamesForAnsiC(ansicRootDir, excludeCategories); } if (!String.IsNullOrEmpty(outputDir)) { if (generateMultiFile) { generator.GenerateMultipleFiles(outputDir, useXmlInitializers, excludeCategories); } else { generator.GenerateInternalSingleFile(outputDir, useXmlInitializers, excludeCategories); } } } catch (Exception e) { if (Environment.CommandLine.Contains(consoleOutputCommandLineArgument)) { System.Console.Error.WriteLine(e.Message); System.Console.Error.WriteLine(e.StackTrace); } else { new ExceptionDlg(e).ShowDialog(); } return(true); } return(true); }