Develop and Download Open Source Software

Browse CVS Repository

Contents of /jyugem/jyusecs/bee/bee.h

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (show annotations) (download) (as text)
Sat Aug 14 14:48:42 2004 UTC (19 years, 7 months ago) by fukasawa
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +9 -1 lines
File MIME type: text/x-chdr
メモリリークの解消。
接続モード(ACTIVE/PASSIVE)をパラメータで指定可能とした。
ダンプメッセージをVERBOSE_LITEモードで出力。

1 /* $Id: bee.h,v 1.9 2004/06/21 16:25:47 fukasawa Exp $ */
2
3 /**
4 * @file bee.h
5 *
6 * @author Fukasawa Mitsuo
7 *
8 *
9 * Copyright (C) 1998-2004 BEE Co.,Ltd. All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 */
25
26 #ifndef BEE_H
27 #define BEE_H
28
29 /*---------------------------------------------------------------------------*/
30 /* system header files */
31 /*---------------------------------------------------------------------------*/
32 #if defined(_DEBUG) && defined(WIN32) && defined(LEAK_CHECK)
33 #define _CRTDBG_MAP_ALLOC
34 #endif
35
36 #include <stdio.h> /* try not to #include stdio.h twice */
37 #include <stdlib.h>
38 #if defined(_DEBUG) && defined(WIN32) && defined(LEAK_CHECK)
39 #include <crtdbg.h>
40 #endif
41 #include <ctype.h>
42 #include <limits.h>
43 #ifdef _MSC_VER
44 #include <tchar.h>
45 #else
46 typedef char TCHAR;
47 #define _T(x) x
48
49 #define _stprintf sprintf
50 #define _stscanf scanf
51 #define _tcscat strcat
52 #define _tcschr strchr
53 #define _tcsstr strstr
54 #define _tcscmp strcmp
55 #define _tcscpy strcpy
56 #define _tcsdup strdup
57 #define _tcsftime strftime
58 #define _tcslen strlen
59 #define _tcsncpy strncpy
60 #define _tcsrchr strrchr
61 #define _tcstol strtol
62 #define _tcstoul strtoul
63 #define _tcstod strtod
64 #define _tprintf printf
65 #define _ttoi atoi
66 #define _vtprintf vprintf
67 #define _vstprintf vsprintf
68 #define _vsntprintf vsnprintf
69 #define _sntprintf snprintf
70
71 #endif
72
73 #ifdef __GNUC__
74 /* disable warning for undefined cuserid(); */
75 #ifndef __USE_XOPEN
76 #define __USE_XOPEN
77 #endif
78 #include <unistd.h>
79 #endif
80
81
82 /*****************************************************************************/
83 /* */
84 /* Symbol */
85 /* */
86 /*****************************************************************************/
87
88 /*---------------------------------------------------------------------------*/
89 /* Define data types */
90 /*---------------------------------------------------------------------------*/
91 #if !defined(_MSC_VER) && !defined(VOID)
92 #define VOID void
93 //typedef signed char CHAR;
94 typedef signed long LONG;
95 typedef signed short SHORT;
96 #endif
97
98 #ifndef NULL
99 #define NULL 0
100 #endif
101
102 #ifndef UCHAR
103 typedef signed int INT;
104 typedef unsigned char UCHAR;
105 typedef unsigned short USHORT;
106 typedef unsigned int UINT;
107 typedef unsigned char BYTE;
108 typedef unsigned short WORD;
109 typedef void * PTR;
110 #endif
111 #ifndef ULONG
112 typedef unsigned long ULONG;
113 #endif
114
115 #ifndef BOOLEAN
116 typedef unsigned char BOOLEAN;
117 typedef short SHORTINT;
118 typedef long LONGINT;
119 typedef unsigned short SHORTCARD;
120 typedef unsigned long LONGCARD;
121 typedef LONGCARD CARDINAL;
122 typedef double LONGREAL;
123 typedef LONGINT INTEGER;
124 typedef float REAL;
125 #endif
126
127 #ifdef uchar
128 typedef unsigned char uchar;
129 typedef unsigned char byte;
130 typedef unsigned short word;
131 typedef unsigned short ushort;
132 typedef unsigned int uint;
133 typedef unsigned long ulong;
134 #endif
135
136 #if _MSC_VER
137 typedef __int64 LONGLONG;
138 typedef unsigned __int64 ULONGLONG;
139 #elif __GNUC__
140 typedef long long LONGLONG;
141 typedef unsigned long long ULONGLONG;
142 #else
143 #error no support 64 bit data type; // LongLong ?
144 #endif
145
146 #ifdef BITSET
147 typedef unsigned long BITSET;
148 typedef char * ADDRESS;
149 typedef int (*PFI)(); /* pointer to function returning int */
150 typedef void (*PFV)(); /* pointer to function with no return*/
151
152 #endif
153
154 /*---------------------------------------------------------------------------*/
155 /* redefine global tokens */
156 /*---------------------------------------------------------------------------*/
157 #define GLOBAL
158 #ifndef EXTERN
159 #define EXTERN extern
160 #endif
161 #define PROTOTYPE extern
162
163 /*----------------------------------------------------------------------------*/
164 /* limit values */
165 /*----------------------------------------------------------------------------*/
166 #ifdef MSDOS
167 #define MAX_INT 32767
168 #define MAX_UINT 0xFFFF
169 #define MAX_INTSTR "32767"
170 #define MAX_UINTSTR "65535"
171 #else
172 #define MAX_INT 2147483647
173 #define MAX_UINT 0xFFFFFFFF
174 #define MAX_INTSTR "2147483647"
175 #define MAX_UINTSTR "4294967295"
176 #endif
177
178 #define MAX_SHORT 32767
179 #define MAX_LONG 2147483647
180 #define MAX_USHORT 0xFFFF
181 #define MAX_ULONG 0xFFFFFFFF
182 #define MAX_SHORTCARD 0xFFFF
183 #define MAX_LONGCARD 0xFFFFFFFF
184 #define MAX_SHORTSTR "32767"
185 #define MAX_LONGSTR "2147483647"
186 #define MAX_USHORTSTR "65535"
187 #define MAX_ULONGSTR "4294967295"
188 #define MIN_REAL ((REAL)1.40129846432481707e-45)
189 #define MAX_REAL ((REAL)3.40282346638528860e+38)
190 #define MIN_LONGREAL 4.94065645841246544e-324
191 #define MAX_LONGREAL 1.79769313486231470e+308
192 #define MAX_LLSTR "9223372036854775807"
193
194 /*****************************************************************************/
195 /* Define ASCII codes */
196 /*****************************************************************************/
197 #ifdef WIN32
198 #define DIR_SEPARATOR_STRING _TX("\\")
199 #define DIR_SEPARATOR_CHAR '\\'
200 #else
201 #define DIR_SEPARATOR_STRING _TX("/")
202 #define DIR_SEPARATOR_CHAR '/'
203 #endif
204
205 #define TAB '\t' /* C definition of ASCII tab */
206 #define NEWLINE '\n' /* C definition of ASCII newline */
207 #define BACKSPACE '\b' /* C definition of ASCII backspace */
208 #define SPACE ' ' /* white space character */
209
210 #define ESC 0x1B /* Standard definition ASCII escape */
211 #define BS 0x08 /* Standard definition ASCII backspace */
212 #define CR 0x0D /* Standard definition ASCII carriage return */
213 #define FF 0x0C /* Standard definition ASCII form feed */
214 #define BEL 0x07 /* Standard definition ASCII bell */
215 #define HT 0x09 /* Standard definition ASCII horizontal tab */
216 #define LF 0x0A /* Standard definition ASCII line feed */
217 #define VT 0x0B /* Standard definition ASCII virtical tab */
218 #define SUB 0x1A
219 #define RS 0x1E
220
221 /*****************************************************************************/
222 /* */
223 /* function macros */
224 /* */
225 /*****************************************************************************/
226
227 #ifndef max
228 #define max(a, b) ((a) >= (b) ? (a) : (b))
229 #endif
230 #ifndef min
231 #define min(a, b) ((a) <= (b) ? (a) : (b))
232 #endif
233 #ifndef Max
234 #define Max(a, b) ((a) >= (b) ? (a) : (b))
235 #endif
236 #ifndef Min
237 #define Min(a, b) ((a) <= (b) ? (a) : (b))
238 #endif
239 #if 0
240 #ifndef MAX
241 #define MAX(a, b) ((a) >= (b) ? (a) : (b))
242 #endif
243 #ifndef MIN
244 #define MIN(a, b) ((a) <= (b) ? (a) : (b))
245 #endif
246 #ifndef abs
247 #define abs(n) ((n) > 0 ? (n) : -(n))
248 #endif
249 #ifndef ABS
250 #define ABS(n) ((n) > 0 ? (n) : -(n))
251 #endif
252 #endif
253
254 /* word operation */
255 #define byte_high(a) (((a) >> 8) & 0x00FF)
256 #define byte_low(a) ((a) & 0x00FF)
257 #define HIGH(c) (((c) >> 8) & 0x00FF)
258 #define LOW(c) ((c) & 0x00FF)
259 #define high(c) (((c) >> 8) & 0x00FF)
260 #define low(c) ((c) & 0x00FF)
261 #define btow(h,l) (((WORD)((BYTE)(h)) << 8) | (BYTE)(l))
262
263 /* long word operation */
264 #define word_high(a) (((a) >> 16) & 0xFFFF)
265 #define word_low(a) ((a) & 0xFFFF)
266
267 /* convert byte and integer */
268 #ifdef _M_IX86
269 #define BUF_TO_SHORT(a,b) (((USHORT)(b) << 8) | ((USHORT)(a) & 0xFF))
270 #define SHORT_TO_BUF(w,a,b) (*((BYTE *)(b)) = ((USHORT)(w) >> 8) & 0xFF, \
271 *((BYTE *)(a)) = (USHORT)(w) & 0xFF)
272 #define BUF_TO_LONG(a,b,c,d) (((ULONG)(d) << 24) | (((ULONG)(c) << 16) & 0xFF0000) | \
273 (((ULONG)(b) << 8) & 0xFF00) | ((ULONG)(a) & 0xFF))
274 #define LONG_TO_BUF(l,a,b,c,d) (*((BYTE *)(d)) = (BYTE)((ULONG)(l) >> 24), \
275 *((BYTE *)(c)) = (BYTE)((ULONG)(l) >> 16), \
276 *((BYTE *)(b)) = (BYTE)((ULONG)(l) >> 8 ), \
277 *((BYTE *)(a)) = (BYTE)((ULONG)(l) & 0xFF))
278 #else
279 #define BUF_TO_SHORT(a,b) (((USHORT)(a) << 8) | ((USHORT)(b) & 0xFF))
280 #define SHORT_TO_BUF(w,a,b) (*((BYTE *)(a)) = (((USHORT)(w)) >> 8) & 0xFF, \
281 *((BYTE *)(b)) = ((USHORT)(w)) & 0xFF)
282 #define BUF_TO_LONG(a,b,c,d) (((ULONG)(a) << 24) | \
283 (((ULONG)(b) << 16) && 0xFF0000) | \
284 (((ULONG)(c) << 8) & 0xFF00) | ((ULONG)(d) & 0xFF))
285 #define LONG_TO_BUF(l,a,b,c,d) (*((BYTE *)(a)) = (BYTE)((ULONG)(l) >> 24), \
286 *((BYTE *)(b)) = (BYTE)((ULONG)(l) >> 16), \
287 *((BYTE *)(c)) = (BYTE)((ULONG)(l) >> 8), \
288 *((BYTE *)(d)) = (BYTE)((ULONG)(l) & 0xFF))
289 #endif
290
291 #define BUFPTR_TO_SHORT(p) BUF_TO_SHORT(*((BYTE *)p), *(((BYTE *)p)+1))
292 #define SHORT_TO_BUFPTR(l, p) SHORT_TO_BUF((l), ((BYTE *)p), (((BYTE *)p)+1))
293 #define BUFPTR_TO_LONG(p) BUF_TO_LONG(*(((BYTE *)p)+0), *(((BYTE *)p)+1), \
294 *(((BYTE *)p)+2), *(((BYTE *)p)+3))
295 #define LONG_TO_BUFPTR(l, p) LONG_TO_BUF((l), ((BYTE *)p), (((BYTE *)p)+1), \
296 (((BYTE *)p)+2), (((BYTE *)p)+3))
297
298 #define BCD_TO_BYTE(x) (((((x) >> 4) & 0xF) * 10) + ((x) & 0xF))
299 #define BCD_TO_SHORT(x) (((((x) >> 12) & 0xF) * 1000) + \
300 ((((x) >> 8) & 0xF) * 100) + \
301 ((((x) >> 4) & 0xF) * 10) + ((x) & 0xF))
302 #define BYTE_TO_BCD(x) (((((x) % 100) / 10) << 4) + ((x) % 10))
303 #define SHORT_TO_BCD(x) ((((x) / 1000) << 12) + \
304 ((((x) % 1000) / 100) << 8) + \
305 ((((x) % 100) / 10) << 4) + ((x) % 10))
306
307 /* check even and odd */
308 #define is_odd(x) ((x) & 1)
309 #define is_even(x) (!((x) & 1))
310 #define ODD(x) (((x) & 01))
311
312 #define bound_word(p) ((((p) + 1) / 2) * 2)
313 #define bound_long(p) ((((p) + 1) / 4) * 4)
314
315 #define EQUALSTR(s, c) ((*s == *c) && (strcmp(s, c) == 0))
316
317 /*---------------------------------------------------------------------------*/
318 /* define boolean */
319 /*---------------------------------------------------------------------------*/
320 #ifndef TRUE
321 #define TRUE 1
322 #endif
323 #ifndef FALSE
324 #define FALSE 0
325 #endif
326 #ifndef SUCCESS
327 #define SUCCESS 0
328 #endif
329
330 #ifndef OK
331 #define OK 0
332 #endif
333 #ifndef NG
334 #define NG 1
335 #endif
336
337 #ifndef YES
338 #define YES 1
339 #endif
340 #ifndef NO
341 #define NO 0
342 #endif
343
344 #ifndef ON
345 #define ON 1
346 #endif
347 #ifndef OFF
348 #define OFF 0
349 #endif
350
351 #ifndef FAILURE
352 #define FAILURE (-1)
353 #endif
354
355 #define BEE_SUCCESS 0
356 #define BEE_ERROR (-1)
357
358 #ifndef LOOP
359 #define LOOP for(;;)
360 #endif
361
362 #ifndef BIG_ENDIAN
363 #define BIG_ENDIAN 1234
364 #define LITTLE_ENDIAN 4321
365 #endif
366 #if defined(_M_IX86) || defined(__386__) || defined(i386)
367 #define ENDIAN LITTLE_ENDIAN
368 #else
369 #define ENDIAN BIG_ENDIAN
370 #endif
371
372 #endif /* BEE_H */

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26