1*c87b03e5Sespie /* Preprocess only, using cpplib.
2*c87b03e5Sespie Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3*c87b03e5Sespie Free Software Foundation, Inc.
4*c87b03e5Sespie Written by Per Bothner, 1994-95.
5*c87b03e5Sespie
6*c87b03e5Sespie This program is free software; you can redistribute it and/or modify it
7*c87b03e5Sespie under the terms of the GNU General Public License as published by the
8*c87b03e5Sespie Free Software Foundation; either version 2, or (at your option) any
9*c87b03e5Sespie later version.
10*c87b03e5Sespie
11*c87b03e5Sespie This program is distributed in the hope that it will be useful,
12*c87b03e5Sespie but WITHOUT ANY WARRANTY; without even the implied warranty of
13*c87b03e5Sespie MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*c87b03e5Sespie GNU General Public License for more details.
15*c87b03e5Sespie
16*c87b03e5Sespie You should have received a copy of the GNU General Public License
17*c87b03e5Sespie along with this program; if not, write to the Free Software
18*c87b03e5Sespie Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19*c87b03e5Sespie
20*c87b03e5Sespie In other words, you are welcome to use, share and improve this program.
21*c87b03e5Sespie You are forbidden to forbid anyone else to use, share and improve
22*c87b03e5Sespie what you give them. Help stamp out software-hoarding! */
23*c87b03e5Sespie
24*c87b03e5Sespie #include "config.h"
25*c87b03e5Sespie #include "system.h"
26*c87b03e5Sespie #include "cpplib.h"
27*c87b03e5Sespie #include "cpphash.h"
28*c87b03e5Sespie
29*c87b03e5Sespie static void setup_callbacks PARAMS ((cpp_reader *));
30*c87b03e5Sespie
31*c87b03e5Sespie /* General output routines. */
32*c87b03e5Sespie static void scan_translation_unit PARAMS ((cpp_reader *));
33*c87b03e5Sespie static void scan_translation_unit_trad PARAMS ((cpp_reader *));
34*c87b03e5Sespie static void account_for_newlines PARAMS ((cpp_reader *, const uchar *,
35*c87b03e5Sespie size_t));
36*c87b03e5Sespie static int dump_macro PARAMS ((cpp_reader *, cpp_hashnode *, void *));
37*c87b03e5Sespie
38*c87b03e5Sespie static void print_line PARAMS ((cpp_reader *, const struct line_map *,
39*c87b03e5Sespie unsigned int, const char *));
40*c87b03e5Sespie static void maybe_print_line PARAMS ((cpp_reader *, const struct line_map *,
41*c87b03e5Sespie unsigned int));
42*c87b03e5Sespie
43*c87b03e5Sespie /* Callback routines for the parser. Most of these are active only
44*c87b03e5Sespie in specific modes. */
45*c87b03e5Sespie static void cb_line_change PARAMS ((cpp_reader *, const cpp_token *, int));
46*c87b03e5Sespie static void cb_define PARAMS ((cpp_reader *, unsigned int, cpp_hashnode *));
47*c87b03e5Sespie static void cb_undef PARAMS ((cpp_reader *, unsigned int, cpp_hashnode *));
48*c87b03e5Sespie static void cb_include PARAMS ((cpp_reader *, unsigned int,
49*c87b03e5Sespie const unsigned char *, const cpp_token *));
50*c87b03e5Sespie static void cb_ident PARAMS ((cpp_reader *, unsigned int,
51*c87b03e5Sespie const cpp_string *));
52*c87b03e5Sespie static void cb_file_change PARAMS ((cpp_reader *, const struct line_map *));
53*c87b03e5Sespie static void cb_def_pragma PARAMS ((cpp_reader *, unsigned int));
54*c87b03e5Sespie
55*c87b03e5Sespie /* Preprocess and output. */
56*c87b03e5Sespie void
cpp_preprocess_file(pfile,in_fname,out_stream)57*c87b03e5Sespie cpp_preprocess_file (pfile, in_fname, out_stream)
58*c87b03e5Sespie cpp_reader *pfile;
59*c87b03e5Sespie const char *in_fname;
60*c87b03e5Sespie FILE *out_stream;
61*c87b03e5Sespie {
62*c87b03e5Sespie /* Initialize the printer structure. Setting print.line to -1 here
63*c87b03e5Sespie is a trick to guarantee that the first token of the file will
64*c87b03e5Sespie cause a linemarker to be output by maybe_print_line. */
65*c87b03e5Sespie pfile->print.line = (unsigned int) -1;
66*c87b03e5Sespie pfile->print.printed = 0;
67*c87b03e5Sespie pfile->print.prev = 0;
68*c87b03e5Sespie pfile->print.map = 0;
69*c87b03e5Sespie pfile->print.outf = out_stream;
70*c87b03e5Sespie
71*c87b03e5Sespie setup_callbacks (pfile);
72*c87b03e5Sespie
73*c87b03e5Sespie if (cpp_read_main_file (pfile, in_fname, NULL))
74*c87b03e5Sespie {
75*c87b03e5Sespie cpp_options *options = &pfile->opts;
76*c87b03e5Sespie cpp_finish_options (pfile);
77*c87b03e5Sespie
78*c87b03e5Sespie /* A successful cpp_read_main_file guarantees that we can call
79*c87b03e5Sespie cpp_scan_nooutput or cpp_get_token next. */
80*c87b03e5Sespie if (options->no_output)
81*c87b03e5Sespie {
82*c87b03e5Sespie /* Scan -included buffers, then the main file. */
83*c87b03e5Sespie while (pfile->buffer->prev)
84*c87b03e5Sespie cpp_scan_nooutput (pfile);
85*c87b03e5Sespie cpp_scan_nooutput (pfile);
86*c87b03e5Sespie }
87*c87b03e5Sespie else if (options->traditional)
88*c87b03e5Sespie scan_translation_unit_trad (pfile);
89*c87b03e5Sespie else
90*c87b03e5Sespie scan_translation_unit (pfile);
91*c87b03e5Sespie
92*c87b03e5Sespie /* -dM command line option. Should this be in cpp_finish? */
93*c87b03e5Sespie if (options->dump_macros == dump_only)
94*c87b03e5Sespie cpp_forall_identifiers (pfile, dump_macro, NULL);
95*c87b03e5Sespie }
96*c87b03e5Sespie
97*c87b03e5Sespie /* Flush any pending output. */
98*c87b03e5Sespie if (pfile->print.printed)
99*c87b03e5Sespie putc ('\n', pfile->print.outf);
100*c87b03e5Sespie }
101*c87b03e5Sespie
102*c87b03e5Sespie /* Set up the callbacks as appropriate. */
103*c87b03e5Sespie static void
setup_callbacks(pfile)104*c87b03e5Sespie setup_callbacks (pfile)
105*c87b03e5Sespie cpp_reader *pfile;
106*c87b03e5Sespie {
107*c87b03e5Sespie cpp_options *options = &pfile->opts;
108*c87b03e5Sespie cpp_callbacks *cb = cpp_get_callbacks (pfile);
109*c87b03e5Sespie
110*c87b03e5Sespie if (! options->no_output)
111*c87b03e5Sespie {
112*c87b03e5Sespie cb->line_change = cb_line_change;
113*c87b03e5Sespie /* Don't emit #pragma or #ident directives if we are processing
114*c87b03e5Sespie assembly language; the assembler may choke on them. */
115*c87b03e5Sespie if (options->lang != CLK_ASM)
116*c87b03e5Sespie {
117*c87b03e5Sespie cb->ident = cb_ident;
118*c87b03e5Sespie cb->def_pragma = cb_def_pragma;
119*c87b03e5Sespie }
120*c87b03e5Sespie if (! options->no_line_commands)
121*c87b03e5Sespie cb->file_change = cb_file_change;
122*c87b03e5Sespie }
123*c87b03e5Sespie
124*c87b03e5Sespie if (options->dump_includes)
125*c87b03e5Sespie cb->include = cb_include;
126*c87b03e5Sespie
127*c87b03e5Sespie if (options->dump_macros == dump_names
128*c87b03e5Sespie || options->dump_macros == dump_definitions)
129*c87b03e5Sespie {
130*c87b03e5Sespie cb->define = cb_define;
131*c87b03e5Sespie cb->undef = cb_undef;
132*c87b03e5Sespie }
133*c87b03e5Sespie }
134*c87b03e5Sespie
135*c87b03e5Sespie /* Writes out the preprocessed file, handling spacing and paste
136*c87b03e5Sespie avoidance issues. */
137*c87b03e5Sespie static void
scan_translation_unit(pfile)138*c87b03e5Sespie scan_translation_unit (pfile)
139*c87b03e5Sespie cpp_reader *pfile;
140*c87b03e5Sespie {
141*c87b03e5Sespie bool avoid_paste = false;
142*c87b03e5Sespie
143*c87b03e5Sespie pfile->print.source = NULL;
144*c87b03e5Sespie for (;;)
145*c87b03e5Sespie {
146*c87b03e5Sespie const cpp_token *token = cpp_get_token (pfile);
147*c87b03e5Sespie
148*c87b03e5Sespie if (token->type == CPP_PADDING)
149*c87b03e5Sespie {
150*c87b03e5Sespie avoid_paste = true;
151*c87b03e5Sespie if (pfile->print.source == NULL
152*c87b03e5Sespie || (!(pfile->print.source->flags & PREV_WHITE)
153*c87b03e5Sespie && token->val.source == NULL))
154*c87b03e5Sespie pfile->print.source = token->val.source;
155*c87b03e5Sespie continue;
156*c87b03e5Sespie }
157*c87b03e5Sespie
158*c87b03e5Sespie if (token->type == CPP_EOF)
159*c87b03e5Sespie break;
160*c87b03e5Sespie
161*c87b03e5Sespie /* Subtle logic to output a space if and only if necessary. */
162*c87b03e5Sespie if (avoid_paste)
163*c87b03e5Sespie {
164*c87b03e5Sespie if (pfile->print.source == NULL)
165*c87b03e5Sespie pfile->print.source = token;
166*c87b03e5Sespie if (pfile->print.source->flags & PREV_WHITE
167*c87b03e5Sespie || (pfile->print.prev
168*c87b03e5Sespie && cpp_avoid_paste (pfile, pfile->print.prev, token))
169*c87b03e5Sespie || (pfile->print.prev == NULL && token->type == CPP_HASH))
170*c87b03e5Sespie putc (' ', pfile->print.outf);
171*c87b03e5Sespie }
172*c87b03e5Sespie else if (token->flags & PREV_WHITE)
173*c87b03e5Sespie putc (' ', pfile->print.outf);
174*c87b03e5Sespie
175*c87b03e5Sespie avoid_paste = false;
176*c87b03e5Sespie pfile->print.source = NULL;
177*c87b03e5Sespie pfile->print.prev = token;
178*c87b03e5Sespie cpp_output_token (token, pfile->print.outf);
179*c87b03e5Sespie
180*c87b03e5Sespie if (token->type == CPP_COMMENT)
181*c87b03e5Sespie account_for_newlines (pfile, token->val.str.text, token->val.str.len);
182*c87b03e5Sespie }
183*c87b03e5Sespie }
184*c87b03e5Sespie
185*c87b03e5Sespie /* Adjust pfile->print.line for newlines embedded in output. */
186*c87b03e5Sespie static void
account_for_newlines(pfile,str,len)187*c87b03e5Sespie account_for_newlines (pfile, str, len)
188*c87b03e5Sespie cpp_reader *pfile;
189*c87b03e5Sespie const uchar *str;
190*c87b03e5Sespie size_t len;
191*c87b03e5Sespie {
192*c87b03e5Sespie while (len--)
193*c87b03e5Sespie if (*str++ == '\n')
194*c87b03e5Sespie pfile->print.line++;
195*c87b03e5Sespie }
196*c87b03e5Sespie
197*c87b03e5Sespie /* Writes out a traditionally preprocessed file. */
198*c87b03e5Sespie static void
scan_translation_unit_trad(pfile)199*c87b03e5Sespie scan_translation_unit_trad (pfile)
200*c87b03e5Sespie cpp_reader *pfile;
201*c87b03e5Sespie {
202*c87b03e5Sespie while (_cpp_read_logical_line_trad (pfile))
203*c87b03e5Sespie {
204*c87b03e5Sespie size_t len = pfile->out.cur - pfile->out.base;
205*c87b03e5Sespie maybe_print_line (pfile, pfile->print.map, pfile->out.first_line);
206*c87b03e5Sespie fwrite (pfile->out.base, 1, len, pfile->print.outf);
207*c87b03e5Sespie pfile->print.printed = 1;
208*c87b03e5Sespie if (!CPP_OPTION (pfile, discard_comments))
209*c87b03e5Sespie account_for_newlines (pfile, pfile->out.base, len);
210*c87b03e5Sespie }
211*c87b03e5Sespie }
212*c87b03e5Sespie
213*c87b03e5Sespie /* If the token read on logical line LINE needs to be output on a
214*c87b03e5Sespie different line to the current one, output the required newlines or
215*c87b03e5Sespie a line marker, and return 1. Otherwise return 0. */
216*c87b03e5Sespie static void
maybe_print_line(pfile,map,line)217*c87b03e5Sespie maybe_print_line (pfile, map, line)
218*c87b03e5Sespie cpp_reader *pfile;
219*c87b03e5Sespie const struct line_map *map;
220*c87b03e5Sespie unsigned int line;
221*c87b03e5Sespie {
222*c87b03e5Sespie /* End the previous line of text. */
223*c87b03e5Sespie if (pfile->print.printed)
224*c87b03e5Sespie {
225*c87b03e5Sespie putc ('\n', pfile->print.outf);
226*c87b03e5Sespie pfile->print.line++;
227*c87b03e5Sespie pfile->print.printed = 0;
228*c87b03e5Sespie }
229*c87b03e5Sespie
230*c87b03e5Sespie if (line >= pfile->print.line && line < pfile->print.line + 8)
231*c87b03e5Sespie {
232*c87b03e5Sespie while (line > pfile->print.line)
233*c87b03e5Sespie {
234*c87b03e5Sespie putc ('\n', pfile->print.outf);
235*c87b03e5Sespie pfile->print.line++;
236*c87b03e5Sespie }
237*c87b03e5Sespie }
238*c87b03e5Sespie else
239*c87b03e5Sespie print_line (pfile, map, line, "");
240*c87b03e5Sespie }
241*c87b03e5Sespie
242*c87b03e5Sespie /* Output a line marker for logical line LINE. Special flags are "1"
243*c87b03e5Sespie or "2" indicating entering or leaving a file. */
244*c87b03e5Sespie static void
print_line(pfile,map,line,special_flags)245*c87b03e5Sespie print_line (pfile, map, line, special_flags)
246*c87b03e5Sespie cpp_reader *pfile;
247*c87b03e5Sespie const struct line_map *map;
248*c87b03e5Sespie unsigned int line;
249*c87b03e5Sespie const char *special_flags;
250*c87b03e5Sespie {
251*c87b03e5Sespie /* End any previous line of text. */
252*c87b03e5Sespie if (pfile->print.printed)
253*c87b03e5Sespie putc ('\n', pfile->print.outf);
254*c87b03e5Sespie pfile->print.printed = 0;
255*c87b03e5Sespie
256*c87b03e5Sespie pfile->print.line = line;
257*c87b03e5Sespie if (! CPP_OPTION (pfile, no_line_commands))
258*c87b03e5Sespie {
259*c87b03e5Sespie size_t to_file_len = strlen (map->to_file);
260*c87b03e5Sespie unsigned char *to_file_quoted = alloca (to_file_len * 4 + 1);
261*c87b03e5Sespie unsigned char *p;
262*c87b03e5Sespie
263*c87b03e5Sespie /* cpp_quote_string does not nul-terminate, so we have to do it
264*c87b03e5Sespie ourselves. */
265*c87b03e5Sespie p = cpp_quote_string (to_file_quoted,
266*c87b03e5Sespie (unsigned char *)map->to_file, to_file_len);
267*c87b03e5Sespie *p = '\0';
268*c87b03e5Sespie fprintf (pfile->print.outf, "# %u \"%s\"%s",
269*c87b03e5Sespie SOURCE_LINE (map, pfile->print.line),
270*c87b03e5Sespie to_file_quoted, special_flags);
271*c87b03e5Sespie
272*c87b03e5Sespie if (map->sysp == 2)
273*c87b03e5Sespie fputs (" 3 4", pfile->print.outf);
274*c87b03e5Sespie else if (map->sysp == 1)
275*c87b03e5Sespie fputs (" 3", pfile->print.outf);
276*c87b03e5Sespie
277*c87b03e5Sespie putc ('\n', pfile->print.outf);
278*c87b03e5Sespie }
279*c87b03e5Sespie }
280*c87b03e5Sespie
281*c87b03e5Sespie /* Called when a line of output is started. TOKEN is the first token
282*c87b03e5Sespie of the line, and at end of file will be CPP_EOF. */
283*c87b03e5Sespie static void
cb_line_change(pfile,token,parsing_args)284*c87b03e5Sespie cb_line_change (pfile, token, parsing_args)
285*c87b03e5Sespie cpp_reader *pfile;
286*c87b03e5Sespie const cpp_token *token;
287*c87b03e5Sespie int parsing_args;
288*c87b03e5Sespie {
289*c87b03e5Sespie if (token->type == CPP_EOF || parsing_args)
290*c87b03e5Sespie return;
291*c87b03e5Sespie
292*c87b03e5Sespie maybe_print_line (pfile, pfile->print.map, token->line);
293*c87b03e5Sespie pfile->print.prev = 0;
294*c87b03e5Sespie pfile->print.source = 0;
295*c87b03e5Sespie
296*c87b03e5Sespie /* Supply enough spaces to put this token in its original column,
297*c87b03e5Sespie one space per column greater than 2, since scan_translation_unit
298*c87b03e5Sespie will provide a space if PREV_WHITE. Don't bother trying to
299*c87b03e5Sespie reconstruct tabs; we can't get it right in general, and nothing
300*c87b03e5Sespie ought to care. Some things do care; the fault lies with them. */
301*c87b03e5Sespie if (!CPP_OPTION (pfile, traditional))
302*c87b03e5Sespie {
303*c87b03e5Sespie pfile->print.printed = 1;
304*c87b03e5Sespie if (token->col > 2)
305*c87b03e5Sespie {
306*c87b03e5Sespie unsigned int spaces = token->col - 2;
307*c87b03e5Sespie
308*c87b03e5Sespie while (spaces--)
309*c87b03e5Sespie putc (' ', pfile->print.outf);
310*c87b03e5Sespie }
311*c87b03e5Sespie }
312*c87b03e5Sespie }
313*c87b03e5Sespie
314*c87b03e5Sespie static void
cb_ident(pfile,line,str)315*c87b03e5Sespie cb_ident (pfile, line, str)
316*c87b03e5Sespie cpp_reader *pfile;
317*c87b03e5Sespie unsigned int line;
318*c87b03e5Sespie const cpp_string * str;
319*c87b03e5Sespie {
320*c87b03e5Sespie maybe_print_line (pfile, pfile->print.map, line);
321*c87b03e5Sespie fprintf (pfile->print.outf, "#ident \"%s\"\n", str->text);
322*c87b03e5Sespie pfile->print.line++;
323*c87b03e5Sespie }
324*c87b03e5Sespie
325*c87b03e5Sespie static void
cb_define(pfile,line,node)326*c87b03e5Sespie cb_define (pfile, line, node)
327*c87b03e5Sespie cpp_reader *pfile;
328*c87b03e5Sespie unsigned int line;
329*c87b03e5Sespie cpp_hashnode *node;
330*c87b03e5Sespie {
331*c87b03e5Sespie maybe_print_line (pfile, pfile->print.map, line);
332*c87b03e5Sespie fputs ("#define ", pfile->print.outf);
333*c87b03e5Sespie
334*c87b03e5Sespie /* -dD command line option. */
335*c87b03e5Sespie if (CPP_OPTION (pfile, dump_macros) == dump_definitions)
336*c87b03e5Sespie fputs ((const char *) cpp_macro_definition (pfile, node),
337*c87b03e5Sespie pfile->print.outf);
338*c87b03e5Sespie else
339*c87b03e5Sespie fputs ((const char *) NODE_NAME (node), pfile->print.outf);
340*c87b03e5Sespie
341*c87b03e5Sespie putc ('\n', pfile->print.outf);
342*c87b03e5Sespie pfile->print.line++;
343*c87b03e5Sespie }
344*c87b03e5Sespie
345*c87b03e5Sespie static void
cb_undef(pfile,line,node)346*c87b03e5Sespie cb_undef (pfile, line, node)
347*c87b03e5Sespie cpp_reader *pfile;
348*c87b03e5Sespie unsigned int line;
349*c87b03e5Sespie cpp_hashnode *node;
350*c87b03e5Sespie {
351*c87b03e5Sespie maybe_print_line (pfile, pfile->print.map, line);
352*c87b03e5Sespie fprintf (pfile->print.outf, "#undef %s\n", NODE_NAME (node));
353*c87b03e5Sespie pfile->print.line++;
354*c87b03e5Sespie }
355*c87b03e5Sespie
356*c87b03e5Sespie static void
cb_include(pfile,line,dir,header)357*c87b03e5Sespie cb_include (pfile, line, dir, header)
358*c87b03e5Sespie cpp_reader *pfile;
359*c87b03e5Sespie unsigned int line;
360*c87b03e5Sespie const unsigned char *dir;
361*c87b03e5Sespie const cpp_token *header;
362*c87b03e5Sespie {
363*c87b03e5Sespie maybe_print_line (pfile, pfile->print.map, line);
364*c87b03e5Sespie fprintf (pfile->print.outf, "#%s %s\n", dir,
365*c87b03e5Sespie cpp_token_as_text (pfile, header));
366*c87b03e5Sespie pfile->print.line++;
367*c87b03e5Sespie }
368*c87b03e5Sespie
369*c87b03e5Sespie /* The file name, line number or system header flags have changed, as
370*c87b03e5Sespie described in MAP. From this point on, the old pfile->print.map might be
371*c87b03e5Sespie pointing to freed memory, and so must not be dereferenced. */
372*c87b03e5Sespie
373*c87b03e5Sespie static void
cb_file_change(pfile,map)374*c87b03e5Sespie cb_file_change (pfile, map)
375*c87b03e5Sespie cpp_reader *pfile;
376*c87b03e5Sespie const struct line_map *map;
377*c87b03e5Sespie {
378*c87b03e5Sespie const char *flags = "";
379*c87b03e5Sespie
380*c87b03e5Sespie /* First time? */
381*c87b03e5Sespie if (pfile->print.map == NULL)
382*c87b03e5Sespie {
383*c87b03e5Sespie /* Avoid printing foo.i when the main file is foo.c. */
384*c87b03e5Sespie if (!CPP_OPTION (pfile, preprocessed))
385*c87b03e5Sespie print_line (pfile, map, map->from_line, flags);
386*c87b03e5Sespie }
387*c87b03e5Sespie else
388*c87b03e5Sespie {
389*c87b03e5Sespie /* Bring current file to correct line when entering a new file. */
390*c87b03e5Sespie if (map->reason == LC_ENTER)
391*c87b03e5Sespie maybe_print_line (pfile, map - 1, map->from_line - 1);
392*c87b03e5Sespie
393*c87b03e5Sespie if (map->reason == LC_ENTER)
394*c87b03e5Sespie flags = " 1";
395*c87b03e5Sespie else if (map->reason == LC_LEAVE)
396*c87b03e5Sespie flags = " 2";
397*c87b03e5Sespie print_line (pfile, map, map->from_line, flags);
398*c87b03e5Sespie }
399*c87b03e5Sespie
400*c87b03e5Sespie pfile->print.map = map;
401*c87b03e5Sespie }
402*c87b03e5Sespie
403*c87b03e5Sespie /* Copy a #pragma directive to the preprocessed output. */
404*c87b03e5Sespie static void
cb_def_pragma(pfile,line)405*c87b03e5Sespie cb_def_pragma (pfile, line)
406*c87b03e5Sespie cpp_reader *pfile;
407*c87b03e5Sespie unsigned int line;
408*c87b03e5Sespie {
409*c87b03e5Sespie maybe_print_line (pfile, pfile->print.map, line);
410*c87b03e5Sespie fputs ("#pragma ", pfile->print.outf);
411*c87b03e5Sespie cpp_output_line (pfile, pfile->print.outf);
412*c87b03e5Sespie pfile->print.line++;
413*c87b03e5Sespie }
414*c87b03e5Sespie
415*c87b03e5Sespie /* Dump out the hash table. */
416*c87b03e5Sespie static int
dump_macro(pfile,node,v)417*c87b03e5Sespie dump_macro (pfile, node, v)
418*c87b03e5Sespie cpp_reader *pfile;
419*c87b03e5Sespie cpp_hashnode *node;
420*c87b03e5Sespie void *v ATTRIBUTE_UNUSED;
421*c87b03e5Sespie {
422*c87b03e5Sespie if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN))
423*c87b03e5Sespie {
424*c87b03e5Sespie fputs ("#define ", pfile->print.outf);
425*c87b03e5Sespie fputs ((const char *) cpp_macro_definition (pfile, node),
426*c87b03e5Sespie pfile->print.outf);
427*c87b03e5Sespie putc ('\n', pfile->print.outf);
428*c87b03e5Sespie pfile->print.line++;
429*c87b03e5Sespie }
430*c87b03e5Sespie
431*c87b03e5Sespie return 1;
432*c87b03e5Sespie }
433