/// <summary> /// Конструктор. Считывает исходники с файла /// </summary> public ConsoleProgram(string[] args) { #region азбор аргyментов командной строки switch (args.Length) { case 1: if (args[0].ToUpper() == "-HELP") { Console.WriteLine(ConsoleProgram.getUserGuide()); } else { throw new ConsoleException("Некорректное использование аргументов командной строки"); } break; case 2: if (args[0].ToUpper() == "-INPUT_FILE") { this.input_file = args[1]; } else if (args[0].ToUpper() == "-OUTPUT_FILE") { this.output_file = args[1]; } else { throw new ConsoleException("Некорректное использование аргументов командной строки"); } break; case 4: if (args[0].ToUpper() == "-INPUT_FILE") { this.input_file = args[1]; if (args[2].ToUpper() == "-OUTPUT_FILE") { this.output_file = args[3]; } else { throw new ConsoleException("Недопустимый ключ! Должен быть -OUTPUT_FILE"); } } else if (args[0].ToUpper() == "-OUTPUT_FILE") { this.output_file = args[1]; if (args[2].ToUpper() == "-INPUT_FILE") { this.input_file = args[3]; } else { throw new ConsoleException("Недопустимый ключ! Должен быть -INPUT_FILE"); } } else { throw new ConsoleException("Некорректное использование аргументов командной строки"); } break; default: throw new ConsoleException("Неверное количество аргументов"); } #endregion string[] temp = null; try { temp = System.IO.File.ReadAllLines(this.input_file); } catch (Exception e) { throw new ConsoleException("Не удалось загрузить данные с файла. Возможно путь к файлу указан неверно"); } this.sourceCode = new SourceCode(temp); this.sourceStrings = new List <string>(temp); }
public static void Main(string[] args) { var handle = GetConsoleWindow(); if (args.Length == 0) { ShowWindow(handle, SW_HIDE); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } else { ShowWindow(handle, SW_SHOW); try { ConsoleProgram program = new ConsoleProgram(args); Console.WriteLine(program.getProgGuide()); string ch = ""; while ((ch = Console.ReadLine().ToUpper().Trim()) != "0") { switch (ch) { case "1": Console.Clear(); if (!program.isEnd) { program.firstRun(); Console.WriteLine(); } else { Console.WriteLine("\nПрограмма завершила свои действия. Запустите ее заново.\n"); } break; case "2": Console.Clear(); if (!program.isEnd) { if (program.firstEnd == true) { program.secondEnd = true; program.isEnd = true; Console.WriteLine("\nВторой проход выполнен\n"); break; } else { Console.WriteLine("\nВыполните сначала 1 проход"); } } else { Console.WriteLine("\nПрограмма завершила свои действия. Запустите ее заново.\n"); } break; case "3": Console.Clear(); Console.WriteLine("\nИсходный код\n"); foreach (string str in program.sourceStrings) { Console.WriteLine(str); } Console.WriteLine(); Console.ReadKey(); break; case "4": Console.Clear(); if (program.secondEnd) { Console.WriteLine("\nАссемблерный код\n"); program.sourceCode.printAsm(); Console.WriteLine(); Console.ReadKey(); } else { Console.WriteLine("\nАссемблерный код не сгенерирован.\n"); } break; case "5": Console.Clear(); if (program.firstEnd) { Console.WriteLine("\nТаблица глобальных переменных\n"); Global.printGlobal(); Console.WriteLine(); Console.ReadKey(); } else { Console.WriteLine("\nВыполните сначала 1 проход.\n"); } break; case "6": Console.Clear(); if (program.firstEnd) { Console.WriteLine("\nТМО\n"); TMO.printTMO(); Console.WriteLine(); Console.ReadKey(); } else { Console.WriteLine("\nВыполните сначала 1 проход.\n"); } break; case "8": Console.Clear(); Console.WriteLine("\nОбновлено все\n"); TMO.refresh(); Global.refresh(); program = new ConsoleProgram(args); program.sourceCode.result = new List <SourceEntity>(); Console.WriteLine(); break; case "7": Console.Clear(); try { StreamWriter sw = new StreamWriter(program.output_file); foreach (SourceEntity se in program.sourceCode.result) { sw.WriteLine(se.ToString()); } sw.Close(); Console.WriteLine("\nЗапись успешна\n"); Process.Start("notepad.exe", program.output_file); } catch { Console.WriteLine("\nЗапись не успешна, возможно не задан или не найден файл\n"); } break; default: Console.WriteLine("\nОшибка! Введен неверный ключ!\n"); break; } Console.WriteLine(program.getProgGuide()); } } catch (ConsoleException ex) { Console.WriteLine("\n\nОшибка " + ex.Message + "\n\n"); Console.WriteLine(ConsoleProgram.getUserGuide()); Console.WriteLine("\nПрограмма завершила свои действия. Запустите ее заново.\n"); } catch (Exception ex) { Console.WriteLine("\n\nОшибка" + ex.Message + "\n\n"); Console.WriteLine(ConsoleProgram.getUserGuide()); Console.WriteLine("\nПрограмма завершила свои действия. Запустите ее заново.\n"); } } }