8sa1-gcc/gcc/cppmain.c
Zack Weinberg 3a2b2c7a20 cppexp.c, [...]: Replace cpp_token with cpp_ttype everywhere.
* cppexp.c, cpphash.c, cpphash.h, cpplex.c, cpplib.c,
	cpplib.h, cppmain.c, fix-header.c, scan-decls.c: Replace
	cpp_token with cpp_ttype everywhere.
	* cpperror.c, cpphash.c, cpplex.c, cpplib.c, scan-decls.c:
	Replace cpp_buf_line_and_col with CPP_BUF_LINE and/or
	CPP_BUF_COL.  Line and column numbers are unsigned int, not
	long.
	* cpplex.c (cpp_buf_line_and_col): Delete.
	* cpplib.h (struct cpp_buffer, struct cpp_reader): Change
	'long lineno' to 'unsigned int lineno'.
	(CPP_BUF_LINE, CPP_BUF_COL): New macros.

From-SVN: r33076
2000-04-11 08:29:34 +00:00

130 lines
3.3 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* 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;
extern int main PARAMS ((int, char **));
int
main (argc, argv)
int argc;
char **argv;
{
char *p;
cpp_reader *pfile = &parse_in;
int argi = 1; /* Next argument to handle. */
enum cpp_ttype kind;
FILE *out;
const char *out_fname;
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);
if (! cpp_start_read (pfile, CPP_OPTION (pfile, in_fname)))
return (FATAL_EXIT_CODE);
/* Now that we know the input file is valid, open the output. */
out_fname = CPP_OPTION (pfile, out_fname);
if (*out_fname == '\0')
{
out_fname = "stdout";
out = stdout;
}
else
{
out = fopen (out_fname, "w");
if (!out)
{
cpp_notice_from_errno (pfile, CPP_OPTION (pfile, out_fname));
return (FATAL_EXIT_CODE);
}
}
if (! CPP_OPTION (pfile, no_output))
{
do
{
kind = cpp_get_token (pfile);
if (CPP_WRITTEN (pfile) >= BUFSIZ || kind == CPP_EOF)
{
size_t rem, count = CPP_WRITTEN (pfile);
rem = fwrite (parse_in.token_buffer, 1, count, out);
if (rem < count)
/* Write error. */
cpp_notice_from_errno (pfile, CPP_OPTION (pfile, out_fname));
CPP_SET_WRITTEN (pfile, 0);
}
}
while (kind != CPP_EOF);
}
else
{
do
{
cpp_scan_buffer (pfile);
kind = cpp_get_token (pfile);
}
while (kind != CPP_EOF);
CPP_SET_WRITTEN (pfile, 0);
}
cpp_finish (pfile);
if (fwrite (parse_in.token_buffer, 1, CPP_WRITTEN (pfile), out)
< CPP_WRITTEN (pfile))
cpp_notice_from_errno (pfile, CPP_OPTION (pfile, out_fname));
if (ferror (out) || fclose (out))
cpp_notice_from_errno (pfile, CPP_OPTION (pfile, out_fname));
cpp_cleanup (pfile);
if (parse_in.errors)
return (FATAL_EXIT_CODE);
return (SUCCESS_EXIT_CODE);
}