1 // /home/jeremie/TaoParser/NGenerator/MainClass.cs
2 // Writtent by jeremie at 21:48 03/06/2007
4 // This file is licensed under the LGPL licence as described in the COPYING file
9 using System
.CodeDom
.Compiler
;
13 public class MainClass
15 static CommandLine cmd
;
17 public static void Main(string[] args
)
19 cmd
= new CommandLine(args
);
20 if (args
.Length
== 0 || cmd
.IsDefined("h"))
22 string[] names
= cmd
.Names
;
24 if (names
== null || (names
!= null && names
.Length
!= 1))
29 Logger
.Debug("CommandLine retrieved and parsed. Processing the files : " + string.Join(", ", names
));
33 if (Options
.Input
== InputType
.Directory
)
34 // TODO changes these things to use Options
35 fi
= GccXmlHelper
.ParseDirectory(Options
.InputFile
.FullName
);
37 fi
= GccXmlHelper
.ParseFile(Options
.InputFile
.FullName
);
39 string filename
= fi
.FullName
;
40 Logger
.Debug("File generated : " + filename
+ ". Does it exists ? : " + fi
.Exists
.ToString());
42 ITranslator trans
= new GccXmlTranslator();
43 CodeCompileUnit cu
= trans
.Translate(filename
);
44 CodeDomProvider cp
= new Microsoft
.CSharp
.CSharpCodeProvider();
45 cp
.GenerateCodeFromCompileUnit(cu
, Options
.Output
, new CodeGeneratorOptions());
48 static void PrintUsageAndExit()
50 string usage
= "NGenerator v0.1 (c) 2007 LAVAL Jérémie -- Generate *clean* C# P/Invoke class and method for interoperating with C libraries\n\n" +
51 "Usage is : ngenerator <options> filepath|directorypath\nWhere <options> may be :\n\n" +
52 "\t-h : print this help notice\n" + "\t-d : Tell NGenerator that the supplied path is a directory path" +
53 "\t-o filename : write the source code in filename\n\t-u Unsafe|Safe[UnsafeWithWrapper : the degree of \"unsafeness\" of the source, see man";
55 Console
.WriteLine(usage
);
60 static void PopulateOptions()
62 Options
.InputFile
= new FileInfo(cmd
.Names
[0]);
63 Options
.Input
= (cmd
.IsDefined("d")) ? InputType
.Directory
: InputType
.SingleFile
;
64 Options
.Output
= (cmd
.IsDefined("o")) ? new StreamWriter(cmd
["o"]) : null;
65 // TODO: make a cool Enum.(Try)Parse method instead of the funny thing that is Enum.Parse()
66 Options
.Unsafe
= (cmd
["u"].Equals("Unsafe", StringComparison
.OrdinalIgnoreCase
)) ? UnsafeLevel
.Unsafe
: UnsafeLevel
.Safe
;
68 // Now Options is read-only