Nilorea Library

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Macros Groups
n_common.h
Go to the documentation of this file.
1
8 #ifndef __COMMON_FOR_C_IMPLEMENTATION__
9 #define __COMMON_FOR_C_IMPLEMENTATION__
10
11 #ifdef __cplusplus
12 extern "C"
13 {
14 #endif
15
22 #define __EXTENSIONS__
23
24 /* common headers */
25 #include <errno.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <strings.h>
32 #include <ctype.h>
33 #include <malloc.h>
34 #include <math.h>
35 #include <time.h>
36 #include <dirent.h>
37 #include <unistd.h>
38 #include <sys/stat.h>
39 #include <sys/types.h>
40 #include <limits.h>
41
42 /* cross compability */
43 #if defined( LINUX ) || defined( SOLARIS ) || defined( AIX )
44
45 #include <sys/time.h>
46 #ifndef NOALLEGRO
47 #ifndef ALLEGRO_ALREADY_INCLUDED
48
49 #define ALLEGRO_ALREADY_INLUDED
50 #include <allegro.h>
51
53 FONT *allegro_font;
54 #endif
55 #endif
56 #ifdef LINUX
57 #include <linux/limits.h>
58 #include <pthread.h>
59 #endif
60
61 #else /* WIN32 */
62
63 #include <time.h>
64 #ifndef NOALLEGRO
65 #ifndef ALLEGRO_ALREADY_INCLUDED
66
67 #define ALLEGRO_ALREADY_INLUDED
68 #include <allegro.h>
69 #include <winalleg.h>
71 FONT *allegro_font;
72 #endif
73 #endif
74 #include <pthread.h>
75 /*#define opendir __mingw_opendir*/
76
77 #endif
78
80 #ifndef true
81 #define true (1==1)
82 #endif
83
85 #ifndef TRUE
86 #define TRUE true
87 #endif
88
90 #ifndef false
91 #define false (1==0)
92 #endif
93
95 #ifndef FALSE
96 #define FALSE false
97 #endif
98
100 #ifndef EMPTY
101 #define EMPTY 2
102 #endif
103
105 #define _str( __PTR ) ((__PTR)?(__PTR):"NULL")
106
107 #define _strw( __PTR ) ((__PTR)?(__PTR):"NULL")
108
109 #define _nstr( __PTR ) ((__PTR&&__PTR->data)?(__PTR->data):"NULL")
110
112 #define Malloc( __ptr , __struct , __size ) \
113 if ( !( __ptr = ( __struct *)calloc( __size , sizeof( __struct ) ) ) ) \
114 { \
115 n_log( LOG_ERR , "( %s *)malloc( %s * sizeof( %d ) ) Error at line %d of %s \n", #__ptr , #__struct , __size , __LINE__ , __FILE__); \
116 }
117
118 #define Free( __ptr )\
119 if ( __ptr )\
120 {\
121 free( __ptr );\
122 __ptr = NULL;\
123 }\
124 else\
125 {\
126 n_log( LOG_DEBUG , "Free( %s ) already done or NULL at line %d of %s \n", #__ptr , __LINE__ , __FILE__ );\
127 }
128
129 #define FreeNoLog( __ptr )\
130 if ( __ptr )\
131 {\
132 free( __ptr );\
133 __ptr = NULL;\
134 }
135
136
138 #define Realloc( __ptr, __struct , __size )\
139 if( !( __ptr = ( __struct *)realloc( __ptr , __size * sizeof( __struct ) ) ) )\
140 { \
141 n_log( LOG_ERR , "( %s *)malloc( %s * sizeof( %d ) ) Error at line %d of %s \n", #__ptr , #__struct , __size , __LINE__ , __FILE__);\
142 __ptr = NULL;\
143 }
144
146 #define Reallocz( __ptr, __struct , __old_size , __size )\
147 if ( !( __ptr = ( __struct *)realloc( __ptr , __size * sizeof( __struct ) ) ) )\
148 {\
149 n_log( LOG_ERR , "( %s *)malloc( %s * sizeof( %d ) ) Error at line %d of %s \n", #__ptr , #__struct , __size , __LINE__ , __FILE__);\
150 __ptr = NULL;\
151 }\
152 else\
153 {\
154 if( __size > __old_size )memset( ( __ptr + __old_size ) , 0 , __size - __old_size );\
155 }
156
158 #define _assert( __ptr , __ret ) \
159 if( !(__ptr) ) \
160 { \
161 n_log( LOG_DEBUG , "%s is NULL at line %d of %s" , #__ptr , __LINE__ , __FILE__ );\
162 __ret ; \
163 }
164
165
166
167
168 #if !defined( LINUX ) && !defined( SOLARIS )
169 /* typedefine for unsigned category for basic native types */
171 typedef unsigned int uint;
173 typedef unsigned long ulong;
175 typedef unsigned short ushort;
177 typedef unsigned char uchar;
178 #endif
179
180
182 #define SET 1234
183
184 #define GET 4321
185
186 #define DEFAULT 1000
187
188 #define RUNNING 1001
189
190 #define STOPWANTED 1002
191
192 #define STOPPED 1003
193
194 #define PAUSED 1004
195
197 #define randomize() { srand((unsigned)time(NULL)); rand(); }
198
199 #ifndef MIN
200
201 #define MIN(a,b) (((a)<(b))?(a):(b))
202 #endif
203 #ifndef MAX
204
205 #define MAX(a,b) (((a)>(b))?(a):(b))
206 #endif
207
209 typedef struct N_TIME
210 {
212 time_t delta;
213 #if !defined( LINUX ) && !defined( SOLARIS ) && !defined( AIX )
214
215 LARGE_INTEGER freq;
217 LARGE_INTEGER startTime;
219 LARGE_INTEGER currentTime;
220 #else
221
222 struct timeval startTime;
224 struct timeval currentTime;
225 #endif
226 } N_TIME;
227
228 /* for the 'press a key to continue' */
229 void PAUSE();
230
231 /* Init or restart from zero any N_TIME HiTimer */
232 int start_HiTimer( N_TIME *timer );
233
234 /* Poll any N_TIME HiTimer, returning usec */
235 time_t get_usec( N_TIME *timer );
236
237 /* Poll any N_TIME HiTimer, returning msec */
238 time_t get_msec( N_TIME *timer );
239
240 /* Poll any N_TIME HiTimer, returning sec */
241 time_t get_sec( N_TIME *timer );
242
243
244 #ifndef NOALLEGRO
245 /* Fill a keyboard buffer */
246 void get_keyboard( char *keybuf , int *cur , int min , int max );
247 #include "lexmenu.h"
248 #endif
249
252 #ifdef __cplusplus
253 }
254 #endif
255
256 #endif /* #ifndef __COMMON_FOR_C_IMPLEMENTATION__ */