2002-09-06 Miguel de Icaza <miguel@ximian.com>
authorMiguel de Icaza <miguel@gnome.org>
Sat, 7 Sep 2002 00:17:26 +0000 (00:17 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Sat, 7 Sep 2002 00:17:26 +0000 (00:17 -0000)
* driver.cs: (CSCParseOption): Support the /codepage: option.

Make default code page Latin-1

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

mcs/mcs/cs-parser.jay
mcs/mcs/cs-tokenizer.cs
mcs/mcs/driver.cs

index 515115e1806671c5cfa8b3b423f6974e0e4184da..a1d1d7c5338c2ed51bc00d48c98ca0e2c10f5375 100755 (executable)
@@ -16,6 +16,7 @@
 //
 //
 using System.Text;
+using System.IO;
 using System;
 
 namespace Mono.CSharp
@@ -3862,17 +3863,16 @@ public Tokenizer Lexer {
        }
 }                 
 
-public CSharpParser (string name, System.IO.Stream input, ArrayList defines)
+public CSharpParser (StreamReader reader, string name, ArrayList defines)
 {
        current_namespace = new Namespace (null, "");
        this.name = name;
-       this.input = input;
        current_container = RootContext.Tree.Types;
        current_container.Namespace = current_namespace;
        oob_stack = new Stack ();
        switch_stack = new Stack ();
 
-       lexer = new Tokenizer (input, name, defines);
+       lexer = new Tokenizer (reader, name, defines);
 }
 
 public override void parse ()
index b75dc9a27ba27fa860573838f2253e09ed9ed954..565674018edf2c2c5635699acc10ee0f926b49a3 100755 (executable)
@@ -324,10 +324,11 @@ namespace Mono.CSharp
                        defines [def] = true;\r
                }\r
                \r
-               public Tokenizer (System.IO.Stream input, string fname, ArrayList defs)\r
+               public Tokenizer (StreamReader input, string fname, ArrayList defs)\r
                {\r
                        this.ref_name = fname;\r
-                       reader = new System.IO.StreamReader (input);\r
+                       reader = input;\r
+                       \r
                        putback_char = -1;\r
 \r
                        if (defs != null){\r
index d0abd8904c94436ceb364112e7676ddb9b13ddea..16aaaedfb15b7b00c4c2baf04afb008cee6dce28 100755 (executable)
@@ -89,6 +89,17 @@ namespace Mono.CSharp
                // Last time we took the time
                //
                static DateTime last_time, first_time;
+
+               //
+               // Encoding: ISO-Latin1 is 28591
+               //
+               static Encoding encoding = Encoding.GetEncoding (28591);
+
+               //
+               // Whether the user has specified a different encoder manually
+               //
+               static bool using_default_encoder = true;
+               
                public static void ShowTime (string msg)
                {
                        if (!timestamps)
@@ -129,7 +140,8 @@ namespace Mono.CSharp
                        }
 
                        using (input){
-                               Tokenizer lexer = new Tokenizer (input, input_file, defines);
+                               StreamReader reader = new StreamReader (input, encoding, using_default_encoder);
+                               Tokenizer lexer = new Tokenizer (reader, input_file, defines);
                                int token, tokens = 0, errors = 0;
 
                                while ((token = lexer.token ()) != Token.EOF){
@@ -157,7 +169,9 @@ namespace Mono.CSharp
                                return;
                        }
 
-                       parser = new CSharpParser (input_file, input, defines);
+                       StreamReader reader = new StreamReader (input, encoding, using_default_encoder);
+                               
+                       parser = new CSharpParser (reader, input_file, defines);
                        parser.yacc_verbose = yacc_verbose;
                        try {
                                parser.parse ();
@@ -175,6 +189,7 @@ namespace Mono.CSharp
                                "mcs [options] source-files\n" +
                                "   --about            About the Mono C# compiler\n" +
                                "   -checked[+|-]      Set default context to checked\n" +
+                               "   -codepage:ID       Sets code page to the one in ID (numer, `utf8' or `reset')" +
                                "   -define:S1[;S2]    Defines one or more symbols (short: /d:)\n" +
                                "   -debug[+-]         Generate debugging information\n" + 
                                "   -g                 Generate debugging information\n" +
@@ -1000,6 +1015,33 @@ namespace Mono.CSharp
                                RootContext.StdLib = true;
                                return true;
 
+                       case "/codepage":
+                               int cp = -1;
+
+                               if (value == "utf8")
+                                       cp = UTF8Encoding.WindowsCodePage;
+                               if (value == "reset"){
+                                       cp = 28591;
+                                       using_default_encoder = true;
+                               }
+                               
+                               try {
+                                       cp = Int32.Parse (value);
+                               } catch { }
+                               
+                               if (cp == -1){
+                                       Console.WriteLine ("Invalid code-page requested");
+                                       Usage ();
+                               }
+
+                               try {
+                                       encoding = Encoding.GetEncoding (cp);
+                                       using_default_encoder = false;
+                               } catch {
+                                       Console.WriteLine ("Code page: {0} not supported", cp);
+                               }
+                               return true;
+
                        }
                        return false;
                }