annotate lwcc/cpp/error.c @ 292:40ecbd5da481 ccdev

Part one of the C preprocessor This is part one of the C preprocessor. It finds and then fails to intepret directives. Also handles line splicing and trigraphs.
author William Astle <lost@l-w.ca>
date Sun, 08 Sep 2013 21:58:12 -0600
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
292
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
1 /*
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
2 lwcc/cpp/error.c
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
3
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
4 Copyright © 2013 William Astle
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
5
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
6 This file is part of LWTOOLS.
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
7
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
11 version.
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
12
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
16 more details.
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
17
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
20 */
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
21
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
22 #include <stdarg.h>
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
23 #include <stdio.h>
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
24 #include <stdlib.h>
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
25
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
26 #include "cpp.h"
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
27
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
28 static void show_file_pos(void)
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
29 {
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
30 if (file_stack == NULL)
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
31 return;
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
32
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
33 fprintf(stderr, "(%s:%d): ", file_stack -> fn, file_stack -> line);
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
34 }
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
35
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
36 void do_error(const char *f, ...)
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
37 {
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
38 va_list arg;
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
39
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
40 va_start(arg, f);
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
41 fprintf(stderr, "ERROR: ");
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
42 show_file_pos();
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
43 vfprintf(stderr, f, arg);
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
44 fprintf(stderr, "\n");
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
45 va_end(arg);
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
46 exit(1);
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
47 }
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
48
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
49 void do_warning(const char *f, ...)
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
50 {
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
51 va_list arg;
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
52
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
53 va_start(arg, f);
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
54 fprintf(stderr, "WARNING: ");
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
55 show_file_pos();
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
56 vfprintf(stderr, f, arg);
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
57 fprintf(stderr, "\n");
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
58 va_end(arg);
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
59 }