Don't ignore inactive type entries
[platform/upstream/libxkbcommon.git] / src / utils.c
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 <ctype.h>
29 #include <stdlib.h>
30 #include <stdarg.h>
31 #include <string.h>
32
33 #include "utils.h"
34
35 static FILE *errorFile = NULL;
36 static int outCount = 0;
37 static char *preMsg = NULL;
38 static char *prefix = NULL;
39
40 bool
41 uSetErrorFile(char *name)
42 {
43     if ((errorFile != NULL) && (errorFile != stderr))
44     {
45         fprintf(errorFile, "switching to %s\n", name ? name : "stderr");
46         fclose(errorFile);
47     }
48     if (name != NULL)
49         errorFile = fopen(name, "w");
50     else
51         errorFile = stderr;
52     if (errorFile == NULL)
53     {
54         errorFile = stderr;
55         return false;
56     }
57     return true;
58 }
59
60 void
61 uInformation(const char *s, ...)
62 {
63     va_list args;
64
65     if (!errorFile)
66         errorFile = stderr;
67
68     va_start(args, s);
69     vfprintf(errorFile, s, args);
70     va_end(args);
71     fflush(errorFile);
72 }
73
74 /***====================================================================***/
75
76 void
77 uAction(const char *s, ...)
78 {
79     va_list args;
80
81     if (!errorFile)
82         errorFile = stderr;
83
84     if (prefix != NULL)
85         fprintf(errorFile, "%s", prefix);
86     fprintf(errorFile, "                  ");
87     va_start(args, s);
88     vfprintf(errorFile, s, args);
89     va_end(args);
90     fflush(errorFile);
91 }
92
93 /***====================================================================***/
94
95 void
96 uWarning(const char *s, ...)
97 {
98     va_list args;
99
100     if (!errorFile)
101         errorFile = stderr;
102
103     if ((outCount == 0) && (preMsg != NULL))
104         fprintf(errorFile, "%s\n", preMsg);
105     if (prefix != NULL)
106         fprintf(errorFile, "%s", prefix);
107     fprintf(errorFile, "Warning:          ");
108     va_start(args, s);
109     vfprintf(errorFile, s, args);
110     va_end(args);
111     fflush(errorFile);
112     outCount++;
113 }
114
115 /***====================================================================***/
116
117 void
118 uError(const char *s, ...)
119 {
120     va_list args;
121
122     if (!errorFile)
123         errorFile = stderr;
124
125     if ((outCount == 0) && (preMsg != NULL))
126         fprintf(errorFile, "%s\n", preMsg);
127     if (prefix != NULL)
128         fprintf(errorFile, "%s", prefix);
129     fprintf(errorFile, "Error:            ");
130     va_start(args, s);
131     vfprintf(errorFile, s, args);
132     va_end(args);
133     fflush(errorFile);
134     outCount++;
135 }
136
137 /***====================================================================***/
138
139 void
140 uFatalError(const char *s, ...)
141 {
142     va_list args;
143
144     if (!errorFile)
145         errorFile = stderr;
146
147     if ((outCount == 0) && (preMsg != NULL))
148         fprintf(errorFile, "%s\n", preMsg);
149     if (prefix != NULL)
150         fprintf(errorFile, "%s", prefix);
151     fprintf(errorFile, "Fatal Error:      ");
152     va_start(args, s);
153     vfprintf(errorFile, s, args);
154     va_end(args);
155     fprintf(errorFile, "                  Exiting\n");
156     fflush(errorFile);
157     outCount++;
158     exit(1);
159     /* NOTREACHED */
160 }
161
162 /***====================================================================***/
163
164 void
165 uInternalError(const char *s, ...)
166 {
167     va_list args;
168
169     if (!errorFile)
170         errorFile = stderr;
171
172     if ((outCount == 0) && (preMsg != NULL))
173         fprintf(errorFile, "%s\n", preMsg);
174     if (prefix != NULL)
175         fprintf(errorFile, "%s", prefix);
176     fprintf(errorFile, "Internal error:   ");
177     va_start(args, s);
178     vfprintf(errorFile, s, args);
179     va_end(args);
180     fflush(errorFile);
181     outCount++;
182 }