]>
Commit | Line | Data |
---|---|---|
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 | ||
5 | This program is free software; you can redistribute it and/or modify it | |
6 | under the terms of the GNU General Public License as published by the | |
7 | Free Software Foundation; either version 2, or (at your option) any | |
8 | later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program; if not, write to the Free Software | |
940d9d63 | 17 | Foundation, 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 |
30 | extern char *getenv (); |
31 | ||
32 | cpp_reader parse_in; | |
33 | cpp_options options; | |
34 | ||
35 | /* More 'friendly' abort that prints the line and file. | |
36 | config.h can #define abort fancy_abort if you like that sort of thing. */ | |
37 | ||
38 | void | |
39 | fancy_abort () | |
40 | { | |
41 | fatal ("Internal gcc abort."); | |
42 | } | |
43 | ||
44 | \f | |
45 | int | |
46 | main (argc, argv) | |
47 | int argc; | |
48 | char **argv; | |
49 | { | |
50 | char *p; | |
51 | int i; | |
52 | int argi = 1; /* Next argument to handle. */ | |
53 | struct cpp_options *opts = &options; | |
54 | ||
55 | p = argv[0] + strlen (argv[0]); | |
56 | while (p != argv[0] && p[-1] != '/') --p; | |
57 | progname = p; | |
58 | ||
59 | init_parse_file (&parse_in); | |
60 | parse_in.data = opts; | |
61 | ||
62 | init_parse_options (opts); | |
63 | ||
64 | argi += cpp_handle_options (&parse_in, argc - argi , argv + argi); | |
65 | if (argi < argc) | |
66 | fatal ("Invalid option `%s'", argv[argi]); | |
67 | parse_in.show_column = 1; | |
68 | ||
69 | i = push_parse_file (&parse_in, opts->in_fname); | |
70 | if (i != SUCCESS_EXIT_CODE) | |
71 | return i; | |
72 | ||
73 | /* Now that we know the input file is valid, open the output. */ | |
74 | ||
75 | if (!opts->out_fname || !strcmp (opts->out_fname, "")) | |
76 | opts->out_fname = "stdout"; | |
77 | else if (! freopen (opts->out_fname, "w", stdout)) | |
78 | cpp_pfatal_with_name (&parse_in, opts->out_fname); | |
79 | ||
80 | for (;;) | |
81 | { | |
7f2935c7 PB |
82 | enum cpp_token kind; |
83 | if (! opts->no_output) | |
84 | { | |
85 | fwrite (parse_in.token_buffer, 1, CPP_WRITTEN (&parse_in), stdout); | |
86 | } | |
87 | parse_in.limit = parse_in.token_buffer; | |
88 | kind = cpp_get_token (&parse_in); | |
89 | if (kind == CPP_EOF) | |
90 | break; | |
7f2935c7 PB |
91 | } |
92 | ||
93 | cpp_finish (&parse_in); | |
94 | ||
95 | if (parse_in.errors) | |
84ee6fd4 | 96 | exit (FATAL_EXIT_CODE); |
7f2935c7 PB |
97 | exit (SUCCESS_EXIT_CODE); |
98 | } |