This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
metaconfig unit change for #16099.
[metaconfig.git] / U / compline / charorder.U
CommitLineData
959f3c4c
JH
1?RCS: $Id: charorder.U,v 3.0.1.1 1994/10/29 16:07:08 ram Exp $
2?RCS:
3?RCS: Copyright (c) 1991-1993, Raphael Manfredi
4?RCS:
5?RCS: You may redistribute only under the terms of the Artistic Licence,
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 Licence; a copy of which may be found at the root
9?RCS: of the source tree for dist 3.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 Compile 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
50echo " "
51echo "Checking out byte order..." >&4
52$cat >byteorder.c <<'EOCP'
53#include <stdio.h>
54
55int 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}
104EOCP
105set byteorder
106if eval $compile_ok ; then
107 : null statement
108@if chorder_short
109 chorder_short=`./byteorder s`
110@end
111@if chorder_int
112 chorder_int=`./byteorder i`
113@end
114@if chorder_long
115 chorder_long=`./byteorder l`
116@end
117else
118 $cat <<EOM
119(I can't seem to get my test program to work. Guessing 32 bits big-endian.)
120EOM
121 chorder_short="c0c1"
122 chorder_int="c0c1c2c3"
123 chorder_long="c0c1c2c3"
124fi
125@if chorder_short
126dflt=$chorder_short
127rp='What is the order of characters in a short?'
128. ./myread
129chorder_short="$ans"
130@end
131@if chorder_int
132dflt=$chorder_int
133rp='What is the order of characters in an int?'
134. ./myread
135chorder_int="$ans"
136@end
137@if chorder_long
138dflt=$chorder_long
139rp='What is the order of characters in a long?'
140. ./myread
141chorder_long="$ans"
142@end
143$rm -f byteorder* core
144