Skip to content

Commit

Permalink
Merge pull request #186 from jmdavis/system
Browse files Browse the repository at this point in the history
Adjustments to std.system.
  • Loading branch information
andralex committed Sep 4, 2011
2 parents 4c8cbd2 + a447bf8 commit 0764204
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 76 deletions.
8 changes: 4 additions & 4 deletions std/format.d
Expand Up @@ -1004,8 +1004,8 @@ if (isIntegral!T)
{
// raw write, skip all else and write the thing
auto begin = cast(const char*) &arg;
if (std.system.endian == Endian.LittleEndian && fs.flPlus
|| std.system.endian == Endian.BigEndian && fs.flDash)
if (std.system.endian == Endian.littleEndian && f.flPlus
|| std.system.endian == Endian.bigEndian && f.flDash)
{
// must swap bytes
foreach_reverse (i; 0 .. arg.sizeof)
Expand Down Expand Up @@ -1135,8 +1135,8 @@ if (isFloatingPoint!D)
{
// raw write, skip all else and write the thing
auto begin = cast(const char*) &obj;
if (std.system.endian == Endian.LittleEndian && fs.flPlus
|| std.system.endian == Endian.BigEndian && fs.flDash)
if (std.system.endian == Endian.littleEndian && f.flPlus
|| std.system.endian == Endian.bigEndian && f.flDash)
{
// must swap bytes
foreach_reverse (i; 0 .. obj.sizeof)
Expand Down
12 changes: 6 additions & 6 deletions std/stream.d
Expand Up @@ -2195,8 +2195,8 @@ enum BOM {
private enum int NBOMS = 5;
immutable Endian[NBOMS] BOMEndian =
[ std.system.endian,
Endian.LittleEndian, Endian.BigEndian,
Endian.LittleEndian, Endian.BigEndian
Endian.littleEndian, Endian.bigEndian,
Endian.littleEndian, Endian.bigEndian
];

immutable ubyte[][NBOMS] ByteOrderMarks =
Expand Down Expand Up @@ -2425,7 +2425,7 @@ class EndianStream : FilterStream {
unittest {
MemoryStream m;
m = new MemoryStream ();
EndianStream em = new EndianStream(m,Endian.BigEndian);
EndianStream em = new EndianStream(m,Endian.bigEndian);
uint x = 0x11223344;
em.write(x);
assert( m.data[0] == 0x11 );
Expand All @@ -2440,7 +2440,7 @@ class EndianStream : FilterStream {
em.position(0);
static ubyte[12] x3 = [1,2,3,4,5,6,7,8,9,10,11,12];
em.fixBO(x3.ptr,12);
if (std.system.endian == Endian.LittleEndian) {
if (std.system.endian == Endian.littleEndian) {
assert( x3[0] == 12 );
assert( x3[1] == 11 );
assert( x3[2] == 10 );
Expand All @@ -2452,7 +2452,7 @@ class EndianStream : FilterStream {
assert( x3[10] == 2 );
assert( x3[11] == 1 );
}
em.endian = Endian.LittleEndian;
em.endian = Endian.littleEndian;
em.write(x);
assert( m.data[0] == 0x44 );
assert( m.data[1] == 0x33 );
Expand All @@ -2464,7 +2464,7 @@ class EndianStream : FilterStream {
assert( m.data[1] == 0x55 );
em.position(0);
em.fixBO(x3.ptr,12);
if (std.system.endian == Endian.BigEndian) {
if (std.system.endian == Endian.bigEndian) {
assert( x3[0] == 12 );
assert( x3[1] == 11 );
assert( x3[2] == 10 );
Expand Down
112 changes: 46 additions & 66 deletions std/system.d
@@ -1,91 +1,71 @@
// Written in the D programming language.

/**
* Information about the target operating system, environment, and CPU
* Information about the target operating system, environment, and CPU.
*
* Macros:
* WIKI = Phobos/StdSystem
*
* Copyright: Copyright Digital Mars 2000 - 2009.
* License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
* Authors: $(WEB digitalmars.com, Walter Bright)
* Source: $(PHOBOSSRC std/_system.d)
*/
/* Copyright Digital Mars 2000 - 2009.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
* Copyright: Copyright Digital Mars 2000 - 2011
* License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
* Authors: $(WEB digitalmars.com, Walter Bright) and Jonathan M Davis
* Source: $(PHOBOSSRC std/_system.d)
*/
module std.system;

const
immutable
{
/++
Operating system.
// Operating system family
enum Family
{
Win32 = 1, // Microsoft 32 bit Windows systems
linux, // all linux systems
OSX,
}
Note:
This is for cases where you need a value representing the OS at
runtime. If you're doing something which should compile differently
on different OSes, then please use $(D version(Win32)),
$(D version(linux)), etc.
version (Win32)
{
Family family = Family.Win32;
}
else version (Posix)
{
Family family = Family.linux;
}
else version (OSX)
{
Family family = Family.OSX;
}
else
See_Also:
<a href="../version.html#PredefinedVersions">Predefined Versions</a>
+/
enum OS
{
static assert(0);
win32 = 1, /// Microsoft 32 bit Windows systems
linux, /// All Linux Systems
osx, /// Mac OS X
freeBSD, /// FreeBSD
solaris, /// Solaris
otherPosix /// Other Posix Systems
}

// More specific operating system name
enum OS
{
Windows95 = 1,
Windows98,
WindowsME,
WindowsNT,
Windows2000,
WindowsXP,
/// The OS that the program was compiled for.
version(Win32) OS os = OS.win32;
else version(linux) OS os = OS.linux;
else version(OSX) OS os = OS.osx;
else version(FreeBSD) OS os = OS.freeBSD;
else version(Posix) OS os = OS.otherPosix;
else static assert(0, "Unknown OS.");

RedHatLinux,
OSX,
}
/++
Byte order endianness.
/// Byte order endianness
Note:
This is intended for cases where you need to deal with endianness at
runtime. If you're doing something which should compile differently
depending on whether you're compiling on a big endian or little
endian machine, then please use $(D version(BigEndian)) and
$(D version(LittleEndian)).
See_Also:
<a href="../version.html#PredefinedVersions">Predefined Versions</a>
+/
enum Endian
{
BigEndian, /// big endian byte order
LittleEndian /// little endian byte order
bigEndian, /// Big endian byte order
littleEndian /// Little endian byte order
}

version(LittleEndian)
{
/// Native system endianness
Endian endian = Endian.LittleEndian;
}
else
{
Endian endian = Endian.BigEndian;
}
/// The endianness that the program was compiled for.
version(LittleEndian) Endian endian = Endian.littleEndian;
else Endian endian = Endian.bigEndian;
}

// The rest should get filled in dynamically at runtime

OS os = OS.WindowsXP;

// Operating system version as in
// os_major.os_minor
uint os_major = 4;
uint os_minor = 0;


0 comments on commit 0764204

Please sign in to comment.