Remove trailing spaces in source files
[profile/ivi/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
76 uAlloc(unsigned size);
77
78 extern Opaque
79 uCalloc(unsigned n, unsigned  size);
80
81 extern Opaque
82 uRealloc(Opaque old, unsigned newSize);
83
84 extern Opaque
85 uRecalloc(Opaque old, unsigned nOld, unsigned nNew, unsigned newSize);
86
87 extern void
88 uFree(Opaque ptr);
89
90 #define uTypedAlloc(t)          ((t *)uAlloc((unsigned)sizeof(t)))
91 #define uTypedCalloc(n,t)       ((t *)uCalloc((unsigned)n,(unsigned)sizeof(t)))
92 #define uTypedRealloc(pO,n,t)   ((t *)uRealloc((Opaque)pO,((unsigned)n)*sizeof(t)))
93 #define uTypedRecalloc(pO,o,n,t) ((t *)uRecalloc((Opaque)pO,((unsigned)o),((unsigned)n),sizeof(t)))
94 #if (defined mdHasAlloca) && (mdHasAlloca)
95 #define uTmpAlloc(n)    ((Opaque)alloca((unsigned)n))
96 #define uTmpFree(p)
97 #else
98 #define uTmpAlloc(n)    uAlloc(n)
99 #define uTmpFree(p)     uFree(p)
100 #endif
101
102 /***====================================================================***/
103
104 extern Boolean
105 uSetErrorFile(char *name);
106
107 #if defined(__GNUC__) && \
108     ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
109 #define __ATTR_PRINTF(i, f) __attribute__ ((format(printf, (i), (f))))
110 #else
111 #define __ATTR_PRINTF(i, f)
112 #endif
113
114 #define INFO                    uInformation
115
116 extern __ATTR_PRINTF(1, 2) void
117 uInformation(const char *s, ...);
118
119 #define ACTION                  uAction
120
121 extern __ATTR_PRINTF(1, 2) void
122 uAction(const char *s, ...);
123
124 #define WARN                    uWarning
125
126 extern __ATTR_PRINTF(1, 2) void
127 uWarning(const char *s, ...);
128
129 #define ERROR                   uError
130
131 extern __ATTR_PRINTF(1, 2) void
132 uError(const char *s, ...);
133
134 #define FATAL                   uFatalError
135
136 extern __ATTR_PRINTF(1, 2) void
137 uFatalError(const char *s, ...);
138
139 /* WSGO stands for "Weird Stuff Going On" (wtf???) */
140 #define WSGO                    uInternalError
141
142 extern __ATTR_PRINTF(1, 2) void
143 uInternalError(const char *s, ...);
144
145 extern void
146 uSetPreErrorMessage(char *msg);
147
148 extern void
149 uSetPostErrorMessage(char *msg);
150
151 extern void
152 uSetErrorPrefix(char *pre);
153
154 extern void
155 uFinishUp(void);
156
157
158 /***====================================================================***/
159
160 #define NullString      ((char *)NULL)
161
162 #define uStringText(s)          ((s)==NullString?"<NullString>":(s))
163 #define uStringEqual(s1,s2)     (uStringCompare(s1,s2)==Equal)
164 #define uStringPrefix(p,s)      (strncmp(p,s,strlen(p))==0)
165 #define uStringCompare(s1,s2)   (((s1)==NullString||(s2)==NullString)?\
166                                  (s1)!=(s2):strcmp(s1,s2))
167 #define uStrCaseEqual(s1,s2)    (uStrCaseCmp(s1,s2)==0)
168 #ifdef HAVE_STRCASECMP
169 #define uStrCaseCmp(s1,s2)      (strcasecmp(s1,s2))
170 #define uStrCasePrefix(p,s)     (strncasecmp(p,s,strlen(p))==0)
171 #else
172 extern int
173 uStrCaseCmp(const char *s1, const char *s2);
174 extern int
175 uStrCasePrefix(const char *p, char *str);
176 #endif
177 #ifdef HAVE_STRDUP
178 #define uStringDup(s1)          ((s1) ? strdup(s1) : NULL)
179 #else
180 extern char *
181 uStringDup(const char *s);
182 #endif
183
184 /***====================================================================***/
185
186 #ifdef  ASSERTIONS_ON
187 #define uASSERT(where,why) \
188         {if (!(why)) uFatalError("assertion botched in %s ( why )\n",where);}
189 #else
190 #define uASSERT(where,why)
191 #endif
192
193 /***====================================================================***/
194
195 #ifndef DEBUG_VAR
196 #define DEBUG_VAR       debugFlags
197 #endif
198
199 extern unsigned int DEBUG_VAR;
200
201 extern __ATTR_PRINTF(1, 2) void
202 uDebug(char *s, ...);
203
204 extern __ATTR_PRINTF(1, 2) void
205 uDebugNOI(char *s, ...);
206
207 extern Boolean
208 uSetDebugFile(char *name);
209
210 extern FILE *uDebugFile;
211 extern int uDebugIndentLevel;
212 extern int uDebugIndentSize;
213
214 #define uDebugIndent(l)         (uDebugIndentLevel+=(l))
215 #define uDebugOutdent(l)        (uDebugIndentLevel-=(l))
216 #ifdef DEBUG_ON
217 #define uDEBUG(f,s)             { if (DEBUG_VAR&(f)) uDebug(s);}
218 #define uDEBUG1(f,s,a)          { if (DEBUG_VAR&(f)) uDebug(s,a);}
219 #define uDEBUG2(f,s,a,b)        { if (DEBUG_VAR&(f)) uDebug(s,a,b);}
220 #define uDEBUG3(f,s,a,b,c)      { if (DEBUG_VAR&(f)) uDebug(s,a,b,c);}
221 #define uDEBUG4(f,s,a,b,c,d)    { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d);}
222 #define uDEBUG5(f,s,a,b,c,d,e)  { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d,e);}
223 #define uDEBUG_NOI(f,s)         { if (DEBUG_VAR&(f)) uDebug(s);}
224 #define uDEBUG_NOI1(f,s,a)      { if (DEBUG_VAR&(f)) uDebugNOI(s,a);}
225 #define uDEBUG_NOI2(f,s,a,b)    { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b);}
226 #define uDEBUG_NOI3(f,s,a,b,c)  { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c);}
227 #define uDEBUG_NOI4(f,s,a,b,c,d) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c,d);}
228 #define uDEBUG_NOI5(f,s,a,b,c,d,e) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c,d,e);}
229 #else
230 #define uDEBUG(f,s)
231 #define uDEBUG1(f,s,a)
232 #define uDEBUG2(f,s,a,b)
233 #define uDEBUG3(f,s,a,b,c)
234 #define uDEBUG4(f,s,a,b,c,d)
235 #define uDEBUG5(f,s,a,b,c,d,e)
236 #define uDEBUG_NOI(f,s)
237 #define uDEBUG_NOI1(f,s,a)
238 #define uDEBUG_NOI2(f,s,a,b)
239 #define uDEBUG_NOI3(f,s,a,b,c)
240 #define uDEBUG_NOI4(f,s,a,b,c,d)
241 #define uDEBUG_NOI5(f,s,a,b,c,d,e)
242 #endif
243
244 extern Boolean
245 uSetEntryFile(char *name);
246
247 extern __ATTR_PRINTF(2, 3) void
248 uEntry(int l, char *s, ...);
249
250 extern void
251 uExit(int l, char *rtVal);
252
253 #ifdef ENTRY_TRACKING_ON
254 #define ENTRY_BIT       0x10
255 #define LOW_ENTRY_BIT   0x1000
256 #define ENTER   (DEBUG_VAR&ENTRY_BIT)
257 #define FLAG(fLag)      (DEBUG_VAR&(fLag))
258
259 extern int uEntryLevel;
260
261 #define uENTRY(s)                       { if (ENTER) uEntry(1,s);}
262 #define uENTRY1(s,a)                    { if (ENTER) uEntry(1,s,a);}
263 #define uENTRY2(s,a,b)                  { if (ENTER) uEntry(1,s,a,b);}
264 #define uENTRY3(s,a,b,c)                { if (ENTER) uEntry(1,s,a,b,c);}
265 #define uENTRY4(s,a,b,c,d)              { if (ENTER) uEntry(1,s,a,b,c,d);}
266 #define uENTRY5(s,a,b,c,d,e)            { if (ENTER) uEntry(1,s,a,b,c,d,e);}
267 #define uENTRY6(s,a,b,c,d,e,f)          { if (ENTER) uEntry(1,s,a,b,c,d,e,f);}
268 #define uENTRY7(s,a,b,c,d,e,f,g)        { if (ENTER) uEntry(1,s,a,b,c,d,e,f,g);}
269 #define uRETURN(v)                      { if (ENTER) uEntryLevel--; return(v); }
270 #define uVOIDRETURN                     { if (ENTER) uEntryLevel--; return; }
271
272 #define uFLAG_ENTRY(w,s)                { if (FLAG(w)) uEntry(0,s);}
273 #define uFLAG_ENTRY1(w,s,a)             { if (FLAG(w)) uEntry(0,s,a);}
274 #define uFLAG_ENTRY2(w,s,a,b)           { if (FLAG(w)) uEntry(0,s,a,b);}
275 #define uFLAG_ENTRY3(w,s,a,b,c)         { if (FLAG(w)) uEntry(0,s,a,b,c);}
276 #define uFLAG_ENTRY4(w,s,a,b,c,d)       { if (FLAG(w)) uEntry(0,s,a,b,c,d);}
277 #define uFLAG_ENTRY5(w,s,a,b,c,d,e)     { if (FLAG(w)) uEntry(0,s,a,b,c,d,e);}
278 #define uFLAG_ENTRY6(w,s,a,b,c,d,e,f)   { if (FLAG(w)) uEntry(0,s,a,b,c,d,e,f);}
279 #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);}
280 #define uFLAG_RETURN(v)                 { return(v);}
281 #define uFLAG_VOIDRETURN                { return; }
282 #else
283 #define uENTRY(s)
284 #define uENTRY1(s,a)
285 #define uENTRY2(s,a1,a2)
286 #define uENTRY3(s,a1,a2,a3)
287 #define uENTRY4(s,a1,a2,a3,a4)
288 #define uENTRY5(s,a1,a2,a3,a4,a5)
289 #define uENTRY6(s,a1,a2,a3,a4,a5,a6)
290 #define uENTRY7(s,a1,a2,a3,a4,a5,a6,a7)
291 #define uRETURN(v)      { return(v); }
292 #define uVOIDRETURN     { return; }
293
294 #define uFLAG_ENTRY(f,s)
295 #define uFLAG_ENTRY1(f,s,a)
296 #define uFLAG_ENTRY2(f,s,a,b)
297 #define uFLAG_ENTRY3(f,s,a,b,c)
298 #define uFLAG_ENTRY4(f,s,a,b,c,d)
299 #define uFLAG_ENTRY5(f,s,a,b,c,d,e)
300 #define uFLAG_ENTRY6(f,s,a,b,c,d,e,g)
301 #define uFLAG_ENTRY7(f,s,a,b,c,d,e,g,h)
302 #define uFLAG_RETURN(v)                 { return(v);}
303 #define uFLAG_VOIDRETURN                { return; }
304 #endif
305
306 #endif /* UTILS_H */