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, ...)
126 for (i = 0; i < uEntryLevel; i++)
128 putc(' ', entryFile);
131 vfprintf(entryFile, s, args);
137 uExit(int l, char *rtVal)
147 for (i = 0; i < uEntryLevel; i++)
149 putc(' ', entryFile);
151 fprintf(entryFile, "---> %p\n", rtVal);
155 /***====================================================================***/
156 /*** PRINT FUNCTIONS ***/
157 /***====================================================================***/
159 FILE *uDebugFile = NULL;
160 int uDebugIndentLevel = 0;
161 int uDebugIndentSize = 4;
164 uSetDebugFile(char *name)
166 if ((uDebugFile != NULL) && (uDebugFile != stderr))
168 fprintf(uDebugFile, "switching to %s\n", name ? name : "stderr");
171 if (name != NullString)
172 uDebugFile = fopen(name, "w");
175 if (uDebugFile == NULL)
192 for (i = (uDebugIndentLevel * uDebugIndentSize); i > 0; i--)
194 putc(' ', uDebugFile);
197 vfprintf(uDebugFile, s, args);
203 uDebugNOI(char *s, ...)
211 vfprintf(uDebugFile, s, args);
216 /***====================================================================***/
218 static FILE *errorFile = NULL;
219 static int outCount = 0;
220 static char *preMsg = NULL;
221 static char *postMsg = NULL;
222 static char *prefix = NULL;
225 uSetErrorFile(char *name)
227 if ((errorFile != NULL) && (errorFile != stderr))
229 fprintf(errorFile, "switching to %s\n", name ? name : "stderr");
232 if (name != NullString)
233 errorFile = fopen(name, "w");
236 if (errorFile == NULL)
245 uInformation(const char *s, ...)
253 vfprintf(errorFile, s, args);
258 /***====================================================================***/
261 uAction(const char *s, ...)
269 fprintf(errorFile, "%s", prefix);
270 fprintf(errorFile, " ");
272 vfprintf(errorFile, s, args);
277 /***====================================================================***/
280 uWarning(const char *s, ...)
287 if ((outCount == 0) && (preMsg != NULL))
288 fprintf(errorFile, "%s\n", preMsg);
290 fprintf(errorFile, "%s", prefix);
291 fprintf(errorFile, "Warning: ");
293 vfprintf(errorFile, s, args);
299 /***====================================================================***/
302 uError(const char *s, ...)
309 if ((outCount == 0) && (preMsg != NULL))
310 fprintf(errorFile, "%s\n", preMsg);
312 fprintf(errorFile, "%s", prefix);
313 fprintf(errorFile, "Error: ");
315 vfprintf(errorFile, s, args);
321 /***====================================================================***/
324 uFatalError(const char *s, ...)
331 if ((outCount == 0) && (preMsg != NULL))
332 fprintf(errorFile, "%s\n", preMsg);
334 fprintf(errorFile, "%s", prefix);
335 fprintf(errorFile, "Fatal Error: ");
337 vfprintf(errorFile, s, args);
339 fprintf(errorFile, " Exiting\n");
346 /***====================================================================***/
349 uInternalError(const char *s, ...)
356 if ((outCount == 0) && (preMsg != NULL))
357 fprintf(errorFile, "%s\n", preMsg);
359 fprintf(errorFile, "%s", prefix);
360 fprintf(errorFile, "Internal error: ");
362 vfprintf(errorFile, s, args);
369 uSetPreErrorMessage(char *msg)
377 uSetPostErrorMessage(char *msg)
384 uSetErrorPrefix(char *pre)
393 if (errorFile && (outCount > 0) && (postMsg != NULL))
394 fprintf(errorFile, "%s\n", postMsg);
398 /***====================================================================***/
402 uStringDup(const char *str)
408 rtrn = (char *) uAlloc(strlen(str) + 1);
414 #ifndef HAVE_STRCASECMP
416 uStrCaseCmp(const char *str1, const char *str2)
418 char buf1[512], buf2[512];
422 for (n = 0, s = buf1; (c = *str1++); n++)
431 for (n = 0, s = buf2; (c = *str2++); n++)
440 return (strcmp(buf1, buf2));
444 uStrCasePrefix(const char *my_prefix, char *str)
448 while (((c1 = *my_prefix) != '\0') && ((c2 = *str) != '\0'))