5
* $Xorg: utils.h,v 1.3 2000/08/17 19:54:33 cpqbld Exp $
8
* DIGITAL EQUIPMENT CORPORATION
9
* MAYNARD, MASSACHUSETTS
10
* ALL RIGHTS RESERVED.
12
* THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
13
* SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
14
* DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE
15
* FOR ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED
18
* IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT
19
* RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN
20
* ADDITION TO THAT SET FORTH ABOVE.
22
* Permission to use, copy, modify, and distribute this software and its
23
* documentation for any purpose and without fee is hereby granted, provided
24
* that the above copyright notice appear in all copies and that both that
25
* copyright notice and this permission notice appear in supporting
26
* documentation, and that the name of Digital Equipment Corporation not be
27
* used in advertising or publicity pertaining to distribution of the
28
* software without specific, written prior permission.
30
/* $XFree86: xc/programs/xkbcomp/utils.h,v 3.6 2002/12/24 17:43:00 tsi Exp $ */
32
/***====================================================================***/
36
#include <X11/Xfuncproto.h>
37
#include <X11/Xfuncs.h>
45
/***====================================================================***/
47
#ifndef OPAQUE_DEFINED
51
#define NullOpaque ((Opaque)NULL)
54
#ifndef BOOLEAN_DEFINED
59
#define True ((Boolean)1)
60
#define False ((Boolean)0)
61
#endif /* ndef True */
62
#define booleanText(b) ((b)?"True":"False")
64
#ifndef COMPARISON_DEFINED
65
typedef int Comparison;
67
#define Greater ((Comparison)1)
68
#define Equal ((Comparison)0)
69
#define Less ((Comparison)-1)
70
#define CannotCompare ((Comparison)-37)
71
#define comparisonText(c) ((c)?((c)<0?"Less":"Greater"):"Equal")
83
/***====================================================================***/
88
extern Opaque uCalloc(
92
extern Opaque uRealloc(
94
unsigned /* newSize */
96
extern Opaque uRecalloc(
100
unsigned /* newSize */
106
#define uTypedAlloc(t) ((t *)uAlloc((unsigned)sizeof(t)))
107
#define uTypedCalloc(n,t) ((t *)uCalloc((unsigned)n,(unsigned)sizeof(t)))
108
#define uTypedRealloc(pO,n,t) ((t *)uRealloc((Opaque)pO,((unsigned)n)*sizeof(t)))
109
#define uTypedRecalloc(pO,o,n,t) ((t *)uRecalloc((Opaque)pO,((unsigned)o),((unsigned)n),sizeof(t)))
110
#if (defined mdHasAlloca) && (mdHasAlloca)
111
#define uTmpAlloc(n) ((Opaque)alloca((unsigned)n))
114
#define uTmpAlloc(n) uAlloc(n)
115
#define uTmpFree(p) uFree(p)
118
/***====================================================================***/
120
extern Boolean uSetErrorFile(
124
#define INFO6 uInformation
125
#define INFO5 uInformation
126
#define INFO4 uInformation
127
#define INFO3 uInformation
128
#define INFO2 uInformation
129
#define INFO1 uInformation
130
#define INFO uInformation
132
extern void uInformation(
135
#if defined(__GNUC__) && \
136
((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
137
__attribute__((format(printf, 1, 2)))
141
#define ACTION6 uAction
142
#define ACTION5 uAction
143
#define ACTION4 uAction
144
#define ACTION3 uAction
145
#define ACTION2 uAction
146
#define ACTION1 uAction
147
#define ACTION uAction
152
#if defined(__GNUC__) && \
153
((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
154
__attribute__((format(printf, 1, 2)))
158
#define WARN6 uWarning
159
#define WARN5 uWarning
160
#define WARN4 uWarning
161
#define WARN3 uWarning
162
#define WARN2 uWarning
163
#define WARN1 uWarning
164
#define WARN uWarning
166
extern void uWarning(
169
#if defined(__GNUC__) && \
170
((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
171
__attribute__((format(printf, 1, 2)))
175
#define ERROR6 uError
176
#define ERROR5 uError
177
#define ERROR4 uError
178
#define ERROR3 uError
179
#define ERROR2 uError
180
#define ERROR1 uError
186
#if defined(__GNUC__) && \
187
((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
188
__attribute__((format(printf, 1, 2)))
192
#define FATAL6 uFatalError
193
#define FATAL5 uFatalError
194
#define FATAL4 uFatalError
195
#define FATAL3 uFatalError
196
#define FATAL2 uFatalError
197
#define FATAL1 uFatalError
198
#define FATAL uFatalError
200
extern void uFatalError(
203
#if defined(__GNUC__) && \
204
((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
205
__attribute__((format(printf, 1, 2)))
209
/* WSGO stands for "Weird Stuff Going On" */
210
#define WSGO6 uInternalError
211
#define WSGO5 uInternalError
212
#define WSGO4 uInternalError
213
#define WSGO3 uInternalError
214
#define WSGO2 uInternalError
215
#define WSGO1 uInternalError
216
#define WSGO uInternalError
218
extern void uInternalError(
221
#if defined(__GNUC__) && \
222
((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
223
__attribute__((format(printf, 1, 2)))
227
extern void uSetPreErrorMessage(
231
extern void uSetPostErrorMessage(
235
extern void uSetErrorPrefix(
239
extern void uFinishUp(
244
/***====================================================================***/
246
#define NullString ((char *)NULL)
248
#define uStringText(s) ((s)==NullString?"<NullString>":(s))
249
#define uStringEqual(s1,s2) (uStringCompare(s1,s2)==Equal)
250
#define uStringPrefix(p,s) (strncmp(p,s,strlen(p))==0)
251
#define uStringCompare(s1,s2) (((s1)==NullString||(s2)==NullString)?\
252
(s1)!=(s2):strcmp(s1,s2))
253
#define uStrCaseEqual(s1,s2) (uStrCaseCmp(s1,s2)==0)
254
#ifdef HAVE_STRCASECMP
255
#define uStrCaseCmp(s1,s2) (strcasecmp(s1,s2))
256
#define uStrCasePrefix(p,s) (strncasecmp(p,s,strlen(p))==0)
258
extern int uStrCaseCmp(
262
extern int uStrCasePrefix(
268
#define uStringDup(s1) (strdup(s1))
270
extern char *uStringDup(
275
/***====================================================================***/
278
#define uASSERT(where,why) \
279
{if (!(why)) uFatalError("assertion botched in %s ( why )\n",where);}
281
#define uASSERT(where,why)
284
/***====================================================================***/
287
#define DEBUG_VAR debugFlags
290
#ifdef DEBUG_VAR_NOT_LOCAL
293
unsigned int DEBUG_VAR;
298
#if defined(__GNUC__) && \
299
((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
300
__attribute__((format(printf, 1, 2)))
304
extern void uDebugNOI( /* no indent */
307
#if defined(__GNUC__) && \
308
((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
309
__attribute__((format(printf, 1, 2)))
313
extern Boolean uSetDebugFile(
317
extern FILE *uDebugFile;
318
extern int uDebugIndentLevel;
319
extern int uDebugIndentSize;
320
#define uDebugIndent(l) (uDebugIndentLevel+=(l))
321
#define uDebugOutdent(l) (uDebugIndentLevel-=(l))
323
#define uDEBUG(f,s) { if (DEBUG_VAR&(f)) uDebug(s);}
324
#define uDEBUG1(f,s,a) { if (DEBUG_VAR&(f)) uDebug(s,a);}
325
#define uDEBUG2(f,s,a,b) { if (DEBUG_VAR&(f)) uDebug(s,a,b);}
326
#define uDEBUG3(f,s,a,b,c) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c);}
327
#define uDEBUG4(f,s,a,b,c,d) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d);}
328
#define uDEBUG5(f,s,a,b,c,d,e) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d,e);}
329
#define uDEBUG_NOI(f,s) { if (DEBUG_VAR&(f)) uDebug(s);}
330
#define uDEBUG_NOI1(f,s,a) { if (DEBUG_VAR&(f)) uDebugNOI(s,a);}
331
#define uDEBUG_NOI2(f,s,a,b) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b);}
332
#define uDEBUG_NOI3(f,s,a,b,c) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c);}
333
#define uDEBUG_NOI4(f,s,a,b,c,d) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c,d);}
334
#define uDEBUG_NOI5(f,s,a,b,c,d,e) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c,d,e);}
337
#define uDEBUG1(f,s,a)
338
#define uDEBUG2(f,s,a,b)
339
#define uDEBUG3(f,s,a,b,c)
340
#define uDEBUG4(f,s,a,b,c,d)
341
#define uDEBUG5(f,s,a,b,c,d,e)
342
#define uDEBUG_NOI(f,s)
343
#define uDEBUG_NOI1(f,s,a)
344
#define uDEBUG_NOI2(f,s,a,b)
345
#define uDEBUG_NOI3(f,s,a,b,c)
346
#define uDEBUG_NOI4(f,s,a,b,c,d)
347
#define uDEBUG_NOI5(f,s,a,b,c,d,e)
350
extern Boolean uSetEntryFile(
357
#if defined(__GNUC__) && \
358
((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
359
__attribute__((format(printf, 2, 3)))
366
#ifdef ENTRY_TRACKING_ON
367
#define ENTRY_BIT 0x10
368
#define LOW_ENTRY_BIT 0x1000
369
#define ENTER (DEBUG_VAR&ENTRY_BIT)
370
#define FLAG(fLag) (DEBUG_VAR&(fLag))
372
extern int uEntryLevel;
374
#define uENTRY(s) { if (ENTER) uEntry(1,s);}
375
#define uENTRY1(s,a) { if (ENTER) uEntry(1,s,a);}
376
#define uENTRY2(s,a,b) { if (ENTER) uEntry(1,s,a,b);}
377
#define uENTRY3(s,a,b,c) { if (ENTER) uEntry(1,s,a,b,c);}
378
#define uENTRY4(s,a,b,c,d) { if (ENTER) uEntry(1,s,a,b,c,d);}
379
#define uENTRY5(s,a,b,c,d,e) { if (ENTER) uEntry(1,s,a,b,c,d,e);}
380
#define uENTRY6(s,a,b,c,d,e,f) { if (ENTER) uEntry(1,s,a,b,c,d,e,f);}
381
#define uENTRY7(s,a,b,c,d,e,f,g) { if (ENTER) uEntry(1,s,a,b,c,d,e,f,g);}
382
#define uRETURN(v) { if (ENTER) uEntryLevel--; return(v); }
383
#define uVOIDRETURN { if (ENTER) uEntryLevel--; return; }
385
#define uFLAG_ENTRY(w,s) { if (FLAG(w)) uEntry(0,s);}
386
#define uFLAG_ENTRY1(w,s,a) { if (FLAG(w)) uEntry(0,s,a);}
387
#define uFLAG_ENTRY2(w,s,a,b) { if (FLAG(w)) uEntry(0,s,a,b);}
388
#define uFLAG_ENTRY3(w,s,a,b,c) { if (FLAG(w)) uEntry(0,s,a,b,c);}
389
#define uFLAG_ENTRY4(w,s,a,b,c,d) { if (FLAG(w)) uEntry(0,s,a,b,c,d);}
390
#define uFLAG_ENTRY5(w,s,a,b,c,d,e) { if (FLAG(w)) uEntry(0,s,a,b,c,d,e);}
391
#define uFLAG_ENTRY6(w,s,a,b,c,d,e,f) { if (FLAG(w)) uEntry(0,s,a,b,c,d,e,f);}
392
#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);}
393
#define uFLAG_RETURN(v) { return(v);}
394
#define uFLAG_VOIDRETURN { return; }
398
#define uENTRY2(s,a1,a2)
399
#define uENTRY3(s,a1,a2,a3)
400
#define uENTRY4(s,a1,a2,a3,a4)
401
#define uENTRY5(s,a1,a2,a3,a4,a5)
402
#define uENTRY6(s,a1,a2,a3,a4,a5,a6)
403
#define uENTRY7(s,a1,a2,a3,a4,a5,a6,a7)
404
#define uRETURN(v) { return(v); }
405
#define uVOIDRETURN { return; }
407
#define uFLAG_ENTRY(f,s)
408
#define uFLAG_ENTRY1(f,s,a)
409
#define uFLAG_ENTRY2(f,s,a,b)
410
#define uFLAG_ENTRY3(f,s,a,b,c)
411
#define uFLAG_ENTRY4(f,s,a,b,c,d)
412
#define uFLAG_ENTRY5(f,s,a,b,c,d,e)
413
#define uFLAG_ENTRY6(f,s,a,b,c,d,e,g)
414
#define uFLAG_ENTRY7(f,s,a,b,c,d,e,g,h)
415
#define uFLAG_RETURN(v) { return(v);}
416
#define uFLAG_VOIDRETURN { return; }