Program.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using CommandLine;
  5. namespace MicroComGenerator
  6. {
  7. class Program
  8. {
  9. public class Options
  10. {
  11. [Option('i', "input", Required = true, HelpText = "Input IDL file")]
  12. public string Input { get; set; }
  13. [Option("cpp", Required = false, HelpText = "C++ output file")]
  14. public string CppOutput { get; set; }
  15. [Option("cs", Required = false, HelpText = "C# output file")]
  16. public string CSharpOutput { get; set; }
  17. }
  18. static int Main(string[] args)
  19. {
  20. var p = Parser.Default.ParseArguments<Options>(args);
  21. if (p is NotParsed<Options>)
  22. {
  23. return 1;
  24. }
  25. var opts = ((Parsed<Options>)p).Value;
  26. var text = File.ReadAllText(opts.Input);
  27. var ast = AstParser.Parse(text);
  28. if (opts.CppOutput != null)
  29. File.WriteAllText(opts.CppOutput, CppGen.GenerateCpp(ast));
  30. if (opts.CSharpOutput != null)
  31. {
  32. File.WriteAllText(opts.CSharpOutput, new CSharpGen(ast).Generate());
  33. // HACK: Can't work out how to get the VS project system's fast up-to-date checks
  34. // to ignore the generated code, so as a workaround set the write time to that of
  35. // the input.
  36. File.SetLastWriteTime(opts.CSharpOutput, File.GetLastWriteTime(opts.Input));
  37. }
  38. return 0;
  39. }
  40. }
  41. }