annotate lwcc/cpp/cpp.h @ 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 c419b3b3d43f
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/cpp.h
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 #ifndef cpp_h_seen___
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
23 #define cpp_h_seen___
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
24
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
25 #include <stdio.h>
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
26
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
27 enum
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
28 {
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
29 CPP_NOUNG = -3,
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
30 CPP_EOL = -2,
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
31 CPP_EOF = -1,
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
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
34 struct file_stack_e
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 const char *fn;
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
37 FILE *fp;
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
38 struct file_stack_e *next;
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
39 int line;
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
40 int col;
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
41 int eolstate; // end of line state for interpreting \r\n \n\r \n \r
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
42 int ra; // read ahead byte for trigraph scan
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
43 int qseen; // number of ? seen during trigraph scan
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
44 int unget; // character that has been "ungot"
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
45 int curc; // the most recent character retrieved
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
46 };
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 extern FILE *output_fp;
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
49 extern int trigraphs;
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
50 extern struct file_stack_e *file_stack;
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
51
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
52 extern int process_file(const char *);
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
53
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
54 extern void do_error(const char *, ...);
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
55 extern void do_warning(const char *, ...);
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
56
40ecbd5da481 Part one of the C preprocessor
William Astle <lost@l-w.ca>
parents:
diff changeset
57 #endif // cpp_h_seen___