scitech.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /****************************************************************************
  2. *
  3. * SciTech Multi-platform Graphics Library
  4. *
  5. * ========================================================================
  6. *
  7. * The contents of this file are subject to the SciTech MGL Public
  8. * License Version 1.0 (the "License"); you may not use this file
  9. * except in compliance with the License. You may obtain a copy of
  10. * the License at http://www.scitechsoft.com/mgl-license.txt
  11. *
  12. * Software distributed under the License is distributed on an
  13. * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  14. * implied. See the License for the specific language governing
  15. * rights and limitations under the License.
  16. *
  17. * The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
  18. *
  19. * The Initial Developer of the Original Code is SciTech Software, Inc.
  20. * All Rights Reserved.
  21. *
  22. * ========================================================================
  23. *
  24. * Language: ANSI C
  25. * Environment: any
  26. *
  27. * Description: General header file for operating system portable code.
  28. *
  29. ****************************************************************************/
  30. #ifndef __SCITECH_H
  31. #define __SCITECH_H
  32. /* We have the following defines to identify the compilation environment:
  33. *
  34. * __16BIT__ Compiling for 16 bit code (any environment)
  35. * __32BIT__ Compiling for 32 bit code (any environment)
  36. * __MSDOS__ Compiling for MS-DOS (includes __WINDOWS16__, __WIN386__)
  37. * __REALDOS__ Compiling for MS-DOS (excludes __WINDOWS16__)
  38. * __MSDOS16__ Compiling for 16 bit MS-DOS
  39. * __MSDOS32__ Compiling for 32 bit MS-DOS
  40. * __WINDOWS__ Compiling for Windows
  41. * __WINDOWS16__ Compiling for 16 bit Windows (__MSDOS__ also defined)
  42. * __WINDOWS32__ Compiling for 32 bit Windows
  43. * __WIN32_VXD__ Compiling for a 32-bit C based VxD
  44. * __NT_DRIVER__ Compiling for a 32-bit C based NT device driver
  45. * __OS2__ Compiling for OS/2
  46. * __OS2_16__ Compiling for 16 bit OS/2
  47. * __OS2_32__ Compiling for 32 bit OS/2
  48. * __UNIX__ Compiling for Unix
  49. * __QNX__ Compiling for the QNX realtime OS (Unix compatible)
  50. * __LINUX__ Compiling for the Linux OS (Unix compatible)
  51. * __FREEBSD__ Compiling for the FreeBSD OS (Unix compatible)
  52. * __BEOS__ Compiling for the BeOS (Unix compatible)
  53. * __SMX32__ Compiling for the SMX 32-bit Real Time OS
  54. * __ENEA_OSE__ Compiling for the OSE embedded OS
  55. * __RTTARGET__ Compiling for the RTTarget 32-bit embedded OS
  56. * __MACOS__ Compiling for the MacOS platform (PowerPC)
  57. * __DRIVER__ Compiling for a 32-bit binary compatible driver
  58. * __CONSOLE__ Compiling for a fullscreen OS console mode
  59. * __SNAP__ Compiling as a Snap executeable or dynamic library
  60. *
  61. * __INTEL__ Compiling for Intel CPU's
  62. * __ALPHA__ Compiling for DEC Alpha CPU's
  63. * __MIPS__ Compiling for MIPS CPU's
  64. * __PPC__ Compiling for PowerPC CPU's
  65. * __MC68K__ Compiling for Motorola 680x0
  66. *
  67. * __BIG_ENDIAN__ Compiling for a big endian processor
  68. *
  69. */
  70. #ifdef __SC__
  71. #if __INTSIZE == 4
  72. #define __SC386__
  73. #endif
  74. #endif
  75. /* Determine some things that are compiler specific */
  76. #ifdef __GNUC__
  77. #ifdef __cplusplus
  78. /* G++ currently fucks this up! */
  79. #define __cdecl
  80. #define __stdcall
  81. #else
  82. #undef __cdecl
  83. #undef __stdcall
  84. #define __cdecl __attribute__ ((cdecl))
  85. #define __stdcall __attribute__ ((stdcall))
  86. #endif
  87. #define __FLAT__ /* GCC is always 32 bit flat model */
  88. #define __HAS_BOOL__ /* Latest GNU C++ has ibool type */
  89. #define __HAS_LONG_LONG__ /* GNU C supports long long type */
  90. #include <stdio.h> /* Bring in for definition of NULL */
  91. #endif
  92. #ifdef __BORLANDC__
  93. #if (__BORLANDC__ >= 0x500) || defined(CLASSLIB_DEFS_H)
  94. #define __HAS_BOOL__ /* Borland C++ 5.0 defines ibool type */
  95. #endif
  96. #if (__BORLANDC__ >= 0x502) && !defined(VTOOLSD) && !defined(__SMX32__)
  97. #define __HAS_INT64__ /* Borland C++ 5.02 supports __int64 type */
  98. #endif
  99. #endif
  100. #if defined(_MSC_VER) && !defined(__SC__) && !defined(VTOOLSD) && !defined(__SMX32__)
  101. #define __HAS_INT64__ /* Visual C++ supports __int64 type */
  102. #endif
  103. #if defined(__WATCOMC__) && (__WATCOMC__ >= 1100) && !defined(VTOOLSD) && !defined(__SMX32__)
  104. #define __HAS_INT64__ /* Watcom C++ 11.0 supports __int64 type */
  105. #endif
  106. /*---------------------------------------------------------------------------
  107. * Determine the compile time environment. This must be done for each
  108. * supported platform so that we can determine at compile time the target
  109. * environment, hopefully without requiring #define's from the user.
  110. *-------------------------------------------------------------------------*/
  111. /* 32-bit binary compatible driver. Compiled as Win32, but as OS neutral */
  112. #ifdef __DRIVER__
  113. #ifndef __32BIT__
  114. #define __32BIT__
  115. #endif
  116. #undef __WINDOWS__
  117. #undef _WIN32
  118. #undef __WIN32__
  119. #undef __NT__
  120. /* 32-bit Snap exe or dll. Compiled as Win32, but as OS neutral */
  121. #elif defined(__SNAP__)
  122. #ifndef __32BIT__
  123. #define __32BIT__
  124. #endif
  125. #undef __WINDOWS__
  126. #undef _WIN32
  127. #undef __WIN32__
  128. #undef __NT__
  129. /* 32-bit Windows VxD compile environment */
  130. #elif defined(__vtoolsd_h_) || defined(VTOOLSD)
  131. #include <vtoolsc.h>
  132. #define __WIN32_VXD__
  133. #ifndef __32BIT__
  134. #define __32BIT__
  135. #endif
  136. #define _MAX_PATH 256
  137. #undef __WINDOWS32__
  138. /* 32-bit Windows NT driver compile environment: TODO!! */
  139. #elif defined(__NT_DRIVER__)
  140. #include "ntdriver.h"
  141. #ifndef __32BIT__
  142. #define __32BIT__
  143. #endif
  144. #define _MAX_PATH 256
  145. #undef __WINDOWS32__
  146. /* 32-bit SMX compile environment */
  147. #elif defined(__SMX32__)
  148. #ifndef __MSDOS__
  149. #define __MSDOS__
  150. #endif
  151. #ifndef __32BIT__
  152. #define __32BIT__
  153. #endif
  154. #ifndef __CONSOLE__
  155. #define __CONSOLE__
  156. #endif
  157. /* 32-bit Enea OSE environment */
  158. #elif defined(__ENEA_OSE__)
  159. #ifndef __32BIT__
  160. #define __32BIT__
  161. #endif
  162. #ifndef __CONSOLE__
  163. #define __CONSOLE__
  164. #endif
  165. /* 32-bit RTTarget-32 environment */
  166. #elif defined(__RTTARGET__)
  167. #ifndef __32BIT__
  168. #define __32BIT__
  169. #endif
  170. #ifndef __CONSOLE__
  171. #define __CONSOLE__
  172. #endif
  173. /* 32-bit extended DOS compile environment */
  174. #elif defined(__MSDOS__) || defined(__MSDOS32__) || defined(__DOS__) || defined(__DPMI32__) || (defined(M_I86) && (!defined(__SC386__) && !defined(M_I386))) || defined(TNT)
  175. #ifndef __MSDOS__
  176. #define __MSDOS__
  177. #endif
  178. #if defined(__MSDOS32__) || defined(__386__) || defined(__FLAT__) || defined(__NT__) || defined(__SC386__)
  179. #ifndef __MSDOS32__
  180. #define __MSDOS32__
  181. #endif
  182. #ifndef __32BIT__
  183. #define __32BIT__
  184. #endif
  185. #ifndef __REALDOS__
  186. #define __REALDOS__
  187. #endif
  188. #ifndef __CONSOLE__
  189. #define __CONSOLE__
  190. #endif
  191. /* 16-bit Windows compile environment */
  192. #elif (defined(_Windows) || defined(_WINDOWS)) && !defined(__DPMI16__)
  193. #ifndef __16BIT__
  194. #define __16BIT__
  195. #endif
  196. #ifndef __WINDOWS16__
  197. #define __WINDOWS16__
  198. #endif
  199. #ifndef __WINDOWS__
  200. #define __WINDOWS__
  201. #endif
  202. #ifndef __MSDOS__
  203. #define __MSDOS__
  204. #endif
  205. /* 16-bit DOS compile environment */
  206. #else
  207. #ifndef __16BIT__
  208. #define __16BIT__
  209. #endif
  210. #ifndef __MSDOS16__
  211. #define __MSDOS16__
  212. #endif
  213. #ifndef __REALDOS__
  214. #define __REALDOS__
  215. #endif
  216. #ifndef __CONSOLE__
  217. #define __CONSOLE__
  218. #endif
  219. #endif
  220. /* 32-bit Windows compile environment */
  221. #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
  222. #ifndef __32BIT__
  223. #define __32BIT__
  224. #endif
  225. #ifndef __WINDOWS32__
  226. #define __WINDOWS32__
  227. #endif
  228. #ifndef _WIN32
  229. #define _WIN32 /* Microsoft Win32 SDK headers use _WIN32 */
  230. #endif
  231. #ifndef WIN32
  232. #define WIN32 /* OpenGL headers use WIN32 */
  233. #endif
  234. #ifndef __WINDOWS__
  235. #define __WINDOWS__
  236. #endif
  237. /* 32-bit OS/2 VDD compile environment */
  238. /* We're assuming (for now) that CL386 must be used */
  239. #elif defined(MSDOS) && defined(M_I386)
  240. /* fixes necessary to compile with CL386 */
  241. #define __cdecl _cdecl
  242. typedef unsigned int size_t;
  243. #include <mvdm.h>
  244. /* This should probably be somewhere else... */
  245. /* Inline eligible functions (we have no CRT libs for CL386) */
  246. #pragma intrinsic (strcpy, strcmp, strlen, strcat)
  247. #pragma intrinsic (memcmp, memcpy, memset)
  248. #define __OS2_VDD__
  249. #ifndef __32BIT__
  250. #define __32BIT__
  251. #endif
  252. #define CCHMAXPATH 256
  253. #define _MAX_PATH 256
  254. #ifndef __OS2__
  255. #define __OS2__
  256. #endif
  257. #ifndef __OS2_32__
  258. #define __OS2_32__
  259. #endif
  260. /* 16-bit OS/2 compile environment */
  261. #elif defined(__OS2_16__)
  262. #ifndef __OS2__
  263. #define __OS2__
  264. #endif
  265. #ifndef __16BIT__
  266. #define __16BIT__
  267. #endif
  268. #ifndef __OS2_PM__
  269. #ifndef __CONSOLE__
  270. #define __CONSOLE__
  271. #endif
  272. #endif
  273. /* 32-bit OS/2 compile environment */
  274. #elif defined(__OS2__) || defined(__OS2_32__)
  275. #ifndef __OS2__
  276. #define __OS2__
  277. #endif
  278. #ifndef __OS2_32__
  279. #define __OS2_32__
  280. #endif
  281. #ifndef __32BIT__
  282. #define __32BIT__
  283. #endif
  284. #ifndef __OS2_PM__
  285. #ifndef __CONSOLE__
  286. #define __CONSOLE__
  287. #endif
  288. #endif
  289. /* 32-bit QNX compile environment */
  290. #elif defined(__QNX__)
  291. #ifndef __32BIT__
  292. #define __32BIT__
  293. #endif
  294. #ifndef __UNIX__
  295. #define __UNIX__
  296. #endif
  297. #ifdef __GNUC__
  298. #define stricmp strcasecmp
  299. #endif
  300. #if !defined(__PHOTON__) && !defined(__X11__)
  301. #ifndef __CONSOLE__
  302. #define __CONSOLE__
  303. #endif
  304. #endif
  305. /* 32-bit Linux compile environment */
  306. #elif defined(__LINUX__) || defined(linux)
  307. #ifndef __LINUX__
  308. #define __LINUX__
  309. #endif
  310. #ifndef __32BIT__
  311. #define __32BIT__
  312. #endif
  313. #ifndef __UNIX__
  314. #define __UNIX__
  315. #endif
  316. #ifdef __GNUC__
  317. #define stricmp strcasecmp
  318. #endif
  319. #ifndef __X11__
  320. #ifndef __CONSOLE__
  321. #define __CONSOLE__
  322. #endif
  323. #endif
  324. /* 32-bit FreeBSD compile environment */
  325. #elif defined(__FREEBSD__)
  326. #ifndef __FREEBSD__
  327. #define __FREEBSD__
  328. #endif
  329. #ifndef __32BIT__
  330. #define __32BIT__
  331. #endif
  332. #ifndef __UNIX__
  333. #define __UNIX__
  334. #endif
  335. #ifdef __GNUC__
  336. #define stricmp strcasecmp
  337. #endif
  338. #ifndef __X11__
  339. #ifndef __CONSOLE__
  340. #define __CONSOLE__
  341. #endif
  342. #endif
  343. /* 32-bit BeOS compile environment */
  344. #elif defined(__BEOS__)
  345. #ifndef __32BIT__
  346. #define __32BIT__
  347. #endif
  348. #ifndef __UNIX__
  349. #define __UNIX__
  350. #endif
  351. #ifdef __GNUC__
  352. #define stricmp strcasecmp
  353. #endif
  354. /* Unsupported OS! */
  355. #else
  356. #error This platform is not currently supported!
  357. #endif
  358. /* Determine the CPU type that we are compiling for */
  359. #if defined(__M_ALPHA) || defined(__ALPHA_) || defined(__ALPHA) || defined(__alpha)
  360. #ifndef __ALPHA__
  361. #define __ALPHA__
  362. #endif
  363. #elif defined(__M_PPC) || defined(__POWERC)
  364. #ifndef __PPC__
  365. #define __PPC__
  366. #endif
  367. #elif defined(__M_MRX000)
  368. #ifndef __MIPS__
  369. #define __MIPS__
  370. #endif
  371. #else
  372. #ifndef __INTEL__
  373. #define __INTEL__ /* Assume Intel if nothing found */
  374. #endif
  375. #endif
  376. /* We have the following defines to define the calling conventions for
  377. * publicly accesible functions:
  378. *
  379. * _PUBAPI - Compiler default calling conventions for all public 'C' functions
  380. * _ASMAPI - Calling conventions for all public assembler functions
  381. * _VARAPI - Modifiers for variables; Watcom C++ mangles C++ globals
  382. * _STDCALL - Win32 __stdcall where possible, __cdecl if not supported
  383. */
  384. #if defined(_MSC_VER) && defined(_WIN32) && !defined(__SC__)
  385. #define __PASCAL __stdcall
  386. #else
  387. #define __PASCAL __pascal
  388. #endif
  389. #if defined(NO_STDCALL)
  390. #define _STDCALL __cdecl
  391. #else
  392. #define _STDCALL __stdcall
  393. #endif
  394. #ifdef __WATCOMC__
  395. #if (__WATCOMC__ >= 1050)
  396. #define _VARAPI __cdecl
  397. #else
  398. #define _VARAPI
  399. #endif
  400. #else
  401. #define _VARAPI
  402. #endif
  403. #if defined(__IBMC__) || defined(__IBMCPP__)
  404. #define PTR_DECL_IN_FRONT
  405. #endif
  406. /* Define the calling conventions for all public functions. For simplicity
  407. * we define all public functions as __cdecl calling conventions, so that
  408. * they are the same across all compilers and runtime DLL's.
  409. */
  410. #define _PUBAPI __cdecl
  411. #define _ASMAPI __cdecl
  412. /* Determine the syntax for declaring a function pointer with a
  413. * calling conventions override. Most compilers require the calling
  414. * convention to be declared in front of the '*', but others require
  415. * it to be declared after the '*'. We handle both in here depending
  416. * on what the compiler requires.
  417. */
  418. #ifdef PTR_DECL_IN_FRONT
  419. #define _PUBAPIP * _PUBAPI
  420. #define _ASMAPIP * _ASMAPI
  421. #else
  422. #define _PUBAPIP _PUBAPI *
  423. #define _ASMAPIP _ASMAPI *
  424. #endif
  425. /* Useful macros */
  426. #define PRIVATE static
  427. #define PUBLIC
  428. /* This HAS to be 0L for 16-bit real mode code to work!!! */
  429. #ifndef NULL
  430. # define _NULL 0L
  431. # define NULL _NULL
  432. #endif
  433. #ifndef MAX
  434. # define MAX(a,b) ( ((a) > (b)) ? (a) : (b))
  435. #endif
  436. #ifndef MIN
  437. # define MIN(a,b) ( ((a) < (b)) ? (a) : (b))
  438. #endif
  439. #ifndef ABS
  440. # define ABS(a) ((a) >= 0 ? (a) : -(a))
  441. #endif
  442. #ifndef SIGN
  443. # define SIGN(a) ((a) > 0 ? 1 : -1)
  444. #endif
  445. /* General typedefs */
  446. #ifndef __GENDEFS
  447. #define __GENDEFS
  448. #if defined(__BEOS__)
  449. #include <SupportDefs.h>
  450. #else
  451. #ifdef __LINUX__
  452. #include <sys/types.h>
  453. #ifdef __STRICT_ANSI__
  454. typedef unsigned short ushort;
  455. typedef unsigned long ulong;
  456. typedef unsigned int uint;
  457. #endif
  458. #ifdef __KERNEL__
  459. #define __GENDEFS_2
  460. #endif
  461. #else
  462. #if !(defined(__QNXNTO__) && defined(GENERAL_STRUCT))
  463. typedef unsigned short ushort;
  464. typedef unsigned long ulong;
  465. #endif
  466. typedef unsigned int uint;
  467. #endif
  468. typedef unsigned char uchar;
  469. #endif
  470. typedef int ibool; /* Integer boolean type */
  471. #ifdef USE_BOOL /* Only for older code */
  472. #ifndef __cplusplus
  473. #define bool ibool /* Standard C */
  474. #else
  475. #ifndef __HAS_BOOL__
  476. #define bool ibool /* Older C++ compilers */
  477. #endif
  478. #endif /* __cplusplus */
  479. #endif /* USE_BOOL */
  480. #endif /* __GENDEFS */
  481. /* More general typedefs compatible with Linux kernel code */
  482. #ifndef __GENDEFS_2
  483. #define __GENDEFS_2
  484. typedef char s8;
  485. typedef unsigned char u8;
  486. typedef short s16;
  487. typedef unsigned short u16;
  488. #ifdef __16BIT__
  489. typedef long s32;
  490. typedef unsigned long u32;
  491. #else
  492. typedef int s32;
  493. typedef unsigned int u32;
  494. #endif
  495. typedef struct {
  496. u32 low;
  497. s32 high;
  498. } __i64;
  499. #ifdef __HAS_LONG_LONG__
  500. #define __NATIVE_INT64__
  501. typedef long long s64;
  502. typedef unsigned long long u64;
  503. #elif defined(__HAS_INT64__) && !defined(__16BIT__)
  504. #define __NATIVE_INT64__
  505. typedef __int64 s64;
  506. typedef unsigned __int64 u64;
  507. #else
  508. typedef __i64 s64;
  509. typedef __i64 u64;
  510. #endif
  511. #endif
  512. /* Boolean truth values */
  513. #undef false
  514. #undef true
  515. #undef NO
  516. #undef YES
  517. #undef FALSE
  518. #undef TRUE
  519. #define false 0
  520. #define true 1
  521. #define NO 0
  522. #define YES 1
  523. #define FALSE 0
  524. #define TRUE 1
  525. /* Inline debugger interrupts for Watcom C++ and Borland C++ */
  526. #ifdef __WATCOMC__
  527. void DebugInt(void);
  528. #pragma aux DebugInt = \
  529. "int 3";
  530. void DebugVxD(void);
  531. #pragma aux DebugVxD = \
  532. "int 1";
  533. #elif defined(__BORLANDC__)
  534. #define DebugInt() __emit__(0xCC)
  535. #define DebugVxD() {__emit__(0xCD); __emit__(0x01);}
  536. #elif defined(_MSC_VER)
  537. #define DebugInt() _asm int 0x3
  538. #define DebugVxD() _asm int 0x1
  539. #elif defined(__GNUC__)
  540. #define DebugInt() asm volatile ("int $0x3")
  541. #define DebugVxD() asm volatile ("int $0x1")
  542. #else
  543. void _ASMAPI DebugInt(void);
  544. void _ASMAPI DebugVxD(void);
  545. #endif
  546. /* Macros to break once and never break again */
  547. #define DebugIntOnce() \
  548. { \
  549. static ibool firstTime = true; \
  550. if (firstTime) { \
  551. firstTime = false; \
  552. DebugInt(); \
  553. } \
  554. }
  555. #define DebugVxDOnce() \
  556. { \
  557. static ibool firstTime = true; \
  558. if (firstTime) { \
  559. firstTime = false; \
  560. DebugVxD(); \
  561. } \
  562. }
  563. /* Macros for linux string compatibility functions */
  564. #ifdef __LINUX__
  565. #define stricmp strcasecmp
  566. #define strnicmp strncasecmp
  567. #endif
  568. /* Macros for NT driver string compatibility functions */
  569. #ifdef __NT_DRIVER__
  570. #define stricmp _stricmp
  571. #define strnicmp _strnicmp
  572. #endif
  573. /* Get rid of some helaciously annoying Visual C++ warnings! */
  574. #if defined(_MSC_VER) && !defined(__MWERKS__) && !defined(__SC__)
  575. #pragma warning(disable:4761) /* integral size mismatch in argument; conversion supplied */
  576. #pragma warning(disable:4244) /* conversion from 'unsigned short ' to 'unsigned char ', possible loss of data */
  577. #pragma warning(disable:4018) /* '<' : signed/unsigned mismatch */
  578. #pragma warning(disable:4305) /* 'initializing' : truncation from 'const double' to 'float' */
  579. #endif
  580. /*---------------------------------------------------------------------------
  581. * Set of debugging macros used by the libraries. If the debug flag is
  582. * set, they are turned on depending on the setting of the flag. User code
  583. * can override the default functions called when a check fails, and the
  584. * MGL does this so it can restore the system from graphics mode to display
  585. * an error message. These functions also log information to the
  586. * scitech.log file in the root directory of the hard drive when problems
  587. * show up.
  588. *
  589. * If you set the value of CHECKED to be 2, it will also enable code to
  590. * insert hard coded debugger interrupt into the source code at the line of
  591. * code where the check fail. This is useful if you run the code under a
  592. * debugger as it will break inside the debugger before exiting with a
  593. * failure condition.
  594. *
  595. * Also for code compiled to run under Windows, we also call the
  596. * OutputDebugString function to send the message to the system debugger
  597. * such as Soft-ICE or WDEB386. Hence if you get any non-fatal warnings you
  598. * will see those on the debugger terminal as well as in the log file.
  599. *-------------------------------------------------------------------------*/
  600. #ifdef __cplusplus
  601. extern "C" { /* Use "C" linkage when in C++ mode */
  602. #endif
  603. extern void (*_CHK_fail)(int fatal,const char *msg,const char *cond,const char *file,int line);
  604. void _CHK_defaultFail(int fatal,const char *msg,const char *cond,const char *file,int line);
  605. #ifdef CHECKED
  606. # define CHK(x) x
  607. #if CHECKED > 1
  608. # define CHECK(p) \
  609. ((p) ? (void)0 : DebugInt(), \
  610. _CHK_fail(1,"Check failed: '%s', file %s, line %d\n", \
  611. #p, __FILE__, __LINE__))
  612. # define WARN(p) \
  613. ((p) ? (void)0 : DebugInt(), \
  614. _CHK_fail(0,"Warning: '%s', file %s, line %d\n", \
  615. #p, __FILE__, __LINE__))
  616. #else
  617. # define CHECK(p) \
  618. ((p) ? (void)0 : \
  619. _CHK_fail(1,"Check failed: '%s', file %s, line %d\n", \
  620. #p, __FILE__, __LINE__))
  621. # define WARN(p) \
  622. ((p) ? (void)0 : \
  623. _CHK_fail(0,"Warning: '%s', file %s, line %d\n", \
  624. #p, __FILE__, __LINE__))
  625. #endif
  626. # define LOGFATAL(msg) \
  627. _CHK_fail(1,"Fatal error: '%s', file %s, line %d\n", \
  628. msg, __FILE__, __LINE__)
  629. # define LOGWARN(msg) \
  630. _CHK_fail(0,"Warning: '%s', file %s, line %d\n", \
  631. msg, __FILE__, __LINE__)
  632. #else
  633. # define CHK(x)
  634. # define CHECK(p) ((void)0)
  635. # define WARN(p) ((void)0)
  636. # define LOGFATAL(msg) ((void)0)
  637. # define LOGWARN(msg) ((void)0)
  638. #endif
  639. #ifdef __cplusplus
  640. } /* End of "C" linkage for C++ */
  641. #endif
  642. #endif /* __SCITECH_H */