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