1 
2   /*\
3    *
4    *                          COPYRIGHT 1990
5    *                    DIGITAL EQUIPMENT CORPORATION
6    *                       MAYNARD, MASSACHUSETTS
7    *                        ALL RIGHTS RESERVED.
8    *
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
13    * WARRANTY.
14    *
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.
18    *
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.
26   \*/
27 
28 #include 	"utils.h"
29 #include	<ctype.h>
30 #include	<stdlib.h>
31 
32 /***====================================================================***/
33 
34 static FILE *errorFile = NULL;
35 
36 Boolean
uSetErrorFile(const char * name)37 uSetErrorFile(const char *name)
38 {
39     if ((errorFile != NULL) && (errorFile != stderr)) {
40         fprintf(errorFile, "switching to %s\n", name ? name : "stderr");
41         fclose(errorFile);
42     }
43     if (name != NullString)
44         errorFile = fopen(name, "w");
45     else
46         errorFile = stderr;
47     if (errorFile == NULL) {
48         errorFile = stderr;
49         return (False);
50     }
51     return (True);
52 }
53 
54 void
uInformation(const char * s,...)55 uInformation(const char *s, ...)
56 {
57     va_list ap;
58 
59     va_start(ap, s);
60     vfprintf(errorFile, s, ap);
61     fflush(errorFile);
62     va_end(ap);
63     return;
64 }
65 
66 /***====================================================================***/
67 
68 void
uAction(const char * s,...)69 uAction(const char *s, ...)
70 {
71     va_list ap;
72 
73     va_start(ap, s);
74     fprintf(errorFile, "                  ");
75     vfprintf(errorFile, s, ap);
76     fflush(errorFile);
77     va_end(ap);
78     return;
79 }
80 
81 /***====================================================================***/
82 
83 void
uWarning(const char * s,...)84 uWarning(const char *s, ...)
85 {
86     va_list ap;
87 
88     va_start(ap, s);
89     fprintf(errorFile, "Warning:          ");
90     vfprintf(errorFile, s, ap);
91     fflush(errorFile);
92     va_end(ap);
93     return;
94 }
95 
96 /***====================================================================***/
97 
98 void
uError(const char * s,...)99 uError(const char *s, ...)
100 {
101     va_list ap;
102 
103     va_start(ap, s);
104     fprintf(errorFile, "Error:            ");
105     vfprintf(errorFile, s, ap);
106     fflush(errorFile);
107     va_end(ap);
108     return;
109 }
110 
111 /***====================================================================***/
112 
113 void
uInternalError(const char * s,...)114 uInternalError(const char *s, ...)
115 {
116     va_list ap;
117 
118     va_start(ap, s);
119     fprintf(errorFile, "Internal error:   ");
120     vfprintf(errorFile, s, ap);
121     fflush(errorFile);
122     va_end(ap);
123     return;
124 }
125 
126 /***====================================================================***/
127 
128 #ifndef HAVE_STRCASECMP
129 int
uStrCaseCmp(const char * str1,const char * str2)130 uStrCaseCmp(const char *str1, const char *str2)
131 {
132     char buf1[512], buf2[512];
133 
134     char c, *s;
135 
136     register int n;
137 
138     for (n = 0, s = buf1; (c = *str1++); n++) {
139         if (isupper(c))
140             c = tolower(c);
141         if (n > 510)
142             break;
143         *s++ = c;
144     }
145     *s = '\0';
146     for (n = 0, s = buf2; (c = *str2++); n++) {
147         if (isupper(c))
148             c = tolower(c);
149         if (n > 510)
150             break;
151         *s++ = c;
152     }
153     *s = '\0';
154     return (strcmp(buf1, buf2));
155 }
156 #endif
157