Call fatal_insn_not_found instead of abort
[official-gcc.git] / gcc / cppmain.c
blob0a45e86907be1742da8050cf0aaa1835df6ff88f
1 /* CPP main program, using CPP Library.
2 Copyright (C) 1995, 1997 Free Software Foundation, Inc.
3 Written by Per Bothner, 1994-95.
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.
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.
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.
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! */
23 #ifndef EMACS
24 #include "config.h"
25 #include "system.h"
26 #include "gansidecl.h"
27 #else
28 #include <stdio.h>
30 extern char *getenv ();
31 #endif /* not EMACS */
33 #include "cpplib.h"
35 char *progname;
37 cpp_reader parse_in;
38 cpp_options options;
40 #ifdef abort
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 void
44 fatal (s)
45 char *s;
47 fputs (s, stderr);
48 exit (FATAL_EXIT_CODE);
51 void
52 fancy_abort ()
54 fatal ("Internal gcc abort.");
56 #endif
59 int
60 main (argc, argv)
61 int argc;
62 char **argv;
64 char *p;
65 int argi = 1; /* Next argument to handle. */
66 struct cpp_options *opts = &options;
68 p = argv[0] + strlen (argv[0]);
69 while (p != argv[0] && p[-1] != '/') --p;
70 progname = p;
72 cpp_reader_init (&parse_in);
73 parse_in.data = opts;
75 cpp_options_init (opts);
77 argi += cpp_handle_options (&parse_in, argc - argi , argv + argi);
78 if (argi < argc && ! CPP_FATAL_ERRORS (&parse_in))
79 cpp_fatal (&parse_in, "Invalid option `%s'", argv[argi]);
80 if (CPP_FATAL_ERRORS (&parse_in))
81 exit (FATAL_EXIT_CODE);
83 parse_in.show_column = 1;
85 if (! cpp_start_read (&parse_in, opts->in_fname))
86 exit (FATAL_EXIT_CODE);
88 /* Now that we know the input file is valid, open the output. */
90 if (!opts->out_fname || !strcmp (opts->out_fname, ""))
91 opts->out_fname = "stdout";
92 else if (! freopen (opts->out_fname, "w", stdout))
93 cpp_pfatal_with_name (&parse_in, opts->out_fname);
95 for (;;)
97 enum cpp_token kind;
98 if (! opts->no_output)
100 fwrite (parse_in.token_buffer, 1, CPP_WRITTEN (&parse_in), stdout);
102 CPP_SET_WRITTEN (&parse_in, 0);
103 kind = cpp_get_token (&parse_in);
104 if (kind == CPP_EOF)
105 break;
108 cpp_finish (&parse_in);
110 if (parse_in.errors)
111 exit (FATAL_EXIT_CODE);
112 exit (SUCCESS_EXIT_CODE);