1 module x11.Xmd; 2 3 version(Posix): 4 5 //~ import std.string; 6 import std.conv; 7 import core.stdc.config; 8 9 import x11.Xtos; 10 11 extern (C) nothrow: 12 /* 13 * Xmd.d: MACHINE DEPENDENT DECLARATIONS. 14 */ 15 16 /* 17 * Special per-machine configuration flags. 18 */ 19 version( X86_64 ){ 20 enum bool LONG64 = true; /* 32/64-bit architecture */ 21 /* 22 * Stuff to handle large architecture machines; the constants were generated 23 * on a 32-bit machine and must correspond to the protocol. 24 */ 25 enum bool MUSTCOPY = true; 26 } else version(AArch64){ 27 enum bool LONG64 = true; /* aarch64 is well, 64 bit */ 28 enum bool MUSTCOPY = true; 29 } 30 else{ 31 enum bool LONG64 = false; 32 enum bool MUSTCOPY = false; 33 } 34 35 36 37 /* 38 * Definition of macro used to set constants for size of network structures; 39 * machines with preprocessors that can't handle all of the sz_ symbols 40 * can define this macro to be sizeof(x) if and only if their compiler doesn't 41 * pad out structures (esp. the xTextElt structure which contains only two 42 * one-byte fields). Network structures should always define sz_symbols. 43 * 44 * The sz_ prefix is used instead of something more descriptive so that the 45 * symbols are no more than 32 characters long (which causes problems for some 46 * compilers and preprocessors). 47 * 48 * The extra indirection is to get macro arguments to expand correctly before 49 * the concatenation, rather than afterward. 50 */ 51 //~ template _SIZEOF(T){ size_t _SIZEOF = T.sizeof; } 52 size_t _SIZEOF(T)(){ return T.sizeof; } 53 alias _SIZEOF SIZEOF; 54 55 /* 56 * Bitfield suffixes for the protocol structure elements, if you 57 * need them. Note that bitfields are not guaranteed to be signed 58 * (or even unsigned) according to ANSI C. 59 */ 60 version( X86_64 ){ 61 alias long INT64; 62 //~ # define B32 :32 63 //~ # define B16 :16 64 alias uint INT32; 65 alias uint INT16; 66 } else version(AArch64){ 67 alias long INT64; 68 //~ # define B32 :32 69 //~ # define B16 :16 70 alias uint INT32; 71 alias uint INT16; 72 } 73 else{ 74 //~ # define B32 75 //~ # define B16 76 static if( LONG64 ){ 77 alias c_long INT64; 78 alias int INT32; 79 } 80 else 81 alias c_long INT32; 82 alias short INT16; 83 } 84 85 alias byte INT8; 86 87 static if( LONG64 ){ 88 alias c_ulong CARD64; 89 alias uint CARD32; 90 } 91 else 92 alias c_ulong CARD32; 93 94 static if( !WORD64 && !LONG64 ) 95 alias ulong CARD64; 96 97 alias ushort CARD16; 98 alias byte CARD8; 99 100 alias CARD32 BITS32; 101 alias CARD16 BITS16; 102 103 alias CARD8 BYTE; 104 alias CARD8 BOOL; 105 106 /* 107 * definitions for sign-extending bitfields on 64-bit architectures 108 */ 109 static if( WORD64 ){ 110 template cvtINT8toInt(INT8 val) { const int cvtINT8toInt = cast(int) (val & 0x00000080) ? (val | 0xffffffffffffff00) : val; } 111 template cvtINT16toInt(INT16 val) { const int cvtINT16toInt = cast(int) (val & 0x00008000) ? (val | 0xffffffffffff0000) : val; } 112 template cvtINT32toInt(INT32 val) { const int cvtINT32toInt = cast(int) (val & 0x80000000) ? (val | 0xffffffff00000000) : val; } 113 template cvtINT8toShort(INT8 val) { const short cvtINT8toShort = cast(short) cvtINT8toInt(val); } 114 template cvtINT16toShort(INT16 val) { const short cvtINT16toShort = cast(short) cvtINT16toInt(val); } 115 template cvtINT32toShort(INT32 val) { const short cvtINT32toShort = cast(short) cvtINT32toInt(val); } 116 template cvtINT8toLong(INT8 val) { const c_long cvtINT8toLong = cast(c_long) cvtINT8toInt(val); } 117 template cvtINT16toLong(INT16 val) { const c_long cvtINT16toLong = cast(c_long) cvtINT16toInt(val); } 118 template cvtINT32toLong(INT32 val) { const c_long cvtINT32toLong = cast(c_long) cvtINT32toInt(val); } 119 } 120 else{ /* WORD64 and UNSIGNEDBITFIELDS */ 121 template cvtINT8toInt(INT8 val) { const int cvtINT8toInt = cast(int) val; } 122 template cvtINT16toInt(INT16 val) { const int cvtINT16toInt = cast(int) val; } 123 template cvtINT32toInt(INT32 val) { const int cvtINT32toInt = cast(int) val; } 124 template cvtINT8toShort(INT8 val) { const short cvtINT8toShort = cast(short) val; } 125 template cvtINT16toShort(INT16 val) { const short cvtINT16toShort = cast(short) val; } 126 template cvtINT32toShort(INT32 val) { const short cvtINT32toShort = cast(short) val; } 127 template cvtINT8toLong(INT8 val) { const c_long cvtINT8toLong = cast(c_long) val; } 128 template cvtINT16toLong(INT16 val) { const c_long cvtINT16toLong = cast(c_long) val; } 129 template cvtINT32toLong(INT32 val) { const c_long cvtINT32toLong = cast(c_long) val; } 130 } 131 132 133 134 static if( MUSTCOPY ){ 135 /* 136 * This macro must not cast or else pointers will get aligned and be wrong 137 */ 138 T NEXTPTR(T)(T p){ const T NEXTPTR = p + SIZEOF!(T); } 139 } 140 else{/* else not MUSTCOPY, this is used for 32-bit machines */ 141 /* 142 * this version should leave result of type (t *), but that should only be 143 * used when not in MUSTCOPY 144 */ 145 T NEXTPTR(T)(T p){ const T NEXTPTR = p + 1; } 146 }/* MUSTCOPY - used machines whose C structs don't line up with proto */