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 //~ # define B32 :32 57 //~ # define B16 :16 58 alias uint INT32; 59 alias uint INT16; 60 } 61 else{ 62 //~ # define B32 63 //~ # define B16 64 static if( LONG64 ){ 65 alias c_long INT64; 66 alias int INT32; 67 } 68 else 69 alias c_long INT32; 70 alias short INT16; 71 } 72 73 alias byte INT8; 74 75 static if( LONG64 ){ 76 alias c_ulong CARD64; 77 alias uint CARD32; 78 } 79 else 80 alias c_ulong CARD32; 81 82 static if( !WORD64 && !LONG64 ) 83 alias ulong CARD64; 84 85 alias ushort CARD16; 86 alias byte CARD8; 87 88 alias CARD32 BITS32; 89 alias CARD16 BITS16; 90 91 alias CARD8 BYTE; 92 alias CARD8 BOOL; 93 94 /* 95 * definitions for sign-extending bitfields on 64-bit architectures 96 */ 97 static if( WORD64 ){ 98 template cvtINT8toInt(INT8 val) { const int cvtINT8toInt = cast(int) (val & 0x00000080) ? (val | 0xffffffffffffff00) : val; } 99 template cvtINT16toInt(INT16 val) { const int cvtINT16toInt = cast(int) (val & 0x00008000) ? (val | 0xffffffffffff0000) : val; } 100 template cvtINT32toInt(INT32 val) { const int cvtINT32toInt = cast(int) (val & 0x80000000) ? (val | 0xffffffff00000000) : val; } 101 template cvtINT8toShort(INT8 val) { const short cvtINT8toShort = cast(short) cvtINT8toInt(val); } 102 template cvtINT16toShort(INT16 val) { const short cvtINT16toShort = cast(short) cvtINT16toInt(val); } 103 template cvtINT32toShort(INT32 val) { const short cvtINT32toShort = cast(short) cvtINT32toInt(val); } 104 template cvtINT8toLong(INT8 val) { const c_long cvtINT8toLong = cast(c_long) cvtINT8toInt(val); } 105 template cvtINT16toLong(INT16 val) { const c_long cvtINT16toLong = cast(c_long) cvtINT16toInt(val); } 106 template cvtINT32toLong(INT32 val) { const c_long cvtINT32toLong = cast(c_long) cvtINT32toInt(val); } 107 } 108 else{ /* WORD64 and UNSIGNEDBITFIELDS */ 109 template cvtINT8toInt(INT8 val) { const int cvtINT8toInt = cast(int) val; } 110 template cvtINT16toInt(INT16 val) { const int cvtINT16toInt = cast(int) val; } 111 template cvtINT32toInt(INT32 val) { const int cvtINT32toInt = cast(int) val; } 112 template cvtINT8toShort(INT8 val) { const short cvtINT8toShort = cast(short) val; } 113 template cvtINT16toShort(INT16 val) { const short cvtINT16toShort = cast(short) val; } 114 template cvtINT32toShort(INT32 val) { const short cvtINT32toShort = cast(short) val; } 115 template cvtINT8toLong(INT8 val) { const c_long cvtINT8toLong = cast(c_long) val; } 116 template cvtINT16toLong(INT16 val) { const c_long cvtINT16toLong = cast(c_long) val; } 117 template cvtINT32toLong(INT32 val) { const c_long cvtINT32toLong = cast(c_long) val; } 118 } 119 120 121 122 static if( MUSTCOPY ){ 123 /* 124 * This macro must not cast or else pointers will get aligned and be wrong 125 */ 126 T NEXTPTR(T)(T p){ const T NEXTPTR = p + SIZEOF!(T); } 127 } 128 else{/* else not MUSTCOPY, this is used for 32-bit machines */ 129 /* 130 * this version should leave result of type (t *), but that should only be 131 * used when not in MUSTCOPY 132 */ 133 T NEXTPTR(T)(T p){ const T NEXTPTR = p + 1; } 134 }/* MUSTCOPY - used machines whose C structs don't line up with proto */