| 1 | ?RCS: $Id$ |
| 2 | ?RCS: |
| 3 | ?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi |
| 4 | ?RCS: |
| 5 | ?RCS: You may redistribute only under the terms of the Artistic License, |
| 6 | ?RCS: as specified in the README file that comes with the distribution. |
| 7 | ?RCS: You may reuse parts of this distribution only within the terms of |
| 8 | ?RCS: that same Artistic License; a copy of which may be found at the root |
| 9 | ?RCS: of the source tree for dist 4.0. |
| 10 | ?RCS: |
| 11 | ?RCS: $Log: charorder.U,v $ |
| 12 | ?RCS: Revision 3.0.1.1 1994/10/29 16:07:08 ram |
| 13 | ?RCS: patch36: added ?F: line for metalint file checking |
| 14 | ?RCS: |
| 15 | ?RCS: Revision 3.0 1993/08/18 12:05:33 ram |
| 16 | ?RCS: Baseline for dist 3.0 netwide release. |
| 17 | ?RCS: |
| 18 | ?MAKE:chorder_int chorder_short chorder_long: Myread cat +cc +ccflags rm |
| 19 | ?MAKE: -pick add $@ %< |
| 20 | ?S:chorder_short (d_cos d_bos): |
| 21 | ?S: Holds the value describing the byte ordering of characters in a short. |
| 22 | ?S: On a Big-Endian machine, that would be "c0c1". |
| 23 | ?S:. |
| 24 | ?S:chorder_int (charoder): |
| 25 | ?S: Holds the value describing the byte ordering of characters in an int. |
| 26 | ?S: For instance, on a Big-Endian machine, this would be: "c0c1c2c3". |
| 27 | ?S:. |
| 28 | ?S:chorder_long (d_col d_bol): |
| 29 | ?S: Holds the value describing the byte ordering of characters in a long. |
| 30 | ?S: On a 64 bits Big-Endian machine, that would yield: "c0c1c2c3c4c5c6c7". |
| 31 | ?S:. |
| 32 | ?C:CHAR_ORDER_SHORT: |
| 33 | ?C: Holds the byte ordering of characters in a short. It's a string |
| 34 | ?C: value like "c0c1" on a Big-Endian machine. |
| 35 | ?C:. |
| 36 | ?C:CHAR_ORDER_INT: |
| 37 | ?C: Holds the byte ordering of characters in an int. It's a string |
| 38 | ?C: value like "c0c1c2c3" on a Big-Endian machine. |
| 39 | ?C:. |
| 40 | ?C:CHAR_ORDER_LONG: |
| 41 | ?C: Holds the byte ordering of characters in a long. It's a string |
| 42 | ?C: value like "c0c1c2c3c4c5c6c7" on a 64 bits Big-Endian machine. |
| 43 | ?C:. |
| 44 | ?H:#define CHAR_ORDER_SHORT "$chorder_short" /* byte order in a short */ |
| 45 | ?H:#define CHAR_ORDER_INT "$chorder_int" /* byte order in an int */ |
| 46 | ?H:#define CHAR_ORDER_LONG "$chorder_long" /* byte order in a long */ |
| 47 | ?H:. |
| 48 | ?F:!byteorder |
| 49 | : check for character ordering |
| 50 | echo " " |
| 51 | echo "Checking out byte order..." >&4 |
| 52 | $cat >byteorder.c <<'EOCP' |
| 53 | #include <stdio.h> |
| 54 | |
| 55 | main(argc, argv) |
| 56 | int argc; |
| 57 | char *argv[]; { |
| 58 | int i; |
| 59 | int max; |
| 60 | union { |
| 61 | short u_s; |
| 62 | int u_i; |
| 63 | long u_l; |
| 64 | char u_c[sizeof(long)]; |
| 65 | } u; |
| 66 | switch (argv[1][0]) { |
| 67 | case 'l': |
| 68 | u.u_l = 0L; |
| 69 | /* HMS: ASSERT: sizeof(long) < 10. */ |
| 70 | for(i = 0; i < sizeof(long); ++i) { |
| 71 | u.u_l *= 0x100L; |
| 72 | u.u_l += (0xc0 + i); |
| 73 | } |
| 74 | max = sizeof(long); |
| 75 | break; |
| 76 | case 's': |
| 77 | u.u_s = 0; |
| 78 | /* HMS: ASSERT: sizeof(short) < 10. */ |
| 79 | for(i = 0; i < sizeof(short); ++i) { |
| 80 | u.u_s *= 0x100L; |
| 81 | u.u_s += (0xc0 + i); |
| 82 | } |
| 83 | max = sizeof(short); |
| 84 | break; |
| 85 | case 'i': |
| 86 | u.u_i = 0; |
| 87 | /* RAM: ASSERT: sizeof(int) < 10. */ |
| 88 | for(i = 0; i < sizeof(int); ++i) { |
| 89 | u.u_l *= 0x100L; |
| 90 | u.u_l += (0xc0 + i); |
| 91 | } |
| 92 | max = sizeof(int); |
| 93 | break; |
| 94 | default: |
| 95 | max = 0; |
| 96 | break; |
| 97 | } |
| 98 | for(i = 0; i < max; i++) { |
| 99 | printf("%x", u.u_c[i] & 0x00FF); |
| 100 | } |
| 101 | printf("\n"); |
| 102 | exit(0); |
| 103 | } |
| 104 | EOCP |
| 105 | if $cc $ccflags -o byteorder byteorder.c >/dev/null 2>&1 ; then |
| 106 | : null statement |
| 107 | @if chorder_short |
| 108 | chorder_short=`./byteorder s` |
| 109 | @end |
| 110 | @if chorder_int |
| 111 | chorder_int=`./byteorder i` |
| 112 | @end |
| 113 | @if chorder_long |
| 114 | chorder_long=`./byteorder l` |
| 115 | @end |
| 116 | else |
| 117 | $cat <<EOM |
| 118 | (I can't seem to get my test program to work. Guessing 32 bits big-endian.) |
| 119 | EOM |
| 120 | chorder_short="c0c1" |
| 121 | chorder_int="c0c1c2c3" |
| 122 | chorder_long="c0c1c2c3" |
| 123 | fi |
| 124 | @if chorder_short |
| 125 | dflt=$chorder_short |
| 126 | rp='What is the order of characters in a short?' |
| 127 | . ./myread |
| 128 | chorder_short="$ans" |
| 129 | @end |
| 130 | @if chorder_int |
| 131 | dflt=$chorder_int |
| 132 | rp='What is the order of characters in an int?' |
| 133 | . ./myread |
| 134 | chorder_int="$ans" |
| 135 | @end |
| 136 | @if chorder_long |
| 137 | dflt=$chorder_long |
| 138 | rp='What is the order of characters in a long?' |
| 139 | . ./myread |
| 140 | chorder_long="$ans" |
| 141 | @end |
| 142 | $rm -f byteorder* core |
| 143 | |