cccp.c

来自「GCC编译器源代码」· C语言 代码 · 共 2,126 行 · 第 1/5 页

C
2,126
字号
/* C Compatible Compiler Preprocessor (CCCP)   Copyright (C) 1986, 87, 89, 92-96, 1997 Free Software Foundation, Inc.   Written by Paul Rubin, June 1986   Adapted to ANSI C, Richard Stallman, Jan 1987This program is free software; you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by theFree Software Foundation; either version 2, or (at your option) anylater version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, 59 Temple Place - Suite 330,Boston, MA 02111-1307, USA. */#include "config.h"#include <sys/types.h>#include <sys/stat.h>#include <ctype.h>#include <stdio.h>#include <signal.h>#ifdef TIME_WITH_SYS_TIME# include <sys/time.h># include <time.h>#else# if HAVE_SYS_TIME_H# include <sys/time.h># else#  include <time.h>#endif#endif#ifdef HAVE_SYS_RESOURCE_H# include <sys/resource.h>#endif#if HAVE_FCNTL_H# include <fcntl.h>#endif#if HAVE_LIMITS_H# include <limits.h>#endif#if HAVE_UNISTD_H# include <unistd.h>#endif#include <errno.h>#if HAVE_STDLIB_H# include <stdlib.h>#endif#ifdef HAVE_STRING_H# include <string.h>#else# ifdef HAVE_STRINGS_H#  include <strings.h>#endif#endiftypedef unsigned char U_CHAR;#include "gansidecl.h"#include "pcp.h"#ifdef NEED_DECLARATION_INDEXextern char *index ();#endif#ifdef NEED_DECLARATION_RINDEXextern char *rindex ();#endif#ifdef NEED_DECLARATION_GETENVextern char *getenv ();#endif#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)# define __attribute__(x)#endif#ifndef STANDARD_INCLUDE_DIR# define STANDARD_INCLUDE_DIR "/usr/include"#endif/* By default, colon separates directories in a path.  */#ifndef PATH_SEPARATOR# define PATH_SEPARATOR ':'#endif/* By default, the suffix for object files is ".o".  */#ifdef OBJECT_SUFFIX# define HAVE_OBJECT_SUFFIX#else# define OBJECT_SUFFIX ".o"#endif#if defined (__STDC__) && defined (HAVE_VPRINTF)# include <stdarg.h># define PRINTF_ALIST(msg) char *msg, ...# define PRINTF_DCL(msg)# define PRINTF_PROTO(ARGS, m, n) PROTO (ARGS) __attribute__ ((format (__printf__, m, n)))#else# include <varargs.h># define PRINTF_ALIST(msg) msg, va_alist# define PRINTF_DCL(msg) char *msg; va_dcl# define PRINTF_PROTO(ARGS, m, n) () __attribute__ ((format (__printf__, m, n)))# define vfprintf(file, msg, args) \    { \      char *a0 = va_arg(args, char *); \      char *a1 = va_arg(args, char *); \      char *a2 = va_arg(args, char *); \      char *a3 = va_arg(args, char *); \      fprintf (file, msg, a0, a1, a2, a3); \    }#endif#define PRINTF_PROTO_1(ARGS) PRINTF_PROTO(ARGS, 1, 2)#define PRINTF_PROTO_2(ARGS) PRINTF_PROTO(ARGS, 2, 3)#define PRINTF_PROTO_3(ARGS) PRINTF_PROTO(ARGS, 3, 4)/* VMS-specific definitions */#ifdef VMS#include <descrip.h>#define open(fname,mode,prot)	VMS_open (fname,mode,prot)#define fopen(fname,mode)	VMS_fopen (fname,mode)#define freopen(fname,mode,ofile) VMS_freopen (fname,mode,ofile)#define fstat(fd,stbuf)		VMS_fstat (fd,stbuf)static int VMS_fstat (), VMS_stat ();static int VMS_open ();static FILE *VMS_fopen ();static FILE *VMS_freopen ();static void hack_vms_include_specification ();#define INO_T_EQ(a, b) (!bcmp((char *) &(a), (char *) &(b), sizeof (a)))#define INO_T_HASH(a) 0#define INCLUDE_LEN_FUDGE 12	/* leave room for VMS syntax conversion */#endif /* VMS *//* Windows does not natively support inodes, and neither does MSDOS.  */#if (defined (_WIN32) && ! defined (CYGWIN32)) || defined (__MSDOS__)#define INO_T_EQ(a, b) 0#endif#ifndef O_RDONLY#define O_RDONLY 0#endif#undef MIN#undef MAX#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))/* Find the largest host integer type and set its size and type.   Watch out: on some crazy hosts `long' is shorter than `int'.  */#ifndef HOST_WIDE_INT# if HAVE_INTTYPES_H#  include <inttypes.h>#  define HOST_WIDE_INT intmax_t# else#  if (HOST_BITS_PER_LONG <= HOST_BITS_PER_INT && HOST_BITS_PER_LONGLONG <= HOST_BITS_PER_INT)#   define HOST_WIDE_INT int#  else#  if (HOST_BITS_PER_LONGLONG <= HOST_BITS_PER_LONG || ! (defined LONG_LONG_MAX || defined LLONG_MAX))#   define HOST_WIDE_INT long#  else#   define HOST_WIDE_INT long long#  endif#  endif# endif#endif#ifndef S_ISREG#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)#endif#ifndef S_ISDIR#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)#endif#ifndef INO_T_EQ#define INO_T_EQ(a, b) ((a) == (b))#endif#ifndef INO_T_HASH#define INO_T_HASH(a) (a)#endif#ifndef INCLUDE_LEN_FUDGE#define INCLUDE_LEN_FUDGE 0#endif/* External declarations.  */extern char *version_string;extern char *update_path PROTO((char *, char *));#ifndef VMS#ifndef HAVE_STRERRORextern int sys_nerr;extern char *sys_errlist[];#else	/* HAVE_STRERROR */char *strerror ();#endif#else	/* VMS */char *strerror (int,...);#endifHOST_WIDE_INT parse_escape PROTO((char **, HOST_WIDE_INT));HOST_WIDE_INT parse_c_expression PROTO((char *, int));#ifndef errnoextern int errno;#endif/* Name under which this program was invoked.  */static char *progname;/* Nonzero means use extra default include directories for C++.  */static int cplusplus;/* Nonzero means handle cplusplus style comments */static int cplusplus_comments;/* Nonzero means handle #import, for objective C.  */static int objc;/* Nonzero means this is an assembly file, and allow   unknown directives, which could be comments.  */static int lang_asm;/* Current maximum length of directory names in the search path   for include files.  (Altered as we get more of them.)  */static int max_include_len;/* Nonzero means turn NOTREACHED into #pragma NOTREACHED etc */static int for_lint = 0;/* Nonzero means copy comments into the output file.  */static int put_out_comments = 0;/* Nonzero means don't process the ANSI trigraph sequences.  */static int no_trigraphs = 0;/* Nonzero means print the names of included files rather than   the preprocessed output.  1 means just the #include "...",   2 means #include <...> as well.  */static int print_deps = 0;/* Nonzero if missing .h files in -M output are assumed to be generated   files and not errors.  */static int print_deps_missing_files = 0;/* Nonzero means print names of header files (-H).  */static int print_include_names = 0;/* Nonzero means don't output line number information.  */static int no_line_directives;/* Nonzero means output the text in failing conditionals,   inside #failed ... #endfailed.  */static int output_conditionals;/* dump_only means inhibit output of the preprocessed text             and instead output the definitions of all user-defined             macros in a form suitable for use as input to cccp.   dump_names means pass #define and the macro name through to output.   dump_definitions means pass the whole definition (plus #define) through*/static enum {dump_none, dump_only, dump_names, dump_definitions}     dump_macros = dump_none;/* Nonzero means pass all #define and #undef directives which we actually   process through to the output stream.  This feature is used primarily   to allow cc1 to record the #defines and #undefs for the sake of   debuggers which understand about preprocessor macros, but it may   also be useful with -E to figure out how symbols are defined, and   where they are defined.  */static int debug_output = 0;/* Nonzero means pass #include lines through to the output,   even if they are ifdefed out.  */static int dump_includes;/* Nonzero indicates special processing used by the pcp program.  The   special effects of this mode are:           Inhibit all macro expansion, except those inside #if directives.     Process #define directives normally, and output their contents      to the output file.     Output preconditions to pcp_outfile indicating all the relevant     preconditions for use of this file in a later cpp run.*/static FILE *pcp_outfile;/* Nonzero means we are inside an IF during a -pcp run.  In this mode   macro expansion is done, and preconditions are output for all macro   uses requiring them.  */static int pcp_inside_if;/* Nonzero means never to include precompiled files.   This is 1 since there's no way now to make precompiled files,   so it's not worth testing for them.  */static int no_precomp = 1;/* Nonzero means give all the error messages the ANSI standard requires.  */int pedantic;/* Nonzero means try to make failure to fit ANSI C an error.  */static int pedantic_errors;/* Nonzero means don't print warning messages.  -w.  */static int inhibit_warnings = 0;/* Nonzero means warn if slash-star appears in a slash-star comment,   or if newline-backslash appears in a slash-slash comment.  */static int warn_comments;/* Nonzero means warn if a macro argument is (or would be)   stringified with -traditional.  */static int warn_stringify;/* Nonzero means warn if there are any trigraphs.  */static int warn_trigraphs;/* Nonzero means warn if undefined identifiers are evaluated in an #if.  */static int warn_undef;/* Nonzero means warn if #import is used.  */static int warn_import = 1;/* Nonzero means turn warnings into errors.  */static int warnings_are_errors;/* Nonzero means try to imitate old fashioned non-ANSI preprocessor.  */int traditional;/* Nonzero for the 1989 C Standard, including corrigenda and amendments.  */int c89;/* Nonzero causes output not to be done,   but directives such as #define that have side effects   are still obeyed.  */static int no_output;/* Nonzero means we should look for header.gcc files that remap file names.  */static int remap;/* Nonzero means this file was included with a -imacros or -include   command line and should not be recorded as an include file.  */static int no_record_file;/* Nonzero means that we have finished processing the command line options.   This flag is used to decide whether or not to issue certain errors   and/or warnings.  */static int done_initializing = 0;/* Line where a newline was first seen in a string constant.  */static int multiline_string_line = 0;/* I/O buffer structure.   The `fname' field is nonzero for source files and #include files   and for the dummy text used for -D and -U.   It is zero for rescanning results of macro expansion   and for expanding macro arguments.  */#define INPUT_STACK_MAX 400static struct file_buf {  char *fname;  /* Filename specified with #line directive.  */  char *nominal_fname;  /* Include file description.  */  struct include_file *inc;  /* Record where in the search path this file was found.     For #include_next.  */  struct file_name_list *dir;  int lineno;  int length;  U_CHAR *buf;  U_CHAR *bufp;  /* Macro that this level is the expansion of.     Included so that we can reenable the macro     at the end of this level.  */  struct hashnode *macro;  /* Value of if_stack at start of this file.     Used to prohibit unmatched #endif (etc) in an include file.  */  struct if_stack *if_stack;  /* Object to be freed at end of input at this level.  */  U_CHAR *free_ptr;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?