5 * DIGITAL EQUIPMENT CORPORATION
6 * MAYNARD, MASSACHUSETTS
9 * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
10 * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
11 * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE
12 * FOR ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED
15 * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT
16 * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN
17 * ADDITION TO THAT SET FORTH ABOVE.
19 * Permission to use, copy, modify, and distribute this software and its
20 * documentation for any purpose and without fee is hereby granted, provided
21 * that the above copyright notice appear in all copies and that both that
22 * copyright notice and this permission notice appear in supporting
23 * documentation, and that the name of Digital Equipment Corporation not be
24 * used in advertising or publicity pertaining to distribution of the
25 * software without specific, written prior permission.
33 /***====================================================================***/
38 return ((Opaque) malloc(size));
41 /***====================================================================***/
44 uCalloc(unsigned n, unsigned size)
46 return ((Opaque) calloc(n, size));
49 /***====================================================================***/
52 uRealloc(Opaque old, unsigned newSize)
55 return ((Opaque) malloc(newSize));
57 return ((Opaque) realloc((char *) old, newSize));
60 /***====================================================================***/
63 uRecalloc(Opaque old, unsigned nOld, unsigned nNew, unsigned itemSize)
68 rtrn = (char *) calloc(nNew, itemSize);
71 rtrn = (char *) realloc((char *) old, nNew * itemSize);
72 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))
102 fprintf(entryFile, "switching to %s\n", name ? name : "stderr");
105 if (name != NullString)
106 entryFile = fopen(name, "w");
109 if (entryFile == NULL)
118 uEntry(int l, char *s, ...)
123 for (i = 0; i < uEntryLevel; i++)
125 putc(' ', entryFile);
128 vfprintf(entryFile, s, args);
134 uExit(int l, char *rtVal)
141 for (i = 0; i < uEntryLevel; i++)
143 putc(' ', entryFile);
145 fprintf(entryFile, "---> %p\n", rtVal);
149 /***====================================================================***/
150 /*** PRINT FUNCTIONS ***/
151 /***====================================================================***/
153 FILE *uDebugFile = NULL;
154 int uDebugIndentLevel = 0;
155 int uDebugIndentSize = 4;
158 uSetDebugFile(char *name)
160 if ((uDebugFile != NULL) && (uDebugFile != stderr))
162 fprintf(uDebugFile, "switching to %s\n", name ? name : "stderr");
165 if (name != NullString)
166 uDebugFile = fopen(name, "w");
169 if (uDebugFile == NULL)
183 for (i = (uDebugIndentLevel * uDebugIndentSize); i > 0; i--)
185 putc(' ', uDebugFile);
188 vfprintf(uDebugFile, s, args);
194 uDebugNOI(char *s, ...)
199 vfprintf(uDebugFile, s, args);
204 /***====================================================================***/
206 static FILE *errorFile = NULL;
207 static int outCount = 0;
208 static char *preMsg = NULL;
209 static char *postMsg = NULL;
210 static char *prefix = NULL;
213 uSetErrorFile(char *name)
215 if ((errorFile != NULL) && (errorFile != stderr))
217 fprintf(errorFile, "switching to %s\n", name ? name : "stderr");
220 if (name != NullString)
221 errorFile = fopen(name, "w");
224 if (errorFile == NULL)
233 uInformation(const char *s, ...)
238 vfprintf(errorFile, s, args);
243 /***====================================================================***/
246 uAction(const char *s, ...)
251 fprintf(errorFile, "%s", prefix);
252 fprintf(errorFile, " ");
254 vfprintf(errorFile, s, args);
259 /***====================================================================***/
262 uWarning(const char *s, ...)
266 if ((outCount == 0) && (preMsg != NULL))
267 fprintf(errorFile, "%s\n", preMsg);
269 fprintf(errorFile, "%s", prefix);
270 fprintf(errorFile, "Warning: ");
272 vfprintf(errorFile, s, args);
278 /***====================================================================***/
281 uError(const char *s, ...)
285 if ((outCount == 0) && (preMsg != NULL))
286 fprintf(errorFile, "%s\n", preMsg);
288 fprintf(errorFile, "%s", prefix);
289 fprintf(errorFile, "Error: ");
291 vfprintf(errorFile, s, args);
297 /***====================================================================***/
300 uFatalError(const char *s, ...)
304 if ((outCount == 0) && (preMsg != NULL))
305 fprintf(errorFile, "%s\n", preMsg);
307 fprintf(errorFile, "%s", prefix);
308 fprintf(errorFile, "Fatal Error: ");
310 vfprintf(errorFile, s, args);
312 fprintf(errorFile, " Exiting\n");
319 /***====================================================================***/
322 uInternalError(const char *s, ...)
326 if ((outCount == 0) && (preMsg != NULL))
327 fprintf(errorFile, "%s\n", preMsg);
329 fprintf(errorFile, "%s", prefix);
330 fprintf(errorFile, "Internal error: ");
332 vfprintf(errorFile, s, args);
339 uSetPreErrorMessage(char *msg)
347 uSetPostErrorMessage(char *msg)
354 uSetErrorPrefix(char *pre)
363 if ((outCount > 0) && (postMsg != NULL))
364 fprintf(errorFile, "%s\n", postMsg);
368 /***====================================================================***/
372 uStringDup(const char *str)
378 rtrn = (char *) uAlloc(strlen(str) + 1);
384 #ifndef HAVE_STRCASECMP
386 uStrCaseCmp(const char *str1, const char *str2)
388 char buf1[512], buf2[512];
392 for (n = 0, s = buf1; (c = *str1++); n++)
401 for (n = 0, s = buf2; (c = *str2++); n++)
410 return (strcmp(buf1, buf2));
414 uStrCasePrefix(const char *my_prefix, char *str)
418 while (((c1 = *my_prefix) != '\0') && ((c2 = *str) != '\0'))