utils.h revision 41667cea
1f46a6179Smrg#ifndef UTILS_H 2f46a6179Smrg#define UTILS_H 1 3f46a6179Smrg 4f46a6179Smrg /*\ 5f46a6179Smrg * 634345a63Smrg * COPYRIGHT 1990 734345a63Smrg * DIGITAL EQUIPMENT CORPORATION 834345a63Smrg * MAYNARD, MASSACHUSETTS 934345a63Smrg * ALL RIGHTS RESERVED. 10f46a6179Smrg * 11f46a6179Smrg * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND 12f46a6179Smrg * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION. 13f46a6179Smrg * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE 14f46a6179Smrg * FOR ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED 15f46a6179Smrg * WARRANTY. 16f46a6179Smrg * 17f46a6179Smrg * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT 18f46a6179Smrg * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN 19f46a6179Smrg * ADDITION TO THAT SET FORTH ABOVE. 20f46a6179Smrg * 21f46a6179Smrg * Permission to use, copy, modify, and distribute this software and its 22f46a6179Smrg * documentation for any purpose and without fee is hereby granted, provided 23f46a6179Smrg * that the above copyright notice appear in all copies and that both that 24f46a6179Smrg * copyright notice and this permission notice appear in supporting 25f46a6179Smrg * documentation, and that the name of Digital Equipment Corporation not be 26f46a6179Smrg * used in advertising or publicity pertaining to distribution of the 27f46a6179Smrg * software without specific, written prior permission. 2834345a63Smrg \*/ 29f46a6179Smrg 30f46a6179Smrg/***====================================================================***/ 31f46a6179Smrg 32f46a6179Smrg#include <stdio.h> 33f46a6179Smrg#include <X11/Xos.h> 34f46a6179Smrg#include <X11/Xfuncproto.h> 35f46a6179Smrg#include <X11/Xfuncs.h> 36f46a6179Smrg 37f46a6179Smrg#include <stddef.h> 3878038a65Smrg#ifdef HAVE_CONFIG_H 3934345a63Smrg#include "config.h" 4078038a65Smrg#endif 41f46a6179Smrg 42f46a6179Smrg#ifndef NUL 43f46a6179Smrg#define NUL '\0' 44f46a6179Smrg#endif 45f46a6179Smrg 46f46a6179Smrg/***====================================================================***/ 47f46a6179Smrg 48f46a6179Smrg#ifndef OPAQUE_DEFINED 4934345a63Smrgtypedef void *Opaque; 50f46a6179Smrg#endif 51f46a6179Smrg#ifndef NullOpaque 52f46a6179Smrg#define NullOpaque ((Opaque)NULL) 53f46a6179Smrg#endif 54f46a6179Smrg 55f46a6179Smrg#ifndef BOOLEAN_DEFINED 5634345a63Smrgtypedef char Boolean; 57f46a6179Smrg#endif 58f46a6179Smrg 59f46a6179Smrg#ifndef True 60f46a6179Smrg#define True ((Boolean)1) 61f46a6179Smrg#define False ((Boolean)0) 62f46a6179Smrg#endif /* ndef True */ 63f46a6179Smrg#define booleanText(b) ((b)?"True":"False") 64f46a6179Smrg 65f46a6179Smrg#ifndef COMPARISON_DEFINED 6634345a63Smrgtypedef int Comparison; 67f46a6179Smrg 68f46a6179Smrg#define Greater ((Comparison)1) 69f46a6179Smrg#define Equal ((Comparison)0) 70f46a6179Smrg#define Less ((Comparison)-1) 71f46a6179Smrg#define CannotCompare ((Comparison)-37) 72f46a6179Smrg#define comparisonText(c) ((c)?((c)<0?"Less":"Greater"):"Equal") 73f46a6179Smrg#endif 74f46a6179Smrg 75f46a6179Smrg/***====================================================================***/ 76f46a6179Smrg 7734345a63Smrgextern Opaque uAlloc(unsigned /* size */ 7834345a63Smrg ); 7934345a63Smrgextern Opaque uCalloc(unsigned /* n */ , 8034345a63Smrg unsigned /* size */ 8134345a63Smrg ); 8234345a63Smrgextern Opaque uRealloc(Opaque /* old */ , 8334345a63Smrg unsigned /* newSize */ 8434345a63Smrg ); 8534345a63Smrgextern Opaque uRecalloc(Opaque /* old */ , 8634345a63Smrg unsigned /* nOld */ , 8734345a63Smrg unsigned /* nNew */ , 8834345a63Smrg unsigned /* newSize */ 8934345a63Smrg ); 9034345a63Smrgextern void uFree(Opaque /* ptr */ 9134345a63Smrg ); 92f46a6179Smrg 93f46a6179Smrg#define uTypedAlloc(t) ((t *)uAlloc((unsigned)sizeof(t))) 94f46a6179Smrg#define uTypedCalloc(n,t) ((t *)uCalloc((unsigned)n,(unsigned)sizeof(t))) 95f46a6179Smrg#define uTypedRealloc(pO,n,t) ((t *)uRealloc((Opaque)pO,((unsigned)n)*sizeof(t))) 96f46a6179Smrg#define uTypedRecalloc(pO,o,n,t) ((t *)uRecalloc((Opaque)pO,((unsigned)o),((unsigned)n),sizeof(t))) 97f46a6179Smrg#if (defined mdHasAlloca) && (mdHasAlloca) 98f46a6179Smrg#define uTmpAlloc(n) ((Opaque)alloca((unsigned)n)) 99f46a6179Smrg#define uTmpFree(p) 100f46a6179Smrg#else 101f46a6179Smrg#define uTmpAlloc(n) uAlloc(n) 102f46a6179Smrg#define uTmpFree(p) uFree(p) 103f46a6179Smrg#endif 104f46a6179Smrg 105f46a6179Smrg/***====================================================================***/ 106f46a6179Smrg 10734345a63Smrgextern Boolean uSetErrorFile(char * /* name */ 10834345a63Smrg ); 109f46a6179Smrg 110f46a6179Smrg#define INFO6 uInformation 111f46a6179Smrg#define INFO5 uInformation 112f46a6179Smrg#define INFO4 uInformation 113f46a6179Smrg#define INFO3 uInformation 114f46a6179Smrg#define INFO2 uInformation 115f46a6179Smrg#define INFO1 uInformation 116f46a6179Smrg#define INFO uInformation 117f46a6179Smrg 11834345a63Smrgextern void 11934345a63SmrguInformation(const char * /* s */ , ... 120e9cdd019Smrg ) _X_ATTRIBUTE_PRINTF(1, 2); 121f46a6179Smrg 122f46a6179Smrg#define ACTION6 uAction 123f46a6179Smrg#define ACTION5 uAction 124f46a6179Smrg#define ACTION4 uAction 125f46a6179Smrg#define ACTION3 uAction 126f46a6179Smrg#define ACTION2 uAction 127f46a6179Smrg#define ACTION1 uAction 128f46a6179Smrg#define ACTION uAction 129f46a6179Smrg 13034345a63Smrg extern void uAction(const char * /* s */ , ... 131e9cdd019Smrg ) _X_ATTRIBUTE_PRINTF(1, 2); 132f46a6179Smrg 133f46a6179Smrg#define WARN6 uWarning 134f46a6179Smrg#define WARN5 uWarning 135f46a6179Smrg#define WARN4 uWarning 136f46a6179Smrg#define WARN3 uWarning 137f46a6179Smrg#define WARN2 uWarning 138f46a6179Smrg#define WARN1 uWarning 139f46a6179Smrg#define WARN uWarning 140f46a6179Smrg 14134345a63Smrg extern void uWarning(const char * /* s */ , ... 142e9cdd019Smrg ) _X_ATTRIBUTE_PRINTF(1, 2); 143f46a6179Smrg 144f46a6179Smrg#define ERROR6 uError 145f46a6179Smrg#define ERROR5 uError 146f46a6179Smrg#define ERROR4 uError 147f46a6179Smrg#define ERROR3 uError 148f46a6179Smrg#define ERROR2 uError 149f46a6179Smrg#define ERROR1 uError 150f46a6179Smrg#define ERROR uError 151f46a6179Smrg 15234345a63Smrg extern void uError(const char * /* s */ , ... 153e9cdd019Smrg ) _X_ATTRIBUTE_PRINTF(1, 2); 154f46a6179Smrg 155f46a6179Smrg#define FATAL6 uFatalError 156f46a6179Smrg#define FATAL5 uFatalError 157f46a6179Smrg#define FATAL4 uFatalError 158f46a6179Smrg#define FATAL3 uFatalError 159f46a6179Smrg#define FATAL2 uFatalError 160f46a6179Smrg#define FATAL1 uFatalError 161f46a6179Smrg#define FATAL uFatalError 162f46a6179Smrg 16334345a63Smrg extern void uFatalError(const char * /* s */ , ... 164b091287fSmrg ) _X_ATTRIBUTE_PRINTF(1, 2) _X_NORETURN; 165f46a6179Smrg 166f46a6179Smrg/* WSGO stands for "Weird Stuff Going On" */ 167f46a6179Smrg#define WSGO6 uInternalError 168f46a6179Smrg#define WSGO5 uInternalError 169f46a6179Smrg#define WSGO4 uInternalError 170f46a6179Smrg#define WSGO3 uInternalError 171f46a6179Smrg#define WSGO2 uInternalError 172f46a6179Smrg#define WSGO1 uInternalError 173f46a6179Smrg#define WSGO uInternalError 174f46a6179Smrg 17534345a63Smrg extern void uInternalError(const char * /* s */ , ... 176e9cdd019Smrg ) _X_ATTRIBUTE_PRINTF(1, 2); 177f46a6179Smrg 17834345a63Smrg extern void uSetPreErrorMessage(char * /* msg */ 17934345a63Smrg ); 180f46a6179Smrg 18134345a63Smrg extern void uSetPostErrorMessage(char * /* msg */ 18234345a63Smrg ); 183f46a6179Smrg 18434345a63Smrg extern void uSetErrorPrefix(char * /* void */ 18534345a63Smrg ); 186f46a6179Smrg 18734345a63Smrg extern void uFinishUp(void); 188f46a6179Smrg 189f46a6179Smrg 190f46a6179Smrg/***====================================================================***/ 191f46a6179Smrg 192f46a6179Smrg#define NullString ((char *)NULL) 193f46a6179Smrg 194f46a6179Smrg#define uStringText(s) ((s)==NullString?"<NullString>":(s)) 195f46a6179Smrg#define uStringEqual(s1,s2) (uStringCompare(s1,s2)==Equal) 196f46a6179Smrg#define uStringPrefix(p,s) (strncmp(p,s,strlen(p))==0) 197f46a6179Smrg#define uStringCompare(s1,s2) (((s1)==NullString||(s2)==NullString)?\ 198f46a6179Smrg (s1)!=(s2):strcmp(s1,s2)) 199f46a6179Smrg#define uStrCaseEqual(s1,s2) (uStrCaseCmp(s1,s2)==0) 200f46a6179Smrg#ifdef HAVE_STRCASECMP 201b091287fSmrg#include <strings.h> 202f46a6179Smrg#define uStrCaseCmp(s1,s2) (strcasecmp(s1,s2)) 203f46a6179Smrg#define uStrCasePrefix(p,s) (strncasecmp(p,s,strlen(p))==0) 204f46a6179Smrg#else 20534345a63Smrg extern int uStrCaseCmp(const char * /* s1 */ , 20634345a63Smrg const char * /* s2 */ 20734345a63Smrg ); 20834345a63Smrg extern int uStrCasePrefix(const char * /* p */ , 20934345a63Smrg char * /* str */ 21034345a63Smrg ); 211f46a6179Smrg#endif 212f46a6179Smrg#ifdef HAVE_STRDUP 213b091287fSmrg#include <string.h> 21434345a63Smrg#define uStringDup(s1) ((s1) ? strdup(s1) : NULL) 215f46a6179Smrg#else 21634345a63Smrg extern char *uStringDup(const char * /* s1 */ 21734345a63Smrg ); 218f46a6179Smrg#endif 219f46a6179Smrg 220f46a6179Smrg/***====================================================================***/ 221f46a6179Smrg 222f46a6179Smrg#ifndef DEBUG_VAR 223f46a6179Smrg#define DEBUG_VAR debugFlags 224f46a6179Smrg#endif 225f46a6179Smrg 226f46a6179Smrgextern 22734345a63Smrg unsigned int DEBUG_VAR; 228f46a6179Smrg 22934345a63Smrg extern void uDebug(char * /* s */ , ... 230e9cdd019Smrg ) _X_ATTRIBUTE_PRINTF(1, 2); 231f46a6179Smrg 23234345a63Smrg extern void uDebugNOI( /* no indent */ 23334345a63Smrg char * /* s */ , ... 234e9cdd019Smrg ) _X_ATTRIBUTE_PRINTF(1, 2); 235f46a6179Smrg 23634345a63Smrg extern Boolean uSetDebugFile(char *name); 237f46a6179Smrg 23834345a63Smrg extern FILE *uDebugFile; 23934345a63Smrg extern int uDebugIndentLevel; 24034345a63Smrg extern int uDebugIndentSize; 241f46a6179Smrg#define uDebugIndent(l) (uDebugIndentLevel+=(l)) 242f46a6179Smrg#define uDebugOutdent(l) (uDebugIndentLevel-=(l)) 24341667ceaSmrg#ifdef DEBUG 244f46a6179Smrg#define uDEBUG(f,s) { if (DEBUG_VAR&(f)) uDebug(s);} 245f46a6179Smrg#define uDEBUG1(f,s,a) { if (DEBUG_VAR&(f)) uDebug(s,a);} 246f46a6179Smrg#define uDEBUG2(f,s,a,b) { if (DEBUG_VAR&(f)) uDebug(s,a,b);} 247f46a6179Smrg#define uDEBUG3(f,s,a,b,c) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c);} 248f46a6179Smrg#define uDEBUG4(f,s,a,b,c,d) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d);} 249f46a6179Smrg#define uDEBUG5(f,s,a,b,c,d,e) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d,e);} 250f46a6179Smrg#define uDEBUG_NOI(f,s) { if (DEBUG_VAR&(f)) uDebug(s);} 251f46a6179Smrg#define uDEBUG_NOI1(f,s,a) { if (DEBUG_VAR&(f)) uDebugNOI(s,a);} 252f46a6179Smrg#define uDEBUG_NOI2(f,s,a,b) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b);} 253f46a6179Smrg#define uDEBUG_NOI3(f,s,a,b,c) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c);} 254f46a6179Smrg#define uDEBUG_NOI4(f,s,a,b,c,d) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c,d);} 255f46a6179Smrg#define uDEBUG_NOI5(f,s,a,b,c,d,e) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c,d,e);} 256f46a6179Smrg#else 257f46a6179Smrg#define uDEBUG(f,s) 258f46a6179Smrg#define uDEBUG1(f,s,a) 259f46a6179Smrg#define uDEBUG2(f,s,a,b) 260f46a6179Smrg#define uDEBUG3(f,s,a,b,c) 261f46a6179Smrg#define uDEBUG4(f,s,a,b,c,d) 262f46a6179Smrg#define uDEBUG5(f,s,a,b,c,d,e) 263f46a6179Smrg#define uDEBUG_NOI(f,s) 264f46a6179Smrg#define uDEBUG_NOI1(f,s,a) 265f46a6179Smrg#define uDEBUG_NOI2(f,s,a,b) 266f46a6179Smrg#define uDEBUG_NOI3(f,s,a,b,c) 267f46a6179Smrg#define uDEBUG_NOI4(f,s,a,b,c,d) 268f46a6179Smrg#define uDEBUG_NOI5(f,s,a,b,c,d,e) 269f46a6179Smrg#endif 270f46a6179Smrg 271f46a6179Smrg#endif /* UTILS_H */ 272