1 #ifndef _REPLACE_Xt_HEADER_
2 #define _REPLACE_Xt_HEADER_
3 
4 /*---- Attempt to finesse old use of Xt in non-graphics code [09 Nov 2018] ---*/
5 /*---- Method: change all 'Xt' to 'Rwc' and then define/typedef them away  ---*/
6 
7 # ifndef offsetof            /* should not be needed */
8 #  define offsetof(st, m) ((size_t)&(((st *)0)->m))
9 # endif
10 
11 /*---- If REPLACE_XT is defined as a compile flag X11 memory allocation is
12      swapped out for C's malloc. This allows libmri.so to be compiled and
13      linked without X11 as a dependency ---*/
14 #ifdef  REPLACE_XT           /* this is the finesse */
15 
16 typedef   void*           RwcPointer ;
17 # define  RwcFree         free
18 # define  RwcCalloc       calloc
19 # define  RwcOffsetOf     offsetof
20 # define  RwcRealloc      realloc
21 # define  RwcMalloc       malloc
22 # define  RwcNew(t)       ((t *)calloc(1,sizeof(t)))
23 # define  RwcNewString(s) (strcpy(malloc(1+strlen(s)),s))
24 
25 typedef   unsigned char   RwcBoolean ;  /* 07 Jul 2020 */
26 #undef  True
27 #undef  False
28 #define True  1
29 #define False 0
30 
31 typedef unsigned int RwcCardinal ;      /* 08 Jul 2020 */
32 typedef void *       RwcWidget ;        /* 10 Jul 2020 */
33 
34 #else                        /* this is the crudesse */
35 
36 # include <X11/Intrinsic.h>
37 # define  RwcPointer      XtPointer
38 # define  RwcBoolean      Boolean
39 # define  RwcFree         XtFree
40 # define  RwcCalloc       XtCalloc
41 # define  RwcOffsetOf     XtOffsetOf
42 # define  RwcRealloc      XtRealloc
43 # define  RwcMalloc       XtMalloc
44 # define  RwcNew          XtNew
45 # define  RwcNewString    XtNewString
46 # define  RwcWidget       Widget
47 # define  RwcCardinal     Cardinal
48 
49 #endif
50 
51 #undef  myRwcFree
52 #undef  myRwcNew
53 
54 /*! Macro to free a pointer and NULL-ize it as well. */
55 #define myRwcFree(xp) (RwcFree((char *)(xp)) , (xp)=NULL)
56 
57 /*! Macro to allocate memory and zero-ize it. */
58 #define myRwcNew(type) ((type *) RwcCalloc(1,(unsigned) sizeof(type)))
59 
60 #endif
61