/* %Z%%M%	%I% %E% Copyright 1997 J. Schilling */
#ifndef lint
static	char sccsid[] =
	"%Z%%M%	%I% %E% Copyright 1997 J. Schilling";
#endif
/*
 *	Copyright (c) 1997 J. Schilling
 */
/*@@C@@*/

#include <stdio.h>

#define	_LITTLE	"#define	_LITTLE_ENDIAN         /* Intel byte order */"
#define	_BIG	"#define	_BIG_ENDIAN            /* Motorola byte order */"

#define	_LTOH	"#define	_BIT_FIELDS_LTOH       /* Intel bit order */"
#define	_HTOL	"#define	_BIT_FIELDS_HTOL       /* Motorola bit order */"

union {
	char			c[4];
	int			i;
	long			l;
	struct {
		unsigned int	b1:4;
		unsigned int	b2:4;
		unsigned int	b3:4;
		unsigned int	b4:4;
		unsigned int	b5:4;
		unsigned int	b6:4;
		unsigned int	b7:4;
		unsigned int	b8:4;
	} bt;
} order;

main()
{
	order.c[0] = 0x12;
	order.c[1] = 0x34;
	order.c[2] = 0x56;
	order.c[3] = 0x78;


	printf("/*\n");
	printf(" * This file has been generated automatically\n");
	printf(" * by %s\n", sccsid);
	printf(" * do not edit by hand.\n");
	printf(" */\n");

	order.l = 0x12345678;

	if (order.c[0] == 0x12 && order.c[1] == 0x34 &&
			order.c[2] == 0x56 && order.c[3] == 0x78) {
		printf("%s\n", _BIG);

	} else if (order.c[0] == 0x78 && order.c[1] == 0x56 &&
			order.c[2] == 0x34 && order.c[3] == 0x12) {
		printf("%s\n", _LITTLE);
	} else {
		printf("c1: %x c2: %x c3: %x c4: %x\n",
			order.c[0], order.c[1], order.c[2], order.c[3]);
		printf("unknown byteorder\n");
	}

	order.c[0] = 0x12;
	order.c[1] = 0x12;
	order.c[2] = 0x12;
	order.c[3] = 0x12;

	if (order.bt.b1 == 0x1 && order.bt.b2 == 0x2) {
		printf("%s\n", _HTOL);

	} else 	if (order.bt.b1 == 0x2 && order.bt.b2 == 0x1) {
		printf("%s\n", _LTOH);
	} else {
		printf("bit order recognition problems\n");
	}
	return(0);
}
