endian_check.c
author matthijs
Thu, 16 Jun 2005 18:04:02 +0000
changeset 1942 c5d5cf5b0263
parent 1692 0b52df38cabc
child 2186 db48cf29b983
permissions -rw-r--r--
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
157
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
     1
#include <stdio.h>
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
     2
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
     3
// This pretty simple file checks if the system is LITTLE_ENDIAN or BIG_ENDIAN
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
     4
//  it does that by putting a 1 and a 0 in an array, and read it out as one
200
03b8104d1479 (svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents: 157
diff changeset
     5
//  number. If it is 1, it is LITTLE_ENDIAN, if it is 256, it is BIG_ENDIAN
157
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
     6
//
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
     7
// After that it outputs the contents of an include files (endian.h)
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
     8
//  that says or TTD_LITTLE_ENDIAN, or TTD_BIG_ENDIAN. Makefile takes
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
     9
//  care of the real writing to the file.
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    10
1692
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    11
int main (int argc, char *argv[]) {
157
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    12
  unsigned char EndianTest[2] = { 1, 0 };
1692
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    13
  int force_BE = 0, force_LE = 0;
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    14
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    15
  if (argc > 1 && strcmp(argv[1], "BE") == 0)
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    16
    force_BE = 1;
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    17
  if (argc > 1 && strcmp(argv[1], "LE") == 0)
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    18
    force_LE = 1;
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    19
157
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    20
  printf("#ifndef ENDIAN_H\n#define ENDIAN_H\n");
1692
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    21
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    22
  if ( (*(short *) EndianTest == 1 && force_BE != 1) || force_LE == 1)
157
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    23
    printf("#define TTD_LITTLE_ENDIAN\n");
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    24
  else
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    25
    printf("#define TTD_BIG_ENDIAN\n");
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    26
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    27
  printf("#endif\n");
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    28
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    29
  return 0;
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    30
}