utils.h revision 010cdda0
1#ifndef UTILS_H 2#define UTILS_H 1 3 4 /*\ 5 * $Xorg: utils.h,v 1.3 2000/08/17 19:54:51 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/xkbutils/utils.h,v 1.5 2001/07/25 15:05:26 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#include <stdarg.h> 39#include <stddef.h> 40 41_XFUNCPROTOBEGIN 42 43 44#ifndef NUL 45#define NUL '\0' 46#endif 47 48/***====================================================================***/ 49 50#ifndef OPAQUE_DEFINED 51typedef void *Opaque; 52#endif 53#ifndef NullOpaque 54#define NullOpaque ((Opaque)NULL) 55#endif 56 57#ifndef BOOLEAN_DEFINED 58typedef char Boolean; 59#endif 60 61#ifndef True 62#define True ((Boolean)1) 63#define False ((Boolean)0) 64#endif /* ndef True */ 65#define booleanText(b) ((b)?"True":"False") 66 67#ifndef COMPARISON_DEFINED 68typedef int Comparison; 69 70#define Greater ((Comparison)1) 71#define Equal ((Comparison)0) 72#define Less ((Comparison)-1) 73#define CannotCompare ((Comparison)-37) 74#define comparisonText(c) ((c)?((c)<0?"Less":"Greater"):"Equal") 75#endif 76 77#ifdef notyet 78typedef union { 79 int i; 80 unsigned u; 81 void *p; 82 void *(*fp)(); 83} Union; 84#endif 85 86/***====================================================================***/ 87 88extern Opaque uAlloc( 89 unsigned /* size */ 90); 91extern Opaque uCalloc( 92 unsigned /* n */, 93 unsigned /* size */ 94); 95extern Opaque uRealloc( 96 Opaque /* old */, 97 unsigned /* newSize */ 98); 99extern Opaque uRecalloc( 100 Opaque /* old */, 101 unsigned /* nOld */, 102 unsigned /* nNew */, 103 unsigned /* newSize */ 104); 105extern void uFree( 106 Opaque /* ptr */ 107); 108 109#define uTypedAlloc(t) ((t *)uAlloc((unsigned)sizeof(t))) 110#define uTypedCalloc(n,t) ((t *)uCalloc((unsigned)n,(unsigned)sizeof(t))) 111#define uTypedRealloc(pO,n,t) ((t *)uRealloc((Opaque)pO,((unsigned)n)*sizeof(t))) 112#define uTypedRecalloc(pO,o,n,t) ((t *)uRecalloc((Opaque)pO,((unsigned)o),((unsigned)n),sizeof(t))) 113#if (defined mdHasAlloca) && (mdHasAlloca) 114#define uTmpAlloc(n) ((Opaque)alloca((unsigned)n)) 115#define uTmpFree(p) 116#else 117#define uTmpAlloc(n) uAlloc(n) 118#define uTmpFree(p) uFree(p) 119#endif 120 121/***====================================================================***/ 122 123extern Boolean uSetErrorFile ( char *name ); 124extern void uInformation ( char *s, ...); 125extern void uAction ( char *s, ... ); 126extern void uWarning ( char *s, ... ); 127extern void uError ( char *s, ... ); 128extern void uFatalError(char *s,...); 129extern void uInternalError ( char *s, ... ); 130 131/***====================================================================***/ 132 133#define NullString ((char *)NULL) 134 135#define uStringText(s) ((s)==NullString?"<NullString>":(s)) 136#define uStringEqual(s1,s2) (uStringCompare(s1,s2)==Equal) 137#define uStringPrefix(p,s) (strncmp(p,s,strlen(p))==0) 138#define uStringCompare(s1,s2) (strcmp(s1,s2)) 139#define uStrCaseEqual(s1,s2) (uStrCaseCmp(s1,s2)==0) 140#ifdef HAVE_STRCASECMP 141#define uStrCaseCmp(s1,s2) (strcasecmp(s1,s2)) 142#define uStrCasePrefix(p,s) (strncasecmp(p,s,strlen(p))==0) 143#else 144extern int uStrCaseCmp( 145 char * /* s1 */, 146 char * /* s2 */ 147); 148extern int uStrCasePrefix( 149 char * /* p */, 150 char * /* str */ 151); 152#endif 153#ifdef HAVE_STRDUP 154#define uStringDup(s1) (strdup(s1)) 155#else 156extern char *uStringDup( 157 char * /* s1 */ 158); 159#endif 160 161/***====================================================================***/ 162 163#ifdef ASSERTIONS_ON 164#define uASSERT(where,why) \ 165 {if (!(why)) uFatalError("assertion botched in %s ( why )\n",where);} 166#else 167#define uASSERT(where,why) 168#endif 169 170/***====================================================================***/ 171 172#ifndef DEBUG_VAR 173#define DEBUG_VAR debugFlags 174#endif 175 176#ifdef DEBUG_VAR_NOT_LOCAL 177extern 178#endif 179unsigned int DEBUG_VAR; 180 181extern void uDebug( char *s, ... ); 182extern void uDebugNOI( char *s, ... ); /* no indent */ 183extern Boolean uSetDebugFile( 184 char *name 185); 186extern FILE *uDebugFile; 187extern int uDebugIndentLevel; 188extern int uDebugIndentSize; 189#define uDebugIndent(l) (uDebugIndentLevel+=(l)) 190#define uDebugOutdent(l) (uDebugIndentLevel-=(l)) 191#ifdef DEBUG_ON 192#define uDEBUG(f,s) { if (DEBUG_VAR&(f)) uDebug(s);} 193#define uDEBUG1(f,s,a) { if (DEBUG_VAR&(f)) uDebug(s,a);} 194#define uDEBUG2(f,s,a,b) { if (DEBUG_VAR&(f)) uDebug(s,a,b);} 195#define uDEBUG3(f,s,a,b,c) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c);} 196#define uDEBUG4(f,s,a,b,c,d) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d);} 197#define uDEBUG5(f,s,a,b,c,d,e) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d,e);} 198#define uDEBUG_NOI(f,s) { if (DEBUG_VAR&(f)) uDebug(s);} 199#define uDEBUG_NOI1(f,s,a) { if (DEBUG_VAR&(f)) uDebugNOI(s,a);} 200#define uDEBUG_NOI2(f,s,a,b) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b);} 201#define uDEBUG_NOI3(f,s,a,b,c) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c);} 202#define uDEBUG_NOI4(f,s,a,b,c,d) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c,d);} 203#define uDEBUG_NOI5(f,s,a,b,c,d,e) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c,d,e);} 204#else 205#define uDEBUG(f,s) 206#define uDEBUG1(f,s,a) 207#define uDEBUG2(f,s,a,b) 208#define uDEBUG3(f,s,a,b,c) 209#define uDEBUG4(f,s,a,b,c,d) 210#define uDEBUG5(f,s,a,b,c,d,e) 211#define uDEBUG_NOI(f,s) 212#define uDEBUG_NOI1(f,s,a) 213#define uDEBUG_NOI2(f,s,a,b) 214#define uDEBUG_NOI3(f,s,a,b,c) 215#define uDEBUG_NOI4(f,s,a,b,c,d) 216#define uDEBUG_NOI5(f,s,a,b,c,d,e) 217#endif 218 219extern Boolean uSetEntryFile( 220 char *name 221); 222extern void uEntry(int l, char *s, ... ); 223extern void uExit( 224 int l,char *rtVal 225); 226#ifdef ENTRY_TRACKING_ON 227#define ENTRY_BIT 0x10 228#define LOW_ENTRY_BIT 0x1000 229#define ENTER (DEBUG_VAR&ENTRY_BIT) 230#define FLAG(fLag) (DEBUG_VAR&(fLag)) 231 232extern int uEntryLevel; 233 234#define uENTRY(s) { if (ENTER) uEntry(1,s);} 235#define uENTRY1(s,a) { if (ENTER) uEntry(1,s,a);} 236#define uENTRY2(s,a,b) { if (ENTER) uEntry(1,s,a,b);} 237#define uENTRY3(s,a,b,c) { if (ENTER) uEntry(1,s,a,b,c);} 238#define uENTRY4(s,a,b,c,d) { if (ENTER) uEntry(1,s,a,b,c,d);} 239#define uENTRY5(s,a,b,c,d,e) { if (ENTER) uEntry(1,s,a,b,c,d,e);} 240#define uENTRY6(s,a,b,c,d,e,f) { if (ENTER) uEntry(1,s,a,b,c,d,e,f);} 241#define uENTRY7(s,a,b,c,d,e,f,g) { if (ENTER) uEntry(1,s,a,b,c,d,e,f,g);} 242#define uRETURN(v) { if (ENTER) uEntryLevel--; return(v); } 243#define uVOIDRETURN { if (ENTER) uEntryLevel--; return; } 244 245#define uFLAG_ENTRY(w,s) { if (FLAG(w)) uEntry(0,s);} 246#define uFLAG_ENTRY1(w,s,a) { if (FLAG(w)) uEntry(0,s,a);} 247#define uFLAG_ENTRY2(w,s,a,b) { if (FLAG(w)) uEntry(0,s,a,b);} 248#define uFLAG_ENTRY3(w,s,a,b,c) { if (FLAG(w)) uEntry(0,s,a,b,c);} 249#define uFLAG_ENTRY4(w,s,a,b,c,d) { if (FLAG(w)) uEntry(0,s,a,b,c,d);} 250#define uFLAG_ENTRY5(w,s,a,b,c,d,e) { if (FLAG(w)) uEntry(0,s,a,b,c,d,e);} 251#define uFLAG_ENTRY6(w,s,a,b,c,d,e,f) { if (FLAG(w)) uEntry(0,s,a,b,c,d,e,f);} 252#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);} 253#define uFLAG_RETURN(v) { return(v);} 254#define uFLAG_VOIDRETURN { return; } 255#else 256#define uENTRY(s) 257#define uENTRY1(s,a) 258#define uENTRY2(s,a1,a2) 259#define uENTRY3(s,a1,a2,a3) 260#define uENTRY4(s,a1,a2,a3,a4) 261#define uENTRY5(s,a1,a2,a3,a4,a5) 262#define uENTRY6(s,a1,a2,a3,a4,a5,a6) 263#define uENTRY7(s,a1,a2,a3,a4,a5,a6,a7) 264#define uRETURN(v) { return(v); } 265#define uVOIDRETURN { return; } 266 267#define uFLAG_ENTRY(f,s) 268#define uFLAG_ENTRY1(f,s,a) 269#define uFLAG_ENTRY2(f,s,a,b) 270#define uFLAG_ENTRY3(f,s,a,b,c) 271#define uFLAG_ENTRY4(f,s,a,b,c,d) 272#define uFLAG_ENTRY5(f,s,a,b,c,d,e) 273#define uFLAG_ENTRY6(f,s,a,b,c,d,e,g) 274#define uFLAG_ENTRY7(f,s,a,b,c,d,e,g,h) 275#define uFLAG_RETURN(v) { return(v);} 276#define uFLAG_VOIDRETURN { return; } 277#endif 278 279_XFUNCPROTOEND 280 281#endif /* UTILS_H */ 282 283 284