Merge branch 'linux1'
[oweals/cde.git] / cde / programs / dthelp / parser / pass2 / util / error.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: error.c /main/3 1995/11/08 11:04:57 rswiston $ */
24 /* Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co. */
25
26 /* Error.c contains procedures for issuing error messages and warnings in
27    BUILD and ELTDEF */
28
29 #include <stdio.h>
30 #include "basic.h"
31
32 extern FILE *m_errfile ;
33 extern int m_line ;
34 extern LOGICAL errexit ;
35
36 void eprefix(
37 #if defined(M_PROTO)
38   LOGICAL flag
39 #endif
40   ) ;
41
42 void m_errline(
43 #if defined(M_PROTO)
44   char *text
45 #endif
46   ) ;
47
48 void m_error(
49 #if defined(M_PROTO)
50   char *text
51 #endif
52   ) ;
53
54 void m_err1(
55 #if defined(M_PROTO)
56   char *text, const M_WCHAR *arg
57 #endif
58   ) ;
59
60 void m_mberr1(
61 #if defined(M_PROTO)
62   char *text, const char *arg
63 #endif
64   ) ;
65
66 void m_err2(
67 #if defined(M_PROTO)
68   const char *text, const M_WCHAR *arg1, const M_WCHAR *arg2
69 #endif
70   ) ;
71
72 void m_err3(
73 #if defined(M_PROTO)
74   char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3
75 #endif
76   ) ;
77
78 void m_err5(
79 #if defined(M_PROTO)
80   char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3, M_WCHAR *arg4,
81               M_WCHAR *arg5
82 #endif
83   ) ;
84
85 void esuffix(
86 #if defined(M_PROTO)
87   void
88 #endif
89   ) ;
90
91 void msgline(
92 #if defined(M_PROTO)
93   char *text
94 #endif
95   ) ;
96
97 void msg1line(
98 #if defined(M_PROTO)
99   char *text, char *arg1
100 #endif
101   ) ;
102
103 void skiptoend(
104 #if defined(M_PROTO)
105   M_NOPAR
106 #endif
107   ) ;
108
109 void m_wctrace(
110 #if defined(M_PROTO)
111   M_WCHAR *text
112 #endif
113   ) ;
114
115 void m_trace(
116 #if defined(M_PROTO)
117   char *text
118 #endif
119   ) ;
120
121 void warning(
122 #if defined(M_PROTO)
123   char *text
124 #endif
125   ) ;
126
127 void warning1(
128 #if defined(M_PROTO)
129   char *text, M_WCHAR *arg
130 #endif
131   ) ;
132
133 void warning2(
134 #if defined(M_PROTO)
135   char *text, M_WCHAR *arg1, M_WCHAR *arg2
136 #endif
137   ) ;
138
139 void warning3(
140 #if defined(M_PROTO)
141   char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3
142 #endif
143   ) ;
144
145 void warning4(
146 #if defined(M_PROTO)
147   char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3, M_WCHAR *arg4
148 #endif
149   ) ;
150
151 /* Write error message prefix */
152 #if defined(M_PROTO)
153 void eprefix(LOGICAL flag)
154 #else
155 void eprefix(flag)
156   LOGICAL flag ;
157 #endif
158   {
159     if (flag) errexit = TRUE ;
160     fprintf(stderr, "\n**** ") ;
161     fprintf(m_errfile, "\n**** ") ;
162     }
163
164 /* Writes part of an error message.  Called from m_malloc instead of
165    m_err1, since PARSER's version of m_err1 calls m_malloc and recursive
166    calls are possible when the heap is exhausted */
167 void m_errline(text)
168 char *text ;
169 {
170 fputs(text, stderr) ;
171 fputs(text, m_errfile) ;
172 }
173
174 /* Writes an error message to standard error and file "error" */
175 void m_error(text)
176   char *text ;
177   {
178     eprefix(TRUE) ;
179     fprintf(stderr,"%s", text) ;
180     fprintf(m_errfile,"%s", text) ;
181     esuffix() ;
182     skiptoend() ;
183   }
184
185 /* Writes an error message with one argument to standard error and file
186    "error" */
187 #if defined(M_PROTO)
188 void m_err1(char *text, const M_WCHAR *arg)
189 #else
190 void m_err1(text, arg)
191   char *text;
192   M_WCHAR *arg ;
193 #endif
194 {
195 char *mb_arg;
196
197 mb_arg = MakeMByteString(arg);
198 eprefix(TRUE) ;
199 fprintf(stderr, text, mb_arg) ;
200 fprintf(m_errfile, text, mb_arg) ;
201 esuffix() ;
202 skiptoend() ;
203 m_free(mb_arg,"multi-byte string");
204 }
205
206 #if defined(M_PROTO)
207 void m_mberr1(char *text, const char *arg)
208 #else
209 void m_err1(text, arg)
210   char *text;
211   char *arg ;
212 #endif
213 {
214 eprefix(TRUE) ;
215 fprintf(stderr, text, arg) ;
216 fprintf(m_errfile, text, arg) ;
217 esuffix() ;
218 skiptoend() ;
219 }
220
221 /* Writes an error message with two arguments to standard error and file
222    "error" */
223 #if defined(M_PROTO)
224 void m_err2( const char *text, const M_WCHAR *arg1, const M_WCHAR *arg2)
225 #else
226 void m_err2(text, arg1, arg2)
227 char *text;
228 M_WCHAR *arg1, *arg2 ;
229 #endif
230 {
231 char *mb_arg1, *mb_arg2;
232
233 mb_arg1 = MakeMByteString(arg1);
234 mb_arg2 = MakeMByteString(arg2);
235 eprefix(TRUE) ;
236 fprintf(stderr, text, mb_arg1, mb_arg2) ;
237 fprintf(m_errfile, text, mb_arg1, mb_arg2) ;
238 esuffix() ;
239 skiptoend() ;
240 m_free(mb_arg1,"multi-byte string");
241 m_free(mb_arg2,"multi-byte string");
242 }
243
244 /* Writes an error message with three arguments to standard error and file
245    "error" */
246 #if defined(M_PROTO)
247 void m_err3( char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3)
248 #else
249 void m_err3(text, arg1, arg2, arg3)
250 char *text;
251 M_WCHAR *arg1, *arg2, *arg3 ;
252 #endif
253 {
254 char *mb_arg1, *mb_arg2, *mb_arg3;
255
256 mb_arg1 = MakeMByteString(arg1);
257 mb_arg2 = MakeMByteString(arg2);
258 mb_arg3 = MakeMByteString(arg3);
259 eprefix(TRUE) ;
260 fprintf(stderr, text, mb_arg1, mb_arg2, mb_arg3) ;
261 fprintf(m_errfile, text, mb_arg1, mb_arg2, mb_arg3) ;
262 esuffix() ;
263 skiptoend() ;
264 m_free(mb_arg1,"multi-byte string");
265 m_free(mb_arg2,"multi-byte string");
266 m_free(mb_arg3,"multi-byte string");
267 }
268
269 /* Writes an error message with five arguments to standard error and file
270    "error" */
271 #if defined(M_PROTO)
272 void m_err5( char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3,
273              M_WCHAR *arg4, M_WCHAR *arg5)
274 #else
275 void m_err5(text, arg1, arg2, arg3, arg4, arg5)
276 char *text;
277 M_WCHAR *arg1, *arg2, *arg3, *arg4, *arg5 ;
278 #endif
279 {
280 char *mb_arg1, *mb_arg2, *mb_arg3, *mb_arg4, *mb_arg5;
281
282 mb_arg1 = MakeMByteString(arg1);
283 mb_arg2 = MakeMByteString(arg2);
284 mb_arg3 = MakeMByteString(arg3);
285 mb_arg4 = MakeMByteString(arg4);
286 mb_arg5 = MakeMByteString(arg5);
287 fprintf(stderr, text, mb_arg1, mb_arg2, mb_arg3, mb_arg4, mb_arg5) ;
288 fprintf(m_errfile, text, mb_arg1, mb_arg2, mb_arg3, mb_arg4, mb_arg5) ;
289 esuffix() ;
290 skiptoend() ;
291 m_free(mb_arg1,"multi-byte string");
292 m_free(mb_arg2,"multi-byte string");
293 m_free(mb_arg3,"multi-byte string");
294 m_free(mb_arg4,"multi-byte string");
295 m_free(mb_arg5,"multi-byte string");
296 }
297
298 /* Write error message suffix */
299 void esuffix(M_NOPAR)
300   {
301     fprintf(stderr, " (line %d) ****\n", m_line) ;
302     fprintf(m_errfile, " (line %d) ****\n", m_line) ;
303     }
304
305 /* Print something to both stderr and m_errfile */
306 void msgline(text)
307   char *text ;
308   {
309     fprintf(stderr, text) ;
310     fprintf(m_errfile, text) ;
311     }
312
313 /* Print something to both stderr and m_errfile */
314 void msg1line(text, arg1)
315   char *text, *arg1 ;
316   {
317     fprintf(stderr, text, arg1) ;
318     fprintf(m_errfile, text, arg1) ;
319     }
320
321 /* Trace used for m_malloc trace output */
322 void m_trace(text)
323 char *text ;
324 {
325 m_errline(text) ;
326 }
327
328 void m_wctrace(text)
329 M_WCHAR *text ;
330 {
331 char *mb_text;
332
333 mb_text = MakeMByteString(text);
334 m_trace(mb_text);
335 m_free(mb_text,"multi-byte string");
336 }
337
338 /* Writes a nonfatal error message to standard error and file "error" */
339 void warning(text)
340   char *text ;
341   {
342     eprefix(FALSE) ;
343     fprintf(stderr,"%s", text) ;
344     fprintf(m_errfile,"%s", text) ;
345     esuffix() ;
346   }
347
348 /* Writes a nonfatal error message with one argument to standard error
349    and file "error" */
350 #if defined(M_PROTO)
351 void warning1( char *text, M_WCHAR *arg)
352 #else
353 void warning1(text, arg)
354 char *text;
355 M_WCHAR *arg ;
356 #endif
357 {
358 char *mb_arg;
359
360 mb_arg = MakeMByteString(arg);
361 eprefix(FALSE) ;
362 fprintf(stderr, text, mb_arg) ;
363 fprintf(m_errfile, text, mb_arg) ;
364 esuffix() ;
365 m_free(mb_arg,"multi-byte string");
366 }
367
368 /* Writes a nonfatal error message with two arguments to standard error
369    and file "error" */
370 #if defined(M_PROTO)
371 void warning2(char *text, M_WCHAR *arg1, M_WCHAR *arg2)
372 #else
373 void warning2(text, arg1, arg2)
374 char *text;
375 M_WCHAR *arg1, *arg2 ;
376 #endif
377 {
378 char *mb_arg1, *mb_arg2;
379
380 mb_arg1 = MakeMByteString(arg1);
381 mb_arg2 = MakeMByteString(arg2);
382 eprefix(FALSE) ;
383 fprintf(stderr, text, mb_arg1, mb_arg2) ;
384 fprintf(m_errfile, text, mb_arg1, mb_arg2) ;
385 esuffix() ;
386 m_free(mb_arg1,"multi-byte string");
387 m_free(mb_arg2,"multi-byte string");
388 }
389
390 /* Writes a nonfatal error message with three arguments to standard error
391    and file "error" */
392 #if defined(M_PROTO)
393 void warning3(char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3)
394 #else
395 void warning3(text, arg1, arg2, arg3)
396 char *text;
397 M_WCHAR *arg1, *arg2, *arg3 ;
398 #endif
399 {
400 char *mb_arg1, *mb_arg2, *mb_arg3;
401
402 mb_arg1 = MakeMByteString(arg1);
403 mb_arg2 = MakeMByteString(arg2);
404 mb_arg3 = MakeMByteString(arg3);
405 eprefix(FALSE) ;
406 fprintf(stderr, text, mb_arg1, mb_arg2, mb_arg3) ;
407 fprintf(m_errfile, text, mb_arg1, mb_arg2, mb_arg3) ;
408 esuffix() ;
409 m_free(mb_arg1,"multi-byte string");
410 m_free(mb_arg2,"multi-byte string");
411 m_free(mb_arg3,"multi-byte string");
412 }
413
414 /* Writes a nonfatal error message with four arguments to standard error
415    and file "error" */
416 #if defined(M_PROTO)
417 void warning4(char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3,
418               M_WCHAR *arg4)
419 #else
420 void warning4(text, arg1, arg2, arg3, arg4)
421 char *text;
422 M_WCHAR *arg1, *arg2, *arg3, *arg4 ;
423 #endif
424 {
425 char *mb_arg1, *mb_arg2, *mb_arg3, *mb_arg4;
426
427 mb_arg1 = MakeMByteString(arg1);
428 mb_arg2 = MakeMByteString(arg2);
429 mb_arg3 = MakeMByteString(arg3);
430 mb_arg4 = MakeMByteString(arg4);
431 eprefix(FALSE) ;
432 fprintf(stderr, text, mb_arg1, mb_arg2, mb_arg3, mb_arg4) ;
433 fprintf(m_errfile, text, mb_arg1, mb_arg2, mb_arg3, mb_arg4) ;
434 esuffix() ;
435 m_free(mb_arg1,"multi-byte string");
436 m_free(mb_arg2,"multi-byte string");
437 m_free(mb_arg3,"multi-byte string");
438 m_free(mb_arg4,"multi-byte string");
439 }