f2d5f0cca2
* cpplex.c (cpp_output_tokens, cpp_scan_buffer_nooutput): New public interfaces. (safe_fwrite, output_line_command): New static functions. (cpp_expand_to_buffer): Now private to cpplib. (cpp_scan_buffer): Take a printer. * cpphash.h: Update prototypes. * cpplib.h: Update prototypes. (cpp_printer): New. (cpp_buffer): Remove last_nominal_fname. (cpp_reader): Remove lineno. * cppmain.c: Use a cpp_printer. * fix-header.c: No need to inhibit line commands. Call cpp_start_read with no printer. * cpperror.c (cpp_notice_from_errno): Provide default name. * cppfiles.c (make_IHASH, _cpp_fake_ihash): New functions. (find_include_file, cpp_read_file): Use make_IHASH. (file_cleanup): Set control_macro and clear input_stack_listing_current here. (_cpp_execute_include): Don't output entering-file marker. * cpphash.c (special_symbol): Look for the line number in the buffer, not the reader. (_cpp_macroexpand): No need to disable line commands. (_cpp_dump_definition): No need to generate line commands. (dump_hash_helper): Remove excess newline from output. * cppinit.c (dump_special_to_buffer): No need to generate line commands. (cpp_printer_init): New. (cpp_start_read): Take a printer, and start it up if it's not NULL. No need to generate line commands. (cpp_finish): Expect no buffers stacked at all. Take a printer argument, and flush the output buffer if it's not NULL. * cpplex.c (_cpp_lex_token): Return EOF if there's no buffer. Don't put two hashes at the beginning of an assertion. (cpp_get_token): Don't increment pfile->lineno or emit line commands here. Return EOF if there's no buffer when we get EOF. * cpplib.c (do_define, skip_if_group): No need to disable line commands. (_cpp_output_line_command): Delete function. (do_line): Don't emit line commands here, but set things up so they will be emitted if necessary. Use _cpp_fake_ihash to make unique nominal_fnames if necessary. (do_elif, do_else, _cpp_handle_eof): Call cpp_error_with_line with 0 for column, not -1. (_cpp_handle_eof): Don't set the control macro here. Don't clear input_stack_listing_current here. Don't emit line commands. From-SVN: r33159
89 lines
2.6 KiB
C
89 lines
2.6 KiB
C
/* CPP main program, using CPP Library.
|
||
Copyright (C) 1995, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
|
||
Written by Per Bothner, 1994-95.
|
||
|
||
This program is free software; you can redistribute it and/or modify it
|
||
under the terms of the GNU General Public License as published by the
|
||
Free Software Foundation; either version 2, or (at your option) any
|
||
later version.
|
||
|
||
This program is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU General Public License for more details.
|
||
|
||
You should have received a copy of the GNU General Public License
|
||
along with this program; if not, write to the Free Software
|
||
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||
|
||
In other words, you are welcome to use, share and improve this program.
|
||
You are forbidden to forbid anyone else to use, share and improve
|
||
what you give them. Help stamp out software-hoarding! */
|
||
|
||
#include "config.h"
|
||
#include "system.h"
|
||
#include "cpplib.h"
|
||
#include "intl.h"
|
||
|
||
const char *progname;
|
||
|
||
cpp_reader parse_in;
|
||
cpp_printer parse_out;
|
||
|
||
|
||
extern int main PARAMS ((int, char **));
|
||
int
|
||
main (argc, argv)
|
||
int argc;
|
||
char **argv;
|
||
{
|
||
char *p;
|
||
cpp_reader *pfile = &parse_in;
|
||
cpp_printer *print;
|
||
int argi = 1; /* Next argument to handle. */
|
||
|
||
p = argv[0] + strlen (argv[0]);
|
||
while (p != argv[0] && p[-1] != '/') --p;
|
||
progname = p;
|
||
|
||
xmalloc_set_program_name (progname);
|
||
|
||
#ifdef HAVE_LC_MESSAGES
|
||
setlocale (LC_MESSAGES, "");
|
||
#endif
|
||
(void) bindtextdomain (PACKAGE, localedir);
|
||
(void) textdomain (PACKAGE);
|
||
|
||
cpp_reader_init (pfile);
|
||
|
||
argi += cpp_handle_options (pfile, argc - argi , argv + argi);
|
||
if (argi < argc && ! CPP_FATAL_ERRORS (pfile))
|
||
cpp_fatal (pfile, "Invalid option %s", argv[argi]);
|
||
if (CPP_FATAL_ERRORS (pfile))
|
||
return (FATAL_EXIT_CODE);
|
||
|
||
/* Open the output now. We must do so even if no_output is on,
|
||
because there may be other output than from the actual
|
||
preprocessing (e.g. from -dM). */
|
||
print = cpp_printer_init (pfile, &parse_out);
|
||
if (! print)
|
||
return (FATAL_EXIT_CODE);
|
||
|
||
if (! cpp_start_read (pfile, print, CPP_OPTION (pfile, in_fname)))
|
||
return (FATAL_EXIT_CODE);
|
||
|
||
if (CPP_OPTION (pfile, no_output))
|
||
while (CPP_BUFFER (pfile) != NULL)
|
||
cpp_scan_buffer_nooutput (pfile);
|
||
else
|
||
while (CPP_BUFFER (pfile) != NULL)
|
||
cpp_scan_buffer (pfile, print);
|
||
|
||
cpp_finish (pfile, print);
|
||
cpp_cleanup (pfile);
|
||
|
||
if (parse_in.errors)
|
||
return (FATAL_EXIT_CODE);
|
||
return (SUCCESS_EXIT_CODE);
|
||
}
|