2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Purpose: define basic common types and macros
34 #if !defined(__TTYPE_H__)
41 /****** Common helper macros ***********************************************/
43 #if !defined(LONIBBLE)
44 #define LONIBBLE(b) ((BYTE)(b) & 0x0F)
46 #if !defined(HINIBBLE)
47 #define HINIBBLE(b) ((BYTE)(((WORD)(b) >> 4) & 0x0F))
51 #define LOBYTE(w) ((BYTE)(w))
54 #define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF))
58 #define LOWORD(d) ((WORD)(d))
61 #define HIWORD(d) ((WORD)((((DWORD)(d)) >> 16) & 0xFFFF))
64 #define LODWORD(q) ((q).u.dwLowDword)
65 #define HIDWORD(q) ((q).u.dwHighDword)
69 #if !defined(MAKEBYTE)
70 #define MAKEBYTE(ln, hn) ((BYTE)(((BYTE)(ln) & 0x0F) | ((BYTE)(hn) << 4)))
72 #if !defined(MAKEWORD)
73 #define MAKEWORD(lb, hb) ((WORD)(((BYTE)(lb)) | (((WORD)((BYTE)(hb))) << 8)))
75 #if !defined(MAKEDWORD)
76 #define MAKEDWORD(lw, hw) ((DWORD)(((WORD)(lw)) | (((DWORD)((WORD)(hw))) << 16)))
78 #if !defined(MAKEQWORD)
79 #define MAKEQWORD(ld, hd, pq) {pq->u.dwLowDword = ld; pq->u.dwHighDword = hd;}
82 #if !defined(MAKELONG)
83 #define MAKELONG(low, high) ((LONG)(((WORD)(low)) | (((DWORD)((WORD)(high))) << 16)))
88 // Bytes Reverse: big endian to little endian convert
90 #define REVWORD(w) ((WORD)( ((WORD)(w) >> 8) | ((WORD)(w) << 8) ))
92 #if !defined(REVDWORD)
93 #define REVDWORD(d) (MAKEDWORD(MAKEWORD(HIBYTE(HIWORD(d)),LOBYTE(HIWORD(d))),MAKEWORD(HIBYTE(LOWORD(d)),LOBYTE(LOWORD(d)))))
96 /* map to known network names */
98 #define ntohs(x) REVWORD(x)
99 #define ntohl(x) REVDWORD(x)
100 #define htons(x) REVWORD(x)
101 #define htonl(x) REVDWORD(x)
108 #define max(a,b) (((a) > (b)) ? (a) : (b))
111 #define min(a,b) (((a) < (b)) ? (a) : (b))
118 /****** Misc macros ********************************************************/
120 // get the field offset in the type(struct, class, ...)
121 #define OFFSET(type, field) ((int)(&((type NEAR*)1)->field)-1)
124 /* string equality shorthand */
125 #define STR_EQ(x, y) (strcmp(x, y) == 0)
126 #define STR_NE(x, y) (strcmp(x, y) != 0)
129 // calculate element # of array
130 #define ELEMENT_NUM(array) (sizeof(array) / sizeof(array[0]))
131 //#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
138 /* Since not all compilers support structure assignment, the ASSIGN()
139 * macro is used. This controls how it's actually implemented.
141 #ifdef NOSTRUCTASSIGN /* Version for old compilers that don't support it */
142 #define ASSIGN(a,b) memcpy((char *)&(a),(char *)&(b),sizeof(b);
143 #else /* Version for compilers that do */
144 #define ASSIGN(a,b) ((a) = (b))
150 #endif // __TMACRO_H__