3
* $XFree86: xc/programs/xkbevd/utils.c,v 3.6 2002/01/14 18:30:11 dawes 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
/* $Xorg: utils.c,v 1.5 2000/08/17 19:54:49 cpqbld Exp $ */
30
#define DEBUG_VAR_LOCAL
35
/***====================================================================***/
41
return((Opaque)malloc(size));
44
/***====================================================================***/
51
return((Opaque)calloc(n,size));
54
/***====================================================================***/
62
return((Opaque)malloc(newSize));
63
else return((Opaque)realloc((char *)old,newSize));
66
/***====================================================================***/
69
uRecalloc(old,nOld,nNew,itemSize)
78
rtrn= (char *)calloc(nNew,itemSize);
80
rtrn= (char *)realloc((char *)old,nNew*itemSize);
81
if ((rtrn)&&(nNew>nOld)) {
82
bzero(&rtrn[nOld*itemSize],(nNew-nOld)*itemSize);
88
/***====================================================================***/
94
if (ptr!=(Opaque)NULL)
99
/***====================================================================***/
100
/*** FUNCTION ENTRY TRACKING ***/
101
/***====================================================================***/
103
static FILE *entryFile= NULL;
110
if ((entryFile!=NULL)&&(entryFile!=stderr)) {
111
fprintf(entryFile,"switching to %s\n",name?name:"stderr");
114
if (name!=NullString) entryFile= fopen(name,"w");
115
else entryFile= stderr;
116
if (entryFile==NULL) {
124
uEntry(int l, char *s,...)
130
for (i=0;i<uEntryLevel;i++) {
133
vfprintf(entryFile,s,ap);
147
if (uEntryLevel<0) uEntryLevel= 0;
148
for (i=0;i<uEntryLevel;i++) {
151
fprintf(entryFile,"---> 0x%p\n",rtVal);
155
/***====================================================================***/
156
/*** PRINT FUNCTIONS ***/
157
/***====================================================================***/
159
FILE *uDebugFile= NULL;
160
int uDebugIndentLevel= 0;
161
int uDebugIndentSize= 4;
167
if ((uDebugFile!=NULL)&&(uDebugFile!=stderr)) {
168
fprintf(uDebugFile,"switching to %s\n",name?name:"stderr");
171
if (name!=NullString) uDebugFile= fopen(name,"w");
172
else uDebugFile= stderr;
173
if (uDebugFile==NULL) {
187
for (i=(uDebugIndentLevel*uDebugIndentSize);i>0;i--) {
188
putc(' ',uDebugFile);
190
vfprintf(uDebugFile,s,ap);
197
uDebugNOI(char *s,...)
202
vfprintf(uDebugFile,s,ap);
208
/***====================================================================***/
210
static FILE *errorFile= NULL;
213
uSetErrorFile(char *name)
215
if ((errorFile!=NULL)&&(errorFile!=stderr)) {
216
fprintf(errorFile,"switching to %s\n",name?name:"stderr");
219
if (name!=NullString) errorFile= fopen(name,"w");
220
else errorFile= stderr;
221
if (errorFile==NULL) {
229
uInformation(char *s,...)
234
vfprintf(errorFile,s,ap);
240
/***====================================================================***/
248
fprintf(errorFile," ");
249
vfprintf(errorFile,s,ap);
255
/***====================================================================***/
258
uWarning(char *s,...)
263
fprintf(errorFile,"Warning: ");
264
vfprintf(errorFile,s,ap);
270
/***====================================================================***/
278
fprintf(errorFile,"Error: ");
279
vfprintf(errorFile,s,ap);
285
/***====================================================================***/
288
uFatalError(char *s,...)
293
fprintf(errorFile,"Fatal Error: ");
294
vfprintf(errorFile,s,ap);
295
fprintf(errorFile," Exiting\n");
302
/***====================================================================***/
305
uInternalError(char *s,...)
310
fprintf(errorFile,"Internal error: ");
311
vfprintf(errorFile,s,ap);
317
/***====================================================================***/
328
rtrn= (char *)uAlloc(strlen(str)+1);
334
#ifndef HAVE_STRCASECMP
336
uStrCaseCmp(str1, str2)
339
char buf1[512],buf2[512];
343
for (n=0, s = buf1; (c = *str1++); n++) {
351
for (n=0, s = buf2; (c = *str2++); n++) {
359
return (strcmp(buf1, buf2));
363
uStrCasePrefix(prefix, str)
368
while (((c1=*prefix)!='\0')&&((c2=*str)!='\0')) {
369
if (isupper(c1)) c1= tolower(c1);
370
if (isupper(c2)) c2= tolower(c2);