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