static DateTime last_time, first_time;
//
- // Encoding: ISO-Latin1 is 28591
+ // Encoding.
//
+ static Encoding defaultEncoding;
static Encoding encoding;
- //
- // Whether the user has specified a different encoder manually
- //
- static bool using_default_encoder = true;
-
static public void Reset ()
{
win32ResourceFile = win32IconFile = null;
defines = null;
output_file = null;
- encoding = null;
- using_default_encoder = true;
+ encoding = defaultEncoding = null;
first_source = null;
}
}
using (input){
- SeekableStreamReader reader = new SeekableStreamReader (input, encoding, using_default_encoder);
+ SeekableStreamReader reader = new SeekableStreamReader (input, encoding);
Tokenizer lexer = new Tokenizer (reader, file, defines);
int token, tokens = 0, errors = 0;
return;
}
- SeekableStreamReader reader = new SeekableStreamReader (input, encoding, using_default_encoder);
-
+ 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 {
public static int counter1, counter2;
- public static int Main (string[] args)
+ public static int Main (string[] args)
{
+ Location.InEmacs = Environment.GetEnvironmentVariable ("EMACS") == "t";
+
bool ok = MainDriver (args);
if (ok && Report.Errors == 0) {
return true;
case "/codepage":
- int cp = -1;
-
- if (value == "utf8"){
+ switch (value) {
+ case "utf8":
encoding = new UTF8Encoding();
- using_default_encoder = false;
- return true;
- }
- if (value == "reset"){
- //
- // 28591 is the code page for ISO-8859-1 encoding.
- //
- cp = 28591;
- using_default_encoder = true;
- }
-
- try {
- cp = Int32.Parse (value);
- encoding = Encoding.GetEncoding (cp);
- using_default_encoder = false;
- } catch {
- Report.Error (2016, "Code page `{0}' is invalid or not installed", value);
+ break;
+ case "reset":
+ encoding = defaultEncoding;
+ break;
+ default:
+ try {
+ encoding = Encoding.GetEncoding (
+ Int32.Parse (value));
+ } catch {
+ Report.Error (2016, "Code page `{0}' is invalid or not installed", value);
+ }
+ break;
}
return true;
}
bool parsing_options = true;
try {
- encoding = Encoding.GetEncoding (28591);
- } catch {
- Console.WriteLine ("Error: could not load encoding 28591, trying 1252");
- encoding = Encoding.GetEncoding (1252);
+ // Latin1
+ defaultEncoding = Encoding.GetEncoding (28591);
+ } catch (Exception) {
+ // iso-8859-1
+ defaultEncoding = Encoding.GetEncoding (1252);
}
-
+ encoding = defaultEncoding;
+
references = new ArrayList ();
soft_references = new ArrayList ();
modules = new ArrayList ();
if (CodeGen.Assembly.IsClsCompliant) {
AttributeTester.VerifyModulesClsCompliance ();
TypeManager.LoadAllImportedTypes ();
- AttributeTester.VerifyTopLevelNameClsCompliance ();
}
}
if (Report.Errors > 0)