utils.c revision 945aa7e3
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/***			PRINT FUNCTIONS					***/
34/***====================================================================***/
35
36static FILE *errorFile = NULL;
37
38Boolean
39uSetErrorFile(const char *name)
40{
41    if ((errorFile != NULL) && (errorFile != stderr)) {
42        fprintf(errorFile, "switching to %s\n", name ? name : "stderr");
43        fclose(errorFile);
44    }
45    if (name != NullString)
46        errorFile = fopen(name, "w");
47    else
48        errorFile = stderr;
49    if (errorFile == NULL) {
50        errorFile = stderr;
51        return (False);
52    }
53    return (True);
54}
55
56void
57uInformation(const char *s, ...)
58{
59    va_list ap;
60
61    va_start(ap, s);
62    vfprintf(errorFile, s, ap);
63    fflush(errorFile);
64    va_end(ap);
65    return;
66}
67
68/***====================================================================***/
69
70void
71uAction(const char *s, ...)
72{
73    va_list ap;
74
75    va_start(ap, s);
76    fprintf(errorFile, "                  ");
77    vfprintf(errorFile, s, ap);
78    fflush(errorFile);
79    va_end(ap);
80    return;
81}
82
83/***====================================================================***/
84
85void
86uWarning(const char *s, ...)
87{
88    va_list ap;
89
90    va_start(ap, s);
91    fprintf(errorFile, "Warning:          ");
92    vfprintf(errorFile, s, ap);
93    fflush(errorFile);
94    va_end(ap);
95    return;
96}
97
98/***====================================================================***/
99
100void
101uError(const char *s, ...)
102{
103    va_list ap;
104
105    va_start(ap, s);
106    fprintf(errorFile, "Error:            ");
107    vfprintf(errorFile, s, ap);
108    fflush(errorFile);
109    va_end(ap);
110    return;
111}
112
113/***====================================================================***/
114
115void
116uFatalError(const char *s, ...)
117{
118    va_list ap;
119
120    va_start(ap, s);
121    fprintf(errorFile, "Fatal Error:      ");
122    vfprintf(errorFile, s, ap);
123    fprintf(errorFile, "                  Exiting\n");
124    fflush(errorFile);
125    va_end(ap);
126    exit(1);
127    /* NOTREACHED */
128}
129
130/***====================================================================***/
131
132void
133uInternalError(const char *s, ...)
134{
135    va_list ap;
136
137    va_start(ap, s);
138    fprintf(errorFile, "Internal error:   ");
139    vfprintf(errorFile, s, ap);
140    fflush(errorFile);
141    va_end(ap);
142    return;
143}
144
145/***====================================================================***/
146
147#ifndef HAVE_STRCASECMP
148int
149uStrCaseCmp(const char *str1, const char *str2)
150{
151    char buf1[512], buf2[512];
152    char c, *s;
153
154    register int n;
155
156    for (n = 0, s = buf1; (c = *str1++); n++) {
157        if (isupper(c))
158            c = tolower(c);
159        if (n > 510)
160            break;
161        *s++ = c;
162    }
163    *s = '\0';
164    for (n = 0, s = buf2; (c = *str2++); n++) {
165        if (isupper(c))
166            c = tolower(c);
167        if (n > 510)
168            break;
169        *s++ = c;
170    }
171    *s = '\0';
172    return (strcmp(buf1, buf2));
173}
174#endif
175