]>
Commit | Line | Data |
---|---|---|
7f2935c7 | 1 | /* CPP main program, using CPP Library. |
b04cd507 | 2 | Copyright (C) 1995, 1997 Free Software Foundation, Inc. |
7f2935c7 PB |
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 | ||
84ee6fd4 RK |
23 | #ifndef EMACS |
24 | #include "config.h" | |
b04cd507 | 25 | #include "system.h" |
487a6e06 | 26 | #include "gansidecl.h" |
b04cd507 KG |
27 | #else |
28 | #include <stdio.h> | |
84ee6fd4 | 29 | |
7f2935c7 | 30 | extern char *getenv (); |
b04cd507 KG |
31 | #endif /* not EMACS */ |
32 | ||
33 | #include "cpplib.h" | |
7f2935c7 | 34 | |
1802bb1c RK |
35 | char *progname; |
36 | ||
7f2935c7 PB |
37 | cpp_reader parse_in; |
38 | cpp_options options; | |
39 | ||
6c8e6d0c | 40 | #ifdef abort |
7f2935c7 PB |
41 | /* More 'friendly' abort that prints the line and file. |
42 | config.h can #define abort fancy_abort if you like that sort of thing. */ | |
43 | ||
44 | void | |
45 | fancy_abort () | |
46 | { | |
47 | fatal ("Internal gcc abort."); | |
48 | } | |
6c8e6d0c | 49 | #endif |
7f2935c7 PB |
50 | |
51 | \f | |
52 | int | |
53 | main (argc, argv) | |
54 | int argc; | |
55 | char **argv; | |
56 | { | |
57 | char *p; | |
0f41302f | 58 | int argi = 1; /* Next argument to handle. */ |
7f2935c7 PB |
59 | struct cpp_options *opts = &options; |
60 | ||
61 | p = argv[0] + strlen (argv[0]); | |
62 | while (p != argv[0] && p[-1] != '/') --p; | |
63 | progname = p; | |
64 | ||
59de0311 | 65 | cpp_reader_init (&parse_in); |
7f2935c7 PB |
66 | parse_in.data = opts; |
67 | ||
59de0311 | 68 | cpp_options_init (opts); |
7f2935c7 PB |
69 | |
70 | argi += cpp_handle_options (&parse_in, argc - argi , argv + argi); | |
6c8e6d0c PB |
71 | if (argi < argc && ! CPP_FATAL_ERRORS (&parse_in)) |
72 | cpp_fatal (&parse_in, "Invalid option `%s'", argv[argi]); | |
59de0311 PB |
73 | if (CPP_FATAL_ERRORS (&parse_in)) |
74 | exit (FATAL_EXIT_CODE); | |
59de0311 | 75 | |
7f2935c7 PB |
76 | parse_in.show_column = 1; |
77 | ||
59de0311 PB |
78 | if (! cpp_start_read (&parse_in, opts->in_fname)) |
79 | exit (FATAL_EXIT_CODE); | |
7f2935c7 PB |
80 | |
81 | /* Now that we know the input file is valid, open the output. */ | |
82 | ||
83 | if (!opts->out_fname || !strcmp (opts->out_fname, "")) | |
84 | opts->out_fname = "stdout"; | |
85 | else if (! freopen (opts->out_fname, "w", stdout)) | |
86 | cpp_pfatal_with_name (&parse_in, opts->out_fname); | |
87 | ||
88 | for (;;) | |
89 | { | |
7f2935c7 PB |
90 | enum cpp_token kind; |
91 | if (! opts->no_output) | |
92 | { | |
93 | fwrite (parse_in.token_buffer, 1, CPP_WRITTEN (&parse_in), stdout); | |
94 | } | |
59de0311 | 95 | CPP_SET_WRITTEN (&parse_in, 0); |
7f2935c7 PB |
96 | kind = cpp_get_token (&parse_in); |
97 | if (kind == CPP_EOF) | |
98 | break; | |
7f2935c7 PB |
99 | } |
100 | ||
101 | cpp_finish (&parse_in); | |
102 | ||
103 | if (parse_in.errors) | |
84ee6fd4 | 104 | exit (FATAL_EXIT_CODE); |
7f2935c7 PB |
105 | exit (SUCCESS_EXIT_CODE); |
106 | } |