Made it compilable with stubs file and current SDI_lib.h
[AROS.git] / workbench / classes / zune / texteditor / include / SDI_lib.h
blob930904c863fc17843194fc4cfc93084df93f79b7
1 #ifndef SDI_LIB_H
2 #define SDI_LIB_H
4 /* Includeheader
6 Name: SDI_lib.h
7 Versionstring: $VER: SDI_lib.h 1.9 (15.03.2009)
8 Author: Jens Langner
9 Distribution: PD
10 Project page: http://www.sf.net/projects/sditools/
11 Description: defines to hide OS specific library function definitions
13 1.0 09.05.04 : initial version which allows to hide OS specific shared
14 library function definition like it has been introduced with
15 the new interface based library system in AmigaOS4.
16 1.1 13.05.04 : replaced the LIBENTRY() macro with some more sophisticated
17 LFUNC_ macros which allow to maintain varargs library functions
18 in a much easier manner.
19 1.2 22.05.04 : removed the anyway not required SAVEDS and ASM statements
20 from the LIBFUNC macro for OS4. Also removed the LIBFUNC
21 statement in the 68k LIBPROTOVA() macro so that no registers
22 can be used in there (which should be the default).
23 1.3 04.07.04 : added empty LIBFUNC define for MorphOS which was missing.
24 1.4 05.10.04 : added missing LIBFUNC call to OS3/MOS interface
25 1.5 19.05.05 : fixed some documentation glitches (Guido Mersmann)
26 1.6 08.06.05 : swapped LIBFUNC and ret within the prototype, because
27 c standard says attributes first and vbcc want them like
28 this. (Guido Mersmann)
29 changed the documentation to explain that LIBFUNC must be
30 set first. (Guido Mersmann)
31 1.7 11.12.05 : adapted all macros to be somewhat more compatible to also
32 OS3 and MorphOS. Now in the real use case (codesets.library)
33 it required a fundamental rework of the macros. (Jens Langner)
34 1.8 28.02.06 : removed "##" in front of the OS3 __VARARGS__ usage as they
35 causing errors on GCC >= 3.x.
36 1.9 15.03.09 : fixed some missing function prototype in LIBPROTOVA()
37 1.10 30.04.09 : added approriate LIBPROTOVA() definition for OS3 and MorphOS
38 to at least make the functions known. The same pattern as for
39 LIBSTUBVA() will be used now (Thore Böckelmann)
40 1.11 04.05.09 : reverted the faulty LIBPROTOVA() definition to its previous
41 version (Thore Böckelmann)
46 ** This is PD (Public Domain). This means you can do with it whatever you want
47 ** without any restrictions. I only ask you to tell me improvements, so I may
48 ** fix the main line of this files as well.
50 ** To keep confusion level low: When changing this file, please note it in
51 ** above history list and indicate that the change was not made by myself
52 ** (e.g. add your name or nick name).
54 ** Find the latest version of this file at:
55 ** http://cvs.sourceforge.net/viewcvs.py/sditools/sditools/headers/
57 ** Jens Langner <Jens.Langner@light-speed.de> and
58 ** Dirk Stöcker <soft@dstoecker.de>
61 #include "SDI_compiler.h"
64 ** Library function macros to handle the definition/usage for different
65 ** Operating System versions.
66 ** Currently special library function handling for AmigaOS version 4 is
67 ** supported
69 ** Example:
71 ** Defines a library jump function "TestFunc" with a ULONG return value and
72 ** which is called by the corresponding library vector of a shared library.
74 ** LIBFUNC ULONG TestFunc(REG(d0, text))
75 ** {
76 ** Printf(text);
77 ** return 0;
78 ** }
80 ** Please note the use of the LIBFUNC macro which defines this function
81 ** automatically as a function which is directly called from within a shared
82 ** library. Since this macro contains compiler attributes it must be
83 ** called first, even if some compiler allow attributes and result type
84 ** mixed, other do not and we want to keep the stuff compiler independent.
86 ** If you now require to have some OS/compiler independent prototype
87 ** definition please use the following statement:
89 ** LIBPROTO(TestFunc, ULONG, REG(d0, text));
91 ** This will ensure that you get a proper prototype for the same function
92 ** where this macro will automatically take care that a libstub_* stub
93 ** will also automatically defines as required if you are generating a
94 ** OS4 shared library which should also be backward compatible to OS3.
96 ** So if you then want to add this function to a library interface please
97 ** use the LFUNC_* macros to generate your library function vector
98 ** like this example one:
100 ** #define libvector LFUNC_FAS(SomeFunc) \
101 ** LFUNC_FA_(TestFunc) \
102 ** LFUNC_VA_(VarargsFunc)
104 ** This way you can then easily put the "libvector" define in your real
105 ** library function vector of your shared library instead of having to
106 ** specify each function with surrounded "#ifdef" defines. These macros
107 ** will then also take automatically care that the varargs functions
108 ** will only be specified on OS versions where these functions are now
109 ** real functions (like with OS4)
111 ** Such stub functions can then also be easily specified as followed
112 ** (in analogy to the above example)
114 ** LIBPROTO(TestFunc, ULONG, REG(d0, text))
115 ** {
116 ** return TestFunc(text);
117 ** }
119 ** On AmigaOS4 using this mechanism for the definition of the library functions
120 ** will automatically ensure that the "struct Interface *self" pointer is included
121 ** and can be easily referenced as such in the function.
123 ** By using this schema a developer might ensure full source code backward
124 ** compatibility to AmigaOS3 without having to introduce dozens of #ifdef
125 ** statements in his code.
128 #ifdef LIBFUNC
129 #undef LIBFUNC
130 #endif
132 #if defined(__amigaos4__)
133 #define LIBFUNC
134 #if !defined(__cplusplus) && \
135 (__STDC_VERSION__ >= 199901L || __GNUC__ >= 3 || \
136 (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
137 #define LIBPROTO(name, ret, ...) \
138 LIBFUNC ret name(__VA_ARGS__); \
139 LIBFUNC ret libstub_##name(struct Interface *self UNUSED, \
140 ## __VA_ARGS__)
141 #define LIBPROTOVA(name, ret, ...) \
142 /*LIBFUNC ret VARARGS68K name(__VA_ARGS__);*/ \
143 LIBFUNC ret VARARGS68K \
144 libstub_##name(struct Interface *self UNUSED, ## __VA_ARGS__)
145 #define LIBSTUB(name, ret, ...) \
146 LIBFUNC ret name(__VA_ARGS__); \
147 LIBFUNC ret libstub_##name(struct Interface *self UNUSED, \
148 ## __VA_ARGS__)
149 #define LIBSTUBVA(name, ret, ...) \
150 LIBFUNC ret VARARGS68K \
151 libstub_##name(struct Interface *self UNUSED, ## __VA_ARGS__)
152 #endif
153 #define LFUNC_FAS(name) libstub_##name
154 #define LFUNC_VAS(name) libstub_##name
155 #define LFUNC_FA_(name) ,libstub_##name
156 #define LFUNC_VA_(name) ,libstub_##name
157 #define LFUNC(name) libstub_##name
158 #elif defined(__MORPHOS__)
159 #define LIBFUNC
160 #if !defined(__cplusplus) && \
161 (__STDC_VERSION__ >= 199901L || __GNUC__ >= 3 || \
162 (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
163 #define LIBPROTO(name, ret, ...) \
164 LIBFUNC ret name(__VA_ARGS__); \
165 LIBFUNC ret libstub_##name(void)
166 #define LIBPROTOVA(name, ret, ...) \
167 LIBFUNC ret VARARGS68K name(__VA_ARGS__);
168 #define LIBSTUB(name, ret, ...) \
169 LIBFUNC ret name(__VA_ARGS__); \
170 LIBFUNC ret libstub_##name(void)
171 #define LIBSTUBVA(name, ret, ...) \
172 LIBFUNC UNUSED ret VARARGS68K libstub_##name(void)
173 #endif
174 #define LFUNC_FAS(name) libstub_##name
175 #define LFUNC_VAS(name)
176 #define LFUNC_FA_(name) ,libstub_##name
177 #define LFUNC_VA_(name)
178 #define LFUNC(name) libstub_##name
179 #else
180 #define LIBFUNC SAVEDS ASM
181 #if !defined(__cplusplus) && \
182 (__STDC_VERSION__ >= 199901L || __GNUC__ >= 3 || \
183 (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
184 #define LIBPROTO(name, ret, ...) \
185 LIBFUNC ret name(__VA_ARGS__)
186 #define LIBPROTOVA(name, ret, ...) \
187 LIBFUNC ret STDARGS VARARGS68K name(__VA_ARGS__);
188 #define LIBSTUB(name, ret, ...) \
189 LIBFUNC ret name(__VA_ARGS__); \
190 LIBFUNC ret libstub_##name(__VA_ARGS__)
191 #define LIBSTUBVA(name, ret, ...) \
192 LIBFUNC UNUSED ret STDARGS VARARGS68K libstub_##name(__VA_ARGS__)
193 #endif
194 #define LFUNC_FAS(name) name
195 #define LFUNC_VAS(name)
196 #define LFUNC_FA_(name) ,name
197 #define LFUNC_VA_(name)
198 #define LFUNC(name) name
199 #endif
201 #if !defined(LIBPROTO) || !defined(LIBPROTOVA)
202 #error "OS or compiler is not yet supported by SDI_lib.h"
203 #endif
205 #endif /* SDI_LIB_H */