2544
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2544
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_f77_fcn_h) |
|
24 #define octave_f77_fcn_h 1 |
|
25 |
|
26 #ifdef __cplusplus |
|
27 extern "C" { |
|
28 #endif |
|
29 |
|
30 #include <setjmp.h> |
|
31 |
|
32 /* Some Fortran compilers append underscores or generate uppercase |
|
33 external names. */ |
|
34 |
|
35 #if defined (F77_APPEND_UNDERSCORE) |
|
36 #if defined (F77_UPPERCASE_NAMES) |
|
37 #define F77_FCN(f, F) F##_ |
|
38 #else |
|
39 #define F77_FCN(f, F) f##_ |
|
40 #endif |
|
41 #else |
|
42 #if defined (F77_UPPERCASE_NAMES) |
|
43 #define F77_FCN(f, F) F |
|
44 #else |
|
45 #define F77_FCN(f, F) f |
|
46 #endif |
|
47 #endif |
|
48 |
|
49 /* How to print an error for the F77_XFCN macro. */ |
|
50 |
|
51 #if defined (F77_UPPERCASE_NAMES) |
|
52 #define F77_XFCN_ERROR(f, F) \ |
|
53 (*current_liboctave_error_handler) \ |
|
54 ("exception encountered in Fortran subroutine %s", #F) |
|
55 #else |
|
56 #define F77_XFCN_ERROR(f, F) \ |
|
57 (*current_liboctave_error_handler) \ |
|
58 ("exception encountered in Fortran subroutine %s", #f) |
|
59 #endif |
|
60 |
|
61 /* This can be used to call a Fortran subroutine that might call |
|
62 XSTOPX. XSTOPX will call lonjmp with f77_context and we'll return, |
|
63 call the error function, restore the previous context. After using |
|
64 this macro, error_state should be checked. */ |
|
65 |
|
66 #define F77_XFCN(f, F, args) \ |
|
67 do \ |
|
68 { \ |
|
69 jmp_buf saved_f77_context; \ |
|
70 f77_exception_encountered = 0; \ |
|
71 copy_f77_context ((char *) f77_context, (char *) saved_f77_context, \ |
|
72 sizeof (jmp_buf)); \ |
|
73 if (setjmp (f77_context)) \ |
|
74 { \ |
|
75 f77_exception_encountered = 1; \ |
|
76 F77_XFCN_ERROR (f, F); \ |
|
77 } \ |
|
78 else \ |
|
79 F77_FCN (f, F) args; \ |
|
80 copy_f77_context ((char *) saved_f77_context, (char *) f77_context, \ |
|
81 sizeof (jmp_buf)); \ |
|
82 } \ |
|
83 while (0) |
|
84 |
|
85 /* So we can check to see if an exception has occurred. */ |
|
86 extern int f77_exception_encountered; |
|
87 |
|
88 /* For setjmp/longjmp. */ |
|
89 extern jmp_buf f77_context; |
|
90 |
|
91 /* Defining this as a separate function allows us to avoid having to |
|
92 include string.h in this file. */ |
|
93 |
|
94 extern void copy_f77_context (void *, void *, unsigned int); |
|
95 |
|
96 #ifdef __cplusplus |
|
97 } |
|
98 #endif |
|
99 |
|
100 #endif |
|
101 |
|
102 /* |
|
103 ;;; Local Variables: *** |
|
104 ;;; mode: C++ *** |
|
105 ;;; End: *** |
|
106 */ |