7 * DIGITAL EQUIPMENT CORPORATION
8 * MAYNARD, MASSACHUSETTS
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
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.
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.
30 /***====================================================================***/
34 #include <X11/Xfuncproto.h>
35 #include <X11/Xfuncs.h>
44 /***====================================================================***/
46 #ifndef OPAQUE_DEFINED
50 #define NullOpaque ((Opaque)NULL)
53 #ifndef BOOLEAN_DEFINED
58 #define True ((Boolean)1)
59 #define False ((Boolean)0)
60 #endif /* ndef True */
61 #define booleanText(b) ((b)?"True":"False")
63 #ifndef COMPARISON_DEFINED
64 typedef int Comparison;
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")
73 /***====================================================================***/
76 uAlloc(unsigned size);
79 uCalloc(unsigned n, unsigned size);
82 uRealloc(Opaque old, unsigned newSize);
85 uRecalloc(Opaque old, unsigned nOld, unsigned nNew, unsigned newSize);
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))
98 #define uTmpAlloc(n) uAlloc(n)
99 #define uTmpFree(p) uFree(p)
102 /***====================================================================***/
105 uSetErrorFile(char *name);
107 #if defined(__GNUC__) && \
108 ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
109 #define __ATTR_PRINTF(i, f) __attribute__ ((format(printf, (i), (f))))
111 #define __ATTR_PRINTF(i, f)
114 #define INFO uInformation
116 extern __ATTR_PRINTF(1, 2) void
117 uInformation(const char *s, ...);
119 #define ACTION uAction
121 extern __ATTR_PRINTF(1, 2) void
122 uAction(const char *s, ...);
124 #define WARN uWarning
126 extern __ATTR_PRINTF(1, 2) void
127 uWarning(const char *s, ...);
131 extern __ATTR_PRINTF(1, 2) void
132 uError(const char *s, ...);
134 #define FATAL uFatalError
136 extern __ATTR_PRINTF(1, 2) void
137 uFatalError(const char *s, ...);
139 /* WSGO stands for "Weird Stuff Going On" (wtf???) */
140 #define WSGO uInternalError
142 extern __ATTR_PRINTF(1, 2) void
143 uInternalError(const char *s, ...);
146 uSetPreErrorMessage(char *msg);
149 uSetPostErrorMessage(char *msg);
152 uSetErrorPrefix(char *pre);
158 /***====================================================================***/
160 #define NullString ((char *)NULL)
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)
173 uStrCaseCmp(const char *s1, const char *s2);
175 uStrCasePrefix(const char *p, char *str);
178 #define uStringDup(s1) ((s1) ? strdup(s1) : NULL)
181 uStringDup(const char *s);
184 /***====================================================================***/
187 #define uASSERT(where,why) \
188 {if (!(why)) uFatalError("assertion botched in %s ( why )\n",where);}
190 #define uASSERT(where,why)
193 /***====================================================================***/
196 #define DEBUG_VAR debugFlags
199 extern unsigned int DEBUG_VAR;
201 extern __ATTR_PRINTF(1, 2) void
202 uDebug(char *s, ...);
204 extern __ATTR_PRINTF(1, 2) void
205 uDebugNOI(char *s, ...);
208 uSetDebugFile(char *name);
210 extern FILE *uDebugFile;
211 extern int uDebugIndentLevel;
212 extern int uDebugIndentSize;
214 #define uDebugIndent(l) (uDebugIndentLevel+=(l))
215 #define uDebugOutdent(l) (uDebugIndentLevel-=(l))
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);}
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)
245 uSetEntryFile(char *name);
247 extern __ATTR_PRINTF(2, 3) void
248 uEntry(int l, char *s, ...);
251 uExit(int l, char *rtVal);
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))
259 extern int uEntryLevel;
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; }
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; }
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; }
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; }