// // (c) 2008, Sigbjorn Finne // using System; namespace HsWrap { class App { [STAThread] static void Main(string[] args) { if ( args.Length > 0 ) { bool createDir = false; bool processingOptions = true; bool withTypeModule=true; Int32 idx = 0; while (processingOptions) { if ( args[idx] == "-d" ) { createDir = true; idx++; continue; } if ( args[idx] == "-n" ) { withTypeModule = false; idx++; continue; } processingOptions=false; } TypeInfo ti = new TypeInfo(args[idx]); if ( ti.Type == null ) { Console.WriteLine("Unable to locate class {0}", args[idx]); return; } String outFile; if (args.Length > (idx+1)) { outFile = args[idx+1]; } else { Int32 modIdx = args[idx].LastIndexOf('.'); String fileStem = ""; if ( modIdx >= 0) { /* Create directory structure? */ if ( createDir ) { String dir; if ( withTypeModule ) { dir = args[idx].Replace('.','\\'); } else { dir = args[idx].Substring(0,modIdx).Replace('.','\\'); } Console.WriteLine("Creating: {0}", dir); System.IO.Directory.CreateDirectory(dir); fileStem = args[idx].Replace('.','\\'); } else { fileStem = args[idx].Substring(modIdx+1); } } else { fileStem = args[idx]; } outFile = String.Concat(fileStem, ".hs"); } Console.WriteLine(outFile); if ( withTypeModule ) { if ( !createDir ) { Console.WriteLine("ERROR: can't create type module without '-d' enabled"); } else { HsOutput hsTy = new HsOutput(ti.Type,ti.Members,false,true); String outTyFile = outFile.Replace(".hs","\\Type.hs"); Console.WriteLine(outTyFile); hsTy.OutputToFile(outTyFile); } } HsOutput hs = new HsOutput(ti.Type,ti.Members,withTypeModule && createDir,false); hs.OutputToFile(outFile); } else { Console.WriteLine("hswrap - creating Haskell modules that wraps up .NET classes"); Console.WriteLine("Usage: hswrap [-d] classname [outfile]"); Console.WriteLine("where '-d' will cause output into a dir hierarchy"); Console.WriteLine("(e.g., System.Foo.X is saved in System/Foo/X.hs)"); } } }; }