usage
[mono.git] / mcs / tools / mjs / mjs.cs
1 //
2 // driver.cs: Guides the compilation process through the different phases.
3 //
4 // Author: 
5 //      Cesar Lopez Nataren (cesar@ciencias.unam.mx)
6 //
7 // (C) 2003, Cesar Lopez Nataren
8 // (C) 2005, Novell Inc. (http://www.novell.com)
9 //
10
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 using System;
33 using System.IO;
34 using Microsoft.Vsa;
35 using Microsoft.JScript;
36 using Microsoft.JScript.Vsa;
37
38 class Driver {          
39         public static void Main (string [] args) {
40         
41                 if (args.Length < 1) {
42                         Console.WriteLine ("Usage: mjs filename.js");
43                         Environment.Exit (0);
44                 }
45
46                 VsaEngine engine = new VsaEngine ();
47                 engine.InitVsaEngine ("mjs:com.mono-project", new MonoEngineSite ());
48
49                 foreach (string fn in args) {
50                         IVsaCodeItem item = (IVsaCodeItem) engine.Items.CreateItem (fn, VsaItemType.Code, VsaItemFlag.None);
51                         item.SourceText = GetCodeFromFile (fn);
52                 }
53                 engine.Compile ();
54         }
55
56         static string GetCodeFromFile (string fn)
57         {
58                 try {
59                         StreamReader reader = new StreamReader (fn);
60                         return reader.ReadToEnd ();
61                 } catch (FileNotFoundException) {
62                         throw new JScriptException (JSError.FileNotFound);
63                 } catch (ArgumentNullException) {
64                         throw new JScriptException (JSError.FileNotFound);
65                 } catch (ArgumentException) {
66                         throw new JScriptException (JSError.FileNotFound);
67                 } catch (IOException) {
68                         throw new JScriptException (JSError.NoError);
69                 } catch (OutOfMemoryException) {
70                         throw new JScriptException (JSError.OutOfMemory);
71                 }
72         }
73 }
74
75 class MonoEngineSite : IVsaSite {
76         public void GetCompiledState (out byte [] pe, out byte [] debugInfo)
77         {
78                 throw new NotImplementedException ();
79         }
80
81         public object GetEventSourceInstance (string itemName, string eventSourceName)
82         {
83                 throw new NotImplementedException ();
84         }
85
86         public object GetGlobalInstance (string name)
87         {
88                 throw new NotImplementedException ();
89         }
90
91         public void Notify (string notify, object info)
92         {
93                 throw new NotImplementedException ();
94         }
95
96         public bool OnCompilerError (IVsaError error)
97         {
98                 throw new NotImplementedException ();
99         }
100 }