cccp.c
来自「GCC编译器源代码」· C语言 代码 · 共 2,126 行 · 第 1/5 页
C
2,126 行
cplusplus_comments = 1; bzero ((char *) pend_files, argc * sizeof (char *)); bzero ((char *) pend_defs, argc * sizeof (char *)); bzero ((char *) pend_undefs, argc * sizeof (char *)); bzero ((char *) pend_assertions, argc * sizeof (char *)); bzero ((char *) 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 simplify_filename (pend_includes[i] = argv[++i]); } if (!strcmp (argv[i], "-imacros")) { if (i + 1 == argc) fatal ("Filename missing after `-imacros' option"); else simplify_filename (pend_files[i] = argv[++i]); } if (!strcmp (argv[i], "-iprefix")) { if (i + 1 == argc) fatal ("Filename missing after `-iprefix' option"); else include_prefix = argv[++i]; } if (!strcmp (argv[i], "-ifoutput")) { output_conditionals = 1; } if (!strcmp (argv[i], "-isystem")) { struct file_name_list *dirtmp; if (! (dirtmp = new_include_prefix (NULL_PTR, NULL_PTR, "", argv[++i]))) break; dirtmp->c_system_include_path = 1; if (before_system == 0) before_system = dirtmp; else last_before_system->next = dirtmp; last_before_system = dirtmp; /* Tail follows the last one */ } /* Add directory to end of path for includes, with the default prefix at the front of its name. */ if (!strcmp (argv[i], "-iwithprefix")) { struct file_name_list *dirtmp; char *prefix; if (include_prefix != 0) prefix = include_prefix; else { prefix = savestring (GCC_INCLUDE_DIR); /* Remove the `include' from /usr/local/lib/gcc.../include. */ if (!strcmp (prefix + strlen (prefix) - 8, "/include")) prefix[strlen (prefix) - 7] = 0; } if (! (dirtmp = new_include_prefix (NULL_PTR, NULL_PTR, prefix, argv[++i]))) break; if (after_include == 0) after_include = dirtmp; else last_after_include->next = dirtmp; last_after_include = dirtmp; /* Tail follows the last one */ } /* Add directory to main path for includes, with the default prefix at the front of its name. */ if (!strcmp (argv[i], "-iwithprefixbefore")) { struct file_name_list *dirtmp; char *prefix; if (include_prefix != 0) prefix = include_prefix; else { prefix = savestring (GCC_INCLUDE_DIR); /* Remove the `include' from /usr/local/lib/gcc.../include. */ if (!strcmp (prefix + strlen (prefix) - 8, "/include")) prefix[strlen (prefix) - 7] = 0; } dirtmp = new_include_prefix (NULL_PTR, NULL_PTR, prefix, argv[++i]); append_include_chain (dirtmp, dirtmp); } /* Add directory to end of path for includes. */ if (!strcmp (argv[i], "-idirafter")) { struct file_name_list *dirtmp; if (! (dirtmp = new_include_prefix (NULL_PTR, NULL_PTR, "", argv[++i]))) break; 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; if (i + 1 == argc) fatal ("Filename missing after -pcp option"); pcp_fname = argv[++i]; pcp_outfile = ((pcp_fname[0] != '-' || pcp_fname[1] != '\0') ? fopen (pcp_fname, "w") : stdout); if (pcp_outfile == 0) pfatal_with_name (pcp_fname); no_precomp = 1; } break; case 't': if (!strcmp (argv[i], "-traditional")) { traditional = 1; cplusplus_comments = 0; } else if (!strcmp (argv[i], "-trigraphs")) { no_trigraphs = 0; } break; case 'l': if (! strcmp (argv[i], "-lang-c")) cplusplus = 0, cplusplus_comments = 1, c89 = 0, objc = 0; if (! strcmp (argv[i], "-lang-c89")) cplusplus = 0, cplusplus_comments = 0, c89 = 1, objc = 0; if (! strcmp (argv[i], "-lang-c++")) cplusplus = 1, cplusplus_comments = 1, c89 = 0, objc = 0; if (! strcmp (argv[i], "-lang-objc")) cplusplus = 0, cplusplus_comments = 1, c89 = 0, objc = 1; if (! strcmp (argv[i], "-lang-objc++")) cplusplus = 1, cplusplus_comments = 1, c89 = 0, objc = 1; if (! strcmp (argv[i], "-lang-asm")) lang_asm = 1; if (! strcmp (argv[i], "-lint")) for_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], "-Wundef")) warn_undef = 1; else if (!strcmp (argv[i], "-Wno-undef")) warn_undef = 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': /* The style of the choices here is a bit mixed. The chosen scheme is a hybrid of keeping all options in one string and specifying each option in a separate argument: -M|-MM|-MD file|-MMD file [-MG]. An alternative is: -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely: -M[M][G][D file]. This is awkward to handle in specs, and is not as extensible. */ /* ??? -MG must be specified in addition to one of -M or -MM. This can be relaxed in the future without breaking anything. The converse isn't true. */ /* -MG isn't valid with -MD or -MMD. This is checked for later. */ if (!strcmp (argv[i], "-MG")) { print_deps_missing_files = 1; break; } 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")) { if (i + 1 == argc) fatal ("Filename missing after %s option", argv[i]); i++; deps_file = argv[i]; deps_mode = "w"; } 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; case 'I': dump_includes = 1; 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"); verbose = 1; break; case 'H': print_include_names = 1; break; case 'D': if (argv[i][2] != 0) pend_defs[i] = argv[i] + 2; else if (i + 1 == argc) fatal ("Macro name missing after -D option"); else i++, pend_defs[i] = argv[i]; break; case 'A': { char *p; 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_directives = 1; break; case '$': /* Don't include $ in identifiers. */ is_idchar['$'] = is_idstart['$'] = 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 = new_include_prefix (last_include, NULL_PTR, "", argv[i][2] ? argv[i] + 2 : 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 'r': if (!strcmp (argv[i], "-remap")) remap = 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. */ cp = getenv ("CPATH"); if (cp && ! no_standard_includes) path_include (cp);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?