OSDN Git Service

top level:
[pf3gnuchains/gcc-fork.git] / gcc / cppmain.c
1 /* CPP main program, using CPP Library.
2    Copyright (C) 1995, 1997, 1998, 1999, 2000 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
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 #include "config.h"
24 #include "system.h"
25 #include "cpplib.h"
26 #include "intl.h"
27
28 const char *progname;
29
30 cpp_reader parse_in;
31 cpp_printer parse_out;
32
33 \f
34 extern int main                         PARAMS ((int, char **));
35 int
36 main (argc, argv)
37      int argc;
38      char **argv;
39 {
40   char *p;
41   cpp_reader *pfile = &parse_in;
42   cpp_printer *print;
43   int argi = 1;  /* Next argument to handle.  */
44
45   p = argv[0] + strlen (argv[0]);
46   while (p != argv[0] && ! IS_DIR_SEPARATOR (p[-1])) --p;
47   progname = p;
48
49   xmalloc_set_program_name (progname);
50
51 #ifdef HAVE_LC_MESSAGES
52   setlocale (LC_MESSAGES, "");
53 #endif
54   (void) bindtextdomain (PACKAGE, localedir);
55   (void) textdomain (PACKAGE);
56
57   cpp_reader_init (pfile);
58   
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))
63     return (FATAL_EXIT_CODE);
64
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)
70     return (FATAL_EXIT_CODE);
71   pfile->printer = print;
72
73   if (! cpp_start_read (pfile, print, CPP_OPTION (pfile, in_fname)))
74     return (FATAL_EXIT_CODE);
75
76   if (CPP_OPTION (pfile, no_output))
77     while (CPP_BUFFER (pfile) != NULL)
78       cpp_scan_buffer_nooutput (pfile);
79   else
80     while (CPP_BUFFER (pfile) != NULL)
81       cpp_scan_buffer (pfile, print);
82
83   cpp_finish (pfile, print);
84   cpp_cleanup (pfile);
85
86   if (parse_in.errors)
87     return (FATAL_EXIT_CODE);
88   return (SUCCESS_EXIT_CODE);
89 }