1#ifndef UTILS_H 2#define UTILS_H 1 3 4 /*\ 5 * 6 * COPYRIGHT 1990 7 * DIGITAL EQUIPMENT CORPORATION 8 * MAYNARD, MASSACHUSETTS 9 * ALL RIGHTS RESERVED. 10 * 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 15 * WARRANTY. 16 * 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. 20 * 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. 28 \*/ 29 30/***====================================================================***/ 31 32#ifdef HAVE_CONFIG_H 33#include "config.h" 34#endif 35 36#include <stdio.h> 37#include <stdlib.h> 38#include <X11/Xos.h> 39#include <X11/Xfuncproto.h> 40#include <X11/Xfuncs.h> 41 42#include <stddef.h> 43 44#ifndef NUL 45#define NUL '\0' 46#endif 47 48/***====================================================================***/ 49 50#ifndef BOOLEAN_DEFINED 51typedef char Boolean; 52#endif 53 54#ifndef True 55#define True ((Boolean)1) 56#define False ((Boolean)0) 57#endif /* ndef True */ 58#define booleanText(b) ((b)?"True":"False") 59 60#ifndef COMPARISON_DEFINED 61typedef int Comparison; 62 63#define Greater ((Comparison)1) 64#define Equal ((Comparison)0) 65#define Less ((Comparison)-1) 66#define CannotCompare ((Comparison)-37) 67#define comparisonText(c) ((c)?((c)<0?"Less":"Greater"):"Equal") 68#endif 69 70/***====================================================================***/ 71 72#ifndef HAVE_REALLOCARRAY 73#define reallocarray(p, n, s) realloc(p, (n) * (s)) 74#endif 75 76#ifndef HAVE_RECALLOCARRAY 77#define recallocarray uRecalloc 78 79extern void *uRecalloc(void * /* old */ , 80 size_t /* nOld */ , 81 size_t /* nNew */ , 82 size_t /* newSize */ 83 ); 84#endif 85 86/***====================================================================***/ 87 88extern Boolean uSetErrorFile(const char * /* name */ 89 ); 90 91#define INFO uInformation 92 93extern void 94uInformation(const char * /* s */ , ... 95 ) _X_ATTRIBUTE_PRINTF(1, 2); 96 97#define ACTION uAction 98 99 extern void uAction(const char * /* s */ , ... 100 ) _X_ATTRIBUTE_PRINTF(1, 2); 101 102#define WARN uWarning 103 104 extern void uWarning(const char * /* s */ , ... 105 ) _X_ATTRIBUTE_PRINTF(1, 2); 106 107#define ERROR uError 108 109 extern void uError(const char * /* s */ , ... 110 ) _X_ATTRIBUTE_PRINTF(1, 2); 111 112#define FATAL uFatalError 113 114 extern void uFatalError(const char * /* s */ , ... 115 ) _X_ATTRIBUTE_PRINTF(1, 2) _X_NORETURN; 116 117/* WSGO stands for "Weird Stuff Going On" */ 118#define WSGO uInternalError 119 120 extern void uInternalError(const char * /* s */ , ... 121 ) _X_ATTRIBUTE_PRINTF(1, 2); 122 123 extern void uSetPreErrorMessage(const char * /* msg */ 124 ); 125 126 extern void uSetPostErrorMessage(const char * /* msg */ 127 ); 128 129 extern void uSetErrorPrefix(const char * /* void */ 130 ); 131 132 extern void uFinishUp(void); 133 134 135/***====================================================================***/ 136 137#define NullString ((char *)NULL) 138 139#define uStringText(s) ((s)==NullString?"<NullString>":(s)) 140#define uStringEqual(s1,s2) (uStringCompare(s1,s2)==Equal) 141#define uStringPrefix(p,s) (strncmp(p,s,strlen(p))==0) 142#define uStringCompare(s1,s2) (((s1)==NullString||(s2)==NullString)?\ 143 (s1)!=(s2):strcmp(s1,s2)) 144#define uStrCaseEqual(s1,s2) (uStrCaseCmp(s1,s2)==0) 145#ifdef HAVE_STRCASECMP 146#include <strings.h> 147#define uStrCaseCmp(s1,s2) (strcasecmp(s1,s2)) 148#define uStrCasePrefix(p,s) (strncasecmp(p,s,strlen(p))==0) 149#else 150 extern int uStrCaseCmp(const char * /* s1 */ , 151 const char * /* s2 */ 152 ); 153 extern int uStrCasePrefix(const char * /* p */ , 154 char * /* str */ 155 ); 156#endif 157#ifdef HAVE_STRDUP 158#include <string.h> 159#define uStringDup(s1) ((s1) ? strdup(s1) : NULL) 160#else 161 extern char *uStringDup(const char * /* s1 */ 162 ); 163#endif 164 165/***====================================================================***/ 166 167#ifdef DEBUG 168#ifndef DEBUG_VAR 169#define DEBUG_VAR debugFlags 170#endif 171 172extern unsigned int DEBUG_VAR; 173 174extern void uDebug(const char *, ...) _X_ATTRIBUTE_PRINTF(1, 2); 175 176extern Boolean uSetDebugFile(const char *name); 177 178extern int uDebugIndentLevel; 179 180#define uDebugIndent(l) (uDebugIndentLevel+=(l)) 181#define uDebugOutdent(l) (uDebugIndentLevel-=(l)) 182 183#define uDEBUG(f,s) { if (DEBUG_VAR&(f)) uDebug(s);} 184#define uDEBUG1(f,s,a) { if (DEBUG_VAR&(f)) uDebug(s,a);} 185#define uDEBUG2(f,s,a,b) { if (DEBUG_VAR&(f)) uDebug(s,a,b);} 186#define uDEBUG3(f,s,a,b,c) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c);} 187#define uDEBUG4(f,s,a,b,c,d) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d);} 188#define uDEBUG5(f,s,a,b,c,d,e) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d,e);} 189#else 190#define uDEBUG(f,s) 191#define uDEBUG1(f,s,a) 192#define uDEBUG2(f,s,a,b) 193#define uDEBUG3(f,s,a,b,c) 194#define uDEBUG4(f,s,a,b,c,d) 195#define uDEBUG5(f,s,a,b,c,d,e) 196#endif 197 198#endif /* UTILS_H */ 199