public static int Main(string[] args) { DateTime ldt = DateTime.Now; PascalABCCompiler.StringResourcesLanguage.LoadDefaultConfig(); Compiler = new PascalABCCompiler.Compiler(null, null); StringResourcesLanguage.CurrentLanguageName = StringResourcesLanguage.AccessibleLanguages[0]; //Console.WriteLine("OK {0}ms", (DateTime.Now - ldt).TotalMilliseconds); ldt = DateTime.Now; //ShowConnectedParsers(); if (args.Length == 0) { Console.WriteLine(StringResourcesGet("COMMANDLINEISABSENT")); return 2; } FileName = args[0]; if (!File.Exists(FileName)) { Console.WriteLine(StringResourcesGet("FILEISABSENT{0}"),FileName); return 3; } outputType = CompilerOptions.OutputType.ConsoleApplicaton; CompilerOptions co = new CompilerOptions(FileName, outputType); if (args.Length==1) co.OutputDirectory = ""; else co.OutputDirectory = args[1]; co.Rebuild = false; co.Debug = true; co.UseDllForSystemUnits = false; bool success = true; if (Compiler.Compile(co) != null) Console.WriteLine("OK"); else { Console.WriteLine(StringResourcesGet("COMPILEERRORS")); success = false; } // Console.WriteLine("OK {0}ms", (DateTime.Now - ldt).TotalMilliseconds); ///// for (int i = 0; i < Compiler.ErrorsList.Count; i++) { if (Compiler.ErrorsList[i] is LocatedError) { SourceLocation sl; if ((sl = (Compiler.ErrorsList[i] as LocatedError).SourceLocation) != null) Console.WriteLine(string.Format("[{0},{1}] {2}: {3}", sl.BeginPosition.Line, sl.BeginPosition.Column, Path.GetFileName(sl.FileName), Compiler.ErrorsList[i].Message)); else Console.WriteLine(Compiler.ErrorsList[i]); } break; // выйти после первой же ошибки } if (success) return 0; else return 1; }
public static int Main(string[] args) { DateTime ldt = DateTime.Now; PascalABCCompiler.StringResourcesLanguage.LoadDefaultConfig(); Compiler = new PascalABCCompiler.Compiler(null, null); StringResourcesLanguage.CurrentLanguageName = StringResourcesLanguage.AccessibleLanguages[0]; //Console.WriteLine("OK {0}ms", (DateTime.Now - ldt).TotalMilliseconds); ldt = DateTime.Now; //ShowConnectedParsers(); if (args.Length == 0) { Console.WriteLine(StringResourcesGet("COMMANDLINEISABSENT")); return(2); } FileName = args[0]; if (!File.Exists(FileName)) { Console.WriteLine(StringResourcesGet("FILEISABSENT{0}"), FileName); return(3); } outputType = CompilerOptions.OutputType.ConsoleApplicaton; CompilerOptions co = new CompilerOptions(FileName, outputType); if (FileName.ToLower().EndsWith(".pabcproj")) { co.ProjectCompiled = true; } if (args.Length == 1) { co.OutputDirectory = ""; } else { co.OutputDirectory = args[1]; } co.Rebuild = false; co.Debug = true; co.UseDllForSystemUnits = false; bool success = true; if (Compiler.Compile(co) != null) { Console.WriteLine("OK"); } else { Console.WriteLine(StringResourcesGet("COMPILEERRORS")); success = false; } // Console.WriteLine("OK {0}ms", (DateTime.Now - ldt).TotalMilliseconds); ///// for (int i = 0; i < Compiler.ErrorsList.Count; i++) { if (Compiler.ErrorsList[i] is LocatedError) { SourceLocation sl; if ((sl = (Compiler.ErrorsList[i] as LocatedError).SourceLocation) != null) { Console.WriteLine(string.Format("[{0},{1}] {2}: {3}", sl.BeginPosition.Line, sl.BeginPosition.Column, Path.GetFileName(sl.FileName), Compiler.ErrorsList[i].Message)); } else { Console.WriteLine(Compiler.ErrorsList[i]); } } break; // выйти после первой же ошибки } if (success) { return(0); } else { return(1); } }
public static int CompileAssembly(string FileName, CompilerOptions.OutputType outputType, bool PauseIfError) { if (RestartOnNewCompile) { Reset(); } StartTime = DateTime.Now; Console.ForegroundColor = ConsoleColor.White; string msg = string.Format(StringResourcesGet("COMPILING_ASSEMBLY{0}"), System.IO.Path.GetFileName(FileName)); if (short_output) { ClearLine(); Console.Write(msg); } else { Console.WriteLine(msg); } DateTime ldt = DateTime.Now; CompilerOptions co = new CompilerOptions(FileName, outputType); if (FileName.ToLower().EndsWith(".pabcproj")) { co.ProjectCompiled = true; } if (OutputDirectory != "") { co.OutputDirectory = OutputDirectory; } co.Rebuild = Rebuild; co.Debug = Debug; co.UseDllForSystemUnits = UseDll; AllFilesCount++; if (Compiler.Compile(co) != null) { SuccessFilesCount++; } if (IgnoreNotSupportedError) { if ((Compiler.ErrorsList.Count == 1) && (Compiler.ErrorsList[0] is Errors.SemanticNonSupportedError)) { Compiler.ErrorsList.Clear(); SuccessFilesCount++; } } if (Compiler.ErrorsList.Count > 0) { //Console.Beep(); if (short_output) { Console.WriteLine(); } Console.ForegroundColor = ConsoleColor.Gray; for (int i = 0; i < Compiler.ErrorsList.Count; i++) { WriteErrorText("[" + i + "]"); if (Compiler.ErrorsList[i] is LocatedError) { SourceLocation sl; if ((sl = (Compiler.ErrorsList[i] as LocatedError).SourceLocation) != null) { Console.WriteLine(string.Format("[{0},{1}] {2}: {3}", sl.BeginPosition.Line, sl.BeginPosition.Column, Path.GetFileName(sl.FileName), Compiler.ErrorsList[i].Message)); } else { Console.WriteLine(Compiler.ErrorsList[i]); } } else { if (Compiler.ErrorsList[i] is CompilerInternalError) { Console.ForegroundColor = ConsoleColor.Red; } Console.WriteLine(Compiler.ErrorsList[i]); } } GlobalErrorsList.AddRange(Compiler.ErrorsList); if (PauseIfError) { Console.ReadKey(); } } else { if (!short_output) { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(string.Format(StringResourcesGet("OK_{0}MS_{1}LINES"), (DateTime.Now - ldt).TotalMilliseconds, Compiler.LinesCompiled)); } } Console.ForegroundColor = ConsoleColor.Gray; return(Compiler.ErrorsList.Count); }
public static int Main(string[] args) { // SSM 18.03.19 Делаю параметры командной строки. Формат: pabcnetc.exe /Dir1=value1 /Dir2=value2 ... fname dir // dir - это пережиток старого - так можно было задавать каталог раньше. Пока - увы - пусть останется // Пока сделаю только директивы /Help /H /? и /Debug=0(1) // Имя директивы - это одно слово. Равенства может не быть - тогда value директивы равно null // Вычленяем первое равенство и делим директиву: до него - name, после него - value. Если name или value - пустые строки, то ошибка DateTime ldt = DateTime.Now; PascalABCCompiler.StringResourcesLanguage.LoadDefaultConfig(); Compiler = new PascalABCCompiler.Compiler(null, null); StringResourcesLanguage.CurrentLanguageName = StringResourcesLanguage.AccessibleLanguages[0]; //Console.WriteLine("OK {0}ms", (DateTime.Now - ldt).TotalMilliseconds); ldt = DateTime.Now; //ShowConnectedParsers(); var n = args.Length; if (n == 0) { //Console.WriteLine(StringResourcesGet("COMMANDLINEISABSENT")); OutputHelp(); return(2); } var n1 = args.TakeWhile(a => a[0] == '/').Count(); // количество директив if (n1 < n - 2) { Console.WriteLine("Error in argument {0}", args[n1 + 2]); Console.WriteLine("Command line cannot contain any arguments after filename '{0}' and outdirname '{1}'", args[n1], args[n1 + 1]); return(4); } if (n1 == n) // только директивы { string name, value; var b = CheckAndSplitDirective(args[0], out name, out value); if (!b) // Сообщение уже будет выдано { return(4); } switch (name) { case "help": case "h": case "?": OutputHelp(); return(0); default: Console.WriteLine("Filename is absent. Nothing to compile"); return(4); } } FileName = args[n1]; // следующий аргумент за директивами - имя файла if (!File.Exists(FileName)) { Console.WriteLine(StringResourcesGet("FILEISABSENT{0}"), "'" + FileName + "'"); return(3); } outputType = CompilerOptions.OutputType.ConsoleApplicaton; CompilerOptions co = new CompilerOptions(FileName, outputType); if (FileName.ToLower().EndsWith(".pabcproj")) { co.ProjectCompiled = true; } if (n1 == n - 1) { co.OutputDirectory = ""; } else { co.OutputDirectory = args[n - 1]; } co.Rebuild = false; co.Debug = false; co.UseDllForSystemUnits = false; for (var i = 0; i < n1; i++) { var b = CheckAndApplyDirective(args[i], co); if (!b) { return(4); } } bool success = true; if (Compiler.Compile(co) != null) { Console.WriteLine("OK"); } else { Console.WriteLine(StringResourcesGet("COMPILEERRORS")); success = false; } // Console.WriteLine("OK {0}ms", (DateTime.Now - ldt).TotalMilliseconds); ///// for (int i = 0; i < Compiler.ErrorsList.Count; i++) { if (Compiler.ErrorsList[i] is LocatedError) { SourceLocation sl; if ((sl = (Compiler.ErrorsList[i] as LocatedError).SourceLocation) != null) { Console.WriteLine(string.Format("[{0},{1}] {2}: {3}", sl.BeginPosition.Line, sl.BeginPosition.Column, Path.GetFileName(sl.FileName), Compiler.ErrorsList[i].Message)); } else { Console.WriteLine(Compiler.ErrorsList[i]); } } break; // выйти после первой же ошибки } if (success) { return(0); } else { return(1); } }