]>
Commit | Line | Data |
---|---|---|
7f2935c7 | 1 | /* CPP main program, using CPP Library. |
5e7b4e25 | 2 | Copyright (C) 1995, 1997, 1998, 1999, 2000 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 | 23 | #include "config.h" |
b04cd507 | 24 | #include "system.h" |
b04cd507 | 25 | #include "cpplib.h" |
ab87f8c8 | 26 | #include "intl.h" |
7f2935c7 | 27 | |
bcc5cac9 | 28 | const char *progname; |
1802bb1c | 29 | |
7f2935c7 | 30 | cpp_reader parse_in; |
f2d5f0cc | 31 | cpp_printer parse_out; |
7f2935c7 | 32 | |
7f2935c7 | 33 | \f |
bcc5cac9 | 34 | extern int main PARAMS ((int, char **)); |
7f2935c7 PB |
35 | int |
36 | main (argc, argv) | |
37 | int argc; | |
38 | char **argv; | |
39 | { | |
40 | char *p; | |
ae79697b | 41 | cpp_reader *pfile = &parse_in; |
f2d5f0cc | 42 | cpp_printer *print; |
0f41302f | 43 | int argi = 1; /* Next argument to handle. */ |
7f2935c7 PB |
44 | |
45 | p = argv[0] + strlen (argv[0]); | |
46 | while (p != argv[0] && p[-1] != '/') --p; | |
47 | progname = p; | |
48 | ||
f95e46b9 ZW |
49 | xmalloc_set_program_name (progname); |
50 | ||
d9b53430 | 51 | #ifdef HAVE_LC_MESSAGES |
ab87f8c8 | 52 | setlocale (LC_MESSAGES, ""); |
d9b53430 | 53 | #endif |
735396d9 KG |
54 | (void) bindtextdomain (PACKAGE, localedir); |
55 | (void) textdomain (PACKAGE); | |
ab87f8c8 | 56 | |
ae79697b | 57 | cpp_reader_init (pfile); |
7f2935c7 | 58 | |
ae79697b ZW |
59 | argi += cpp_handle_options (pfile, argc - argi , argv + argi); |
60 | if (argi < argc && ! CPP_FATAL_ERRORS (pfile)) | |
61 | cpp_fatal (pfile, "Invalid option %s", argv[argi]); | |
62 | if (CPP_FATAL_ERRORS (pfile)) | |
bcc5cac9 | 63 | return (FATAL_EXIT_CODE); |
7f2935c7 | 64 | |
f2d5f0cc ZW |
65 | /* Open the output now. We must do so even if no_output is on, |
66 | because there may be other output than from the actual | |
67 | preprocessing (e.g. from -dM). */ | |
68 | print = cpp_printer_init (pfile, &parse_out); | |
69 | if (! print) | |
bcc5cac9 | 70 | return (FATAL_EXIT_CODE); |
7f2935c7 | 71 | |
f2d5f0cc ZW |
72 | if (! cpp_start_read (pfile, print, CPP_OPTION (pfile, in_fname))) |
73 | return (FATAL_EXIT_CODE); | |
74 | ||
75 | if (CPP_OPTION (pfile, no_output)) | |
76 | while (CPP_BUFFER (pfile) != NULL) | |
77 | cpp_scan_buffer_nooutput (pfile); | |
5d83f44b | 78 | else |
f2d5f0cc ZW |
79 | while (CPP_BUFFER (pfile) != NULL) |
80 | cpp_scan_buffer (pfile, print); | |
7f2935c7 | 81 | |
f2d5f0cc | 82 | cpp_finish (pfile, print); |
ae79697b | 83 | cpp_cleanup (pfile); |
a9ae4483 | 84 | |
7f2935c7 | 85 | if (parse_in.errors) |
bcc5cac9 KG |
86 | return (FATAL_EXIT_CODE); |
87 | return (SUCCESS_EXIT_CODE); | |
7f2935c7 | 88 | } |