Merge pull request #2698 from esdrubal/iosxmlarray
[mono.git] / mcs / tools / sgen / sgen.cs
index c4f0d7386d3e5e191cfd1723d2a044799628e6ca..2ab376d3bfb61df230ed0c4312aa003b724d5913 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;
@@ -38,7 +40,6 @@ public class Driver
        bool verbose;
        string unknownArg;
        
-#if NET_2_0
 
        public int Run (string[] args)
        {
@@ -78,35 +79,65 @@ 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 ();
                
                if (verbose)
                        Console.WriteLine ("Generating serializer for the following types:");
-               
-               foreach (Type t in asm.GetTypes())
-               {
-                       try {
-                               maps.Add (imp.ImportTypeMapping (t));
-                               if (types == null || types.Contains (t.ToString())) {
+
+               if (types == null) {
+                       foreach (Type t in asm.GetTypes ()) {
+                               try {
+                                       maps.Add (imp.ImportTypeMapping (t));
                                        userTypes.Add (t);
-                                       if (verbose) Console.WriteLine (" - " + t);
+                                       if (verbose)
+                                               Console.WriteLine( " - " + t );
+                               } catch (InvalidOperationException ex) {
+                                       if (verbose)
+                                               Console.WriteLine (" - Warning: " + ex.Message);
+                               } catch (NotImplementedException ex) {
+                                       if (verbose) {
+                                               Console.WriteLine (" - Warning: ignoring '" + t + "'");
+                                               Console.WriteLine ("   " + ex.Message);
+                                       }
+                               } catch (NotSupportedException ex) {
+                                       if (verbose)
+                                               Console.WriteLine (" - Warning: " + ex.Message);
                                }
                        }
-                       catch (Exception ex)
-                       {
-                               if (verbose) {
-                                       Console.WriteLine (" - Warning: ignoring '" + t + "'");
-                                       Console.WriteLine ("   " + ex.Message);
+               } else {
+                       foreach (string type in types) {
+                               try {
+                                       Type t = asm.GetType (type);
+                                       maps.Add (imp.ImportTypeMapping (t));
+                                       userTypes.Add (t);
+                                       if (verbose)
+                                               Console.WriteLine (" - " + t);
+                               } catch (InvalidOperationException ex) {
+                                       if (verbose)
+                                               Console.WriteLine (" - Warning: " + ex.Message);
+                               } catch (NotImplementedException ex) {
+                                       if (verbose) {
+                                               Console.WriteLine (" - Warning: ignoring '" + type + "'");
+                                               Console.WriteLine ("   " + ex.Message);
+                                       }
+                               } catch (NotSupportedException ex) {
+                                       if (verbose)
+                                               Console.WriteLine (" - Warning: " + ex.Message);
                                }
                        }
                }
-               
+
                if (verbose)
                        Console.WriteLine ();
                        
@@ -139,31 +170,23 @@ public class Driver
                
                return 0;
        }
-#else
-       public int Run (string[] args)
-       {
-               Console.WriteLine ("This tool is only supported in Mono 2.0");
-               return 1;
-       }
-
-#endif
 
        void ParseArgs (string[] args)
        {
                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).ToLowerInvariant ();
+                       string param = (i < arg.Length - index) ? arg.Substring (i + 1) : "";
                        if (op == "assembly" || op == "a") {
                                assembly = param;
                        }
@@ -216,3 +239,4 @@ public class Driver
                }
        }
 }
+