Subversion Repositories tendra.SVN

Rev

Rev 5 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 41... Line 71...
41
 * and ``longjmp''), and should be used in preference to it.  The mechanism is
71
 * and ``longjmp''), and should be used in preference to it.  The mechanism is
42
 * implemented as a set of macros.
72
 * implemented as a set of macros.
43
 *
73
 *
44
 * This file requires that two external functions are provided:
74
 * This file requires that two external functions are provided:
45
 *
75
 *
46
 *	extern void			E_exception_unhandled
-
 
47
 *			PROTO_S ((ExceptionP, CStringP, unsigned));
76
 *	extern void E_exception_unhandled(ExceptionP, CStringP, unsigned)
48
 *	extern void			E_exception_corrupt_handler
77
 *	extern void E_exception_corrupt_handler(CStringP, unsigned)
49
 *			PROTO_S ((CStringP, unsigned));
-
 
50
 *
78
 *
51
 * The first of these functions will be called if there is an unhandled
79
 * The first of these functions will be called if there is an unhandled
52
 * exception.  The exception will be given as an argument, along with the name
80
 * exception.  The exception will be given as an argument, along with the name
53
 * of the file, and the line within that file that the exception was thrown
81
 * of the file, and the line within that file that the exception was thrown
54
 * from.  The second function will be called if a corrupt exception handler
82
 * from.  The second function will be called if a corrupt exception handler
Line 88... Line 116...
88
 * This type is used internally to store data about the exception handler
116
 * This type is used internally to store data about the exception handler
89
 * stack.
117
 * stack.
90
 *
118
 *
91
 ***=== FUNCTIONS ============================================================
119
 ***=== FUNCTIONS ============================================================
92
 *
120
 *
93
 ** Function:	CStringP		exception_name
121
 ** Function:	CStringP exception_name(ExceptionP exception)
94
 *			PROTO_S ((ExceptionP exception))
-
 
95
 *
122
 *
96
 * This function returns the name of the specified exception.  The return
123
 * This function returns the name of the specified exception.  The return
97
 * value should not be modified or deallocated.
124
 * value should not be modified or deallocated.
98
 *
125
 *
99
 ***=== MACROS ===============================================================
126
 ***=== MACROS ===============================================================
Line 249... Line 276...
249
} HandlerT, *HandlerP;
276
} HandlerT, *HandlerP;
250
 
277
 
251
/*--------------------------------------------------------------------------*/
278
/*--------------------------------------------------------------------------*/
252
 
279
 
253
extern	CStringP		exception_name
280
extern	CStringP		exception_name
254
	PROTO_S ((ExceptionP));
281
(ExceptionP);
255
 
282
 
256
/*--------------------------------------------------------------------------*/
283
/*--------------------------------------------------------------------------*/
257
 
284
 
258
extern HandlerP			X__exception_handler_stack;
285
extern HandlerP			X__exception_handler_stack;
259
extern ThrowDataT		X__exception_throw_data;
286
extern ThrowDataT		X__exception_throw_data;
260
extern NoReturnT		X__exception_throw
287
extern NoReturnT		X__exception_throw
261
	PROTO_S ((void));
288
(void);
262
 
289
 
263
/*--------------------------------------------------------------------------*/
290
/*--------------------------------------------------------------------------*/
264
 
291
 
265
#define EXCEPTION(name) name
292
#define EXCEPTION(name)	name
266
 
293
 
267
#define THROW(exc) \
294
#define THROW(exc)\
268
{X__exception_throw_data.exception = (exc); \
295
	{X__exception_throw_data.exception = (exc); \
269
 X__exception_throw_data.data      = NIL (GenericP); \
296
		X__exception_throw_data.data	= NIL(GenericP); \
270
 X__exception_throw_data.line      = __LINE__; \
297
		X__exception_throw_data.line	= __LINE__; \
271
 X__exception_throw_data.file      = __FILE__; \
298
		X__exception_throw_data.file	= __FILE__; \
272
 X__exception_throw ();}
299
		X__exception_throw();}
273
 
300
 
