3 * $Xorg: utils.c,v 1.5 2000/08/17 19:54:50 cpqbld Exp $
6 * DIGITAL EQUIPMENT CORPORATION
7 * MAYNARD, MASSACHUSETTS
10 * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
11 * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
12 * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE
13 * FOR ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED
16 * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT
17 * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN
18 * ADDITION TO THAT SET FORTH ABOVE.
20 * Permission to use, copy, modify, and distribute this software and its
21 * documentation for any purpose and without fee is hereby granted, provided
22 * that the above copyright notice appear in all copies and that both that
23 * copyright notice and this permission notice appear in supporting
24 * documentation, and that the name of Digital Equipment Corporation not be
25 * used in advertising or publicity pertaining to distribution of the
26 * software without specific, written prior permission.
28 /* $XFree86: xc/programs/xkbprint/utils.c,v 3.4 2001/01/17 23:46:11 dawes Exp $ */
34 unsigned int debugFlags;
37 /***====================================================================***/
42 return((Opaque)malloc(size));
45 /***====================================================================***/
48 uCalloc(unsigned n, unsigned size)
50 return((Opaque)calloc(n,size));
53 /***====================================================================***/
56 uRealloc(Opaque old, unsigned newSize)
59 return((Opaque)malloc(newSize));
60 else return((Opaque)realloc((char *)old,newSize));
63 /***====================================================================***/
66 uRecalloc(Opaque old, unsigned nOld, unsigned nNew, unsigned itemSize)
71 rtrn= (char *)calloc(nNew,itemSize);
73 rtrn= (char *)realloc((char *)old,nNew*itemSize);
74 if ((rtrn)&&(nNew>nOld)) {
75 bzero(&rtrn[nOld*itemSize],(nNew-nOld)*itemSize);
81 /***====================================================================***/
86 if (ptr!=(Opaque)NULL)
91 /***====================================================================***/
92 /*** FUNCTION ENTRY TRACKING ***/
93 /***====================================================================***/
95 static FILE *entryFile= NULL;
96 static int uEntryLevel;
99 uSetEntryFile(char *name)
101 if ((entryFile!=NULL)&&(entryFile!=stderr)) {
102 fprintf(entryFile,"switching to %s\n",name?name:"stderr");
105 if (name!=NullString) entryFile= fopen(name,"w");
106 else entryFile= stderr;
107 if (entryFile==NULL) {
115 uEntry(int l, char *s,...)
121 for (i=0;i<uEntryLevel;i++) {
124 vfprintf(entryFile,s,ap);
131 uExit(int l, char *rtVal)
136 if (uEntryLevel<0) uEntryLevel= 0;
137 for (i=0;i<uEntryLevel;i++) {
140 fprintf(entryFile,"---> 0x%p\n",rtVal);
144 /***====================================================================***/
145 /*** PRINT FUNCTIONS ***/
146 /***====================================================================***/
148 FILE *uDebugFile= NULL;
149 int uDebugIndentLevel= 0;
150 int uDebugIndentSize= 4;
153 uSetDebugFile(char *name)
155 if ((uDebugFile!=NULL)&&(uDebugFile!=stderr)) {
156 fprintf(uDebugFile,"switching to %s\n",name?name:"stderr");
159 if (name!=NullString) uDebugFile= fopen(name,"w");
160 else uDebugFile= stderr;
161 if (uDebugFile==NULL) {
175 for (i=(uDebugIndentLevel*uDebugIndentSize);i>0;i--) {
176 putc(' ',uDebugFile);
178 vfprintf(uDebugFile,s,ap);
185 uDebugNOI(char *s,...)
190 vfprintf(uDebugFile,s,ap);
196 /***====================================================================***/
198 static FILE *errorFile= NULL;
201 uSetErrorFile(char *name)
203 if ((errorFile!=NULL)&&(errorFile!=stderr)) {
204 fprintf(errorFile,"switching to %s\n",name?name:"stderr");
207 if (name!=NullString) errorFile= fopen(name,"w");
208 else errorFile= stderr;
209 if (errorFile==NULL) {
217 uInformation(char *s,...)
222 vfprintf(errorFile,s,ap);
228 /***====================================================================***/
236 fprintf(errorFile," ");
237 vfprintf(errorFile,s,ap);
243 /***====================================================================***/
246 uWarning(char *s,...)
251 fprintf(errorFile,"Warning: ");
252 vfprintf(errorFile,s,ap);
258 /***====================================================================***/
266 fprintf(errorFile,"Error: ");
267 vfprintf(errorFile,s,ap);
273 /***====================================================================***/
276 uFatalError(char *s,...)
281 fprintf(errorFile,"Fatal Error: ");
282 vfprintf(errorFile,s,ap);
283 fprintf(errorFile," Exiting\n");
290 /***====================================================================***/
293 uInternalError(char *s,...)
298 fprintf(errorFile,"Internal error: ");
299 vfprintf(errorFile,s,ap);
305 /***====================================================================***/
309 uStringDup(char *str)
315 rtrn= (char *)uAlloc(strlen(str)+1);
321 #ifndef HAVE_STRCASECMP
323 uStrCaseCmp(char *str1, char *str2)
325 char buf1[512],buf2[512];
329 for (n=0, s = buf1; (c = *str1++); n++) {
337 for (n=0, s = buf2; (c = *str2++); n++) {
345 return (strcmp(buf1, buf2));
349 uStrCasePrefix(char *prefix, char *str)
353 while (((c1=*prefix)!='\0')&&((c2=*str)!='\0')) {
354 if (isupper(c1)) c1= tolower(c1);
355 if (isupper(c2)) c2= tolower(c2);