utils.h revision f46a6179
1#ifndef UTILS_H 2#define UTILS_H 1 3 4 /*\ 5 * $Xorg: utils.h,v 1.3 2000/08/17 19:54:33 cpqbld Exp $ 6 * 7 * COPYRIGHT 1990 8 * DIGITAL EQUIPMENT CORPORATION 9 * MAYNARD, MASSACHUSETTS 10 * ALL RIGHTS RESERVED. 11 * 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 16 * WARRANTY. 17 * 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. 21 * 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. 29 \*/ 30/* $XFree86: xc/programs/xkbcomp/utils.h,v 3.5 2002/06/05 00:00:37 dawes Exp $ */ 31 32/***====================================================================***/ 33 34#include <stdio.h> 35#include <X11/Xos.h> 36#include <X11/Xfuncproto.h> 37#include <X11/Xfuncs.h> 38 39#include <stddef.h> 40 41#ifndef NUL 42#define NUL '\0' 43#endif 44 45/***====================================================================***/ 46 47#ifndef OPAQUE_DEFINED 48typedef void *Opaque; 49#endif 50#ifndef NullOpaque 51#define NullOpaque ((Opaque)NULL) 52#endif 53 54#ifndef BOOLEAN_DEFINED 55typedef char Boolean; 56#endif 57 58#ifndef True 59#define True ((Boolean)1) 60#define False ((Boolean)0) 61#endif /* ndef True */ 62#define booleanText(b) ((b)?"True":"False") 63 64#ifndef COMPARISON_DEFINED 65typedef int Comparison; 66 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") 72#endif 73 74#if 0 75typedef union { 76 int i; 77 unsigned u; 78 void *p; 79 void *(*fp)(); 80} Union; 81#endif 82 83/***====================================================================***/ 84 85extern Opaque uAlloc( 86 unsigned /* size */ 87); 88extern Opaque uCalloc( 89 unsigned /* n */, 90 unsigned /* size */ 91); 92extern Opaque uRealloc( 93 Opaque /* old */, 94 unsigned /* newSize */ 95); 96extern Opaque uRecalloc( 97 Opaque /* old */, 98 unsigned /* nOld */, 99 unsigned /* nNew */, 100 unsigned /* newSize */ 101); 102extern void uFree( 103 Opaque /* ptr */ 104); 105 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)) 112#define uTmpFree(p) 113#else 114#define uTmpAlloc(n) uAlloc(n) 115#define uTmpFree(p) uFree(p) 116#endif 117 118/***====================================================================***/ 119 120extern Boolean uSetErrorFile( 121 char * /* name */ 122); 123 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 131 132extern void uInformation( 133 const char * /* s */, ... 134) 135#if defined(__GNUC__) && \ 136 ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6))) 137__attribute__((format(printf, 1, 2))) 138#endif 139; 140 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 148 149extern void uAction( 150 const char * /* s */, ... 151) 152#if defined(__GNUC__) && \ 153 ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6))) 154__attribute__((format(printf, 1, 2))) 155#endif 156; 157 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 165 166extern void uWarning( 167 const char * /* s */, ... 168) 169#if defined(__GNUC__) && \ 170 ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6))) 171__attribute__((format(printf, 1, 2))) 172#endif 173; 174 175#define ERROR6 uError 176#define ERROR5 uError 177#define ERROR4 uError 178#define ERROR3 uError 179#define ERROR2 uError 180#define ERROR1 uError 181#define ERROR uError 182 183extern void uError( 184 const char * /* s */, ... 185) 186#if defined(__GNUC__) && \ 187 ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6))) 188__attribute__((format(printf, 1, 2))) 189#endif 190; 191 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 199 200extern void uFatalError( 201 const char * /* s */, ... 202) 203#if defined(__GNUC__) && \ 204 ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6))) 205__attribute__((format(printf, 1, 2))) 206#endif 207; 208 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 217 218extern void uInternalError( 219 const char * /* s */, ... 220) 221#if defined(__GNUC__) && \ 222 ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6))) 223__attribute__((format(printf, 1, 2))) 224#endif 225; 226 227extern void uSetPreErrorMessage( 228 char * /* msg */ 229); 230 231extern void uSetPostErrorMessage( 232 char * /* msg */ 233); 234 235extern void uSetErrorPrefix( 236 char * /* void */ 237); 238 239extern void uFinishUp( 240 void 241); 242 243 244/***====================================================================***/ 245 246#define NullString ((char *)NULL) 247 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) 257#else 258extern int uStrCaseCmp( 259 const char * /* s1 */, 260 const char * /* s2 */ 261); 262extern int uStrCasePrefix( 263 const char * /* p */, 264 char * /* str */ 265); 266#endif 267#ifdef HAVE_STRDUP 268#define uStringDup(s1) (strdup(s1)) 269#else 270extern char *uStringDup( 271 const char * /* s1 */ 272); 273#endif 274 275/***====================================================================***/ 276 277#ifdef ASSERTIONS_ON 278#define uASSERT(where,why) \ 279 {if (!(why)) uFatalError("assertion botched in %s ( why )\n",where);} 280#else 281#define uASSERT(where,why) 282#endif 283 284/***====================================================================***/ 285 286#ifndef DEBUG_VAR 287#define DEBUG_VAR debugFlags 288#endif 289 290#ifdef DEBUG_VAR_NOT_LOCAL 291extern 292#endif 293unsigned int DEBUG_VAR; 294 295extern void uDebug( 296 char * /* s */, ... 297) 298#if defined(__GNUC__) && \ 299 ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6))) 300__attribute__((format(printf, 1, 2))) 301#endif 302; 303 304extern void uDebugNOI( /* no indent */ 305 char * /* s */, ... 306) 307#if defined(__GNUC__) && \ 308 ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6))) 309__attribute__((format(printf, 1, 2))) 310#endif 311; 312 313extern Boolean uSetDebugFile( 314 char *name 315); 316 317extern FILE *uDebugFile; 318extern int uDebugIndentLevel; 319extern int uDebugIndentSize; 320#define uDebugIndent(l) (uDebugIndentLevel+=(l)) 321#define uDebugOutdent(l) (uDebugIndentLevel-=(l)) 322#ifdef DEBUG_ON 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);} 335#else 336#define uDEBUG(f,s) 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) 348#endif 349 350extern Boolean uSetEntryFile( 351 char *name 352); 353extern void uEntry( 354 int /* l */, 355 char * /* s */, ... 356) 357#if defined(__GNUC__) && \ 358 ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6))) 359__attribute__((format(printf, 2, 3))) 360#endif 361; 362 363extern void uExit( 364 int l,char *rtVal 365); 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)) 371 372extern int uEntryLevel; 373 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; } 384 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; } 395#else 396#define uENTRY(s) 397#define uENTRY1(s,a) 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; } 406 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; } 417#endif 418 419 420#endif /* UTILS_H */ 421 422 423