xkbcomp: Remove duplicated macros
[platform/upstream/libxkbcommon.git] / src / xkbcomp / utils.h
1 #ifndef UTILS_H
2 #define UTILS_H 1
3
4   /*\
5    *
6    *                          COPYRIGHT 1990
7    *                    DIGITAL EQUIPMENT CORPORATION
8    *                       MAYNARD, MASSACHUSETTS
9    *                        ALL RIGHTS RESERVED.
10    *
11    * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
12    * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
13    * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE 
14    * FOR ANY PURPOSE.  IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED 
15    * WARRANTY.
16    *
17    * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT
18    * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN
19    * ADDITION TO THAT SET FORTH ABOVE.
20    *
21    * Permission to use, copy, modify, and distribute this software and its
22    * documentation for any purpose and without fee is hereby granted, provided
23    * that the above copyright notice appear in all copies and that both that
24    * copyright notice and this permission notice appear in supporting
25    * documentation, and that the name of Digital Equipment Corporation not be
26    * used in advertising or publicity pertaining to distribution of the 
27    * software without specific, written prior permission.
28    \*/
29
30 /***====================================================================***/
31
32 #include        <stdio.h>
33 #include        <X11/Xos.h>
34 #include        <X11/Xfuncproto.h>
35 #include        <X11/Xfuncs.h>
36
37 #include <stddef.h>
38 #include "config.h"
39
40 #ifndef NUL
41 #define NUL     '\0'
42 #endif
43
44 /***====================================================================***/
45
46 #ifndef OPAQUE_DEFINED
47 typedef void *Opaque;
48 #endif
49 #ifndef NullOpaque
50 #define NullOpaque      ((Opaque)NULL)
51 #endif
52
53 #ifndef BOOLEAN_DEFINED
54 typedef char Boolean;
55 #endif
56
57 #ifndef True
58 #define True    ((Boolean)1)
59 #define False   ((Boolean)0)
60 #endif /* ndef True */
61 #define booleanText(b)  ((b)?"True":"False")
62
63 #ifndef COMPARISON_DEFINED
64 typedef int Comparison;
65
66 #define Greater         ((Comparison)1)
67 #define Equal           ((Comparison)0)
68 #define Less            ((Comparison)-1)
69 #define CannotCompare   ((Comparison)-37)
70 #define comparisonText(c)       ((c)?((c)<0?"Less":"Greater"):"Equal")
71 #endif
72
73 /***====================================================================***/
74
75 extern Opaque uAlloc(unsigned   /* size */
76     );
77 extern Opaque uCalloc(unsigned /* n */ ,
78                       unsigned  /* size */
79     );
80 extern Opaque uRealloc(Opaque /* old */ ,
81                        unsigned /* newSize */
82     );
83 extern Opaque uRecalloc(Opaque /* old */ ,
84                         unsigned /* nOld */ ,
85                         unsigned /* nNew */ ,
86                         unsigned        /* newSize */
87     );
88 extern void uFree(Opaque        /* ptr */
89     );
90
91 #define uTypedAlloc(t)          ((t *)uAlloc((unsigned)sizeof(t)))
92 #define uTypedCalloc(n,t)       ((t *)uCalloc((unsigned)n,(unsigned)sizeof(t)))
93 #define uTypedRealloc(pO,n,t)   ((t *)uRealloc((Opaque)pO,((unsigned)n)*sizeof(t)))
94 #define uTypedRecalloc(pO,o,n,t) ((t *)uRecalloc((Opaque)pO,((unsigned)o),((unsigned)n),sizeof(t)))
95 #if (defined mdHasAlloca) && (mdHasAlloca)
96 #define uTmpAlloc(n)    ((Opaque)alloca((unsigned)n))
97 #define uTmpFree(p)
98 #else
99 #define uTmpAlloc(n)    uAlloc(n)
100 #define uTmpFree(p)     uFree(p)
101 #endif
102
103 /***====================================================================***/
104
105 extern Boolean uSetErrorFile(char *     /* name */
106     );
107
108 #define INFO                    uInformation
109
110 extern void
111 uInformation(const char * /* s */ , ...
112     )
113 #if defined(__GNUC__) && \
114     ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
115     __attribute__ ((format(printf, 1, 2)))
116 #endif
117     ;
118
119 #define ACTION                  uAction
120
121      extern void uAction(const char * /* s  */ , ...
122     )
123 #if defined(__GNUC__) && \
124     ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
125     __attribute__ ((format(printf, 1, 2)))
126 #endif
127     ;
128
129 #define WARN                    uWarning
130
131      extern void uWarning(const char * /* s  */ , ...
132     )
133 #if defined(__GNUC__) && \
134     ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
135     __attribute__ ((format(printf, 1, 2)))
136 #endif
137     ;
138
139 #define ERROR                   uError
140
141      extern void uError(const char * /* s  */ , ...
142     )
143 #if defined(__GNUC__) && \
144     ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
145     __attribute__ ((format(printf, 1, 2)))
146 #endif
147     ;
148
149 #define FATAL                   uFatalError
150
151      extern void uFatalError(const char * /* s  */ , ...
152     )
153 #if defined(__GNUC__) && \
154     ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
155     __attribute__ ((format(printf, 1, 2)))
156 #endif
157     ;
158
159 /* WSGO stands for "Weird Stuff Going On" (wtf???) */
160 #define WSGO                    uInternalError
161
162      extern void uInternalError(const char * /* s  */ , ...
163     )
164 #if defined(__GNUC__) && \
165     ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
166     __attribute__ ((format(printf, 1, 2)))
167 #endif
168     ;
169
170      extern void uSetPreErrorMessage(char *     /* msg */
171     );
172
173      extern void uSetPostErrorMessage(char *    /* msg */
174     );
175
176      extern void uSetErrorPrefix(char * /* void */
177     );
178
179      extern void uFinishUp(void);
180
181
182 /***====================================================================***/
183
184 #define NullString      ((char *)NULL)
185
186 #define uStringText(s)          ((s)==NullString?"<NullString>":(s))
187 #define uStringEqual(s1,s2)     (uStringCompare(s1,s2)==Equal)
188 #define uStringPrefix(p,s)      (strncmp(p,s,strlen(p))==0)
189 #define uStringCompare(s1,s2)   (((s1)==NullString||(s2)==NullString)?\
190                                  (s1)!=(s2):strcmp(s1,s2))
191 #define uStrCaseEqual(s1,s2)    (uStrCaseCmp(s1,s2)==0)
192 #ifdef HAVE_STRCASECMP
193 #define uStrCaseCmp(s1,s2)      (strcasecmp(s1,s2))
194 #define uStrCasePrefix(p,s)     (strncasecmp(p,s,strlen(p))==0)
195 #else
196      extern int uStrCaseCmp(const char * /* s1 */ ,
197                             const char *        /* s2 */
198     );
199      extern int uStrCasePrefix(const char * /* p */ ,
200                                char *   /* str */
201     );
202 #endif
203 #ifdef HAVE_STRDUP
204 #define uStringDup(s1)          (strdup(s1))
205 #else
206      extern char *uStringDup(const char *       /* s1 */
207     );
208 #endif
209
210 /***====================================================================***/
211
212 #ifdef  ASSERTIONS_ON
213 #define uASSERT(where,why) \
214         {if (!(why)) uFatalError("assertion botched in %s ( why )\n",where);}
215 #else
216 #define uASSERT(where,why)
217 #endif
218
219 /***====================================================================***/
220
221 #ifndef DEBUG_VAR
222 #define DEBUG_VAR       debugFlags
223 #endif
224
225 extern
226      unsigned int DEBUG_VAR;
227
228      extern void uDebug(char * /* s  */ , ...
229     )
230 #if defined(__GNUC__) && \
231     ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
232     __attribute__ ((format(printf, 1, 2)))
233 #endif
234     ;
235
236      extern void uDebugNOI(     /* no indent */
237                               char * /* s  */ , ...
238     )
239 #if defined(__GNUC__) && \
240     ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
241     __attribute__ ((format(printf, 1, 2)))
242 #endif
243     ;
244
245      extern Boolean uSetDebugFile(char *name);
246
247      extern FILE *uDebugFile;
248      extern int uDebugIndentLevel;
249      extern int uDebugIndentSize;
250 #define uDebugIndent(l)         (uDebugIndentLevel+=(l))
251 #define uDebugOutdent(l)        (uDebugIndentLevel-=(l))
252 #ifdef DEBUG_ON
253 #define uDEBUG(f,s)             { if (DEBUG_VAR&(f)) uDebug(s);}
254 #define uDEBUG1(f,s,a)          { if (DEBUG_VAR&(f)) uDebug(s,a);}
255 #define uDEBUG2(f,s,a,b)        { if (DEBUG_VAR&(f)) uDebug(s,a,b);}
256 #define uDEBUG3(f,s,a,b,c)      { if (DEBUG_VAR&(f)) uDebug(s,a,b,c);}
257 #define uDEBUG4(f,s,a,b,c,d)    { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d);}
258 #define uDEBUG5(f,s,a,b,c,d,e)  { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d,e);}
259 #define uDEBUG_NOI(f,s)         { if (DEBUG_VAR&(f)) uDebug(s);}
260 #define uDEBUG_NOI1(f,s,a)      { if (DEBUG_VAR&(f)) uDebugNOI(s,a);}
261 #define uDEBUG_NOI2(f,s,a,b)    { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b);}
262 #define uDEBUG_NOI3(f,s,a,b,c)  { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c);}
263 #define uDEBUG_NOI4(f,s,a,b,c,d) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c,d);}
264 #define uDEBUG_NOI5(f,s,a,b,c,d,e) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c,d,e);}
265 #else
266 #define uDEBUG(f,s)
267 #define uDEBUG1(f,s,a)
268 #define uDEBUG2(f,s,a,b)
269 #define uDEBUG3(f,s,a,b,c)
270 #define uDEBUG4(f,s,a,b,c,d)
271 #define uDEBUG5(f,s,a,b,c,d,e)
272 #define uDEBUG_NOI(f,s)
273 #define uDEBUG_NOI1(f,s,a)
274 #define uDEBUG_NOI2(f,s,a,b)
275 #define uDEBUG_NOI3(f,s,a,b,c)
276 #define uDEBUG_NOI4(f,s,a,b,c,d)
277 #define uDEBUG_NOI5(f,s,a,b,c,d,e)
278 #endif
279
280      extern Boolean uSetEntryFile(char *name);
281      extern void uEntry(int /* l */ ,
282                         char * /* s  */ , ...
283     )
284 #if defined(__GNUC__) && \
285     ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
286     __attribute__ ((format(printf, 2, 3)))
287 #endif
288     ;
289
290      extern void uExit(int l, char *rtVal);
291 #ifdef ENTRY_TRACKING_ON
292 #define ENTRY_BIT       0x10
293 #define LOW_ENTRY_BIT   0x1000
294 #define ENTER   (DEBUG_VAR&ENTRY_BIT)
295 #define FLAG(fLag)      (DEBUG_VAR&(fLag))
296
297      extern int uEntryLevel;
298
299 #define uENTRY(s)                       { if (ENTER) uEntry(1,s);}
300 #define uENTRY1(s,a)                    { if (ENTER) uEntry(1,s,a);}
301 #define uENTRY2(s,a,b)                  { if (ENTER) uEntry(1,s,a,b);}
302 #define uENTRY3(s,a,b,c)                { if (ENTER) uEntry(1,s,a,b,c);}
303 #define uENTRY4(s,a,b,c,d)              { if (ENTER) uEntry(1,s,a,b,c,d);}
304 #define uENTRY5(s,a,b,c,d,e)            { if (ENTER) uEntry(1,s,a,b,c,d,e);}
305 #define uENTRY6(s,a,b,c,d,e,f)          { if (ENTER) uEntry(1,s,a,b,c,d,e,f);}
306 #define uENTRY7(s,a,b,c,d,e,f,g)        { if (ENTER) uEntry(1,s,a,b,c,d,e,f,g);}
307 #define uRETURN(v)                      { if (ENTER) uEntryLevel--; return(v); }
308 #define uVOIDRETURN                     { if (ENTER) uEntryLevel--; return; }
309
310 #define uFLAG_ENTRY(w,s)                { if (FLAG(w)) uEntry(0,s);}
311 #define uFLAG_ENTRY1(w,s,a)             { if (FLAG(w)) uEntry(0,s,a);}
312 #define uFLAG_ENTRY2(w,s,a,b)           { if (FLAG(w)) uEntry(0,s,a,b);}
313 #define uFLAG_ENTRY3(w,s,a,b,c)         { if (FLAG(w)) uEntry(0,s,a,b,c);}
314 #define uFLAG_ENTRY4(w,s,a,b,c,d)       { if (FLAG(w)) uEntry(0,s,a,b,c,d);}
315 #define uFLAG_ENTRY5(w,s,a,b,c,d,e)     { if (FLAG(w)) uEntry(0,s,a,b,c,d,e);}
316 #define uFLAG_ENTRY6(w,s,a,b,c,d,e,f)   { if (FLAG(w)) uEntry(0,s,a,b,c,d,e,f);}
317 #define uFLAG_ENTRY7(w,s,a,b,c,d,e,f,g) { if(FLAG(w))uEntry(0,s,a,b,c,d,e,f,g);}
318 #define uFLAG_RETURN(v)                 { return(v);}
319 #define uFLAG_VOIDRETURN                { return; }
320 #else
321 #define uENTRY(s)
322 #define uENTRY1(s,a)
323 #define uENTRY2(s,a1,a2)
324 #define uENTRY3(s,a1,a2,a3)
325 #define uENTRY4(s,a1,a2,a3,a4)
326 #define uENTRY5(s,a1,a2,a3,a4,a5)
327 #define uENTRY6(s,a1,a2,a3,a4,a5,a6)
328 #define uENTRY7(s,a1,a2,a3,a4,a5,a6,a7)
329 #define uRETURN(v)      { return(v); }
330 #define uVOIDRETURN     { return; }
331
332 #define uFLAG_ENTRY(f,s)
333 #define uFLAG_ENTRY1(f,s,a)
334 #define uFLAG_ENTRY2(f,s,a,b)
335 #define uFLAG_ENTRY3(f,s,a,b,c)
336 #define uFLAG_ENTRY4(f,s,a,b,c,d)
337 #define uFLAG_ENTRY5(f,s,a,b,c,d,e)
338 #define uFLAG_ENTRY6(f,s,a,b,c,d,e,g)
339 #define uFLAG_ENTRY7(f,s,a,b,c,d,e,g,h)
340 #define uFLAG_RETURN(v)                 { return(v);}
341 #define uFLAG_VOIDRETURN                { return; }
342 #endif
343
344
345 #endif /* UTILS_H */