OSDN Git Service

Add atoffset macro
[hengband/hengband.git] / src / h-define.h
1 /* File: h-define.h */
2
3 #ifndef INCLUDED_H_DEFINE_H
4 #define INCLUDED_H_DEFINE_H
5
6 /*
7  * Define some simple constants
8  */
9
10
11 /*
12  * Hack -- Define NULL
13  */
14 #ifndef NULL
15 # ifdef __STDC__
16 #  define NULL ((void*)0)
17 # else
18 #  define NULL ((char*)0)
19 # endif /* __STDC__ */
20 #endif /* NULL */
21
22
23 /*
24  * Hack -- assist "main-acn.c" XXX XXX XXX
25  */
26 #ifdef ACORN
27 # define O_RDONLY       0
28 # define O_WRONLY       1
29 # define O_RDWR         2
30 #endif
31
32
33 /*
34  * Hack -- force definitions -- see fd_seek()
35  */
36 #ifndef SEEK_SET
37 # define SEEK_SET       0
38 #endif
39 #ifndef SEEK_CUR
40 # define SEEK_CUR       1
41 #endif
42 #ifndef SEEK_END
43 # define SEEK_END       2
44 #endif
45
46 /*
47  * Hack -- force definitions -- see fd_lock()  XXX XXX XXX
48  */
49 #ifndef F_UNLCK
50 # define F_UNLCK        0
51 #endif
52 #ifndef F_RDLCK
53 # define F_RDLCK        1
54 #endif
55 #ifndef F_WRLCK
56 # define F_WRLCK        2
57 #endif
58
59
60 /*
61  * The constants "TRUE" and "FALSE"
62  */
63
64 #undef TRUE
65 #define TRUE    1
66
67 #undef FALSE
68 #define FALSE   0
69
70
71
72
73 /**** Simple "Macros" ****/
74
75 #ifdef ZANGBAND_JP
76 #define lbtokg(x) ((int)(((x)*4536)/1000))
77 #define lbtokg1(x) ((lbtokg(x)+5)/100)
78 #define lbtokg2(x) ( ( (lbtokg(x)+5)%100)/10) 
79 #elif defined(JP)
80 #define lbtokg(x) ((int)((x)*5))
81 #define lbtokg1(x) (lbtokg(x)/100)
82 #define lbtokg2(x) ((lbtokg(x)%100)/10) 
83 #endif
84 /*
85  * Force a character to lowercase/uppercase
86  */
87 #define FORCELOWER(A)  ((isupper((A))) ? tolower((A)) : (A))
88 #define FORCEUPPER(A)  ((islower((A))) ? toupper((A)) : (A))
89
90
91 /*
92  * Non-typed minimum value macro
93  */
94 #undef MIN
95 #define MIN(a,b)        (((a) > (b)) ? (b)  : (a))
96
97 /*
98  * Non-typed maximum value macro
99  */
100 #undef MAX
101 #define MAX(a,b)        (((a) < (b)) ? (b)  : (a))
102
103 /*
104  * Non-typed absolute value macro
105  */
106 #undef ABS
107 #define ABS(a)          (((a) < 0)   ? (-(a)) : (a))
108
109 /*
110  * Non-typed sign extractor macro
111  */
112 #undef SGN
113 #define SGN(a)          (((a) < 0)   ? (-1) : ((a) != 0))
114
115
116 /*
117  * Hack -- allow use of "ASCII" and "EBCDIC" for "indexes", "digits",
118  * and "Control-Characters".
119  *
120  * Note that all "index" values must be "lowercase letters", while
121  * all "digits" must be "digits".  Control characters can be made
122  * from any legal characters.  XXX XXX XXX
123  */
124 #ifdef VM
125 #  define A2I(X)        alphatoindex(X)
126 #  define I2A(X)        indextoalpha(X)
127 #  define D2I(X)        ((X) - '0')
128 #  define I2D(X)        ((X) + '0')
129 #  define KTRL(X)       ((X) & 0x1F)
130 #  define ESCAPE        '\033'
131 #else
132 #  define A2I(X)        ((X) - 'a')
133 #  define I2A(X)        ((X) + 'a')
134 #  define D2I(X)        ((X) - '0')
135 #  define I2D(X)        ((X) + '0')
136 #  define KTRL(X)       ((X) & 0x1F)
137 #  define ESCAPE        '\033'
138 #endif
139
140 /*
141  * Refer to the member at offset of structure
142  */
143 #define atoffset(TYPE, STRUCT_PTR, OFFSET) (*(TYPE*)(((char*)STRUCT_PTR) + (OFFSET)))
144
145 #endif
146