]> gcc.gnu.org Git - gcc.git/blame - gcc/cppmain.c
* cpperror.c (fatal): Removed function.
[gcc.git] / gcc / cppmain.c
CommitLineData
7f2935c7
PB
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
940d9d63 17Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7f2935c7
PB
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
84ee6fd4
RK
26#ifndef EMACS
27#include "config.h"
28#endif /* not EMACS */
29
7f2935c7
PB
30extern char *getenv ();
31
1802bb1c
RK
32char *progname;
33
7f2935c7
PB
34cpp_reader parse_in;
35cpp_options options;
36
37/* More 'friendly' abort that prints the line and file.
38 config.h can #define abort fancy_abort if you like that sort of thing. */
39
40void
41fancy_abort ()
42{
43 fatal ("Internal gcc abort.");
44}
45
46\f
47int
48main (argc, argv)
49 int argc;
50 char **argv;
51{
52 char *p;
53 int i;
54 int argi = 1; /* Next argument to handle. */
55 struct cpp_options *opts = &options;
56
57 p = argv[0] + strlen (argv[0]);
58 while (p != argv[0] && p[-1] != '/') --p;
59 progname = p;
60
59de0311 61 cpp_reader_init (&parse_in);
7f2935c7
PB
62 parse_in.data = opts;
63
59de0311 64 cpp_options_init (opts);
7f2935c7
PB
65
66 argi += cpp_handle_options (&parse_in, argc - argi , argv + argi);
59de0311
PB
67 if (CPP_FATAL_ERRORS (&parse_in))
68 exit (FATAL_EXIT_CODE);
7f2935c7 69 if (argi < argc)
59de0311
PB
70 cpp_fatal (&parse_in, "Invalid option `%s'", argv[argi]);
71
7f2935c7
PB
72 parse_in.show_column = 1;
73
59de0311
PB
74 if (! cpp_start_read (&parse_in, opts->in_fname))
75 exit (FATAL_EXIT_CODE);
7f2935c7
PB
76
77 /* Now that we know the input file is valid, open the output. */
78
79 if (!opts->out_fname || !strcmp (opts->out_fname, ""))
80 opts->out_fname = "stdout";
81 else if (! freopen (opts->out_fname, "w", stdout))
82 cpp_pfatal_with_name (&parse_in, opts->out_fname);
83
84 for (;;)
85 {
7f2935c7
PB
86 enum cpp_token kind;
87 if (! opts->no_output)
88 {
89 fwrite (parse_in.token_buffer, 1, CPP_WRITTEN (&parse_in), stdout);
90 }
59de0311 91 CPP_SET_WRITTEN (&parse_in, 0);
7f2935c7
PB
92 kind = cpp_get_token (&parse_in);
93 if (kind == CPP_EOF)
94 break;
7f2935c7
PB
95 }
96
97 cpp_finish (&parse_in);
98
99 if (parse_in.errors)
84ee6fd4 100 exit (FATAL_EXIT_CODE);
7f2935c7
PB
101 exit (SUCCESS_EXIT_CODE);
102}
This page took 0.109199 seconds and 5 git commands to generate.