📄 cccp.c
字号:
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. */ 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; dirtmp->c_system_include_path = 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]; dirtmp->got_name_map = 0; 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. */ cp = getenv ("CPATH"); if (cp && ! no_standard_includes) path_include (cp); /* Now that dollars_in_ident is known, initialize is_idchar. */ initialize_char_syntax (); /* Initialize output buffer */ outbuf.buf = (U_CHAR *) xmalloc (OUTBUF_SIZE); outbuf.bufp = outbuf.buf; outbuf.length = OUTBUF_SIZE; /* Do partial setup of input buffer for the sake of generating early #line directives (when -g is in effect). */ fp = &instack[++indepth]; if (in_fname == NULL) in_fname = ""; fp->nominal_fname = fp->fname = in_fname; fp->lineno = 0; /* In C++, wchar_t is a distinct basic type, and we can expect __wchar_t to be defined by cc1plus. */ if (cplusplus) wchar_type = "__wchar_t"; /* Install __LINE__, etc. Must follow initialize_char_syntax and option processing. */ initialize_builtins (fp, &outbuf); /* Do standard #defines and assertions that identify system and machine type. */ if (!inhibit_predefs) { char *p = (char *) alloca (strlen (predefs) + 1); strcpy (p, predefs); while (*p) { char *q; while (*p == ' ' || *p == '\t') p++; /* Handle -D options. */ if (p[0] == '-' && p[1] == 'D') { q = &p[2]; while (*p && *p != ' ' && *p != '\t') p++; if (*p != 0) *p++= 0; if (debug_output) output_line_directive (fp, &outbuf, 0, same_file); make_definition (q, &outbuf); while (*p == ' ' || *p == '\t') p++; } else if (p[0] == '-' && p[1] == 'A') { /* Handle -A options (assertions). */ char *assertion; char *past_name; char *value; char *past_value; char *termination; int save_char; assertion = &p[2]; past_name = assertion; /* Locate end of name. */ while (*past_name && *past_name != ' ' && *past_name != '\t' && *past_name != '(') past_name++; /* Locate `(' at start of value. */ value = past_name; while (*value && (*value == ' ' || *value == '\t')) value++; if (*value++ != '(') abort (); while (*value && (*value == ' ' || *value == '\t')) value++; past_value = value; /* Locate end of value. */ while (*past_value && *past_value != ' ' && *past_value != '\t' && *past_value != ')') past_value++; termination = past_value; while (*termination && (*termination == ' ' || *termination == '\t')) termination++; if (*termination++ != ')') abort (); if (*termination && *termination != ' ' && *termination != '\t') abort (); /* Temporarily null-terminate the value. */ save_char = *termination; *termination = '\0'; /* Install the assertion. */ make_assertion ("-A", assertion); *termination = (char) save_char; p = termination; while (*p == ' ' || *p == '\t') p++; } else { abort (); } } } /* Now handle the command line options. */ /* Do -U's, -D's and -A's in the order they were seen. */ for (i = 1; i < argc; i++) { if (pend_undefs[i]) { if (debug_output) output_line_directive (fp, &outbuf, 0, same_file); make_undef (pend_undefs[i], &outbuf); } if (pend_defs[i]) { if (debug_output) output_line_directive (fp, &outbuf, 0, same_file); make_definition (pend_defs[i], &outbuf); } if (pend_assertions[i]) make_assertion (pend_assertion_options[i], pend_assertions[i]); } done_initializing = 1; { /* read the appropriate environment variable and if it exists replace include_defaults with the listed path. */ char *epath = 0; switch ((objc << 1) + cplusplus) { case 0: epath = getenv ("C_INCLUDE_PATH"); break; case 1: epath = getenv ("CPLUS_INCLUDE_PATH"); break; case 2: epath = getenv ("OBJC_INCLUDE_PATH"); break; case 3: epath = getenv ("OBJCPLUS_INCLUDE_PATH"); break; } /* If the environment var for this language is set, add to the default list of include directories. */ if (epath) { char *nstore = (char *) alloca (strlen (epath) + 2); int num_dirs; char *startp, *endp; for (num_dirs = 1, startp = epath; *startp; startp++) if (*startp == PATH_SEPARATOR) num_dirs++; include_defaults = (struct default_include *) xmalloc ((num_dirs * sizeof (struct default_include)) + sizeof (include_defaults_array)); startp = endp = epath; num_dirs = 0; while (1) { /* Handle cases like c:/usr/lib:d:/gcc/lib */ if ((*endp == PATH_SEPARATOR#if 0 /* Obsolete, now that we use semicolons as the path separator. */#ifdef __MSDOS__ && (endp-startp != 1 || !isalpha (*startp))#endif#endif ) || *endp == 0) { strncpy (nstore, startp, endp-startp); if (endp == startp) strcpy (nstore, "."); else nstore[endp-startp] = '\0'; include_defaults[num_dirs].fname = savestring (nstore); include_defaults[num_dirs].cplusplus = cplusplus; include_defaults[num_dirs].cxx_aware = 1; num_dirs++; if (*endp == '\0') break; endp = startp = endp + 1; } else endp++; } /* Put the usual defaults back in at the end. */ bcopy ((char *) include_defaults_array, (char *) &include_defaults[num_dirs], sizeof (include_defaults_array)); } } append_include_chain (before_system, last_before_system); first_system_include = before_system; /* Unless -fnostdinc, tack on the standard include file dirs to the specified list */ if (!no_standard_includes) { struct default_include *p = include_defaults; char *specd_prefix = include_prefix; char *default_prefix = savestring (GCC_INCLUDE_DIR); int default_len = 0; /* Remove the `include' from /usr/local/lib/gcc.../include. */ if (!strcmp (default_prefix + strlen (default_prefix) - 8, "/include")) { default_len = strlen (default_prefix) - 7; default_prefix[default_len] = 0; } /* Search "translated" versions of GNU directories. These have /usr/local/lib/gcc... replaced by specd_prefix. */ if (specd_prefix != 0 && default_len != 0) for (p = include_defaults; p->fname; p++) { /* Some standard dirs are only for C++. */ if (!p->cplusplus || (cplusplus && !no_standard_cplusplus_includes)) { /* Does this dir start with the prefix? */ if (!strncmp (p->fname, default_prefix, default_len)) { /* Yes; change prefix and add to search list. */ struct file_name_list *new = (struct file_name_list *) xmalloc (sizeof (struct file_name_list)); int this_len = strlen (specd_prefix) + strlen (p->fname) - default_len; char *str = xmalloc (this_len + 1); strcpy (str, specd_prefix); strcat (str, p->fname + default_len); new->fname = str; new->control_macro = 0; new->c_system_include_path = !p->cxx_aware; new->got_name_map = 0; append_include_chain (new, new); if (first_system_include == 0) first_system_include = new; } } } /* Search ordinary names for GNU include directories. */ for (p = include_defaults; p->fname; p++) { /* Some standard dirs are only for C++. */ if (!p->cplusplus || (cplusplus && !no_standard_cplusplus_includes)) { struct file_name_list *new = (struct file_name_list *) xmalloc (sizeof (struct file_name_list)); new->control_macro = 0; new->c_system_include_path = !p->cxx_aware; new->fname = p->fname; new->got_name_map = 0; append_include_chain (new, new); if (first_system_include == 0) first_system_include = new; } } } /* Tack the after_include chain at the end of the include chain. */ append_include_chain (after_include, last_after_include); if (first_system_include == 0) first_system_include = after_include; /* With -v, print the list of dirs to search. */ if (verbose) { struct file_name_list *p; fprintf (stderr, "#include \"...\" search starts here:\n"); for (p = include; p; p = p->next) { if (p == first_bracket_include) fprintf (stderr, "#include <...> search starts here:\n"); fprintf (stderr, " %s\n", p->fname); } fprintf (stderr, "End of search list.\n"); } /* Scan the -imacros files before the main input. Much like #including them, but with no_output set so that only their macro definitions matter. */ no_output++; no_record_file++; for (i = 1; i < argc; i++) if (pend_files[i]) { int fd = open (pend_files[i], O_RDONLY, 0666); if (fd < 0) { perror_with_name (pend_files[i]); return FATAL_EXIT_CODE; } finclude (fd, pend_files[i], &outbuf, 0, NULL_PTR); } no_output--; no_record_file--; /* Copy the entire contents of the main input file into the stacked input buffer previously allocated for it. */ /* JF check for stdin */ if (in_fname == NULL || *in_fname == 0) { in_fname = ""; f = 0; } else if ((f = open (in_fname, O_RDONLY, 0666)) < 0) goto perror; /* -MG doesn't select the form of output and must be specified with one of -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't inhibit compilation. */ if (print_deps_missing_files && (print_deps == 0 || !inhibit_output)) fatal ("-MG must be specified with one of -M or -MM"); /* Either of two environment variables can specify output of deps. Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to and DEPS_TARGET is the target to mention in the deps. */ if (print_deps == 0 && (getenv ("SUNPRO_DEPENDENCIES") != 0 || getenv ("DEPENDENCIES_OUTPUT") != 0)) { char *spec = getenv ("DEPENDENCIES_OUTPUT"); char *s; char *output_file; if (spec == 0) { spec = getenv ("SUNPRO_DEPENDENCIES"); print_deps = 2; } else print_deps = 1; s = spec; /* Find the space before the DEPS_TARGET, if there is one. */ /* This should use index. (mrs) */ while (*s != 0 && *s != ' ') s++; if (*s != 0) { deps_target = s + 1; output_file = xmalloc (s - spec + 1); bcopy (spec, output_file, s - spec); output_file[s - spec] = 0; } else { deps_target = 0; output_file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -