~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/endian_check.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: endian_check.cpp 10684 2007-07-25 00:16:30Z rubidium $ */
 
1
/* $Id: endian_check.cpp 13571 2008-06-18 21:19:04Z smatz $ */
2
2
 
3
3
/** @file endian_check.cpp
4
4
 * This pretty simple file checks if the system is LITTLE_ENDIAN or BIG_ENDIAN
12
12
#include <stdio.h>
13
13
#include <string.h>
14
14
 
 
15
/** Supported endian types */
 
16
enum Endian {
 
17
        ENDIAN_LITTLE, ///< little endian
 
18
        ENDIAN_BIG     ///< big endian
 
19
};
 
20
 
 
21
/**
 
22
 * Shortcut to printf("#define TTD_ENDIAN TTD_*_ENDIAN")
 
23
 * @param endian endian type to define
 
24
 */
 
25
static inline void printf_endian(Endian endian)
 
26
{
 
27
        printf("#define TTD_ENDIAN %s\n", endian == ENDIAN_LITTLE ? "TTD_LITTLE_ENDIAN" : "TTD_BIG_ENDIAN");
 
28
}
 
29
 
15
30
/**
16
31
 * Main call of the endian_check program
17
32
 * @param argc argument count
30
45
        printf("#ifndef ENDIAN_H\n#define ENDIAN_H\n");
31
46
 
32
47
        if (force_LE == 1) {
33
 
                printf("#define TTD_LITTLE_ENDIAN\n");
 
48
                printf_endian(ENDIAN_LITTLE);
34
49
        } else if (force_BE == 1) {
35
 
                printf("#define TTD_BIG_ENDIAN\n");
 
50
                printf_endian(ENDIAN_BIG);
36
51
        } else if (force_PREPROCESSOR == 1) {
37
52
                /* Support for universal binaries on OSX
38
53
                 * Universal binaries supports both PPC and x86
39
54
                 * If a compiler for OSX gets this setting, it will always pick the correct endian and no test is needed
40
55
                 */
41
56
                printf("#ifdef __BIG_ENDIAN__\n");
42
 
                printf("#define TTD_BIG_ENDIAN\n");
 
57
                printf_endian(ENDIAN_BIG);
43
58
                printf("#else\n");
44
 
                printf("#define TTD_LITTLE_ENDIAN\n");
 
59
                printf_endian(ENDIAN_LITTLE);
45
60
                printf("#endif\n");
46
61
        } else if (*(short*)endian_test == 1 ) {
47
 
                printf("#define TTD_LITTLE_ENDIAN\n");
 
62
                printf_endian(ENDIAN_LITTLE);
48
63
        } else {
49
 
                printf("#define TTD_BIG_ENDIAN\n");
 
64
                printf_endian(ENDIAN_BIG);
50
65
        }
51
66
        printf("#endif\n");
52
67