274
#define THROW_VALUE(exc,val) \
301
#define THROW_VALUE(exc,val)\
275
{X__exception_throw_data.exception = (exc); \
302
	{X__exception_throw_data.exception = (exc); \
276
 X__exception_throw_data.data      = ((GenericP) (val)); \
303
		X__exception_throw_data.data	= ((GenericP)(val)); \
277
 X__exception_throw_data.line      = __LINE__; \
304
		X__exception_throw_data.line	= __LINE__; \
278
 X__exception_throw_data.file      = __FILE__; \
305
		X__exception_throw_data.file	= __FILE__; \
279
 X__exception_throw ();}
306
		X__exception_throw();}
280
 
307
 
281
#ifdef PO_EXCEPTION_STACK_DIRECTION
308
#ifdef PO_EXCEPTION_STACK_DIRECTION
282
#define X__EXCEPTION_MAGIC (0x1234)
309
#define X__EXCEPTION_MAGIC	(0x1234)
283
 
310
 
284
#define HANDLE \
311
#define HANDLE \
285
{HandlerT X___exception_handler; \
312
	{HandlerT X___exception_handler; \
286
 X___exception_handler.magic_start = X__EXCEPTION_MAGIC; \
313
	X___exception_handler.magic_start = X__EXCEPTION_MAGIC; \
287
 X___exception_handler.file        = __FILE__; \
314
		X___exception_handler.file	= __FILE__; \
288
 X___exception_handler.line        = __LINE__; \
315
		X___exception_handler.line	= __LINE__; \
289
 X___exception_handler.next        = X__exception_handler_stack; \
316
		X___exception_handler.next	= X__exception_handler_stack; \
290
 X___exception_handler.magic_end   = X__EXCEPTION_MAGIC; \
317
		X___exception_handler.magic_end	= X__EXCEPTION_MAGIC; \
291
 X__exception_handler_stack        = &X___exception_handler; \
318
		X__exception_handler_stack	= &X___exception_handler; \
292
 if (!setjmp (X___exception_handler.buffer)) {
319
		if (!setjmp(X___exception_handler.buffer)) {
293
#else
320
#else
294
#define HANDLE \
321
#define HANDLE \
295
{HandlerT X___exception_handler; \
322
	 {HandlerT X___exception_handler; \
296
 X___exception_handler.next = X__exception_handler_stack; \
323
		 X___exception_handler.next = X__exception_handler_stack; \
297
 X__exception_handler_stack = &X___exception_handler; \
324
		 X__exception_handler_stack = &X___exception_handler; \
298
 if (!setjmp (X___exception_handler.buffer)) {
325
		 if (!setjmp(X___exception_handler.buffer)) {
299
#endif /* defined (PO_EXCEPTION_STACK_DIRECTION) */
326
#endif /* defined (PO_EXCEPTION_STACK_DIRECTION) */
300
 
327
 
301
#define WITH \
328
#define WITH \
302
     X__exception_handler_stack = X___exception_handler.next; \
329
     X__exception_handler_stack = X___exception_handler.next; \
303
 } else { \
330
 } else { \
304
     X__exception_handler_stack = X___exception_handler.next; {
331
     X__exception_handler_stack = X___exception_handler.next; {
305
 
332
 
306
#define END_HANDLE }}}
333
#define END_HANDLE }}}
307
 
334
 
308
#define EXCEPTION_EXCEPTION() \
-
 
309
X__exception_throw_data.exception
335
#define EXCEPTION_EXCEPTION()	X__exception_throw_data.exception
310
 
336
 
311
#define EXCEPTION_VALUE() \
-
 
312
X__exception_throw_data.data
337
#define EXCEPTION_VALUE()	X__exception_throw_data.data
313
 
338
 
314
#define EXCEPTION_LINE() \
-
 
315
X__exception_throw_data.line
339
#define EXCEPTION_LINE()	X__exception_throw_data.line
316
 
340
 
317
#define EXCEPTION_FILE() \
-
 
318
X__exception_throw_data.file
341
#define EXCEPTION_FILE()	X__exception_throw_data.file
319
 
342
 
320
#define RETHROW() \
-
 
321
X__exception_throw ();
343
#define RETHROW()	X__exception_throw();
322
 
344
 
323
#define UNHANDLE X__exception_handler_stack = X___exception_handler.next;
345
#define UNHANDLE	X__exception_handler_stack = X___exception_handler.next;
324
 
346
 
325
#endif /* !defined (H_EXCEPTION) */
347
#endif /* !defined (H_EXCEPTION) */