From 8f5e5726134ce5b4bd436b16f367796d851df553 Mon Sep 17 00:00:00 2001 From: Manoj Srivastava Date: Sun, 27 Apr 2014 17:54:01 -0700 Subject: Imported Upstream version 3.5-36 --- mcon/U/byteorder.U | 123 ++++++++++++++++++++--------------------------------- 1 file changed, 46 insertions(+), 77 deletions(-) (limited to 'mcon/U/byteorder.U') diff --git a/mcon/U/byteorder.U b/mcon/U/byteorder.U index a2242c5..8989838 100644 --- a/mcon/U/byteorder.U +++ b/mcon/U/byteorder.U @@ -1,99 +1,68 @@ -?RCS: $Id: byteorder.U 1 2006-08-24 12:32:52Z rmanfredi $ ?RCS: -?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi +?RCS: Copyright (c) 1991-1997, 2004-2006, 2012 Raphael Manfredi ?RCS: -?RCS: You may redistribute only under the terms of the Artistic Licence, +?RCS: You may redistribute only under the terms of the Artistic License, ?RCS: as specified in the README file that comes with the distribution. ?RCS: You may reuse parts of this distribution only within the terms of -?RCS: that same Artistic Licence; a copy of which may be found at the root +?RCS: that same Artistic License; a copy of which may be found at the root ?RCS: of the source tree for dist 4.0. ?RCS: -?RCS: $Log: byteorder.U,v $ -?RCS: Revision 3.0.1.2 1997/02/28 15:24:55 ram -?RCS: patch61: no longer ask the user if the test runs ok -?RCS: -?RCS: Revision 3.0.1.1 1994/10/29 16:02:58 ram -?RCS: patch36: added ?F: line for metalint file checking -?RCS: -?RCS: Revision 3.0 1993/08/18 12:05:28 ram -?RCS: Baseline for dist 3.0 netwide release. -?RCS: -?MAKE:byteorder: cat Myread Oldconfig Loc +cc +ccflags rm +?MAKE:byteorder: cat contains echo n c Myread Oldconfig Loc +cc +ccflags rm _o ?MAKE: -pick add $@ %< ?S:byteorder: ?S: This variable holds the byte order. In the following, larger digits ?S: indicate more significance. The variable byteorder is either 4321 -?S: on a big-endian machine, or 1234 on a little-endian, or 87654321 -?S: on a Cray ... or 3412 with weird order ! +?S: on a big-endian machine, or 1234 on a little-endian one. +?S: cannot figure it out. ?S:. ?C:BYTEORDER: -?C: This symbol hold the hexadecimal constant defined in byteorder, -?C: i.e. 0x1234 or 0x4321, etc... +?C: This symbol holds the hexadecimal constant defined in byteorder, +?C: i.e. 1234 for little-endian or 4321 for big-ending. ?C:. ?H:#define BYTEORDER 0x$byteorder /* large digits for MSB */ ?H:. -?T:xxx_prompt -?F:!try -: check for ordering of bytes in a long -case "$byteorder" in -'') - $cat <<'EOM' - -In the following, larger digits indicate more significance. A big-endian -machine like a Pyramid or a Motorola 680?0 chip will come out to 4321. A -little-endian machine like a Vax or an Intel 80?86 chip would be 1234. Other -machines may have weird orders like 3412. A Cray will report 87654321. If -the test program works the default is probably right. -I'm now running the test program... -EOM - $cat >try.c <<'EOCP' -#include -int main() -{ - int i; - union { - unsigned long l; - char c[sizeof(long)]; - } u; - - if (sizeof(long) > 4) - u.l = (0x08070605L << 32) | 0x04030201L; - else - u.l = 0x04030201L; - for (i = 0; i < sizeof(long); i++) - printf("%c", u.c[i]+'0'); - printf("\n"); - exit(0); -} +?T:order +: check for ordering of bytes in a word +?X: +?X: An idea from Guido Draheim checking the endianness +?X: without actually executing code, which allows cross-compiling. +?X: +echo " " +$echo $n "Checking integer byte-ordering...$c" >&4 +$cat >try.c <<'EOCP' +short ascii_be[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 }; +short ascii_le[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 }; +short ebcdic_be[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 }; +short ebcdic_le[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 }; EOCP - xxx_prompt=y - if $cc $ccflags -o try try.c >/dev/null 2>&1 && ./try > /dev/null; then - dflt=`./try` - case "$dflt" in - [1-4][1-4][1-4][1-4]|12345678|87654321) - echo "(The test program ran ok.)" - echo "byteorder=$dflt" - xxx_prompt=n - ;; - ????|????????) echo "(The test program ran ok.)" ;; - *) echo "(The test program didn't run right for some reason.)" ;; - esac +order='' +if $cc -c $ccflags try.c >/dev/null 2>&1; then + if $contains BIGenDianSyS try$_o >/dev/null 2>&1; then + order=4321 + elif $contains LiTTleEnDian try$_o >/dev/null 2>&1; then + order=1234 else - dflt='4321' - cat <<'EOM' -(I can't seem to compile the test program. Guessing big-endian...) -EOM + $echo $n " wild guessing$c" >&4 + order=4321 fi - case "$xxx_prompt" in - y) - rp="What is the order of bytes in a long?" - . ./myread - byteorder="$ans" - ;; - *) byteorder=$dflt - ;; +fi +case "$order" in +'') + echo " cannot compute it." >&4 + rp="Are integers stored in big-endian format?" + case "$byteorder" in + 1234) dflt=n;; + *) dflt=y;; + esac + . ./myread + case "$ans" in + y*) order=4321;; + *) order=1234;; esac ;; +1234) echo " little-endian." >&4;; +4321) echo " big-endian." >&4;; esac -$rm -f try.c try +byteorder=$order +$rm -f try.c try$_o -- cgit v1.2.3