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