📄 cccp.c
字号:
int lineno; /* similarly */ int if_succeeded; /* true if a leg of this if-group has been passed through rescan */ U_CHAR *control_macro; /* For #ifndef at start of file, this is the macro name tested. */ enum node_type type; /* type of last directive seen in this group */};typedef struct if_stack IF_STACK_FRAME;static IF_STACK_FRAME *if_stack = NULL;/* Buffer of -M output. */static char *deps_buffer;/* Number of bytes allocated in above. */static int deps_allocated_size;/* Number of bytes used. */static int deps_size;/* Number of bytes since the last newline. */static int deps_column;/* Nonzero means -I- has been seen, so don't look for #include "foo" the source-file directory. */static int ignore_srcdir;intmain (argc, argv) int argc; char **argv;{ int st_mode; long st_size; char *in_fname, *out_fname; char *p; int f, i; FILE_BUF *fp; char **pend_files = (char **) xmalloc (argc * sizeof (char *)); char **pend_defs = (char **) xmalloc (argc * sizeof (char *)); char **pend_undefs = (char **) xmalloc (argc * sizeof (char *)); char **pend_assertions = (char **) xmalloc (argc * sizeof (char *)); char **pend_includes = (char **) xmalloc (argc * sizeof (char *)); /* Record the option used with each element of pend_assertions. This is preparation for supporting more than one option for making an assertion. */ char **pend_assertion_options = (char **) xmalloc (argc * sizeof (char *)); int inhibit_predefs = 0; int no_standard_includes = 0; int no_standard_cplusplus_includes = 0; int missing_newline = 0; /* Non-0 means don't output the preprocessed program. */ int inhibit_output = 0; /* File name which deps are being written to. This is 0 if deps are being written to stdout. */ char *deps_file = 0; /* Stream on which to print the dependency information. */ FILE *deps_stream = 0; /* Target-name to write with the dependency information. */ char *deps_target = 0;#ifdef RLIMIT_STACK /* Get rid of any avoidable limit on stack size. */ { struct rlimit rlim; /* Set the stack limit huge so that alloca (particularly stringtab * in dbxread.c) does not fail. */ getrlimit (RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max; setrlimit (RLIMIT_STACK, &rlim); }#endif /* RLIMIT_STACK defined */ progname = argv[0];#ifdef VMS { /* Remove directories from PROGNAME. */ char *s; progname = savestring (argv[0]); if (!(s = rindex (progname, ']'))) s = rindex (progname, ':'); if (s) strcpy (progname, s+1); if (s = rindex (progname, '.')) *s = '\0'; }#endif in_fname = NULL; out_fname = NULL; /* Initialize is_idchar to allow $. */ dollars_in_ident = 1; initialize_char_syntax (); dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 0; no_line_commands = 0; no_trigraphs = 1; dump_macros = dump_none; no_output = 0; cplusplus = 0; cplusplus_comments = 0; bzero (pend_files, argc * sizeof (char *)); bzero (pend_defs, argc * sizeof (char *)); bzero (pend_undefs, argc * sizeof (char *)); bzero (pend_assertions, argc * sizeof (char *)); bzero (pend_includes, argc * sizeof (char *)); /* Process switches and find input file name. */ for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { if (out_fname != NULL) fatal ("Usage: %s [switches] input output", argv[0]); else if (in_fname != NULL) out_fname = argv[i]; else in_fname = argv[i]; } else { switch (argv[i][1]) { case 'i': if (!strcmp (argv[i], "-include")) { if (i + 1 == argc) fatal ("Filename missing after -include option"); else pend_includes[i] = argv[i+1], i++; } if (!strcmp (argv[i], "-imacros")) { if (i + 1 == argc) fatal ("Filename missing after -imacros option"); else pend_files[i] = argv[i+1], i++; } if (!strcmp (argv[i], "-iprefix")) { if (i + 1 == argc) fatal ("Filename missing after -iprefix option"); else include_prefix = argv[++i]; } /* Add directory to end of path for includes. */ if (!strcmp (argv[i], "-idirafter")) { struct file_name_list *dirtmp; dirtmp = (struct file_name_list *) xmalloc (sizeof (struct file_name_list)); dirtmp->next = 0; /* New one goes on the end */ dirtmp->control_macro = 0; if (i + 1 == argc) fatal ("Directory name missing after -idirafter option"); else dirtmp->fname = argv[++i]; if (after_include == 0) after_include = dirtmp; else last_after_include->next = dirtmp; last_after_include = dirtmp; /* Tail follows the last one */ } break; case 'o': if (out_fname != NULL) fatal ("Output filename specified twice"); if (i + 1 == argc) fatal ("Filename missing after -o option"); out_fname = argv[++i]; if (!strcmp (out_fname, "-")) out_fname = ""; break; case 'p': if (!strcmp (argv[i], "-pedantic")) pedantic = 1; else if (!strcmp (argv[i], "-pedantic-errors")) { pedantic = 1; pedantic_errors = 1; } else if (!strcmp (argv[i], "-pcp")) { char *pcp_fname = argv[++i]; pcp_outfile = ((pcp_fname[0] != '-' || pcp_fname[1] != '\0') ? fopen (pcp_fname, "w") : fdopen (dup (fileno (stdout)), "w")); if (pcp_outfile == 0) pfatal_with_name (pcp_fname); no_precomp = 1; } break; case 't': if (!strcmp (argv[i], "-traditional")) { traditional = 1; if (dollars_in_ident > 0) dollars_in_ident = 1; } else if (!strcmp (argv[i], "-trigraphs")) { no_trigraphs = 0; } break; case 'l': if (! strcmp (argv[i], "-lang-c")) cplusplus = 0, cplusplus_comments = 0, objc = 0; if (! strcmp (argv[i], "-lang-c++")) cplusplus = 1, cplusplus_comments = 1, objc = 0; if (! strcmp (argv[i], "-lang-objc")) objc = 1, cplusplus = 0, cplusplus_comments = 1; if (! strcmp (argv[i], "-lang-objc++")) objc = 1, cplusplus = 1, cplusplus_comments = 1; if (! strcmp (argv[i], "-lang-asm")) lang_asm = 1; if (! strcmp (argv[i], "-lint")) lint = 1; break; case '+': cplusplus = 1, cplusplus_comments = 1; break; case 'w': inhibit_warnings = 1; break; case 'W': if (!strcmp (argv[i], "-Wtrigraphs")) warn_trigraphs = 1; else if (!strcmp (argv[i], "-Wno-trigraphs")) warn_trigraphs = 0; else if (!strcmp (argv[i], "-Wcomment")) warn_comments = 1; else if (!strcmp (argv[i], "-Wno-comment")) warn_comments = 0; else if (!strcmp (argv[i], "-Wcomments")) warn_comments = 1; else if (!strcmp (argv[i], "-Wno-comments")) warn_comments = 0; else if (!strcmp (argv[i], "-Wtraditional")) warn_stringify = 1; else if (!strcmp (argv[i], "-Wno-traditional")) warn_stringify = 0; else if (!strcmp (argv[i], "-Wimport")) warn_import = 1; else if (!strcmp (argv[i], "-Wno-import")) warn_import = 0; else if (!strcmp (argv[i], "-Werror")) warnings_are_errors = 1; else if (!strcmp (argv[i], "-Wno-error")) warnings_are_errors = 0; else if (!strcmp (argv[i], "-Wall")) { warn_trigraphs = 1; warn_comments = 1; } break; case 'M': if (!strcmp (argv[i], "-M")) print_deps = 2; else if (!strcmp (argv[i], "-MM")) print_deps = 1; else if (!strcmp (argv[i], "-MD")) print_deps = 2; else if (!strcmp (argv[i], "-MMD")) print_deps = 1; /* For -MD and -MMD options, write deps on file named by next arg. */ if (!strcmp (argv[i], "-MD") || !strcmp (argv[i], "-MMD")) { i++; deps_file = argv[i]; } else { /* For -M and -MM, write deps on standard output and suppress the usual output. */ deps_stream = stdout; inhibit_output = 1; } break; case 'd': { char *p = argv[i] + 2; char c; while (c = *p++) { /* Arg to -d specifies what parts of macros to dump */ switch (c) { case 'M': dump_macros = dump_only; no_output = 1; break; case 'N': dump_macros = dump_names; break; case 'D': dump_macros = dump_definitions; break; } } } break; case 'g': if (argv[i][2] == '3') debug_output = 1; break; case 'v': fprintf (stderr, "GNU CPP version %s", version_string);#ifdef TARGET_VERSION TARGET_VERSION;#endif fprintf (stderr, "\n"); break; case 'H': print_include_names = 1; break; case 'D': { char *p, *p1; if (argv[i][2] != 0) p = argv[i] + 2; else if (i + 1 == argc) fatal ("Macro name missing after -D option"); else p = argv[++i]; pend_defs[i] = p; } break; case 'A': { char *p, *p1; if (argv[i][2] != 0) p = argv[i] + 2; else if (i + 1 == argc) fatal ("Assertion missing after -A option"); else p = argv[++i]; if (!strcmp (p, "-")) { /* -A- eliminates all predefined macros and assertions. Let's include also any that were specified earlier on the command line. That way we can get rid of any that were passed automatically in from GCC. */ int j; inhibit_predefs = 1; for (j = 0; j < i; j++) pend_defs[j] = pend_assertions[j] = 0; } else { pend_assertions[i] = p; pend_assertion_options[i] = "-A"; } } break; case 'U': /* JF #undef something */ if (argv[i][2] != 0) pend_undefs[i] = argv[i] + 2; else if (i + 1 == argc) fatal ("Macro name missing after -U option"); else pend_undefs[i] = argv[i+1], i++; break; case 'C': put_out_comments = 1; break; case 'E': /* -E comes from cc -E; ignore it. */ break; case 'P': no_line_commands = 1; break; case '$': /* Don't include $ in identifiers. */ dollars_in_ident = 0; break; case 'I': /* Add directory to path for includes. */ { struct file_name_list *dirtmp; if (! ignore_srcdir && !strcmp (argv[i] + 2, "-")) { ignore_srcdir = 1; /* Don't use any preceding -I directories for #include <...>. */ first_bracket_include = 0; } else { dirtmp = (struct file_name_list *) xmalloc (sizeof (struct file_name_list)); dirtmp->next = 0; /* New one goes on the end */ dirtmp->control_macro = 0; if (argv[i][2] != 0) dirtmp->fname = argv[i] + 2; else if (i + 1 == argc) fatal ("Directory name missing after -I option"); else dirtmp->fname = argv[++i]; append_include_chain (dirtmp, dirtmp); } } break; case 'n': if (!strcmp (argv[i], "-nostdinc")) /* -nostdinc causes no default include directories. You must specify all include-file directories with -I. */ no_standard_includes = 1; else if (!strcmp (argv[i], "-nostdinc++")) /* -nostdinc++ causes no default C++-specific include directories. */ no_standard_cplusplus_includes = 1; else if (!strcmp (argv[i], "-noprecomp")) no_precomp = 1; break; case 'u': /* Sun compiler passes undocumented switch "-undef". Let's assume it means to inhibit the predefined symbols. */ inhibit_predefs = 1; break; case '\0': /* JF handle '-' as file name meaning stdin or stdout */ if (in_fname == NULL) { in_fname = ""; break; } else if (out_fname == NULL) { out_fname = ""; break; } /* else fall through into error */ default: fatal ("Invalid option `%s'", argv[i]); } } } /* Add dirs from CPATH after dirs from -I. */ /* There seems to be confusion about what CPATH should do, so for the moment it is not documented. */ /* Some people say that CPATH should replace the standard include dirs, but that seems pointless: it comes before them, so it overrides them anyway. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -