📄 gcc.c
字号:
if (machine_suffix) { strcpy (temp, standard_exec_prefix_1); strcat (temp, machine_suffix); strcat (temp, name); win = (access (temp, R_OK) == 0); } if (!win) { strcpy (temp, standard_exec_prefix_1); strcat (temp, name); win = (access (temp, R_OK) == 0); } } if (!win) { if (machine_suffix) { strcpy (temp, standard_startfile_prefix); strcat (temp, machine_suffix); strcat (temp, name); win = (access (temp, R_OK) == 0); } if (!win) { strcpy (temp, standard_startfile_prefix); strcat (temp, name); win = (access (temp, R_OK) == 0); } } if (!win) { if (machine_suffix) { strcpy (temp, standard_startfile_prefix_1); strcat (temp, machine_suffix); strcat (temp, name); win = (access (temp, R_OK) == 0); } if (!win) { strcpy (temp, standard_startfile_prefix_1); strcat (temp, name); win = (access (temp, R_OK) == 0); } } if (!win) { if (machine_suffix) { strcpy (temp, standard_startfile_prefix_2); strcat (temp, machine_suffix); strcat (temp, name); win = (access (temp, R_OK) == 0); } if (!win) { strcpy (temp, standard_startfile_prefix_2); strcat (temp, name); win = (access (temp, R_OK) == 0); } } if (!win) { if (machine_suffix) { strcpy (temp, "./"); strcat (temp, machine_suffix); strcat (temp, name); win = (access (temp, R_OK) == 0); } if (!win) { strcpy (temp, "./"); strcat (temp, name); win = (access (temp, R_OK) == 0); } } if (win) return save_string (temp, strlen (temp)); return name;}/* On fatal signals, delete all the temporary files. */voidfatal_error (signum) int signum;{ signal (signum, SIG_DFL); delete_failure_queue (); delete_temp_files (); /* Get the same signal again, this time not handled, so its normal effect occurs. */ kill (getpid (), signum);}intmain (argc, argv) int argc; char **argv;{ register int i; int value; int error_count = 0; int linker_was_run = 0; char *explicit_link_files; programname = argv[0]; if (signal (SIGINT, SIG_IGN) != SIG_IGN) signal (SIGINT, fatal_error); if (signal (SIGHUP, SIG_IGN) != SIG_IGN) signal (SIGHUP, fatal_error); if (signal (SIGTERM, SIG_IGN) != SIG_IGN) signal (SIGTERM, fatal_error); if (signal (SIGPIPE, SIG_IGN) != SIG_IGN) signal (SIGPIPE, fatal_error); argbuf_length = 10; argbuf = (char **) xmalloc (argbuf_length * sizeof (char *)); obstack_init (&obstack); choose_temp_base (); /* Make a table of what switches there are (switches, n_switches). Make a table of specified input files (infiles, n_infiles). */ process_command (argc, argv); if (vflag) { extern char *version_string; fprintf (stderr, "gcc version %s\n", version_string); if (n_infiles == 0) exit (0); } if (n_infiles == 0) fatal ("No input files specified."); /* Make a place to record the compiler output file names that correspond to the input files. */ outfiles = (char **) xmalloc (n_infiles * sizeof (char *)); bzero (outfiles, n_infiles * sizeof (char *)); /* Record which files were specified explicitly as link input. */ explicit_link_files = (char *) xmalloc (n_infiles); bzero (explicit_link_files, n_infiles); for (i = 0; i < n_infiles; i++) { register struct compiler *cp; int this_file_error = 0; /* Tell do_spec what to substitute for %i. */ input_filename = infiles[i]; input_filename_length = strlen (input_filename); input_file_number = i; /* Use the same thing in %o, unless cp->spec says otherwise. */ outfiles[i] = input_filename; /* Figure out which compiler from the file's suffix. */ for (cp = compilers; cp->spec; cp++) { if (strlen (cp->suffix) < input_filename_length && !strcmp (cp->suffix, infiles[i] + input_filename_length - strlen (cp->suffix))) { /* Ok, we found an applicable compiler. Run its spec. */ /* First say how much of input_filename to substitute for %b */ register char *p; input_basename = input_filename; for (p = input_filename; *p; p++) if (*p == '/') input_basename = p + 1; basename_length = (input_filename_length - strlen (cp->suffix) - (input_basename - input_filename)); value = do_spec (cp->spec); if (value < 0) this_file_error = 1; break; } } /* If this file's name does not contain a recognized suffix, record it as explicit linker input. */ if (! cp->spec) explicit_link_files[i] = 1; /* Clear the delete-on-failure queue, deleting the files in it if this compilation failed. */ if (this_file_error) { delete_failure_queue (); error_count++; } /* If this compilation succeeded, don't delete those files later. */ clear_failure_queue (); } /* Run ld to link all the compiler output files. */ if (error_count == 0) { int tmp = execution_count; value = do_spec (link_spec); if (value < 0) error_count = 1; linker_was_run = (tmp != execution_count); } /* If options said don't run linker, complain about input files to be given to the linker. */ if (! linker_was_run && error_count == 0) for (i = 0; i < n_infiles; i++) if (explicit_link_files[i]) error ("%s: linker input file unused since linking not done", outfiles[i]); /* Set the `valid' bits for switches that match anything in any spec. */ validate_all_switches (); /* Warn about any switches that no pass was interested in. */ for (i = 0; i < n_switches; i++) if (! switches[i].valid) error ("unrecognized option `-%s'", switches[i].part1); /* Delete some or all of the temporary files we made. */ if (error_count) delete_failure_queue (); delete_temp_files (); exit (error_count);}xmalloc (size) int size;{ register int value = malloc (size); if (value == 0) fatal ("virtual memory exhausted"); return value;}xrealloc (ptr, size) int ptr, size;{ register int value = realloc (ptr, size); if (value == 0) fatal ("virtual memory exhausted"); return value;}/* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */char *concat (s1, s2, s3) char *s1, *s2, *s3;{ int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); char *result = (char *) xmalloc (len1 + len2 + len3 + 1); strcpy (result, s1); strcpy (result + len1, s2); strcpy (result + len1 + len2, s3); *(result + len1 + len2 + len3) = 0; return result;}char *save_string (s, len) char *s; int len;{ register char *result = (char *) xmalloc (len + 1); bcopy (s, result, len); result[len] = 0; return result;}pfatal_with_name (name) char *name;{ extern int errno, sys_nerr; extern char *sys_errlist[]; char *s; if (errno < sys_nerr) s = concat ("%s: ", sys_errlist[errno], ""); else s = "cannot open %s"; fatal (s, name);}perror_with_name (name) char *name;{ extern int errno, sys_nerr; extern char *sys_errlist[]; char *s; if (errno < sys_nerr) s = concat ("%s: ", sys_errlist[errno], ""); else s = "cannot open %s"; error (s, name);}perror_exec (name) char *name;{ extern int errno, sys_nerr; extern char *sys_errlist[]; char *s; if (errno < sys_nerr) s = concat ("installation problem, cannot exec %s: ", sys_errlist[errno], ""); else s = "installation problem, cannot exec %s"; error (s, name);}/* More 'friendly' abort that prints the line and file. config.h can #define abort fancy_abort if you like that sort of thing. */voidfancy_abort (){ fatal ("Internal gcc abort.");}#ifdef HAVE_VPRINTF/* Output an error message and exit */int fatal (va_alist) va_dcl{ va_list ap; char *format; va_start(ap); format = va_arg (ap, char *); fprintf (stderr, "%s: ", programname); vfprintf (stderr, format, ap); va_end (ap); fprintf (stderr, "\n"); delete_temp_files (); exit (1);} error (va_alist) va_dcl{ va_list ap; char *format; va_start(ap); format = va_arg (ap, char *); fprintf (stderr, "%s: ", programname); vfprintf (stderr, format, ap); va_end (ap); fprintf (stderr, "\n");}#else /* not HAVE_VPRINTF */fatal (msg, arg1, arg2) char *msg, *arg1, *arg2;{ error (msg, arg1, arg2); delete_temp_files (0); exit (1);}error (msg, arg1, arg2) char *msg, *arg1, *arg2;{ fprintf (stderr, "%s: ", programname); fprintf (stderr, msg, arg1, arg2); fprintf (stderr, "\n");}#endif /* not HAVE_VPRINTF */voidvalidate_all_switches (){ struct compiler *comp; register char *p; register char c; for (comp = compilers; comp->spec; comp++) { p = comp->spec; while (c = *p++) if (c == '%' && *p == '{') /* We have a switch spec. */ validate_switches (p + 1); } p = link_spec; while (c = *p++) if (c == '%' && *p == '{') /* We have a switch spec. */ validate_switches (p + 1); /* Now notice switches mentioned in the machine-specific specs. */#ifdef ASM_SPEC p = ASM_SPEC; while (c = *p++) if (c == '%' && *p == '{') /* We have a switch spec. */ validate_switches (p + 1);#endif#ifdef CPP_SPEC p = CPP_SPEC; while (c = *p++) if (c == '%' && *p == '{') /* We have a switch spec. */ validate_switches (p + 1);#endif#ifdef SIGNED_CHAR_SPEC p = SIGNED_CHAR_SPEC; while (c = *p++) if (c == '%' && *p == '{') /* We have a switch spec. */ validate_switches (p + 1);#endif#ifdef CC1_SPEC p = CC1_SPEC; while (c = *p++) if (c == '%' && *p == '{') /* We have a switch spec. */ validate_switches (p + 1);#endif#ifdef LINK_SPEC p = LINK_SPEC; while (c = *p++) if (c == '%' && *p == '{') /* We have a switch spec. */ validate_switches (p + 1);#endif#ifdef LIB_SPEC p = LIB_SPEC; while (c = *p++) if (c == '%' && *p == '{') /* We have a switch spec. */ validate_switches (p + 1);#endif#ifdef STARTFILE_SPEC p = STARTFILE_SPEC; while (c = *p++) if (c == '%' && *p == '{') /* We have a switch spec. */ validate_switches (p + 1);#endif}/* Look at the switch-name that comes after START and mark as valid all supplied switches that match it. */voidvalidate_switches (start) char *start;{ register char *p = start; char *filter; register int i; if (*p == '|') ++p; if (*p == '!') ++p; filter = p; while (*p != ':' && *p != '}') p++; if (p[-1] == '*') { /* Mark all matching switches as valid. */ --p; for (i = 0; i < n_switches; i++) if (!strncmp (switches[i].part1, filter, p - filter)) switches[i].valid = 1; } else { /* Mark an exact matching switch as valid. */ for (i = 0; i < n_switches; i++) { if (!strncmp (switches[i].part1, filter, p - filter) && switches[i].part1[p - filter] == 0) switches[i].valid = 1; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -