spBase
読み取り中…
検索中…
一致する文字列を見つけられません
spDefs.h
[詳解]
1
4#ifndef __SPDEFS_H
5#define __SPDEFS_H
6
7#if defined(_WIN32)
8#define _USE_MATH_DEFINES
9#endif
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14#include <math.h>
15
16#if defined(_WIN32) && defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
17/*#define _CRTDBG_MAP_ALLOC*/
18#include <crtdbg.h>
19#endif
20
21#if defined(ANDROID)
22#include <android/log.h>
23#include <endian.h>
24#elif defined(__APPLE__) && defined(__MACH__)
25#include <TargetConditionals.h>
26#include <AvailabilityMacros.h>
27#endif
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
36 /*----@addtogroup spDefsGroup----*/
37
38#define SPB_VERSION_STRING "0.8.24"
39#define SPB_VERSION 0
40#define SPB_REVISION 8
41#define SPB_UPDATE_LEVEL 24
42#define SPB_VERSION_ID (SPB_VERSION * 1000 + SPB_REVISION)
43
49#define SPB_CHECK_VERSION(version, revision, update) \
50 (SPB_VERSION > (version) || \
51 (SPB_VERSION == (version) && SPB_REVISION > (revision)) || \
52 (SPB_VERSION == (version) && SPB_REVISION == (revision) && SPB_UPDATE_LEVEL >= (update)))
53
54typedef int (*spMainFunc)(int argc, char *argv[]);
55
56#if defined(__CYGWIN__)
57#if !defined(_WIN32_IE)
58#define _WIN32_IE 0x0400
59#endif
60#if !defined(_WIN32)
61#define _WIN32
62#endif
63#if !defined(__CYGWIN32__)
64#define __CYGWIN32__
65#endif
66#endif
67
68#if (TARGET_RT_MAC_MACHO || defined(__APPLE__)) && !defined(MACOSX)
69#define MACOSX
70#endif
71
72#if defined(MACOSX)
73#if !defined(IPHONE)
74#if (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) || (defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR)
75#define IPHONE 1
76#endif
77#endif /* !defined(IPHONE) */
78
79#if !defined(IPHONE) && !defined(__LP64__) && !defined(COCOA)
80#ifndef TARGET_API_MAC_CARBON
81#define TARGET_API_MAC_CARBON 1
82#endif
83#endif /* !defined(IPHONE) && !defined(__LP64__) && !defined(COCOA) */
84#ifndef MACOS
85#define MACOS
86#endif
87#ifndef powerc
88#define powerc 1
89#endif
90#if defined(__LP64__) && !defined(MACOSX64)
91#define MACOSX64
92#endif
93#ifndef HAVE_PTHREAD
94#define HAVE_PTHREAD
95#endif
96#endif /* defined(MACOSX) */
97
98#ifndef MACOS
99#if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || defined(__MRC__) ||\
100 defined(THINK_C) || defined(__SC__) || (defined(TARGET_OS_MAC) && TARGET_OS_MAC == 1)
101#define MACOS
102#if !defined(powerc) && defined(__MRC__)
103#define powerc 1
104#endif
105#endif
106#endif
107
108#if defined(MACOS) && !defined(MACOSX)
109#define MACOS9
110#ifndef TARGET_API_MAC_CARBON
111#define TARGET_API_MAC_CARBON 0
112#endif
113#endif /* defined(MACOS) && !defined(MACOSX) */
114
115#if TARGET_API_MAC_CARBON
116#ifndef HIGH_LEVEL_EVENT
117#define HIGH_LEVEL_EVENT
118#endif
119#endif
120
121#if defined(__CYGWIN32__) || defined(__MINGW32__) || (!defined(_WIN32) && !defined(MACOS9)) || defined(ANDROID)
122#define SP_SUPPORT_UTF8_STRING
123#endif
124
125#ifndef __P
126#if __STDC__
127#define __P(args) args
128#else
129#define __P(args) ()
130#endif
131#endif
132
133/* spLong: 32bit on 32bit platform, 64bit on 64bit platform */
134#if defined(_WIN64)
135#if defined(__MINGW64__) || defined(__CYGWIN64__)
136#define spLong long long
137#define spULong unsigned long long
138#else /* defined(__MINGW64__) || defined(__CYGWIN64__) */
139#define spLong __int64
140#define spULong unsigned __int64
141#endif /* !(defined(__MINGW64__) || defined(__CYGWIN64__)) */
142#else /* defined(_WIN64) */
143#define spLong long
144#define spULong unsigned long
145#endif /* !defined(_WIN64) */
146
147#if defined(_WIN32) && !(defined(__CYGWIN32__) || defined(__MINGW32__))
148#define SP_SUPPORT_64BIT_INT
149#define spLong64 __int64
150#define spULong64 unsigned __int64
151#elif defined(MACOS9)
152#if TYPE_LONGLONG
153#define SP_SUPPORT_64BIT_INT
154#define spLong64 SInt64
155#define spULong64 UInt64
156#endif
157#else /* defined(MACOS9) */
158#define SP_SUPPORT_64BIT_INT
159#define spLong64 long long
160#define spULong64 unsigned long long
161#endif /* !defined(MACOS9) */
162
163#if defined(__alpha__) || defined(__alpha) || defined(__LP64__) || defined(__ia64__) || \
164 defined(__s390x__) || defined(__ppc64__) || defined(__x86_64__)
165#define spLong32 int
166#define spULong32 unsigned int
167#define SP_LONG32_IS_INT
168#else
169#define spLong32 long
170#define spULong32 unsigned long
171#define SP_LONG32_IS_LONG
172#endif
173
189#if defined(_WIN32)
190#define spLONG spLong32
191#define spULONG spULong32
192#else /* defined(_WIN32) */
193/* internal format */
194#define spLONG long
195#define spULONG unsigned long
196#endif /* !defined(_WIN32) */
197#define spDWORD spULONG
198#define spINT8 signed char
199#define spINT16 short
200#define spBYTE unsigned char
201#define spWORD unsigned short
202
203#if defined(_WIN32) && !defined(__CYGWIN32__)
204#define spFileOffset __int64
205#elif defined(HAVE_FSEEKO)
206#define spFileOffset off_t
207#else
208#define spFileOffset long
209#endif
210
211#if defined(_WIN32) && !defined(__CYGWIN32__)
212#if defined(_MSC_VER) && (_MSC_VER >= 1400/*VS2005*/)
213#define HAVE_VSPRINTF_S 1
214#define HAVE_SPRINTF_S 1
215#define HAVE_FOPEN_S 1
216#define HAVE_STRCPY_S 1
217#define HAVE_STRCAT_S 1
218#define HAVE_STRNCPY_S 1
219#define HAVE_STRNCAT_S 1
220#define HAVE_SPLITPATH_S 1
221#define HAVE_DUPENV_S 1
222#define HAVE_SSCANF_S 1
223#endif
224#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L/*C99*/)
225#define HAVE_VSNPRINTF 1
226#define HAVE_SNPRINTF 1
227#endif
228
229#if defined(sun) && !defined(HAVE_MEMCPY)
230#define memmove(dst,src,len) bcopy((char *)(src),(char *)(dst),(int)(len))
231#define memcpy(dst,src,len) bcopy((char *)(src),(char *)(dst),(int)(len))
232#define memcmp(b1,b2,len) bcmp((char *)(b1),(char *)(b2),(int)(len))
233#endif
234
235#define SP_MAX_NAME 128
236#define SP_MAX_LINE 192
237#define SP_MAX_PATHNAME 256
238#define SP_MAX_MESSAGE 1024
239#define SP_MAX_IE_URL 2084
240#define SP_MAX_SUFFIX_SIZE 8
241#define SP_MAX_LANGUAGE 32 /* for locale */
242#define SP_EPSILON /*1.0e-10*/2.2204460492503131e-016
243#define SP_TINY_NUMBER 1.0e-10
244#define SP_EPSILONF /*1.0e-10f*/1.192092896e-07f
245#define SP_TINY_NUMBERF 1.0e-10f
246
248typedef int spBool;
249
250#define SP_TRUE 1
251#define SP_FALSE 0
252#define SP_TRUE_STRING "1"
253#define SP_FALSE_STRING "0"
255#define SP_ON SP_TRUE
256#define SP_OFF SP_FALSE
257#define SP_SUCCESS 1
258#define SP_FAILURE 0
259#define SP_EXIT_SUCCESS 0
260#define SP_EXIT_FAILURE 1
261
262#define SP_UNIX_DEFAULT_PATH_LIST "/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:~/bin"
263#define SP_UNIX_DEFAULT_LIBRARY_PATH_LIST "/usr/lib:/usr/local/lib:~/lib"
264#define SP_UNIX_DEFAULT_SHARE_PATH_LIST "/usr/share:/usr/local/share:~/share"
265#define SP_BROWSER_COMMAND_ENV "SP_BROWSER"
266
267#define SP_WIN_DIR_SEPARATOR '\\'
268#define SP_WIN_DIR_SEPARATOR_STRING "\\"
269#define SP_UNIX_DIR_SEPARATOR '/'
270#define SP_UNIX_DIR_SEPARATOR_STRING "/"
271#define SP_MAC_DIR_SEPARATOR ':'
272#define SP_MAC_DIR_SEPARATOR_STRING ":"
273
274#define SP_WIN_PARENT_DIR_STRING ".."
275#define SP_WIN_CURRENT_DIR_STRING "."
276#define SP_UNIX_PARENT_DIR_STRING ".."
277#define SP_UNIX_CURRENT_DIR_STRING "."
278#define SP_MAC_PARENT_DIR_STRING "::"
279#define SP_MAC_CURRENT_DIR_STRING ":"
280
281#define SP_WIN_SEPARATED_PARENT_DIR_STRING "..\\"
282#define SP_WIN_SEPARATED_CURRENT_DIR_STRING ".\\"
283#define SP_UNIX_SEPARATED_PARENT_DIR_STRING "../"
284#define SP_UNIX_SEPARATED_CURRENT_DIR_STRING "./"
285#define SP_MAC_SEPARATED_PARENT_DIR_STRING "::"
286#define SP_MAC_SEPARATED_CURRENT_DIR_STRING ":"
287
292#if defined(_WIN32)
293#if !defined(__CYGWIN32__)
294#define SP_DIR_SEPARATOR SP_WIN_DIR_SEPARATOR
295#define SP_DIR_SEPARATOR_STRING SP_WIN_DIR_SEPARATOR_STRING
296#define SP_PARENT_DIR_STRING SP_WIN_PARENT_DIR_STRING
297#define SP_CURRENT_DIR_STRING SP_WIN_CURRENT_DIR_STRING
298#define SP_SEPARATED_PARENT_DIR_STRING SP_WIN_SEPARATED_PARENT_DIR_STRING
299#define SP_SEPARATED_CURRENT_DIR_STRING SP_WIN_SEPARATED_CURRENT_DIR_STRING
300#define SP_ANOTHER_DIR_SEPARATOR SP_UNIX_DIR_SEPARATOR
301#define SP_ANOTHER_DIR_SEPARATOR_STRING SP_UNIX_DIR_SEPARATOR_STRING
302#else
303#define SP_DIR_SEPARATOR SP_UNIX_DIR_SEPARATOR
304#define SP_DIR_SEPARATOR_STRING SP_UNIX_DIR_SEPARATOR_STRING
305#define SP_PARENT_DIR_STRING SP_UNIX_PARENT_DIR_STRING
306#define SP_CURRENT_DIR_STRING SP_UNIX_CURRENT_DIR_STRING
307#define SP_SEPARATED_PARENT_DIR_STRING SP_UNIX_SEPARATED_PARENT_DIR_STRING
308#define SP_SEPARATED_CURRENT_DIR_STRING SP_UNIX_SEPARATED_CURRENT_DIR_STRING
309#define SP_ANOTHER_DIR_SEPARATOR SP_WIN_DIR_SEPARATOR
310#define SP_ANOTHER_DIR_SEPARATOR_STRING SP_WIN_DIR_SEPARATOR_STRING
311#endif
312
313#define SP_DEFAULT_DIRECTORY "c:"
314#define SP_PATHLIST_SEPARATOR ';'
315
316#define SP_DEFAULT_LF_STRING "\r\n"
317
318#elif defined(MACOS9)
319
320#define SP_DIR_SEPARATOR SP_MAC_DIR_SEPARATOR
321#define SP_DIR_SEPARATOR_STRING SP_MAC_DIR_SEPARATOR_STRING
322#define SP_PARENT_DIR_STRING SP_MAC_PARENT_DIR_STRING
323#define SP_CURRENT_DIR_STRING SP_MAC_CURRENT_DIR_STRING
324#define SP_SEPARATED_PARENT_DIR_STRING SP_MAC_SEPARATED_PARENT_DIR_STRING
325#define SP_SEPARATED_CURRENT_DIR_STRING SP_MAC_SEPARATED_CURRENT_DIR_STRING
326
327#define SP_ANOTHER_DIR_SEPARATOR SP_UNIX_DIR_SEPARATOR
328#define SP_ANOTHER_DIR_SEPARATOR_STRING SP_UNIX_DIR_SEPARATOR_STRING
329#define SP_DEFAULT_DIRECTORY ":"
330#define SP_PATHLIST_SEPARATOR ';'
331
332#if defined(MACOSX)
333#define SP_DEFAULT_LF_STRING "\n"
334#else
335#define SP_DEFAULT_LF_STRING "\r"
336#endif
337
338#else
339
340#define SP_DIR_SEPARATOR SP_UNIX_DIR_SEPARATOR
341#define SP_DIR_SEPARATOR_STRING SP_UNIX_DIR_SEPARATOR_STRING
342#define SP_PARENT_DIR_STRING SP_UNIX_PARENT_DIR_STRING
343#define SP_CURRENT_DIR_STRING SP_UNIX_CURRENT_DIR_STRING
344#define SP_SEPARATED_PARENT_DIR_STRING SP_UNIX_SEPARATED_PARENT_DIR_STRING
345#define SP_SEPARATED_CURRENT_DIR_STRING SP_UNIX_SEPARATED_CURRENT_DIR_STRING
346
347#if defined(MACOSX)
348#define SP_ANOTHER_DIR_SEPARATOR SP_MAC_DIR_SEPARATOR
349#define SP_ANOTHER_DIR_SEPARATOR_STRING SP_MAC_DIR_SEPARATOR_STRING
350#define SP_DEFAULT_DIRECTORY "/"
351#define SP_PATHLIST_SEPARATOR ';'
352#else
353#define SP_ANOTHER_DIR_SEPARATOR SP_UNIX_DIR_SEPARATOR
354#define SP_ANOTHER_DIR_SEPARATOR_STRING SP_UNIX_DIR_SEPARATOR_STRING
355#define SP_DEFAULT_DIRECTORY "/"
356#define SP_PATHLIST_SEPARATOR ':'
357#endif
358
359#define SP_DEFAULT_LF_STRING "\n"
360#endif
361
362#define spMax(a, b) ((a) > (b) ? (a) : (b))
363#define spMin(a, b) ((a) < (b) ? (a) : (b))
364#define spAbs(x) ((x) >= 0 ? (x) : -(x))
365#define spCAbs(xr, xi) sqrt((double)(xr)*(double)(xr)+(double)(xi)*(double)(xi))
366#define spCAbsf(xr, xi) sqrtf((float)((xr)*(xr)+(xi)*(xi)))
367#define spSquare(x) ((x) * (x))
368#define spCSquare(xr, xi) ((xr)*(xr)+(xi)*(xi))
369#define spPow2(p) (1 << (long)(p))
371#define spArraySize(array) ((unsigned int)(sizeof(array) / sizeof(array[0])))
372#define spStrEq(s1, s2) ((s1 != NULL) && (s2 != NULL) && (strcmp((s1), (s2)) == 0) ? 1 : 0)
373#define spStrNEq(s1, s2, n) ((s1 != NULL) && (s2 != NULL) && (strncmp((s1), (s2), n) == 0) ? 1 : 0)
374#define spStrVEq(s1, s2) ((s1 != NULL) && (s2 != NULL) && (strncmp((s1), (s2), strlen(s2)) == 0) ? 1 : 0)
375#define spStrNone(string) (((string) == NULL || *(string) == NUL) ? 1 : 0)
376#define spIsTrue(flag) ((flag) != SP_FALSE ? SP_TRUE : SP_FALSE)
377#define spIsFalse(flag) ((flag) == SP_FALSE ? SP_TRUE : SP_FALSE)
379#define spdBf(x) (20.0f * log10f((float)((x) <= 0.0f ? SP_TINY_NUMBER : (x))))
380#define spdB(x) (20.0 * log10((double)((x) <= 0.0 ? SP_TINY_NUMBER : (x))))
381#define spdBpowf(x) (10.0f * log10f((float)((x) <= 0.0f ? SP_TINY_NUMBER : (x))))
382#define spdBpow(x) (10.0 * log10((double)((x) <= 0.0 ? SP_TINY_NUMBER : (x))))
384#ifdef XtOffset
385#define spOffset XtOffset
386#else
387#define spOffset(typep, field) \
388 ((int) (((char *) (&(((typep)0)->field))) - ((char *)0)))
389#endif
390
391#ifdef XtOffsetOf
392#define spOffsetOf XtOffsetOf
393#else
394#ifdef offsetof
395#define spOffsetOf offsetof
396#else
397#define spOffsetOf(type, field) spOffset(type*, field)
398#endif
399#endif
400
401#define SP_NUL '\0'
403#if !defined(SP_DISABLE_ABBREVIATION)
404#ifdef NUL
405#undef NUL
406#endif
407#define NUL SP_NUL
408
409#ifndef NULL
410#define NULL 0
411#endif
412
413#ifndef PI
414#ifdef M_PI
415#define PI M_PI
416#else
417#define PI 3.1415926535897932385
418#endif
419#endif
420
421#ifndef RAND_MAX
422#ifdef INT_MAX
423#define RAND_MAX INT_MAX
424#else
425#define RAND_MAX 2147483647
426#endif
427#endif
428
429#ifndef MAX
430#define MAX spMax
431#endif
432#ifndef MIN
433#define MIN spMin
434#endif
435#ifndef ABS
436#define ABS spAbs
437#endif
438#ifndef FABS
439#define FABS spAbs
440#endif
441#ifndef CABS
442#define CABS spCAbs
443#endif
444#ifndef CABSF
445#define CABSF spCAbsf
446#endif
447#ifndef SQUARE
448#define SQUARE spSquare
449#endif
450#ifndef CSQUARE
451#define CSQUARE spCSquare
452#endif
453#ifndef POW2
454#define POW2 spPow2
455#endif
456
457#ifndef arrsize
458#define arrsize spArraySize
459#endif
460#ifndef streq
461#define streq spStrEq
462#endif
463#ifndef strneq
464#define strneq spStrNEq
465#endif
466#ifndef strveq
467#define strveq spStrVEq
468#endif
469#ifndef strnone
470#define strnone spStrNone
471#endif
472
473#define dBf spdBf
474#define dB spdB
475#define dBpowf spdBpowf
476#define dBpow spdBpow
477#endif /* !defined(SP_DISABLE_ABBREVIATION) */
478
479#if defined(ANDROID)
480#define printf(...) __android_log_print(ANDROID_LOG_INFO,"printf",__VA_ARGS__)
481#define fprintf(fp, ...) \
482 if (fp == stdout) { \
483 __android_log_print(ANDROID_LOG_INFO,"printf",__VA_ARGS__); \
484 } else if (fp == stderr) { \
485 __android_log_print(ANDROID_LOG_WARN,"printf",__VA_ARGS__); \
486 } else { \
487 fprintf(fp, __VA_ARGS__); \
488 }
489#endif
490
491#if defined(__CUDACC__)
492#if !defined(_WIN32) || (defined(_WIN32) && defined(_DEBUG))
493#define spCudaSafeCall(err) __spCudaSafeCall(err, __FILE__, __LINE__)
494#define spCudaCheckMsg(msg) __spCudaCheckMsg(msg, __FILE__, __LINE__)
495#else
496#define spCudaSafeCall(err) err
497#define spCudaCheckMsg(msg)
498#endif
499inline void __spCudaSafeCall(cudaError err, const char *file, const int line)
500{
501 if (cudaSuccess != err) {
502 fprintf(stderr, "%s(%i) : CUDA Runtime API error : %s.\n", file, line, cudaGetErrorString(err));
503 exit(-1);
504 }
505}
506
507inline void __spCudaCheckMsg(const char *errorMessage, const char *file, const int line)
508{
509 cudaError_t err = cudaGetLastError();
510
511 if (cudaSuccess != err) {
512 fprintf(stderr, "%s(%i) : CUDA error : %s : %s.\n",
513 file, line, errorMessage, cudaGetErrorString(err));
514 exit(-1);
515 }
516}
517#endif
518
519 /*----@addtogroup spDefsGroup----*/
520
521#ifdef __cplusplus
522} /* Close scope of 'extern "C"' declaration */
523#endif
524
525#endif /* __SPDEFS_H */
int spBool
Definition spDefs.h:248