1 /*
2  * Motif Tools Library, Version 3.1
3  * $Id: Xmt.h,v 1.2 2001/09/19 02:57:18 grmcdorman Exp $
4  *
5  * Written by David Flanagan.
6  * Copyright (c) 1992-2001 by David Flanagan.
7  * All Rights Reserved.  See the file COPYRIGHT for details.
8  * This is open source software.  See the file LICENSE for details.
9  * There is no warranty for this software.  See NO_WARRANTY for details.
10  *
11  * $Log: Xmt.h,v $
12  * Revision 1.2  2001/09/19 02:57:18  grmcdorman
13  * This change makes the following modifications:
14  *   A new program, printConfig, is provided. This is built by a
15  *   simple rule in the Makefile and not installed. It prints
16  *   significant defines from Xmt.tmpl.
17  *
18  *   XmtP.h is now generated from XmtP.h.in using printConfig. As
19  *   a result, code compiled outside of the Xmt Imakefiles will
20  *   have all of the Xmt.tmpl defines.
21  *
22  *   Source files are modified to use XmtP.h instead of Xmt.h.
23  *
24  *   WorkingBox.c is modified to use the new Progress widget.
25  *   It can be compiled in the old style if WORKINGBOX_USE_SCALE is
26  *   defined at compile time.
27  *
28  *   Because XmtP.h is generated dynamically, it is removed from CVS
29  *   with this check-in.
30  *
31  * Revision 1.1.1.1  2001/02/10 13:52:09  motiftools
32  * Initial import of Xmt310 to CVS
33  *
34  *
35  */
36 
37 #ifndef _Xmt_h
38 #define _Xmt_h
39 
40 /*
41  * This header will contain whatever #ifdefs and #includes are needed to
42  * make the Xmt library portable on as many platforms as possible
43  */
44 
45 /*
46  * Standard X header files
47  */
48 #include <X11/Intrinsic.h>
49 #include <X11/StringDefs.h>
50 
51 /*
52  * If the compiler can't handle prototypes, tell the Motif headers so
53  */
54 #if NeedFunctionPrototypes == 0
55 #ifndef _NO_PROTO
56 #define _NO_PROTO
57 #endif
58 #endif
59 
60 /*
61  * The standard Motif header file
62  */
63 #include <Xm/Xm.h>
64 
65 /*
66  * Specify what version of Xmt this is.
67  */
68 #define XmtVERSION      4
69 #define XmtREVISION     0
70 #define XmtVersion      (XmtVERSION * 1000 + XmtREVISION)
71 #define XmtPatchlevel   0
72 
73 /*
74  * figure out what version of Xt we're using.
75  */
76 #if defined(XtSpecificationRelease)
77 #  define X11R4
78 #else
79 #  undef X11R4
80 #endif
81 #if defined(XtSpecificationRelease) && XtSpecificationRelease >= 5
82 #  define X11R5
83 #else
84 #  undef X11R5
85 #endif
86 
87 /*
88  * There were some useful Xrm functions, etc. added in R5.
89  * Pre-R5, they can be approximated as follows:
90  */
91 #ifndef X11R5
92 #  define XrmGetDatabase(dpy) ((dpy)->db)
93 #  define XrmSetDatabase(dpy, database) ((dpy)->db = (database))
94 #  define XtScreenDatabase(screen) XtDatabase(DisplayOfScreen(screen))
95 #  define XrmPermStringToQuark(str) XrmStringToQuark(str)
96 #  define XPointer caddr_t
97 #endif
98 
99 /*
100  * The MIT X11R5 implementation defines some useful C++
101  * portability stuff.  We redefine it here in case we're using
102  * X11R4 or some other implementation
103  */
104 #ifndef _XFUNCPROTOBEGIN
105 #  ifdef __cplusplus	       	/* for C++ V2.0 */
106 #    define _XFUNCPROTOBEGIN extern "C" {
107 #    define _XFUNCPROTOEND }
108 #  else
109 #    define _XFUNCPROTOBEGIN
110 #    define _XFUNCPROTOEND
111 #  endif /* __cplusplus */
112 #endif /* _XFUNCPROTOBEGIN */
113 
114 /*
115  * const String s; is the same as char * const s; not const char *s;
116  * The latter is really what we want.  As a workaround, we define
117  * a new type StringConst which is a const char *.
118  * Note that we can declare: const StringConst s;
119  */
120 #if __STDC__ || defined(__cplusplus) || defined(c_plusplus)
121 typedef const char *StringConst;
122 #ifndef _Xconst
123 #define _Xconst const
124 #endif
125 #else
126 typedef char * StringConst;
127 #ifndef _Xconst
128 #define _Xconst /* as nothing */
129 #endif
130 #endif
131 
132 /*
133  * In R4 we get the database of a widget with XtDatabase(); in
134  * R5 we use XtScreenDatabase().  So we define a macro that will
135  * do the right thing for us.
136  */
137 #ifndef X11R5
138 #define XmtDatabaseOfWidget(w) (XtDatabase(XtDisplayOfObject(w)))
139 #else
140 #define XmtDatabaseOfWidget(w) (XtScreenDatabase(XtScreenOfObject(w)))
141 #endif
142 
143 /*
144  * Standard C and K&R C handle varargs routines slightly differently.
145  */
146 #if NeedVarargsPrototypes
147 # include <stdarg.h>
148 # define Va_start(a,b) va_start(a,b)
149 #else
150 # include <varargs.h>
151 # define Va_start(a,b) va_start(a)
152 #endif
153 
154 /*
155  * In K&R C, function arguments are all made at least as long as an int.
156  * In ANSI-C, using prototypes, it is possible to pass function arguments
157  * in their "narrow" form.  This library might be compiled with an ANSI
158  * compiler, but linked with code compiled with K&R, so we have to be
159  * careful not to use narrow arguments in this way, unless we are
160  * explicitly told not to worry about it.
161  *
162  * Client code generally doesn't need to worry about being compiled with
163  * mixed compilers, so you shouldn't have to use these.  If you do, only
164  * use them in the prototypes for function definitions and declarations,
165  * not as variables or structure fields.
166  */
167 #if NeedWidePrototypes /* almost always defined to True */
168 #define XmtWideBoolean int
169 #define XmtWideDimension unsigned int
170 #define XmtWidePosition int
171 #else
172 #define XmtWideBoolean Boolean
173 #define XmtWideDimension Dimension
174 #define XmtWidePosition Position
175 #endif
176 
177 /*
178  * if compiling with gcc version 2, there are some cool type-checking and
179  * optimizations things we can do, through gcc extensions to the C grammar.
180  * use -Wformat (or -Wall) to get warnings about bad printf style args.
181  */
182 #if defined(__GNUC__) && __GNUC__ >= 2 && !defined(__STRICT_ANSI__)
183 /*
184  * these first two are superseded in gcc 2.5, and are no longer
185  * used anywhere in Xmt.  They remain here in case someone else
186  * started using them, though.
187  */
188 #define gcc_const_func const
189 #define gcc_volatile_func volatile
190 #define gcc_printf_func(format_arg_num, first_vararg_num)\
191    __attribute__((format (printf, format_arg_num, first_vararg_num)))
192 #if defined(__GNUC_MINOR__) && __GNUC_MINOR__ >= 5 && !defined(__STRICT_ANSI__)
193 /*
194  * In gcc 2.5 and later, we can define these to help the compiler optimize.
195  * They are actually used in Xmt, so compiling with gcc 2.5 gives a minor
196  * optimization boost.
197  */
198 #define gcc_const_attribute __attribute__((const))
199 #define gcc_volatile_attribute __attribute__((noreturn))
200 #else
201 /* if not gcc 2.5 or later, these two aren't defined */
202 #define gcc_const_attribute
203 #define gcc_volatile_attribute
204 #endif
205 #else
206 /* if not gcc 2.0 or later , none of these are defined */
207 #define gcc_const_func
208 #define gcc_volatile_func
209 #define gcc_printf_func(a,b)
210 #define gcc_const_attribute
211 #define gcc_volatile_attribute
212 #endif
213 
214 /*
215  * In X11R5, Intrinsic.h includes Xosdefs.h which defines the symbols
216  * X_NOT_STDC_ENV and X_NOT_POSIX_ENV for systems without the standard
217  * C and Posix header files.  These are useful to know when we can
218  * to include <stdlib.h>, for example, and when we should just declare
219  * the functions we want explicitly.
220  *
221  * X_NOT_STDC_ENV means does not have ANSI C header files.  Lack of this
222  * symbol does NOT mean that the system has stdarg.h.
223  *
224  * X_NOT_POSIX means does not have POSIX header files.  Lack of this
225  * symbol does NOT mean that the POSIX environment is the default.
226  * You may still have to define _POSIX_SOURCE to get it.
227  *
228  * For X11R4, we just include the contents of the X11R5 file here
229  * See the file COPYRIGHT for the applicable MIT copyright notice.
230  */
231 #ifndef X11R5
232 #ifndef _XOSDEFS_H_
233 #define _XOSDEFS_H_
234 
235 #ifdef NOSTDHDRS
236 #define X_NOT_POSIX
237 #define X_NOT_STDC_ENV
238 #endif
239 
240 #ifdef sony
241 #ifndef SYSTYPE_SYSV
242 #define X_NOT_POSIX
243 #endif
244 #endif
245 
246 #ifdef UTEK
247 #define X_NOT_POSIX
248 #define X_NOT_STDC_ENV
249 #endif
250 
251 #ifdef CRAY
252 #define X_NOT_POSIX
253 #endif
254 
255 #ifdef vax
256 #ifndef ultrix			/* assume vanilla BSD */
257 #define X_NOT_POSIX
258 #define X_NOT_STDC_ENV
259 #endif
260 #endif
261 
262 #ifdef luna
263 #define X_NOT_POSIX
264 #define X_NOT_STDC_ENV
265 #endif
266 
267 #ifdef Mips
268 #define X_NOT_POSIX
269 #define X_NOT_STDC_ENV
270 #endif
271 
272 #ifdef USL
273 #ifdef SYSV /* (release 3.2) */
274 #define X_NOT_POSIX
275 #define X_NOT_STDC_ENV
276 #endif
277 #endif
278 
279 #ifdef SYSV386
280 #ifdef SYSV
281 #define X_NOT_POSIX
282 #define X_NOT_STDC_ENV
283 #endif
284 #endif
285 
286 #ifdef MOTOROLA
287 #ifdef SYSV
288 #define X_NOT_STDC_ENV
289 #endif
290 #endif
291 #endif /* _XOSDEFS_H_ */
292 #endif
293 
294 /*
295  * some special representation types used in the library
296  */
297 
298 /* A special type used in a number of places; different from XtRString */
299 #ifndef XmtRBuffer
300 #define XmtRBuffer "Buffer"
301 #endif
302 
303 /* Xt doesn't define an XtRDouble */
304 #ifndef XmtRDouble
305 #define XmtRDouble "Double"
306 #endif
307 
308 /*
309  * This macro is an analog to XtOffsetOf.  Instead of returning the
310  * offset of a field in a structure of the specified type, however,
311  * it returns the size of that field.  It is particularly useful when
312  * declaring resource lists with XmtRBuffer resources, because we can't
313  * just use sizeof() with fields like "char name[40];"
314  */
315 #define XmtSizeOf(type, field) sizeof(((type *)0)->field)
316 
317 /*
318  * Here is some portability stuff for Motif 1.1
319  */
320 #if XmVersion == 1001
321 #define XmGetPixmapByDepth(s,i,f,b,d) XmGetPixmap(s,i,f,b)
322 #endif
323 
324 /*
325  * Some common Xmt functions
326  */
327 #include <Xmt/Util.h>
328 
329 #endif /* _Xmt_h */
330