]> gcc.gnu.org Git - gcc.git/blame_incremental - gcc/cppmain.c
(pfatal_with_name, fatal_io_error, vfatal): Use FATAL_EXIT_CODE
[gcc.git] / gcc / cppmain.c
... / ...
CommitLineData
1/* CPP main program, using CPP Library.
2 Copyright (C) 1995 Free Software Foundation, Inc.
3 Written by Per Bothner, 1994-95.
4
5This program is free software; you can redistribute it and/or modify it
6under the terms of the GNU General Public License as published by the
7Free Software Foundation; either version 2, or (at your option) any
8later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 In other words, you are welcome to use, share and improve this program.
20 You are forbidden to forbid anyone else to use, share and improve
21 what you give them. Help stamp out software-hoarding! */
22
23#include "cpplib.h"
24#include <stdio.h>
25
26extern char *getenv ();
27
28cpp_reader parse_in;
29cpp_options options;
30
31/* More 'friendly' abort that prints the line and file.
32 config.h can #define abort fancy_abort if you like that sort of thing. */
33
34void
35fancy_abort ()
36{
37 fatal ("Internal gcc abort.");
38}
39
40\f
41int
42main (argc, argv)
43 int argc;
44 char **argv;
45{
46 char *p;
47 int i;
48 int argi = 1; /* Next argument to handle. */
49 struct cpp_options *opts = &options;
50
51 p = argv[0] + strlen (argv[0]);
52 while (p != argv[0] && p[-1] != '/') --p;
53 progname = p;
54
55 init_parse_file (&parse_in);
56 parse_in.data = opts;
57
58 init_parse_options (opts);
59
60 argi += cpp_handle_options (&parse_in, argc - argi , argv + argi);
61 if (argi < argc)
62 fatal ("Invalid option `%s'", argv[argi]);
63 parse_in.show_column = 1;
64
65 i = push_parse_file (&parse_in, opts->in_fname);
66 if (i != SUCCESS_EXIT_CODE)
67 return i;
68
69 /* Now that we know the input file is valid, open the output. */
70
71 if (!opts->out_fname || !strcmp (opts->out_fname, ""))
72 opts->out_fname = "stdout";
73 else if (! freopen (opts->out_fname, "w", stdout))
74 cpp_pfatal_with_name (&parse_in, opts->out_fname);
75
76 for (;;)
77 {
78 enum cpp_token kind;
79 if (! opts->no_output)
80 {
81 fwrite (parse_in.token_buffer, 1, CPP_WRITTEN (&parse_in), stdout);
82 }
83 parse_in.limit = parse_in.token_buffer;
84 kind = cpp_get_token (&parse_in);
85 if (kind == CPP_EOF)
86 break;
87 }
88
89 cpp_finish (&parse_in);
90
91 if (parse_in.errors)
92 exit (FAILURE_EXIT_CODE);
93 exit (SUCCESS_EXIT_CODE);
94}
This page took 0.025954 seconds and 5 git commands to generate.