From e24740f7ec39840c6a1fb450a19ad8724cdbdd59 Mon Sep 17 00:00:00 2001 From: Jim Richardson Date: Wed, 22 Aug 2001 08:44:07 +0000 Subject: [PATCH] Implemented additional functionality. Verified compilation. Added to appropriate .src files. svn path=/trunk/mcs/; revision=555 --- mcs/class/corlib/System/Environment.cs | 42 +++++++++++++++++----- mcs/class/corlib/System/OperatingSystem.cs | 25 +++++++------ mcs/class/corlib/System/PlatformID.cs | 6 +++- mcs/class/corlib/System/unix.src | 1 + mcs/class/corlib/System/windows.src | 1 + 5 files changed, 54 insertions(+), 21 deletions(-) diff --git a/mcs/class/corlib/System/Environment.cs b/mcs/class/corlib/System/Environment.cs index 6800e84ec51..104ef3c808f 100644 --- a/mcs/class/corlib/System/Environment.cs +++ b/mcs/class/corlib/System/Environment.cs @@ -85,8 +85,7 @@ namespace System public static string MachineName { get - { - // TODO: needs more research/work/thought + { // TODO: needs more research/work/thought return GetEnvironmentVariable("HOSTNAME"); } } @@ -98,7 +97,7 @@ namespace System { get { - return "\n"; + return PlatformSpecific.NewLine; } } @@ -114,7 +113,7 @@ namespace System } /// - /// Get a string containing a trace of the stack + /// Get StackTrace /// public static string StackTrace { @@ -131,7 +130,7 @@ namespace System { get { - return null; + return GetFolderPath(SpecialFolder.System); } } @@ -142,7 +141,7 @@ namespace System { get { - return 0; + return getTickCount(); } } @@ -232,15 +231,39 @@ namespace System /// public static string GetEnvironmentVariable(string variable) { - return null; + return getEnvironmentStrings()[variable]; } /// /// Return a set of all environment variables and their values /// - public static IDictionary GetEnvironmentVariables() + + public static IDictionary getEnvironmentStrings() { - return null; + // could cache these in a member variable, but that + // wouldn't be very safe because the environment is + // dyanamic ya know + string strEnv = getEnvironment(); + string[] arEnv = strEnv.Split('\t'); + string[] arStr; + Hashtable ht = new Hashtable(); + foreach(string str in arEnv) + { + arStr = str.Split('=', 2); + switch(arStr.Length) + { + case 1: + ht.Add(arStr[0], ""); + break; + case 2: + ht.Add(arStr[0], arStr[1]); + break; + default: + Debug.Assert(false); // this shouldn't happen + break; + } + } + return ht; } /// @@ -258,5 +281,6 @@ namespace System { return null; } + } } diff --git a/mcs/class/corlib/System/OperatingSystem.cs b/mcs/class/corlib/System/OperatingSystem.cs index f5d92202fae..bc5b0c4ccca 100644 --- a/mcs/class/corlib/System/OperatingSystem.cs +++ b/mcs/class/corlib/System/OperatingSystem.cs @@ -18,7 +18,7 @@ namespace System /// public sealed class OperatingSystem : ICloneable { - private PlatformID itsPlatform; + private System.PlatformID itsPlatform; private Version itsVersion; public OperatingSystem(PlatformID platform, Version version) @@ -28,14 +28,6 @@ namespace System throw new ArgumentNullException(); } - // the doc doesn't say this, but I would - //if(platform < minPlatform || platform >= maxPlatform) - //{ - // throw new ArgumentOutOfRangeException(); - // TODO: find out if C# has assertion mechanism - // isn't learning new languages fun? :) - //} - itsPlatform = platform; itsVersion = version; } @@ -86,7 +78,7 @@ namespace System /// Return hash code /// public override int GetHashCode() - { + { // this leave us enuf for 256 unique platforms which should suffice for a good while return ((int)itsPlatform << 24) | itsVersion.GetHashCode() >> 8; } @@ -95,7 +87,18 @@ namespace System /// public override string ToString() { - return itsPlatform.ToString() + ", " + itsVersion.ToString(); + string str; + + switch(itsPlatform) + { + case System.PlatformID.Win32NT: str = "Microsoft Windows NT"; break; + case System.PlatformID.Win32S: str = "Microsoft Win32S"; break; + case System.PlatformID.Win32Windows: str = "Microsoft Windows 98"; break; + case System.PlatformID.Linux86Redhat: str = "Redhat Linux"; break; + default: str = ""; break; + } + + return str + " " + itsVersion.ToString(); } } } diff --git a/mcs/class/corlib/System/PlatformID.cs b/mcs/class/corlib/System/PlatformID.cs index 599f9b1d153..8a8a6f0b52d 100644 --- a/mcs/class/corlib/System/PlatformID.cs +++ b/mcs/class/corlib/System/PlatformID.cs @@ -15,8 +15,12 @@ namespace System public enum PlatformID { // TODO: determine what definitions to incorporate // possibilities are quite varied + // my redhat example is just an idea that + // can / will be determined at a later date + // I chose Redhat as an ex since that is the distro I am familiar with Win32NT, Win32S, - Win32Windows + Win32Windows, + Linux86Redhat } } \ No newline at end of file diff --git a/mcs/class/corlib/System/unix.src b/mcs/class/corlib/System/unix.src index e69de29bb2d..88f35a4d7a5 100755 --- a/mcs/class/corlib/System/unix.src +++ b/mcs/class/corlib/System/unix.src @@ -0,0 +1 @@ +Unix.cs diff --git a/mcs/class/corlib/System/windows.src b/mcs/class/corlib/System/windows.src index e69de29bb2d..2b6f20dc9bf 100755 --- a/mcs/class/corlib/System/windows.src +++ b/mcs/class/corlib/System/windows.src @@ -0,0 +1 @@ +Windoze.cs -- 2.25.1