X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=gmqcc.h;h=71873dc72ac53019c4673724706dfa2773cffe41;hp=fdcb56ba8a5efa4f1a5dfe0c313600c5b8e1954c;hb=c7a62970a6d6f69166730a4d1fa6c227e6b1c818;hpb=b360245b45856d709213a255af225c840cb08882 diff --git a/gmqcc.h b/gmqcc.h index fdcb56b..71873dc 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -139,6 +139,88 @@ # include #endif +/* + * Very roboust way at determining endianess at compile time: this handles + * almost every possible situation. Otherwise a runtime check has to be + * performed. + */ +#define GMQCC_BYTE_ORDER_LITTLE 1234 +#define GMQCC_BYTE_ORDER_BIG 4321 + +#if defined (__GNUC__) || defined (__GNU_LIBRARY__) +# if defined (__FreeBSD__) || defined (__OpenBSD__) +# include +# elif defined (BSD) && (BSD >= 199103) || defined (__DJGPP__) || defined (__CYGWIN32__) +# include +# elif defined (__APPLE__) +# if defined (__BIG_ENDIAN__) && !defined(BIG_ENDIAN) +# define BIG_ENDIAN +# elif defined (__LITTLE_ENDIAN__) && !defined (LITTLE_ENDIAN) +# define LITTLE_ENDIAN +# endif +# elif !defined (__MINGW32__) +# include +# if !defined (__BEOS__) +# include +# endif +# endif +#endif +#if !defined(PLATFORM_BYTE_ORDER) +# if defined (LITTLE_ENDIAN) || defined (BIG_ENDIAN) +# if defined (LITTLE_ENDIAN) && !defined(BIG_ENDIAN) +# define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE +# elif !defined (LITTLE_ENDIAN) && defined (BIG_ENDIAN) +# define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG +# elif defined (BYTE_ORDER) && (BYTE_ORDER == LITTLE_ENDIAN) +# define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE +# elif defined (BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN) +# define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG +# endif +# elif defined (_LITTLE_ENDIAN) || defined (_BIG_ENDIAN) +# if defined (_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) +# define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE +# elif !defined (_LITTLE_ENDIAN) && defined (_BIG_ENDIAN) +# define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG +# elif defined (_BYTE_ORDER) && (_BYTE_ORDER == _LITTLE_ENDIAN) +# define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE +# elif defined (_BYTE_ORDER) && (_BYTE_ORDER == _BIG_ENDIAN) +# define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG +# endif +# elif defined (__LITTLE_ENDIAN__) || defined (__BIG_ENDIAN__) +# if defined (__LITTLE_ENDIAN__) && !defined (__BIG_ENDIAN__) +# define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE +# elif !defined (__LITTLE_ENDIAN__) && defined (__BIG_ENDIAN__) +# define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG +# elif defined (__BYTE_ORDER__) && (__BYTE_ORDER__ == __LITTLE_ENDIAN__) +# define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE +# elif defined (__BYTE_ORDER__) && (__BYTE_ORDER__ == __BIG_ENDIAN__) +# define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG +# endif +# endif +#endif +#if !defined (PLATFORM_BYTE_ORDER) +# if defined (__aplha__) || defined (__aplha) || defined (i386) || \ + defined (__i386__) || defined (_M_I86) || defined (_M_IX86) || \ + defined (__OS2__) || defined (sun386) || defined (__TURBOC__) || \ + defined (vax) || defined (vms) || defined (VMS) || \ + defined (__VMS) || defined (__x86_64__) || defined (_M_IA64) || \ + defined (_M_X64) || defined (__i386) || defined (__x86_64) +# define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE +# elif defined (AMIGA) || defined (applec) || defined (__AS400__) || \ + defined (_CRAY) || defined (__hppa) || defined (__hp9000) || \ + defined (ibm370) || defined (mc68000) || defined (m68k) || \ + defined (__MRC__) || defined (__MVS__) || defined (__MWERKS__) || \ + defined (sparc) || defined (__sparc) || defined (SYMANTEC_C) || \ + defined (__TANDEM) || defined (THINK_C) || defined (__VMCMS__) || \ + defined (__PPC__) || defined (__PPC) || defined (PPC) +# define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG +# else +# define PLATFORM_BYTE_ORDER -1 +# endif +#endif + + + /*===================================================================*/ /*=========================== util.c ================================*/ /*===================================================================*/ @@ -160,7 +242,7 @@ char *util_strsws (const char *); char *util_strchp (const char *, const char *); void util_debug (const char *, const char *, ...); int util_getline (char **, size_t *, FILE *); -void util_endianswap (void *, int, int); +void util_endianswap (void *, size_t, unsigned int); size_t util_strtocmd (const char *, char *, size_t); size_t util_strtononcmd (const char *, char *, size_t); @@ -290,7 +372,6 @@ enum { #define CV_WRONG 0x8000 extern const char *type_name [TYPE_COUNT]; -extern size_t type_sizeof [TYPE_COUNT]; extern uint16_t type_store_instr [TYPE_COUNT]; extern uint16_t field_store_instr[TYPE_COUNT]; @@ -826,9 +907,10 @@ typedef struct { longbit bit; } opts_flag_def; -bool opts_setflag (const char *, bool); -bool opts_setwarn (const char *, bool); -bool opts_setoptim(const char *, bool); +bool opts_setflag (const char *, bool); +bool opts_setwarn (const char *, bool); +bool opts_setwerror(const char *, bool); +bool opts_setoptim (const char *, bool); void opts_init (const char *, int, size_t); void opts_set (uint32_t *, size_t, bool);