Fix warning.
[mono.git] / mcs / gmcs / driver.cs
index 88b702164849f2ed01d3f056cf866574bdc12217..63d95d355c1fca7c30265f44e6ea8c372a90ff5b 100644 (file)
@@ -6,7 +6,7 @@
 // Licensed under the terms of the GNU GPL
 //
 // (C) 2001, 2002, 2003 Ximian, Inc (http://www.ximian.com)
-// (C) 2004 Novell, Inc
+// (C) 2004, 2005 Novell, Inc
 //
 
 namespace Mono.CSharp
@@ -94,6 +94,7 @@ namespace Mono.CSharp
                //
                // Encoding.
                //
+               static Encoding default_encoding;
                static Encoding encoding;
 
                static public void Reset ()
@@ -108,7 +109,7 @@ namespace Mono.CSharp
                        win32ResourceFile = win32IconFile = null;
                        defines = null;
                        output_file = null;
-                       encoding = null;
+                       encoding = default_encoding = null;
                        first_source = null;
                }
 
@@ -181,7 +182,15 @@ namespace Mono.CSharp
                        }
 
                        SeekableStreamReader reader = new SeekableStreamReader (input, encoding);
-                               
+
+                       // Check 'MZ' header
+                       if (reader.Read () == 77 && reader.Read () == 90) {
+                               Report.Error (2015, "Source file `{0}' is a binary file and not a text file", file.Name);
+                               input.Close ();
+                               return;
+                       }
+
+                       reader.Position = 0;
                        parser = new CSharpParser (reader, file, defines);
                        parser.ErrorOutput = Report.Stderr;
                        try {
@@ -210,7 +219,7 @@ namespace Mono.CSharp
                static void Usage ()
                {
                        Console.WriteLine (
-                               "Mono C# compiler, (C) 2001 - 2003 Ximian, Inc.\n" +
+                               "Mono C# compiler, (C) 2001 - 2005 Novell, Inc.\n" +
                                "mcs [options] source-files\n" +
                                "   --about            About the Mono C# compiler\n" +
                                "   -addmodule:MODULE  Adds the module to the generated assembly\n" + 
@@ -258,7 +267,7 @@ namespace Mono.CSharp
                static void About ()
                {
                        Console.WriteLine (
-                               "The Mono C# compiler is (C) 2001, 2002, 2003 Ximian, Inc.\n\n" +
+                               "The Mono C# compiler is (C) 2001-2005, Novell, Inc.\n\n" +
                                "The compiler source code is released under the terms of the GNU GPL\n\n" +
 
                                "For more information on Mono, visit the project Web site\n" +
@@ -270,9 +279,11 @@ namespace Mono.CSharp
 
                public static int counter1, counter2;
                
-       public static int Main (string[] args)
+               public static int Main (string[] args)
                {
                        RootContext.Version = LanguageVersion.Default;
+                       Location.InEmacs = Environment.GetEnvironmentVariable ("EMACS") == "t";
+
                        bool ok = MainDriver (args);
                        
                        if (ok && Report.Errors == 0) {
@@ -1296,12 +1307,12 @@ namespace Mono.CSharp
                                        encoding = new UTF8Encoding();
                                        break;
                                case "reset":
-                                       encoding = Encoding.Default;
+                                       encoding = default_encoding;
                                        break;
                                default:
                                        try {
                                                encoding = Encoding.GetEncoding (
-                                                       Int32.Parse (value));
+                                               Int32.Parse (value));
                                        } catch {
                                                Report.Error (2016, "Code page `{0}' is invalid or not installed", value);
                                        }
@@ -1309,11 +1320,15 @@ namespace Mono.CSharp
                                }
                                return true;
                        }
-                       //Report.Error (2007, String.Format ("Unrecognized command-line option: `{0}'", option));
-                       //Environment.Exit (1);
+
                        return false;
                }
                
+               static void Error_WrongOption (string option)
+               {
+                       Report.Error (2007, "Unrecognized command-line option: `{0}'", option);
+               }
+
                static string [] AddArgs (string [] args, string [] extra_args)
                {
                        string [] new_args;
@@ -1353,7 +1368,14 @@ namespace Mono.CSharp
                        int i;
                        bool parsing_options = true;
 
-                       encoding = Encoding.Default;
+                       try {
+                               // Latin1
+                               default_encoding = Encoding.GetEncoding (28591);
+                       } catch (Exception) {
+                               // iso-8859-1
+                               default_encoding = Encoding.GetEncoding (1252);
+                       }
+                       encoding = default_encoding;
 
                        references = new ArrayList ();
                        soft_references = new ArrayList ();
@@ -1417,10 +1439,19 @@ namespace Mono.CSharp
                                                string csc_opt = "/" + arg.Substring (1);
                                                if (CSCParseOption (csc_opt, ref args, ref i))
                                                        continue;
+
+                                               Error_WrongOption (arg);
+                                               return false;
                                        } else {
-                                               if (arg.StartsWith ("/")){
+                                               if (arg [0] == '/'){
                                                        if (CSCParseOption (arg, ref args, ref i))
                                                                continue;
+
+                                                       // Need to skip `/home/test.cs' however /test.cs is considered as error
+                                                       if (arg.Length < 2 || arg.IndexOf ('/', 2) == -1) {
+                                                               Error_WrongOption (arg);
+                                                               return false;
+                                                       }
                                                }
                                        }
                                }
@@ -1592,7 +1623,6 @@ namespace Mono.CSharp
                                if (CodeGen.Assembly.IsClsCompliant) {
                                AttributeTester.VerifyModulesClsCompliance ();
                                TypeManager.LoadAllImportedTypes ();
-                                       AttributeTester.VerifyTopLevelNameClsCompliance ();
                                }
                        }
                        if (Report.Errors > 0)
@@ -1634,7 +1664,7 @@ namespace Mono.CSharp
 
                                if (ep == null) {
                                        if (RootContext.MainClass != null) {
-                                               DeclSpace main_cont = RootContext.Tree.GetDecl (MemberName.FromDotted (RootContext.MainClass));
+                                               DeclSpace main_cont = RootContext.Tree.GetDecl (MemberName.FromDotted (RootContext.MainClass, Location.Null));
                                                if (main_cont == null) {
                                                        Report.Error (1555, "Could not find `{0}' specified for Main method", RootContext.MainClass); 
                                                        return false;