📄 cccp.c
字号:
/* C Compatible Compiler Preprocessor (CCCP)Copyright (C) 1986, 1987, 1989, 1992 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, 675 Mass Ave, Cambridge, MA 02139, 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! */typedef unsigned char U_CHAR;#ifdef EMACS#define NO_SHORTNAMES#include "../src/config.h"#ifdef open#undef open#undef read#undef write#endif /* open */#endif /* EMACS *//* The macro EMACS is defined when cpp is distributed as part of Emacs, for the sake of machines with limited C compilers. */#ifndef EMACS#include "config.h"#endif /* not EMACS */#ifndef STANDARD_INCLUDE_DIR#define STANDARD_INCLUDE_DIR "/usr/include"#endif#ifndef LOCAL_INCLUDE_DIR#define LOCAL_INCLUDE_DIR "/usr/local/include"#endif#if 0 /* We can't get ptrdiff_t, so I arranged not to need PTR_INT_TYPE. */#ifdef __STDC__#define PTR_INT_TYPE ptrdiff_t#else#define PTR_INT_TYPE long#endif#endif /* 0 */#include "pcp.h"#ifndef STDC_VALUE#define STDC_VALUE 1#endif/* By default, colon separates directories in a path. */#ifndef PATH_SEPARATOR#define PATH_SEPARATOR ':'#endif/* In case config.h defines these. */#undef bcopy#undef bzero#undef bcmp#include <sys/types.h>#include <sys/stat.h>#include <ctype.h>#include <stdio.h>#ifndef VMS#ifndef USG#include <sys/time.h> /* for __DATE__ and __TIME__ */#include <sys/resource.h>#else#include <time.h>#include <fcntl.h>#endif /* USG */#endif /* not VMS *//* VMS-specific definitions */#ifdef VMS#include <time.h>#include <errno.h> /* This defines "errno" properly */#include <perror.h> /* This defines sys_errlist/sys_nerr properly */#include <descrip.h>#define O_RDONLY 0 /* Open arg for Read/Only */#define O_WRONLY 1 /* Open arg for Write/Only */#define read(fd,buf,size) VMS_read(fd,buf,size)#define write(fd,buf,size) VMS_write(fd,buf,size)#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 strncat(dst,src,cnt) VMS_strncat(dst,src,cnt)static char * VMS_strncat ();static int VMS_read ();static int VMS_write ();static int VMS_open ();static FILE * VMS_fopen ();static FILE * VMS_freopen ();static void hack_vms_include_specification ();typedef struct { unsigned :16, :16, :16; } vms_ino_t;#define ino_t vms_ino_t#define INCLUDE_LEN_FUDGE 10 /* leave room for VMS syntax conversion */#ifdef __GNUC__#define BSTRING /* VMS/GCC supplies the bstring routines */#endif /* __GNUC__ */#endif /* VMS */ extern char *index ();extern char *rindex ();#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. */#ifndef HOST_BITS_PER_WIDE_INT#if HOST_BITS_PER_LONG > HOST_BITS_PER_INT#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG#define HOST_WIDE_INT long#else#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT#define HOST_WIDE_INT int#endif#endif#ifndef S_ISREG#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)#endif/* Define a generic NULL if one hasn't already been defined. */#ifndef NULL#define NULL 0#endif#ifndef GENERIC_PTR#if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)#define GENERIC_PTR void *#else#define GENERIC_PTR char *#endif#endif#ifndef NULL_PTR#define NULL_PTR ((GENERIC_PTR)0)#endif#ifndef INCLUDE_LEN_FUDGE#define INCLUDE_LEN_FUDGE 0#endif/* Forward declarations. */char *xmalloc ();void error ();void warning ();/* External declarations. */extern char *getenv ();extern FILE *fdopen ();extern char *version_string;extern struct tm *localtime ();extern int sys_nerr;extern const char *const sys_errlist[];#ifndef errnoextern int errno;#endif/* Forward declarations. */struct directive;struct file_buf;struct arglist;struct argdata;#if defined(USG) || defined(VMS)#ifndef BSTRINGvoid bcopy ();void bzero ();int bcmp ();#endif#endif/* These functions are declared to return int instead of void since they are going to be placed in a table and some old compilers have trouble with pointers to functions returning void. */static int do_define ();static int do_line ();static int do_include ();static int do_undef ();static int do_error ();static int do_pragma ();static int do_ident ();static int do_if ();static int do_xifdef ();static int do_else ();static int do_elif ();static int do_endif ();static int do_sccs ();static int do_once ();static int do_assert ();static int do_unassert ();static int do_warning ();static void add_import ();static void append_include_chain ();static void deps_output ();static void make_undef ();static void make_definition ();static void make_assertion ();static void path_include ();static void initialize_builtins ();static void initialize_char_syntax ();static void dump_arg_n ();static void dump_defn_1 ();static void delete_macro ();static void trigraph_pcp ();static void rescan ();static void finclude ();static void validate_else ();static int comp_def_part ();static void error_from_errno ();static void error_with_line ();void pedwarn ();static void pedwarn_with_file_and_line ();static void fatal ();void fancy_abort ();static void pfatal_with_name ();static void perror_with_name ();static void print_containing_files ();static int lookup_import ();static int redundant_include_p ();static is_system_include ();static int check_preconditions ();static void pcfinclude ();static void pcstring_used ();static void write_output ();static int check_macro_name ();static int compare_defs ();static int compare_token_lists ();static int eval_if_expression ();static int discard_comments ();static int delete_newlines ();static int line_for_error ();static int hashf ();static int file_size_and_mode ();static struct arglist *read_token_list ();static void free_token_list ();static struct hashnode *install ();struct hashnode *lookup ();static struct assertion_hashnode *assertion_install ();static struct assertion_hashnode *assertion_lookup ();static char *xrealloc ();static char *xcalloc ();static char *savestring ();static void delete_assertion ();static void macroexpand ();static void dump_all_macros ();static void conditional_skip ();static void skip_if_group ();static void output_line_command ();/* Last arg to output_line_command. */enum file_change_code {same_file, enter_file, leave_file};static int grow_outbuf ();static int handle_directive ();static void memory_full ();static U_CHAR *macarg1 ();static char *macarg ();static U_CHAR *skip_to_end_of_comment ();static U_CHAR *skip_quoted_string ();static U_CHAR *skip_paren_group ();static char *check_precompiled ();/* static struct macrodef create_definition (); [moved below] */static void dump_single_macro ();#ifndef FAILURE_EXIT_CODE#define FAILURE_EXIT_CODE 33 /* gnu cc command understands this */#endif#ifndef SUCCESS_EXIT_CODE#define SUCCESS_EXIT_CODE 0 /* 0 means success on Unix. */#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 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 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_commands;/* 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 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. */static int no_precomp;/* 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 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 #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 causes output not to be done, but directives such as #define that have side effects are still obeyed. */static int no_output;/* 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. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -