public static OptionSet GetCommonTypeCobolOptions(TypeCobolConfiguration typeCobolConfig) { var commonOptions = new OptionSet() { { "i|input=", "{PATH} to an input file to parse. This option can be specified more than once.", v => typeCobolConfig.InputFiles.Add(v) }, { "o|output=", "{PATH} to an output file where to generate code. This option can be specified more than once.", v => typeCobolConfig.OutputFiles.Add(v) }, { "d|diagnostics=", "{PATH} to the error diagnostics file.", v => typeCobolConfig.ErrorFile = v }, { "s|skeletons=", "{PATH} to the skeletons file.", v => typeCobolConfig.skeletonPath = v }, { "a|autoremarks", "Enable automatic remarks creation while parsing and generating Cobol", v => typeCobolConfig.AutoRemarks = true }, { "hc|haltonmissingcopy=", "HaltOnMissingCopy will generate a file to list all the absent copies", v => typeCobolConfig.HaltOnMissingCopyFilePath = v }, { "ets|exectostep=", "ExecToStep will execute TypeCobol Compiler until the included given step (Scanner/0, Preprocessor/1, SyntaxCheck/2, SemanticCheck/3, CrossCheck/4, Generate/5)", v => typeCobolConfig.RawExecToStep = v }, { "e|encoding=", "{ENCODING} of the file(s) to parse. It can be one of \"rdz\"(this is the default), \"zos\", or \"utf8\". " + "If this option is not present, the parser will attempt to guess the {ENCODING} automatically.", v => typeCobolConfig.RawFormat = v }, { "y|intrinsic=", "{PATH} to intrinsic definitions to load.\nThis option can be specified more than once.", v => typeCobolConfig.Copies.Add(v) }, { "c|copies=", "Folder where COBOL copies can be found.\nThis option can be specified more than once.", v => typeCobolConfig.CopyFolders.Add(v) }, { "dp|dependencies=", "Path to folder containing programs to load and to use for parsing a generating the input program.", v => typeCobolConfig.Dependencies.Add(v) }, { "t|telemetry", "If set to true telemetry will send automatic email in case of bug and it will provide to TypeCobol Team data on your usage.", v => typeCobolConfig.Telemetry = true }, { "md|maximumdiagnostics=", "Wait for an int value that will represent the maximum number of diagnostics that TypeCobol have to return.", v => typeCobolConfig.RawMaximumDiagnostics = v }, { "f|outputFormat=", "Output format (default is Cobol 85). (Cobol85/0, PublicSignature/1, Cobol85Mixed/3)", v => typeCobolConfig.RawOutputFormat = v }, { "ec|expandingcopy=", "Generate a file with all COPY directives expanded in the source code. This option will be executed if the Preprocessor step is enabled.", v => typeCobolConfig.ExpandingCopyFilePath = v }, { "exc|extractusedcopy=", "Generate a file with all COPIES detected by the parser", v => typeCobolConfig.ExtractedCopiesFilePath = v }, { "antlrp|antlrprogparse", "Use ANTLR to parse a program", v => typeCobolConfig.UseAntlrProgramParsing = true }, { "cmr|copymovereport=", "{PATH} to Report all Move and Initialize statements that target a COPY.", v => typeCobolConfig.ReportCopyMoveInitializeFilePath = v }, { "zcr|zcallreport=", "{PATH} to report of all program called by zcallpgm.", v => typeCobolConfig.ReportZCallFilePath = v }, { "dcs|disablecopysuffixing", "Deactivate Euro-Information suffixing", v => typeCobolConfig.UseEuroInformationLegacyReplacingSyntax = false } }; return(commonOptions); }
/// <summary> /// CreateFormat method to get the format name. /// </summary> /// <param name="encoding">string</param> /// <param name="config">Config</param> /// <returns>DocumentFormat</returns> public static Compiler.DocumentFormat CreateFormat(string encoding, ref TypeCobolConfiguration config) { config.EncFormat = encoding; if (encoding == null) { return(null); } if (encoding.ToLower().Equals("zos")) { return(TypeCobol.Compiler.DocumentFormat.ZOsReferenceFormat); } if (encoding.ToLower().Equals("utf8")) { return(TypeCobol.Compiler.DocumentFormat.FreeUTF8Format); } /*if (encoding.ToLower().Equals("rdz"))*/ return(TypeCobol.Compiler.DocumentFormat.RDZReferenceFormat); }
public static OptionSet GetCommonTypeCobolOptions(TypeCobolConfiguration typeCobolConfig) { var commonOptions = new OptionSet() { { "i|input=", "{PATH} to an input file to parse. This option can be specified more than once.", v => typeCobolConfig.InputFiles.Add(v) }, { "o|output=", "{PATH} to an ouput file where to generate code. This option can be specified more than once.", v => typeCobolConfig.OutputFiles.Add(v) }, { "d|diagnostics=", "{PATH} to the error diagnostics file.", v => typeCobolConfig.ErrorFile = v }, { "s|skeletons=", "{PATH} to the skeletons files.", v => typeCobolConfig.skeletonPath = v }, { "a|autoremarks", "Enable automatic remarks creation while parsing and generating Cobol", v => typeCobolConfig.AutoRemarks = true }, { "hc|haltonmissingcopy=", "HaltOnMissingCopy will generate a file to list all the absent copies", v => typeCobolConfig.HaltOnMissingCopyFilePath = v }, { "ets|exectostep=", "ExecToStep will execute TypeCobol Compiler until the included given step (Scanner/0, Preprocessor/1, SyntaxCheck/2, SemanticCheck/3, Generate/4)", v => Enum.TryParse(v.ToString(), true, out typeCobolConfig.ExecToStep) }, { "e|encoding=", "{ENCODING} of the file(s) to parse. It can be one of \"rdz\"(this is the default), \"zos\", or \"utf8\". " + "If this option is not present, the parser will attempt to guess the {ENCODING} automatically.", v => typeCobolConfig.Format = CreateFormat(v, ref typeCobolConfig) }, { "y|intrinsic=", "{PATH} to intrinsic definitions to load.\nThis option can be specified more than once.", v => typeCobolConfig.Copies.Add(v) }, { "c|copies=", "Folder where COBOL copies can be found.\nThis option can be specified more than once.", v => typeCobolConfig.CopyFolders.Add(v) }, { "dp|dependencies=", "Path to folder containing programs to load and to use for parsing a generating the input program.", v => typeCobolConfig.Dependencies.Add(v) }, { "t|telemetry=", "If set to true telemrty will send automatic email in case of bug and it will provide to TypeCobol Team data on your usage.", v => typeCobolConfig.Telemetry = true }, { "md|maximumdiagnostics=", "Wait for an int value that will represent the maximum number of diagnostics that TypeCobol have to return.", v => typeCobolConfig.MaximumDiagnostics = int.Parse(v.ToString()) } }; return(commonOptions); }
public static Dictionary <ReturnCode, string> InitializeCobolOptions(TypeCobolConfiguration config, IEnumerable <string> args, OptionSet options) { Dictionary <ReturnCode, string> errorStack = new Dictionary <ReturnCode, string>(); List <string> unexpectedStrings = new List <string>(); try { unexpectedStrings = options.Parse(args); } catch (OptionException ex) { // Last parameter doesn't have any value errorStack.Add(ReturnCode.FatalError, ex.Message); } // ExecToStepError if (!Enum.TryParse(config.RawExecToStep, true, out config.ExecToStep)) { errorStack.Add(ReturnCode.ExecToStepError, TypeCobolConfiguration.ErrorMessages[ReturnCode.ExecToStepError]); } //// Check required options //InputFileMissing if (config.InputFiles.IsNullOrEmpty()) { errorStack.Add(ReturnCode.InputFileMissing, TypeCobolConfiguration.ErrorMessages[ReturnCode.InputFileMissing]); } //OutputFileMissing/OutputFileError if (config.ExecToStep == ExecutionStep.Generate && !errorStack.ContainsKey(ReturnCode.ExecToStepError)) { if (config.OutputFiles.IsNullOrEmpty()) { errorStack.Add(ReturnCode.OutputFileMissing, TypeCobolConfiguration.ErrorMessages[ReturnCode.OutputFileMissing]); } else if (config.InputFiles.Count != config.OutputFiles.Count) { errorStack.Add(ReturnCode.OutputFileError, TypeCobolConfiguration.ErrorMessages[ReturnCode.OutputFileError]); } } //SkeletonMissing if (config.ExecToStep == ExecutionStep.Generate && config.skeletonPath.IsNullOrEmpty() && !errorStack.ContainsKey(ReturnCode.ExecToStepError)) { errorStack.Add(ReturnCode.SkeletonMissing, TypeCobolConfiguration.ErrorMessages[ReturnCode.SkeletonMissing]); } //// Check unexpected token if (unexpectedStrings.Count != 0) { errorStack.Add(ReturnCode.UnexpectedParamError, TypeCobolConfiguration.ErrorMessages[ReturnCode.UnexpectedParamError]); } //// Options values verification //InputFileError VerifFiles(config.InputFiles, ReturnCode.InputFileError, ref errorStack); //outputFilePathsWrong foreach (var path in config.OutputFiles) { if (!CanCreateFile(path) && !errorStack.ContainsKey(ReturnCode.OutputPathError)) { errorStack.Add(ReturnCode.OutputPathError, TypeCobolConfiguration.ErrorMessages[ReturnCode.OutputPathError]); } } //ErrorFilePathError if (!CanCreateFile(config.ErrorFile) && !config.ErrorFile.IsNullOrEmpty()) { errorStack.Add(ReturnCode.ErrorFileError, TypeCobolConfiguration.ErrorMessages[ReturnCode.ErrorFileError]); } //SkeletonFileError if (config.ExecToStep == ExecutionStep.Generate && !config.skeletonPath.IsNullOrEmpty() && !errorStack.ContainsKey(ReturnCode.ExecToStepError)) { if (FileSystem.GetFiles(config.skeletonPath, recursive: false).IsNullOrEmpty() && !errorStack.ContainsKey(ReturnCode.SkeletonFileError)) { errorStack.Add(ReturnCode.SkeletonFileError, TypeCobolConfiguration.ErrorMessages[ReturnCode.SkeletonFileError]); } } //HaltOnMissingCopyFilePathError if (!CanCreateFile(config.HaltOnMissingCopyFilePath) && !config.HaltOnMissingCopyFilePath.IsNullOrEmpty()) { errorStack.Add(ReturnCode.HaltOnMissingCopyError, TypeCobolConfiguration.ErrorMessages[ReturnCode.HaltOnMissingCopyError]); } // EncodingError config.Format = CreateFormat(config.RawFormat, ref config); //IntrinsicError VerifFiles(config.Copies, ReturnCode.IntrinsicError, ref errorStack); //CopiesError VerifFiles(config.CopyFolders, ReturnCode.CopiesError, ref errorStack, true); //DependenciesError VerifFiles(config.Dependencies, ReturnCode.DependenciesError, ref errorStack); // MaxDiagnosticsError if (!config.RawMaximumDiagnostics.IsNullOrEmpty()) { if (!int.TryParse(config.RawMaximumDiagnostics, out config.MaximumDiagnostics)) { errorStack.Add(ReturnCode.MaxDiagnosticsError, TypeCobolConfiguration.ErrorMessages[ReturnCode.MaxDiagnosticsError]); } } // OutputFormatError if (!Enum.TryParse(config.RawOutputFormat, true, out config.OutputFormat)) { errorStack.Add(ReturnCode.OutputFormatError, TypeCobolConfiguration.ErrorMessages[ReturnCode.OutputFormatError]); } //ExpandingCopyFilePathError if (!CanCreateFile(config.ExpandingCopyFilePath) && !config.ExpandingCopyFilePath.IsNullOrEmpty()) { errorStack.Add(ReturnCode.ExpandingCopyError, TypeCobolConfiguration.ErrorMessages[ReturnCode.ExpandingCopyError]); } //HaltOnMissingCopyFilePathError if (!CanCreateFile(config.ExtractedCopiesFilePath) && !config.ExtractedCopiesFilePath.IsNullOrEmpty()) { errorStack.Add(ReturnCode.ExtractusedCopyError, TypeCobolConfiguration.ErrorMessages[ReturnCode.ExtractusedCopyError]); } return(errorStack); }