limit fstBC to 30bp in Python3 ver.
[GalaxyCodeBases.git] / c_cpp / etc / calc / endian.c
blob358e2704cb163f0e747e86da866183be8535abeb
1 /*
2 * endian - determine the byte order of a long on your machine
4 * Copyright (C) 1999-2013 Landon Curt Noll
6 * Calc is open software; you can redistribute it and/or modify it under
7 * the terms of the version 2.1 of the GNU Lesser General Public License
8 * as published by the Free Software Foundation.
10 * Calc is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
13 * Public License for more details.
15 * A copy of version 2.1 of the GNU Lesser General Public License is
16 * distributed with calc under the filename COPYING-LGPL. You should have
17 * received a copy with calc; if not, write to Free Software Foundation, Inc.
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * @(#) $Revision: 30.4 $
21 * @(#) $Id: endian.c,v 30.4 2013/05/05 13:57:08 chongo Exp $
22 * @(#) $Source: /usr/local/src/bin/calc/RCS/endian.c,v $
24 * Under source code control: 1993/11/15 04:32:58
25 * File existed as early as: 1993
27 * chongo <was here> /\oo/\ http://www.isthe.com/chongo/
28 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
32 * Big Endian: Amdahl, 68k, Pyramid, Mips, Sparc, ...
33 * Little Endian: Vax, 32k, Spim (Dec Mips), i386, i486, ...
37 #include <stdio.h>
39 #include "have_stdlib.h"
40 #if defined(HAVE_STDLIB_H)
41 #include <stdlib.h>
42 #endif
44 #include "have_unistd.h"
45 #if defined(HAVE_UNISTD_H)
46 #include <unistd.h>
47 #endif
49 /* byte order array */
50 char byte[8] = { (char)0x12, (char)0x36, (char)0x48, (char)0x59,
51 (char)0x01, (char)0x23, (char)0x45, (char)0x67 };
53 int
54 main(void)
56 /* pointers into the byte order array */
57 #if defined(DEBUG) || (!defined(BIG_ENDIAN) && !defined(BIG_ENDIAN))
58 int *intp = (int *)byte;
59 #endif
60 #if defined(DEBUG)
61 short *shortp = (short *)byte;
62 long *longp = (long *)byte;
64 printf("byte: %02x %02x %02x %02x %02x %02x %02x %02x\n",
65 byte[0], byte[1], byte[2], byte[3],
66 byte[4], byte[5], byte[6], byte[7]);
67 printf("short: %04x %04x %04x %04x\n",
68 shortp[0], shortp[1], shortp[2], shortp[3]);
69 printf("int: %08x %08x\n",
70 intp[0], intp[1]);
71 printf("long: %08x %08x\n",
72 longp[0], longp[1]);
73 #endif
75 /* Print the standard <machine/endian.h> defines */
76 printf("#undef BIG_ENDIAN\n");
77 printf("#define BIG_ENDIAN\t4321\n");
78 printf("#undef LITTLE_ENDIAN\n");
79 printf("#define LITTLE_ENDIAN\t1234\n");
80 printf("#undef CALC_BYTE_ORDER\n");
82 #if defined(BIG_ENDIAN)
83 printf("#define CALC_BYTE_ORDER\tBIG_ENDIAN\n");
84 #elif defined(LITTLE_ENDIAN)
85 printf("#define CALC_BYTE_ORDER\tLITTLW_ENDIAN\n");
86 #else
87 /* Determine byte order */
88 if (intp[0] == 0x12364859) {
89 /* Most Significant Byte first */
90 printf("#define CALC_BYTE_ORDER\tBIG_ENDIAN\n");
91 } else if (intp[0] == 0x59483612) {
92 /* Least Significant Byte first */
93 printf("#define CALC_BYTE_ORDER\tLITTLE_ENDIAN\n");
94 } else {
95 fprintf(stderr, "@=-=@ Fatal build error - cannot @=-=@\n");
96 fprintf(stderr, "@=-=@ determine byte order. Set @=-=@\n");
97 fprintf(stderr, "@=-=@ ${CALC_BYTE_ORDER} in the Makefile @=-=@\n");
98 fprintf(stderr, "@=-=@ to be either -DBIG_ENDIAN or @=-=@\n");
99 fprintf(stderr, "@=-=@ to be -DLITTLE_ENDIAN @=-=@\n");
100 exit(1);
102 #endif
103 /* exit(0); */
104 return 0;