Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / lint / lpass2 / report.c
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  */
5 /* $Id: report.c,v 1.10 1995/08/17 15:01:56 ceriel Exp $ */
6
7 #if __STDC__
8 #include        <stdarg.h>
9 extern panic(char *, ...);
10 #else
11 #include        <varargs.h>
12 #endif
13
14 #include        <system.h>
15 #include        "private.h"
16 #include        "l_class.h"
17 #include        "class.h"
18 #include        "inpdef.h"
19
20 #define MSGOUT          STDERR  /* file descr. on which to write the messages */
21 #define ERROUT          STDERR  /* file descr. on which to write the panics */
22
23 extern int LineNr;
24
25 PRIVATE rep_loc();
26
27 #if __STDC__
28 /* VARARGS */
29 report(char *fmt, ...)
30 {
31         va_list ap;
32
33         va_start(ap, fmt);
34         {
35 #else
36 /* VARARGS */
37 report(va_alist)
38         va_dcl
39 {
40         va_list ap;
41
42         va_start(ap);
43         {
44                 char *fmt = va_arg(ap, char*);
45 #endif
46                 register char *f = fmt;
47                 register char fc;
48
49                 /*      First see if the first arg is an inpdef with
50                         a global file name not ending in .c; if so,
51                         skip this message.
52                 */
53                 if (f[0] == '%' && f[1] == 'L') {
54                         /* it is an inpdef */
55                         register struct inpdef *id =
56                                 va_arg(ap, struct inpdef *);
57                         register char *fn = id->id_file;
58
59                         f += 2;
60                         
61                         if (    /* the file name global */
62                                 fn[0] == '/'
63                         &&      /* it is not a .c file */
64                                 strcmp(&fn[strlen(fn)-2], ".c") != 0
65                         ) {
66                                 /* we skip this message */
67                                 return;
68                         }
69                         /*      otherwise, we have used up the argument,
70                                 so print it here
71                         */
72                         fprint(MSGOUT, "\"%s\", line %d",
73                                 fn, id->id_line);
74                 }
75                 while ((fc = *f++)) {
76                         if (fc == '%') {
77                                 switch (*f++) {
78                                         register struct inpdef *id;
79                                         register char *s;
80                                         register int i;
81                                 case 'L':       /* a location item */
82                                         id = va_arg(ap, struct inpdef *);
83                                         rep_loc(id);
84                                         break;
85                                 case 's':       /* a string item */
86                                         s = va_arg(ap, char *);
87                                         fprint(MSGOUT, "%s", s);
88                                         break;
89                                 case 'd':       /* an int item */
90                                         i = va_arg(ap, int);
91                                         fprint(MSGOUT, "%d", i);
92                                         break;
93                                 default:
94                                         panic("internal error: bad format %s",
95                                                 fmt);
96                                         break;
97                                 }
98                         }
99                         else {
100                                 fprint(MSGOUT, "%c", fc);
101                         }
102                 }
103                 fprint(MSGOUT, "\n");
104         }
105         va_end(ap);
106 }
107
108 PRIVATE
109 rep_loc(id)
110         struct inpdef *id;
111 {
112         /* a definition can come from a number of places */
113         if (!id) {
114                 fprint(MSGOUT, "format");
115         }
116         else
117         if (is_class(id, CL_LIB)) {
118                 fprint(MSGOUT, "library");
119         }
120         else {
121                 fprint(MSGOUT, "\"%s\", line %d",
122                         id->id_file, id->id_line);
123         }
124 }
125
126 #if __STDC__
127 /* VARARGS */
128 panic(char *fmt, ...)                           /* fmt, args */
129 {
130         va_list ap;
131
132         va_start(ap, fmt);
133         {
134                 fprint(ERROUT, "PANIC, lint, pass2: line %d: ", LineNr);
135                 doprnt(ERROUT, fmt, ap);
136                 fprint(ERROUT, "\n");
137         }
138         va_end(ap);
139
140         exit(1);
141 }
142 #else
143 /* VARARGS */
144 panic(va_alist)                         /* fmt, args */
145         va_dcl
146 {
147         va_list ap;
148
149         va_start(ap);
150         {
151                 char *fmt = va_arg(ap, char *);
152
153                 fprint(ERROUT, "PANIC, lint, pass2: line %d: ", LineNr);
154                 doprnt(ERROUT, fmt, ap);
155                 fprint(ERROUT, "\n");
156         }
157         va_end(ap);
158
159         exit(1);
160 }
161 #endif