Support colors on 256-color terminals
[mono.git] / mcs / tools / mono-xsd / NewMonoXSD.cs
index de7c0f992d3e81923383fda680faf5d9817e1b23..06879b37c3d37bc0a65127325c5f1990d9f5bff4 100644 (file)
@@ -78,9 +78,12 @@ namespace Mono.Util {
                        {\r
                                new Driver().Run (args);\r
                        }\r
-                       catch (Exception ex)\r
+                       catch (ApplicationException ex)\r
                        {\r
                                Console.WriteLine (ex.Message);\r
+                       }\r
+                       catch (Exception ex)\r
+                       {\r
                                Console.WriteLine (ex);\r
                        }\r
                }\r
@@ -118,7 +121,7 @@ namespace Mono.Util {
                                {\r
                                        if ((arg.EndsWith (".dll") || arg.EndsWith (".exe")) && !arg.Substring (1).StartsWith ("generator:") && !arg.Substring (1).StartsWith ("g:"))\r
                                        {\r
-                                               if (!readingFiles) throw new Exception (incorrectOrder);\r
+                                               if (!readingFiles) throw new ApplicationException (incorrectOrder);\r
                                                assemblies.Add (arg);\r
                                                assemblyOptions = true;\r
                                                continue;\r
@@ -207,6 +210,10 @@ namespace Mono.Util {
                                        Console.WriteLine (helpString);\r
                                        return;\r
                                }\r
+                               else if (option == "nologo")\r
+                               {\r
+                                       // ignore, since we do not output a logo anyway\r
+                               }\r
                                else\r
                                        Error (unknownOption, option);\r
                        }\r
@@ -374,7 +381,7 @@ namespace Mono.Util {
                        foreach (string fileName in schemaNames)\r
                        {\r
                                StreamReader sr = new StreamReader (fileName);\r
-                               schemas.Add (XmlSchema.Read (sr, null));\r
+                               schemas.Add (XmlSchema.Read (sr, new ValidationEventHandler (HandleValidationError)));\r
                                sr.Close ();\r
 \r
                                if (targetFile == "") targetFile = Path.GetFileNameWithoutExtension (fileName);\r
@@ -399,10 +406,10 @@ namespace Mono.Util {
                        else\r
                        {\r
                                foreach (XmlSchema schema in schemas) {\r
-                                       if (!schema.IsCompiled) schema.Compile (null);\r
-                                       foreach (XmlSchemaObject ob in schema.Items)\r
-                                               if (ob is XmlSchemaElement)\r
-                                                       qnames.Add (((XmlSchemaElement)ob).QualifiedName);\r
+                                       if (!schema.IsCompiled) schema.Compile (new ValidationEventHandler (HandleValidationError));\r
+                                       foreach (XmlSchemaElement el in schema.Elements.Values)\r
+                                               if (!qnames.Contains (el.QualifiedName))\r
+                                                       qnames.Add (el.QualifiedName);\r
                                }\r
                        }\r
 \r
@@ -472,14 +479,22 @@ namespace Mono.Util {
                        Console.WriteLine ("Written file " + genFile);\r
                }\r
 \r
+               void HandleValidationError (object o, ValidationEventArgs e)\r
+               {\r
+                       Console.WriteLine ("{0}: {1} {2}",\r
+                               e.Severity == XmlSeverityType.Error ? "Error" : "Warning",\r
+                               e.Message,\r
+                               e.Exception != null ? e.Exception.Message : null);\r
+               }\r
+\r
                public void Error (string msg)\r
                {\r
-                       throw new Exception (msg);\r
+                       throw new ApplicationException (msg);\r
                }\r
 \r
                public void Error (string msg, string param)\r
                {\r
-                       throw new Exception (string.Format(msg,param));\r
+                       throw new ApplicationException (string.Format(msg,param));\r
                }\r
 \r
                private string StripQuot (string input)\r