3 * $Xorg: utils.c,v 1.6 2000/08/17 19:54:51 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/xkbutils/utils.c,v 3.4 2001/01/17 23:46:13 dawes Exp $ */
34 unsigned int debugFlags;
36 /***====================================================================***/
41 return((Opaque)malloc(size));
44 /***====================================================================***/
47 uCalloc(unsigned n, unsigned size)
49 return((Opaque)calloc(n,size));
52 /***====================================================================***/
55 uRealloc(Opaque old, unsigned newSize)
58 return((Opaque)malloc(newSize));
59 else return((Opaque)realloc((char *)old,newSize));
62 /***====================================================================***/
65 uRecalloc(Opaque old, unsigned nOld, unsigned nNew, unsigned itemSize)
70 rtrn= (char *)calloc(nNew,itemSize);
72 rtrn= (char *)realloc((char *)old,nNew*itemSize);
73 if ((rtrn)&&(nNew>nOld)) {
74 bzero(&rtrn[nOld*itemSize],(nNew-nOld)*itemSize);
80 /***====================================================================***/
85 if (ptr!=(Opaque)NULL)
90 /***====================================================================***/
91 /*** FUNCTION ENTRY TRACKING ***/
92 /***====================================================================***/
94 static FILE *entryFile= NULL;
98 uSetEntryFile(char *name)
100 if ((entryFile!=NULL)&&(entryFile!=stderr)) {
101 fprintf(entryFile,"switching to %s\n",name?name:"stderr");
104 if (name!=NullString) entryFile= fopen(name,"w");
105 else entryFile= stderr;
106 if (entryFile==NULL) {
114 uEntry(int l, char *s,...)
120 for (i=0;i<uEntryLevel;i++) {
123 vfprintf(entryFile,s,ap);
130 uExit(int l, char *rtVal)
135 if (uEntryLevel<0) uEntryLevel= 0;
136 for (i=0;i<uEntryLevel;i++) {
139 fprintf(entryFile,"---> 0x%p\n",rtVal);
143 /***====================================================================***/
144 /*** PRINT FUNCTIONS ***/
145 /***====================================================================***/
147 FILE *uDebugFile= NULL;
148 int uDebugIndentLevel= 0;
149 int uDebugIndentSize= 4;
152 uSetDebugFile(char *name)
154 if ((uDebugFile!=NULL)&&(uDebugFile!=stderr)) {
155 fprintf(uDebugFile,"switching to %s\n",name?name:"stderr");
158 if (name!=NullString) uDebugFile= fopen(name,"w");
159 else uDebugFile= stderr;
160 if (uDebugFile==NULL) {
174 for (i=(uDebugIndentLevel*uDebugIndentSize);i>0;i--) {
175 putc(' ',uDebugFile);
177 vfprintf(uDebugFile,s,ap);
184 uDebugNOI(char *s,...)
189 vfprintf(uDebugFile,s,ap);
195 /***====================================================================***/
197 static FILE *errorFile= NULL;
200 uSetErrorFile(char *name)
202 if ((errorFile!=NULL)&&(errorFile!=stderr)) {
203 fprintf(errorFile,"switching to %s\n",name?name:"stderr");
206 if (name!=NullString) errorFile= fopen(name,"w");
207 else errorFile= stderr;
208 if (errorFile==NULL) {
216 uInformation(char *s,...)
221 vfprintf(errorFile,s,ap);
227 /***====================================================================***/
235 fprintf(errorFile," ");
236 vfprintf(errorFile,s,ap);
242 /***====================================================================***/
245 uWarning(char *s,...)
250 fprintf(errorFile,"Warning: ");
251 vfprintf(errorFile,s,ap);
257 /***====================================================================***/
265 fprintf(errorFile,"Error: ");
266 vfprintf(errorFile,s,ap);
272 /***====================================================================***/
275 uFatalError(char *s,...)
280 fprintf(errorFile,"Fatal Error: ");
281 vfprintf(errorFile,s,ap);
282 fprintf(errorFile," Exiting\n");
289 /***====================================================================***/
292 uInternalError(char *s,...)
297 fprintf(errorFile,"Internal error: ");
298 vfprintf(errorFile,s,ap);
304 /***====================================================================***/
308 uStringDup(char *str)
314 rtrn= (char *)uAlloc(strlen(str)+1);
320 #ifndef HAVE_STRCASECMP
322 uStrCaseCmp(char *str1, char *str2)
324 char buf1[512],buf2[512];
328 for (n=0, s = buf1; (c = *str1++); n++) {
336 for (n=0, s = buf2; (c = *str2++); n++) {
344 return (strcmp(buf1, buf2));
348 uStrCasePrefix(char *prefix, char *str)
352 while (((c1=*prefix)!='\0')&&((c2=*str)!='\0')) {
353 if (isupper(c1)) c1= tolower(c1);
354 if (isupper(c2)) c2= tolower(c2);