error.c - scc - simple c99 compiler
HTML git clone git://git.simple-cc.org/scc
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
error.c (1195B)
---
1 #include <stdarg.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 #include <scc/cstd.h>
6 #include <scc/scc.h>
7
8 #include "cc1.h"
9
10 #define MAXERRNUM 10
11
12 extern int failure;
13 static unsigned nerrors;
14
15 static void
16 warn_error(int flag, char *fmt, va_list va)
17 {
18 if (flag == 0)
19 return;
20 fprintf(stderr, "%s:%u: %s: ",
21 filenam, lineno,
22 (flag < 0) ? "error" : "warning");
23 vfprintf(stderr, fmt, va);
24 putc('\n', stderr);
25
26 if (flag < 0) {
27 if (!failure)
28 fclose(stdout);
29 failure = 1;
30 if (++nerrors == MAXERRNUM) {
31 fputs("too many errors\n", stderr);
32 exit(1);
33 }
34 }
35 }
36
37 void
38 warn(char *fmt, ...)
39 {
40 extern int warnings;
41
42 va_list va;
43 va_start(va, fmt);
44 warn_error(warnings, fmt, va);
45 va_end(va);
46 }
47
48 void
49 error(char *fmt, ...)
50 {
51 va_list va;
52
53 va_start(va, fmt);
54 warn_error(-1, fmt, va);
55 va_end(va);
56 discard();
57 }
58
59 void
60 errorp(char *fmt, ...)
61 {
62 va_list va;
63 va_start(va, fmt);
64 warn_error(-1, fmt, va);
65 va_end(va);
66 }
67
68 void
69 cpperror(char *fmt, ...)
70 {
71 va_list va;
72 va_start(va, fmt);
73 warn_error(-1, fmt, va);
74 va_end(va);
75
76 /* discard input until the end of the line */
77 if (input)
78 *input->p = '\0';
79 next();
80 }
81
82 void
83 unexpected(void)
84 {
85 error("unexpected '%s'", yytext);
86 }