1 /*
2  * (c) Thomas Pornin 1999 - 2002
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  * 4. The name of the authors may not be used to endorse or promote
13  *    products derived from this software without specific prior written
14  *    permission.
15  *
16  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
22  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 #ifndef UCPP__REENT__
31 #define UCPP__REENT__
32 
33 #include "tune.h"
34 
35 #ifdef UCPP_REENTRANT
36 
37 #include "nhash.h"
38 
39 #define pCPP	struct CPP *REENTR
40 #define pCPP_	pCPP,
41 #define aCPP	REENTR
42 #define aCPP_	aCPP,
43 
44 #define useCPP	(void) aCPP
45 
46 typedef struct _cppm *CPPM;
47 
48 struct CPP {
49 	int	no_special_macros,
50 		emit_dependencies,
51 		emit_defines,
52 		emit_assertions;
53 	int	c99_compliant,
54 		c99_hosted;
55 	FILE	*emit_output;
56 	char	*current_filename,
57 		*current_long_filename;
58 
59 	/*
60 	 * Can be used to store an arbitrary pointer value
61 	 * that can be retrieved by the callback functions
62 	 * ucpp_(ouch|error|warning).
63 	 */
64 	void	*callback_arg;
65 
66 	void	(*ucpp_ouch)(pCPP_ char *, ...);
67 	void	(*ucpp_error)(pCPP_ long, char *, ...);
68 	void	(*ucpp_warning)(pCPP_ long, char *, ...);
69 
70 	int	*transient_characters;
71 
72 	struct protect {
73 		char *macro;
74 		int state;
75 		struct found_file *ff;
76 	}	protect_detect;
77 
78 	struct {
79 
80 	/* from macro.c */
81 		struct lexer_state dsharp_lexer;
82 		char compile_time[12], compile_date[24];
83 #ifdef PRAGMA_TOKENIZE
84 		struct lexer_state tokenize_lexer;
85 #endif
86 
87 	/* from eval.c */
88 		long eval_line;
89 		JMP_BUF eval_exception;
90 
91 	}	_global;
92 
93 	struct {
94 		HTT assertions;
95 		int assertions_init_done;
96 	}	_assert;
97 
98 	struct {
99 		HTT macros;
100 		int macros_init_done;
101 	}	_macro;
102 
103 	struct {
104 		char **include_path;
105 		size_t include_path_nb;
106 		int current_incdir;
107 		struct file_context *ls_stack;
108 		size_t ls_depth;
109 		int find_file_error;
110 		struct protect *protect_detect_stack;
111 		HTT found_files;
112 		HTT found_files_sys;
113 		int found_files_init_done;
114 		int found_files_sys_init_done;
115 	}	_cpp;
116 
117 	struct {
118 		int emit_eval_warnings;
119 	}	_eval;
120 
121 	struct {
122 		CPPM sm;
123 	}	_lexer;
124 };
125 
126 #else
127 
128 #define pCPP	void
129 #define pCPP_
130 #define aCPP
131 #define aCPP_
132 
133 #define useCPP	(void) 0
134 
135 #endif
136 
137 #endif
138