19 #include <grass/Vect.h>
58 #define TEST_PATTERN 1.3333
59 #define LONG_TEST 0x01020304
60 #define INT_TEST 0x01020304
61 #define SHORT_TEST 0x0102
70 unsigned char c[PORT_DOUBLE];
75 static unsigned char dbl_cmpr[] =
76 { 0x3f, 0xf5, 0x55, 0x32, 0x61, 0x7c, 0x1b, 0xda };
78 static unsigned char flt_cmpr[] = { 0x3f, 0xaa, 0xa9, 0x93 };
79 static unsigned char lng_cmpr[] = { 0x01, 0x02, 0x03, 0x04 };
80 static unsigned char int_cmpr[] = { 0x01, 0x02, 0x03, 0x04 };
81 static unsigned char shrt_cmpr[] = { 0x01, 0x02 };
93 static int find_offset(
unsigned char *,
unsigned char,
int);
94 static int dumpflags(
void);
97 int main(
int argc,
char **argv)
105 printf(
"\n/* Native machine sizes */\n");
106 printf(
"#define NATIVE_DOUBLE %d\n", (
nat_dbl =
sizeof(
double)));
107 printf(
"#define NATIVE_FLOAT %d\n", (
nat_flt =
sizeof(
float)));
108 printf(
"#define NATIVE_LONG %d\n", (
nat_lng =
sizeof(
long)));
109 printf(
"#define NATIVE_INT %d\n", (
nat_int =
sizeof(
int)));
110 printf(
"#define NATIVE_SHORT %d\n", (
nat_shrt =
sizeof(
short)));
111 printf(
"#define NATIVE_CHAR %d\n", (nat_char =
sizeof(
char)));
116 fprintf(stderr,
"ERROR, sizeof (double) != %d\n", PORT_DOUBLE);
120 fprintf(stderr,
"ERROR, sizeof (float) != %d\n", PORT_DOUBLE);
124 fprintf(stderr,
"ERROR, sizeof (long) < %d\n", PORT_LONG);
128 fprintf(stderr,
"ERROR, sizeof (int) < %d\n", PORT_INT);
132 fprintf(stderr,
"ERROR, sizeof (short) < %d\n", PORT_SHORT);
135 if (nat_char != PORT_CHAR) {
136 fprintf(stderr,
"ERROR, sizeof (char) != %d\n", PORT_CHAR);
147 for (i = 0; i < PORT_DOUBLE; i++) {
148 tmp = find_offset(u.
c, dbl_cmpr[i], PORT_DOUBLE);
150 fprintf(stderr,
"ERROR, could not find '%x' in double\n",
157 for (i = 0; i < PORT_DOUBLE; i++) {
160 if (
dbl_cnvrt[i] != (PORT_DOUBLE - i - 1))
164 dbl_order = ENDIAN_BIG;
166 dbl_order = ENDIAN_LITTLE;
168 dbl_order = ENDIAN_OTHER;
172 for (i = 0; i < PORT_FLOAT; i++) {
173 tmp = find_offset(u.
c, flt_cmpr[i], PORT_FLOAT);
175 fprintf(stderr,
"ERROR, could not find '%x' in float\n",
182 for (i = 0; i < PORT_FLOAT; i++) {
185 if (
flt_cnvrt[i] != (PORT_FLOAT - i - 1))
189 flt_order = ENDIAN_BIG;
191 flt_order = ENDIAN_LITTLE;
193 flt_order = ENDIAN_OTHER;
197 for (i = 0; i < PORT_LONG; i++) {
198 tmp = find_offset(u.
c, lng_cmpr[i],
nat_lng);
200 fprintf(stderr,
"ERROR, could not find '%x' in long\n",
207 for (i = 0; i < PORT_LONG; i++) {
214 lng_order = ENDIAN_BIG;
216 lng_order = ENDIAN_LITTLE;
218 lng_order = ENDIAN_OTHER;
222 for (i = 0; i < PORT_INT; i++) {
223 tmp = find_offset(u.
c, int_cmpr[i],
nat_int);
225 fprintf(stderr,
"ERROR, could not find '%x' in int\n",
232 for (i = 0; i < PORT_INT; i++) {
239 int_order = ENDIAN_BIG;
241 int_order = ENDIAN_LITTLE;
243 int_order = ENDIAN_OTHER;
247 for (i = 0; i < PORT_SHORT; i++) {
248 tmp = find_offset(u.
c, shrt_cmpr[i],
nat_shrt);
250 fprintf(stderr,
"ERROR, could not find '%x' in shrt\n",
257 for (i = 0; i < PORT_SHORT; i++) {
264 shrt_order = ENDIAN_BIG;
266 shrt_order = ENDIAN_LITTLE;
268 shrt_order = ENDIAN_OTHER;
270 printf(
"\n/* Native machine byte orders */\n");
271 printf(
"#define DOUBLE_ORDER %d\n", dbl_order);
272 printf(
"#define FLOAT_ORDER %d\n", flt_order);
273 printf(
"#define LONG_ORDER %d\n", lng_order);
274 printf(
"#define INT_ORDER %d\n", int_order);
275 printf(
"#define SHORT_ORDER %d\n", shrt_order);
277 printf(
"\n\n/* Translation matrices from big endian to native */\n");
289 find_offset(
unsigned char *basis,
unsigned char search_value,
int size)
293 for (i = 0; i <
size; i++)
294 if (basis[i] == search_value)
301 static int dumpflags(
void)
305 fprintf(stdout,
"\n/* Double format: */\nstatic int dbl_cnvrt[] = {");
310 fprintf(stdout,
", ");
312 fprintf(stdout,
"};\n\n");
314 fprintf(stdout,
"/* Float format : */\nstatic int flt_cnvrt[] = {");
319 fprintf(stdout,
", ");
321 fprintf(stdout,
"};\n\n");
323 fprintf(stdout,
"/* Long format : */\nstatic int lng_cnvrt[] = {");
328 fprintf(stdout,
", ");
330 fprintf(stdout,
"};\n\n");
332 fprintf(stdout,
"/* Int format : */\nstatic int int_cnvrt[] = {");
337 fprintf(stdout,
", ");
339 fprintf(stdout,
"};\n\n");
341 fprintf(stdout,
"/* Short format : */\nstatic int shrt_cnvrt[] = {");
346 fprintf(stdout,
", ");
348 fprintf(stdout,
"};\n\n");
unsigned char lng_cnvrt[sizeof(long)]
int main(int argc, char *argv[])
unsigned char dbl_cnvrt[sizeof(double)]
unsigned char int_cnvrt[sizeof(int)]
unsigned char c[PORT_DOUBLE]
unsigned char shrt_cnvrt[sizeof(short)]
unsigned char flt_cnvrt[sizeof(float)]