1 /* Id: error.c,v 1.8 2008/05/10 07:53:41 ragge Exp */
2 /* $NetBSD: error.c,v 1.1.1.2 2010/06/03 18:57:46 plunky Exp $ */
3 /*
4 * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code and documentation must retain the above
11 * copyright notice, this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed or owned by Caldera
18 * International, Inc.
19 * Neither the name of Caldera International, Inc. nor the names of other
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
24 * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
28 * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
32 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
33 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37 #include <stdarg.h>
38
39 #include "defines.h"
40 #include "defs.h"
41
42 void
warn(char * s,...)43 warn(char *s, ...)
44 {
45 va_list ap;
46
47 if(nowarnflag)
48 return;
49
50 va_start(ap, s);
51 fprintf(diagfile, "Warning on line %d of %s: ", lineno, infname);
52 vfprintf(diagfile, s, ap);
53 fprintf(diagfile, "\n");
54 va_end(ap);
55 ++nwarn;
56 }
57
58 void
err(char * s,...)59 err(char *s, ...)
60 {
61 va_list ap;
62
63 va_start(ap, s);
64 fprintf(diagfile, "Error on line %d of %s: ", lineno, infname);
65 vfprintf(diagfile, s, ap);
66 fprintf(diagfile, "\n");
67 va_end(ap);
68 ++nerr;
69 }
70
71 void
yyerror(s)72 yyerror(s)
73 char *s;
74 { err(s); }
75
76
77 void
dclerr(s,v)78 dclerr(s, v)
79 char *s;
80 struct bigblock *v;
81 {
82 char buff[100];
83
84 if(v) {
85 sprintf(buff, "Declaration error for %s: %s",
86 varstr(VL, v->b_name.varname), s);
87 err( buff);
88 } else
89 err1("Declaration error %s", s);
90 }
91
92
93 void
execerr(char * s,...)94 execerr(char *s, ...)
95 {
96 va_list ap;
97
98 va_start(ap, s);
99 fprintf(diagfile, "Error on line %d of %s: Execution error ",
100 lineno, infname);
101 vfprintf(diagfile, s, ap);
102 fprintf(diagfile, "\n");
103 va_end(ap);
104 ++nerr;
105 }
106
107 void
fatal(char * s,...)108 fatal(char *s, ...)
109 {
110 va_list ap;
111
112 va_start(ap, s);
113 fprintf(diagfile, "Compiler error line %d of %s: ", lineno, infname);
114 vfprintf(diagfile, s, ap);
115 fprintf(diagfile, "\n");
116 va_end(ap);
117
118 if(debugflag)
119 abort();
120 done(3);
121 exit(3);
122 }
123