xref: /trueos/usr.bin/migcom/error.c (revision a567dc5a34c609044a1c02b08e01dc67a19b121e)
1 /*
2  * Copyright 1991-1998 by Open Software Foundation, Inc.
3  *              All Rights Reserved
4  *
5  * Permission to use, copy, modify, and distribute this software and
6  * its documentation for any purpose and without fee is hereby granted,
7  * provided that the above copyright notice appears in all copies and
8  * that both the copyright notice and this permission notice appear in
9  * supporting documentation.
10  *
11  * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
12  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13  * FOR A PARTICULAR PURPOSE.
14  *
15  * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
16  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17  * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
18  * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
19  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  */
21 /*
22  * cmk1.1
23  */
24 /*
25  * Mach Operating System
26  * Copyright (c) 1991,1990 Carnegie Mellon University
27  * All Rights Reserved.
28  *
29  * Permission to use, copy, modify and distribute this software and its
30  * documentation is hereby granted, provided that both the copyright
31  * notice and this permission notice appear in all copies of the
32  * software, derivative works or modified versions, and any portions
33  * thereof, and that both notices appear in supporting documentation.
34  *
35  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
36  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
37  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
38  *
39  * Carnegie Mellon requests users of this software to return to
40  *
41  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
42  *  School of Computer Science
43  *  Carnegie Mellon University
44  *  Pittsburgh PA 15213-3890
45  *
46  * any improvements or extensions that they make and grant Carnegie the
47  * rights to redistribute these changes.
48  */
49 /*
50  * 91/02/05  17:54:11  mrt
51  * 	Changed to new Mach copyright
52  * 	[91/02/01  17:53:53  mrt]
53  *
54  * 90/06/02  15:04:25  rpd
55  * 	Created for new IPC.
56  * 	[90/03/26  21:10:17  rpd]
57  *
58  * 07-Apr-89  Richard Draves (rpd) at Carnegie-Mellon University
59  *	Extensive revamping.  Added polymorphic arguments.
60  *	Allow multiple variable-sized inline arguments in messages.
61  *
62  * 28-May-87  Richard Draves (rpd) at Carnegie-Mellon University
63  *	Created.
64  */
65 
66 #include <stdio.h>
67 #include <stdlib.h>
68 #include <stdarg.h>
69 #include "global.h"
70 #include "error.h"
71 
72 extern int lineno;
73 extern const char *yyinname;
74 
75 static const char *program;
76 int errors = 0;
77 
78 /*ARGSUSED*/
79 /*VARARGS1*/
80 void
fatal(const char * format,...)81 fatal(const char *format, ...)
82 {
83     va_list pvar;
84     va_start(pvar, format);
85     fprintf(stderr, "%s: fatal: \"%s\", line %d: ", program, yyinname, lineno-1);
86     (void) vfprintf(stderr, format, pvar);
87     fprintf(stderr, "\n");
88     va_end(pvar);
89     exit(1);
90 }
91 
92 /*ARGSUSED*/
93 /*VARARGS1*/
94 void
warn(const char * format,...)95 warn(const char *format, ...)
96 {
97     va_list pvar;
98     va_start(pvar, format);
99     if (!BeQuiet && (errors == 0))
100     {
101 	fprintf(stderr, "\"%s\", line %d: warning: ", yyinname, lineno-1);
102 	(void) vfprintf(stderr, format, pvar);
103 	fprintf(stderr, "\n");
104     }
105     va_end(pvar);
106 }
107 
108 /*ARGSUSED*/
109 /*VARARGS1*/
110 void
error(const char * format,...)111 error(const char *format, ...)
112 {
113     va_list pvar;
114     va_start(pvar, format);
115     fprintf(stderr, "\"%s\", line %d: ", yyinname, lineno-1);
116     (void) vfprintf(stderr, format, pvar);
117     fprintf(stderr, "\n");
118     va_end(pvar);
119     errors++;
120 }
121 
122 void
set_program_name(const char * name)123 set_program_name(const char *name)
124 {
125     program = name;
126 }
127