2006-11-14 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Tue, 14 Nov 2006 14:02:51 +0000 (14:02 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Tue, 14 Nov 2006 14:02:51 +0000 (14:02 -0000)
* sgen.cs : some fixes.
  - catch Assembly.LoadFrom() errors.
  - command line options were working only with /, not with --.
  - --type (/t) are to limit target types, so skip non-target types.

svn path=/trunk/mcs/; revision=67845

mcs/tools/sgen/ChangeLog
mcs/tools/sgen/sgen.cs

index f3aa97a7fe4372e7d054d5359fbc7d468cd76d39..5df126dd0accb287711ce3931667138b5bee7e5e 100644 (file)
@@ -1,3 +1,10 @@
+2006-11-14  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * sgen.cs : some fixes.
+         - catch Assembly.LoadFrom() errors.
+         - command line options were working only with /, not with --.
+         - --type (/t) are to limit target types, so skip non-target types.
+
 2004-07-10  Lluis Sanchez Gual  <lluis@novell.com>
 
        * sgen.cs, Makefile, sgen.exe.sources: New files
index c4f0d7386d3e5e191cfd1723d2a044799628e6ca..127a2b2f66eff62252acced897ce51a0b9765948 100644 (file)
@@ -1,10 +1,12 @@
 // 
-// genxs.cs
+// sgen.cs
 //
-// Author:
+// Authors:
 //   Lluis Sanchez Gual (lluis@ximian.com)
+//   Atsushi Enomoto (atsushi@ximian.com)
 //
 // Copyright (C) 2003 Ximian, Inc.
+// Copyright (C) 2006 Novell, Inc.
 //
 
 using System;
@@ -78,10 +80,15 @@ public class Driver
                }
                catch {}
                
-               if (asm == null)
-                       asm = Assembly.LoadFrom (assembly);
-                       
-                       
+               if (asm == null) {
+                       try {
+                               asm = Assembly.LoadFrom (assembly);
+                       } catch {
+                               Console.WriteLine ("Specified assembly cannot be loaded.");
+                               Console.WriteLine ();
+                               return 1;
+                       }
+               }
                ArrayList userTypes = new ArrayList ();
                ArrayList maps = new ArrayList ();
                XmlReflectionImporter imp = new XmlReflectionImporter ();
@@ -92,13 +99,14 @@ public class Driver
                foreach (Type t in asm.GetTypes())
                {
                        try {
+                               if (types != null && !types.Contains (t.ToString()))
+                                       continue;
+
                                maps.Add (imp.ImportTypeMapping (t));
-                               if (types == null || types.Contains (t.ToString())) {
-                                       userTypes.Add (t);
-                                       if (verbose) Console.WriteLine (" - " + t);
-                               }
+                               userTypes.Add (t);
+                               if (verbose) Console.WriteLine (" - " + t);
                        }
-                       catch (Exception ex)
+                       catch (NotImplementedException ex)
                        {
                                if (verbose) {
                                        Console.WriteLine (" - Warning: ignoring '" + t + "'");
@@ -142,7 +150,7 @@ public class Driver
 #else
        public int Run (string[] args)
        {
-               Console.WriteLine ("This tool is only supported in Mono 2.0");
+               Console.WriteLine ("This tool is only supported in 2.0 profile.");
                return 1;
        }
 
@@ -152,18 +160,18 @@ public class Driver
        {
                foreach (string arg in args)
                {
-                       
-                       if (!arg.StartsWith ("--") && !arg.StartsWith ("/"))
+                       int index = arg.Length > 2 && arg [0] == '-' && arg [1] == '-' ? 2 : -1;
+                       index = index >= 0 ? index : arg.Length > 0 && arg [0] == '/' ? 1 : -1;
+                       if (index < 0)
                        {
                                assembly = arg;
                                continue;
                        }
                        
-                       int i = arg.IndexOf (":");
+                       int i = arg.IndexOf (':', index);
                        if (i == -1) i = arg.Length;
-                       string op = arg.Substring (1,i-1);
-                       string param = (i<arg.Length-1) ? arg.Substring (i+1) : "";
-                       
+                       string op = arg.Substring (index, i - index);
+                       string param = (i < arg.Length - index) ? arg.Substring (i + 1) : "";
                        if (op == "assembly" || op == "a") {
                                assembly = param;
                        }