utils.h revision 6ae2c069
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. 13370d0a5eSmrg * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE 14370d0a5eSmrg * 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 26370d0a5eSmrg * used in advertising or publicity pertaining to distribution of the 27f46a6179Smrg * software without specific, written prior permission. 2834345a63Smrg \*/ 29f46a6179Smrg 30f46a6179Smrg/***====================================================================***/ 31f46a6179Smrg 326ae2c069Smrg#ifdef HAVE_CONFIG_H 336ae2c069Smrg#include "config.h" 346ae2c069Smrg#endif 356ae2c069Smrg 36f46a6179Smrg#include <stdio.h> 376ae2c069Smrg#include <stdlib.h> 38f46a6179Smrg#include <X11/Xos.h> 39f46a6179Smrg#include <X11/Xfuncproto.h> 40f46a6179Smrg#include <X11/Xfuncs.h> 41f46a6179Smrg 42f46a6179Smrg#include <stddef.h> 43f46a6179Smrg 44f46a6179Smrg#ifndef NUL 45f46a6179Smrg#define NUL '\0' 46f46a6179Smrg#endif 47f46a6179Smrg 48f46a6179Smrg/***====================================================================***/ 49f46a6179Smrg 50f46a6179Smrg#ifndef BOOLEAN_DEFINED 5134345a63Smrgtypedef char Boolean; 52f46a6179Smrg#endif 53f46a6179Smrg 54f46a6179Smrg#ifndef True 55f46a6179Smrg#define True ((Boolean)1) 56f46a6179Smrg#define False ((Boolean)0) 57f46a6179Smrg#endif /* ndef True */ 58f46a6179Smrg#define booleanText(b) ((b)?"True":"False") 59f46a6179Smrg 60f46a6179Smrg#ifndef COMPARISON_DEFINED 6134345a63Smrgtypedef int Comparison; 62f46a6179Smrg 63f46a6179Smrg#define Greater ((Comparison)1) 64f46a6179Smrg#define Equal ((Comparison)0) 65f46a6179Smrg#define Less ((Comparison)-1) 66f46a6179Smrg#define CannotCompare ((Comparison)-37) 67f46a6179Smrg#define comparisonText(c) ((c)?((c)<0?"Less":"Greater"):"Equal") 68f46a6179Smrg#endif 69f46a6179Smrg 70f46a6179Smrg/***====================================================================***/ 71f46a6179Smrg 726ae2c069Smrg#ifndef HAVE_REALLOCARRAY 736ae2c069Smrg#define reallocarray(p, n, s) realloc(p, (n) * (s)) 746ae2c069Smrg#endif 75f46a6179Smrg 766ae2c069Smrg#ifndef HAVE_RECALLOCARRAY 776ae2c069Smrg#define recallocarray uRecalloc 786ae2c069Smrg 796ae2c069Smrgextern void *uRecalloc(void * /* old */ , 806ae2c069Smrg size_t /* nOld */ , 816ae2c069Smrg size_t /* nNew */ , 826ae2c069Smrg size_t /* newSize */ 836ae2c069Smrg ); 84f46a6179Smrg#endif 85f46a6179Smrg 86f46a6179Smrg/***====================================================================***/ 87f46a6179Smrg 886ae2c069Smrgextern Boolean uSetErrorFile(const char * /* name */ 8934345a63Smrg ); 90f46a6179Smrg 91f46a6179Smrg#define INFO uInformation 92f46a6179Smrg 9334345a63Smrgextern void 9434345a63SmrguInformation(const char * /* s */ , ... 95e9cdd019Smrg ) _X_ATTRIBUTE_PRINTF(1, 2); 96f46a6179Smrg 97f46a6179Smrg#define ACTION uAction 98f46a6179Smrg 9934345a63Smrg extern void uAction(const char * /* s */ , ... 100e9cdd019Smrg ) _X_ATTRIBUTE_PRINTF(1, 2); 101f46a6179Smrg 102f46a6179Smrg#define WARN uWarning 103f46a6179Smrg 10434345a63Smrg extern void uWarning(const char * /* s */ , ... 105e9cdd019Smrg ) _X_ATTRIBUTE_PRINTF(1, 2); 106f46a6179Smrg 107f46a6179Smrg#define ERROR uError 108f46a6179Smrg 10934345a63Smrg extern void uError(const char * /* s */ , ... 110e9cdd019Smrg ) _X_ATTRIBUTE_PRINTF(1, 2); 111f46a6179Smrg 112f46a6179Smrg#define FATAL uFatalError 113f46a6179Smrg 11434345a63Smrg extern void uFatalError(const char * /* s */ , ... 115b091287fSmrg ) _X_ATTRIBUTE_PRINTF(1, 2) _X_NORETURN; 116f46a6179Smrg 117f46a6179Smrg/* WSGO stands for "Weird Stuff Going On" */ 118f46a6179Smrg#define WSGO uInternalError 119f46a6179Smrg 12034345a63Smrg extern void uInternalError(const char * /* s */ , ... 121e9cdd019Smrg ) _X_ATTRIBUTE_PRINTF(1, 2); 122f46a6179Smrg 1236ae2c069Smrg extern void uSetPreErrorMessage(const char * /* msg */ 12434345a63Smrg ); 125f46a6179Smrg 1266ae2c069Smrg extern void uSetPostErrorMessage(const char * /* msg */ 12734345a63Smrg ); 128f46a6179Smrg 1296ae2c069Smrg extern void uSetErrorPrefix(const char * /* void */ 13034345a63Smrg ); 131f46a6179Smrg 13234345a63Smrg extern void uFinishUp(void); 133f46a6179Smrg 134f46a6179Smrg 135f46a6179Smrg/***====================================================================***/ 136f46a6179Smrg 137f46a6179Smrg#define NullString ((char *)NULL) 138f46a6179Smrg 139f46a6179Smrg#define uStringText(s) ((s)==NullString?"<NullString>":(s)) 140f46a6179Smrg#define uStringEqual(s1,s2) (uStringCompare(s1,s2)==Equal) 141f46a6179Smrg#define uStringPrefix(p,s) (strncmp(p,s,strlen(p))==0) 142f46a6179Smrg#define uStringCompare(s1,s2) (((s1)==NullString||(s2)==NullString)?\ 143f46a6179Smrg (s1)!=(s2):strcmp(s1,s2)) 144f46a6179Smrg#define uStrCaseEqual(s1,s2) (uStrCaseCmp(s1,s2)==0) 145f46a6179Smrg#ifdef HAVE_STRCASECMP 146b091287fSmrg#include <strings.h> 147f46a6179Smrg#define uStrCaseCmp(s1,s2) (strcasecmp(s1,s2)) 148f46a6179Smrg#define uStrCasePrefix(p,s) (strncasecmp(p,s,strlen(p))==0) 149f46a6179Smrg#else 15034345a63Smrg extern int uStrCaseCmp(const char * /* s1 */ , 15134345a63Smrg const char * /* s2 */ 15234345a63Smrg ); 15334345a63Smrg extern int uStrCasePrefix(const char * /* p */ , 15434345a63Smrg char * /* str */ 15534345a63Smrg ); 156f46a6179Smrg#endif 157f46a6179Smrg#ifdef HAVE_STRDUP 158b091287fSmrg#include <string.h> 15934345a63Smrg#define uStringDup(s1) ((s1) ? strdup(s1) : NULL) 160f46a6179Smrg#else 16134345a63Smrg extern char *uStringDup(const char * /* s1 */ 16234345a63Smrg ); 163f46a6179Smrg#endif 164f46a6179Smrg 165f46a6179Smrg/***====================================================================***/ 166f46a6179Smrg 1676ae2c069Smrg#ifdef DEBUG 168f46a6179Smrg#ifndef DEBUG_VAR 169f46a6179Smrg#define DEBUG_VAR debugFlags 170f46a6179Smrg#endif 171f46a6179Smrg 1726ae2c069Smrgextern unsigned int DEBUG_VAR; 173f46a6179Smrg 1746ae2c069Smrgextern void uDebug(const char *, ...) _X_ATTRIBUTE_PRINTF(1, 2); 175f46a6179Smrg 1766ae2c069Smrgextern Boolean uSetDebugFile(const char *name); 177f46a6179Smrg 1786ae2c069Smrgextern int uDebugIndentLevel; 179f46a6179Smrg 180f46a6179Smrg#define uDebugIndent(l) (uDebugIndentLevel+=(l)) 181f46a6179Smrg#define uDebugOutdent(l) (uDebugIndentLevel-=(l)) 1826ae2c069Smrg 183f46a6179Smrg#define uDEBUG(f,s) { if (DEBUG_VAR&(f)) uDebug(s);} 184f46a6179Smrg#define uDEBUG1(f,s,a) { if (DEBUG_VAR&(f)) uDebug(s,a);} 185f46a6179Smrg#define uDEBUG2(f,s,a,b) { if (DEBUG_VAR&(f)) uDebug(s,a,b);} 186f46a6179Smrg#define uDEBUG3(f,s,a,b,c) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c);} 187f46a6179Smrg#define uDEBUG4(f,s,a,b,c,d) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d);} 188f46a6179Smrg#define uDEBUG5(f,s,a,b,c,d,e) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d,e);} 189f46a6179Smrg#else 190f46a6179Smrg#define uDEBUG(f,s) 191f46a6179Smrg#define uDEBUG1(f,s,a) 192f46a6179Smrg#define uDEBUG2(f,s,a,b) 193f46a6179Smrg#define uDEBUG3(f,s,a,b,c) 194f46a6179Smrg#define uDEBUG4(f,s,a,b,c,d) 195f46a6179Smrg#define uDEBUG5(f,s,a,b,c,d,e) 196f46a6179Smrg#endif 197f46a6179Smrg 198f46a6179Smrg#endif /* UTILS_H */ 199