Commit 6aa62cff by Doug Evans

gcc.c: #include "gansidecl.h".

	* gcc.c: #include "gansidecl.h".
	(PROTO,VPROTO,PVPROTO,VPROTO,VA_START,NULL): Delete.
	(GENERIC_PTR,NULL_PTR,P_tmpdir): Delete.
	(choose_temp_base): Declare as extern, delete internal copy.
	(concat): Rewrite to take a variable number of arguments.
	(choose_temp_base_try,concat[346]): Delete.
	(translate_options,set_spec,process_command,do_spec_1,
	is_directory,main): Always use concat, not concat[346].  Pass
	NULL_PTR as trailing arg to concat.

From-SVN: r11794
parent 0afdf565
...@@ -47,6 +47,8 @@ int __spawnvp (); ...@@ -47,6 +47,8 @@ int __spawnvp ();
#include "config.h" #include "config.h"
#include "obstack.h" #include "obstack.h"
#include "gansidecl.h"
#ifdef __STDC__ #ifdef __STDC__
#include <stdarg.h> #include <stdarg.h>
#else #else
...@@ -76,62 +78,15 @@ int __spawnvp (); ...@@ -76,62 +78,15 @@ int __spawnvp ();
#define WEXITSTATUS(S) (((S) & 0xff00) >> 8) #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
#endif #endif
/* Add prototype support. */
#ifndef PROTO
#if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
#define PROTO(ARGS) ARGS
#else
#define PROTO(ARGS) ()
#endif
#endif
#ifndef VPROTO
#ifdef __STDC__
#define PVPROTO(ARGS) ARGS
#define VPROTO(ARGS) ARGS
#define VA_START(va_list,var) va_start(va_list,var)
#else
#define PVPROTO(ARGS) ()
#define VPROTO(ARGS) (va_alist) va_dcl
#define VA_START(va_list,var) va_start(va_list)
#endif
#endif
/* Define a generic NULL if one hasn't already been defined. */
#ifndef NULL
#define NULL 0
#endif
/* Define O_RDONLY if the system hasn't defined it for us. */ /* Define O_RDONLY if the system hasn't defined it for us. */
#ifndef O_RDONLY #ifndef O_RDONLY
#define O_RDONLY 0 #define O_RDONLY 0
#endif #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
#ifdef USG #ifdef USG
#define vfork fork #define vfork fork
#endif /* USG */ #endif /* USG */
/* On MSDOS, write temp files in current dir
because there's no place else we can expect to use. */
#ifdef __MSDOS__
#ifndef P_tmpdir
#define P_tmpdir "."
#endif
#endif
/* Test if something is a normal file. */ /* Test if something is a normal file. */
#ifndef S_ISREG #ifndef S_ISREG
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
...@@ -171,6 +126,8 @@ static char dir_separator_str[] = {DIR_SEPARATOR, 0}; ...@@ -171,6 +126,8 @@ static char dir_separator_str[] = {DIR_SEPARATOR, 0};
extern void free (); extern void free ();
extern char *getenv (); extern char *getenv ();
extern char *choose_temp_base PROTO((void));
#ifndef errno #ifndef errno
extern int errno; extern int errno;
#endif #endif
...@@ -279,16 +236,10 @@ static void delete_if_ordinary PROTO((char *)); ...@@ -279,16 +236,10 @@ static void delete_if_ordinary PROTO((char *));
static void delete_temp_files PROTO((void)); static void delete_temp_files PROTO((void));
static void delete_failure_queue PROTO((void)); static void delete_failure_queue PROTO((void));
static void clear_failure_queue PROTO((void)); static void clear_failure_queue PROTO((void));
static char *choose_temp_base_try PROTO((char *, char *));
static void choose_temp_base PROTO((void));
static int check_live_switch PROTO((int, int)); static int check_live_switch PROTO((int, int));
static char *handle_braces PROTO((char *)); static char *handle_braces PROTO((char *));
static char *save_string PROTO((char *, int)); static char *save_string PROTO((char *, int));
static char *concat PROTO((char *, char *)); static char *concat PVPROTO((char *, ...));
static char *concat3 PROTO((char *, char *, char *));
static char *concat4 PROTO((char *, char *, char *, char *));
static char *concat6 PROTO((char *, char *, char *, char *, char *, \
char *));
static int do_spec PROTO((char *)); static int do_spec PROTO((char *));
static int do_spec_1 PROTO((char *, int, char *)); static int do_spec_1 PROTO((char *, int, char *));
static char *find_file PROTO((char *)); static char *find_file PROTO((char *));
...@@ -961,7 +912,8 @@ translate_options (argcp, argvp) ...@@ -961,7 +912,8 @@ translate_options (argcp, argvp)
/* Store the translation as one argv elt or as two. */ /* Store the translation as one argv elt or as two. */
if (arg != 0 && index (arginfo, 'j') != 0) if (arg != 0 && index (arginfo, 'j') != 0)
newv[newindex++] = concat (option_map[j].equivalent, arg); newv[newindex++] = concat (option_map[j].equivalent, arg,
NULL_PTR);
else if (arg != 0) else if (arg != 0)
{ {
newv[newindex++] = option_map[j].equivalent; newv[newindex++] = option_map[j].equivalent;
...@@ -1226,7 +1178,7 @@ set_spec (name, spec) ...@@ -1226,7 +1178,7 @@ set_spec (name, spec)
old_spec = sl->spec; old_spec = sl->spec;
if (name && spec[0] == '+' && isspace (spec[1])) if (name && spec[0] == '+' && isspace (spec[1]))
sl->spec = concat (old_spec, spec + 1); sl->spec = concat (old_spec, spec + 1, NULL_PTR);
else else
sl->spec = save_string (spec, strlen (spec)); sl->spec = save_string (spec, strlen (spec));
...@@ -1448,7 +1400,8 @@ store_arg (arg, delete_always, delete_failure) ...@@ -1448,7 +1400,8 @@ store_arg (arg, delete_always, delete_failure)
This prefix comes from the envvar TMPDIR if it is defined; This prefix comes from the envvar TMPDIR if it is defined;
otherwise, from the P_tmpdir macro if that is defined; otherwise, from the P_tmpdir macro if that is defined;
otherwise, in /usr/tmp or /tmp. */ otherwise, in /usr/tmp or /tmp;
or finally the current directory if all else fails. */
static char *temp_filename; static char *temp_filename;
...@@ -1561,65 +1514,7 @@ clear_failure_queue () ...@@ -1561,65 +1514,7 @@ clear_failure_queue ()
{ {
failure_delete_queue = 0; failure_delete_queue = 0;
} }
/* Compute a string to use as the base of all temporary file names.
It is substituted for %g. */
static char *
choose_temp_base_try (try, base)
char *try;
char *base;
{
char *rv;
if (base)
rv = base;
else if (try == (char *)0)
rv = 0;
else if (access (try, R_OK | W_OK) != 0)
rv = 0;
else
rv = try;
return rv;
}
static void
choose_temp_base ()
{
char *base = 0;
int len;
base = choose_temp_base_try (getenv ("TMPDIR"), base);
base = choose_temp_base_try (getenv ("TMP"), base);
base = choose_temp_base_try (getenv ("TEMP"), base);
#ifdef P_tmpdir
base = choose_temp_base_try (P_tmpdir, base);
#endif
base = choose_temp_base_try (concat4 (dir_separator_str, "usr",
dir_separator_str, "tmp"),
base);
base = choose_temp_base_try (concat (dir_separator_str, "tmp"), base);
/* If all else fails, use the current directory! */
if (base == (char *)0) base = concat(".", dir_separator_str);
len = strlen (base);
temp_filename = xmalloc (len + strlen (concat (dir_separator_str,
"ccXXXXXX")) + 1);
strcpy (temp_filename, base);
if (len > 0 && temp_filename[len-1] != '/'
&& temp_filename[len-1] != DIR_SEPARATOR)
temp_filename[len++] = DIR_SEPARATOR;
strcpy (temp_filename + len, "ccXXXXXX");
mktemp (temp_filename);
temp_filename_length = strlen (temp_filename);
if (temp_filename_length == 0)
abort ();
}
/* Routine to add variables to the environment. We do this to pass /* Routine to add variables to the environment. We do this to pass
the pathname of the gcc driver, and the directories search to the the pathname of the gcc driver, and the directories search to the
collect2 program, which is being run as ld. This way, we can be collect2 program, which is being run as ld. This way, we can be
...@@ -2425,7 +2320,7 @@ process_command (argc, argv) ...@@ -2425,7 +2320,7 @@ process_command (argc, argv)
{ {
strncpy (nstore, startp, endp-startp); strncpy (nstore, startp, endp-startp);
if (endp == startp) if (endp == startp)
strcpy (nstore, concat (".", dir_separator_str)); strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR) else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
{ {
nstore[endp-startp] = DIR_SEPARATOR; nstore[endp-startp] = DIR_SEPARATOR;
...@@ -2456,7 +2351,7 @@ process_command (argc, argv) ...@@ -2456,7 +2351,7 @@ process_command (argc, argv)
{ {
strncpy (nstore, startp, endp-startp); strncpy (nstore, startp, endp-startp);
if (endp == startp) if (endp == startp)
strcpy (nstore, concat (".", dir_separator_str)); strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR) else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
{ {
nstore[endp-startp] = DIR_SEPARATOR; nstore[endp-startp] = DIR_SEPARATOR;
...@@ -2488,7 +2383,7 @@ process_command (argc, argv) ...@@ -2488,7 +2383,7 @@ process_command (argc, argv)
{ {
strncpy (nstore, startp, endp-startp); strncpy (nstore, startp, endp-startp);
if (endp == startp) if (endp == startp)
strcpy (nstore, concat (".", dir_separator_str)); strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR) else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
{ {
nstore[endp-startp] = DIR_SEPARATOR; nstore[endp-startp] = DIR_SEPARATOR;
...@@ -2680,7 +2575,7 @@ process_command (argc, argv) ...@@ -2680,7 +2575,7 @@ process_command (argc, argv)
value = p + 1; value = p + 1;
add_prefix (&exec_prefixes, value, 1, 0, &warn_B); add_prefix (&exec_prefixes, value, 1, 0, &warn_B);
add_prefix (&startfile_prefixes, value, 1, 0, &warn_B); add_prefix (&startfile_prefixes, value, 1, 0, &warn_B);
add_prefix (&include_prefixes, concat (value, "include"), add_prefix (&include_prefixes, concat (value, "include", NULL_PTR),
1, 0, NULL_PTR); 1, 0, NULL_PTR);
/* As a kludge, if the arg is "[foo/]stageN/", just add /* As a kludge, if the arg is "[foo/]stageN/", just add
...@@ -2779,8 +2674,8 @@ process_command (argc, argv) ...@@ -2779,8 +2674,8 @@ process_command (argc, argv)
add_prefix (&startfile_prefixes, standard_exec_prefix, 0, 1, warn_std_ptr); add_prefix (&startfile_prefixes, standard_exec_prefix, 0, 1, warn_std_ptr);
add_prefix (&startfile_prefixes, standard_exec_prefix_1, 0, 1, warn_std_ptr); add_prefix (&startfile_prefixes, standard_exec_prefix_1, 0, 1, warn_std_ptr);
tooldir_prefix = concat3 (tooldir_base_prefix, spec_machine, tooldir_prefix = concat (tooldir_base_prefix, spec_machine,
dir_separator_str); dir_separator_str, NULL_PTR);
/* If tooldir is relative, base it on exec_prefixes. A relative /* If tooldir is relative, base it on exec_prefixes. A relative
tooldir lets us move the installed tree as a unit. tooldir lets us move the installed tree as a unit.
...@@ -2794,29 +2689,29 @@ process_command (argc, argv) ...@@ -2794,29 +2689,29 @@ process_command (argc, argv)
if (gcc_exec_prefix) if (gcc_exec_prefix)
{ {
char *gcc_exec_tooldir_prefix char *gcc_exec_tooldir_prefix
= concat6 (gcc_exec_prefix, spec_machine, dir_separator_str, = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
spec_version, dir_separator_str, tooldir_prefix); spec_version, dir_separator_str, tooldir_prefix, NULL_PTR);
add_prefix (&exec_prefixes, add_prefix (&exec_prefixes,
concat3 (gcc_exec_tooldir_prefix, "bin", concat (gcc_exec_tooldir_prefix, "bin",
dir_separator_str), dir_separator_str, NULL_PTR),
0, 0, NULL_PTR); 0, 0, NULL_PTR);
add_prefix (&startfile_prefixes, add_prefix (&startfile_prefixes,
concat3 (gcc_exec_tooldir_prefix, "lib", concat (gcc_exec_tooldir_prefix, "lib",
dir_separator_str), dir_separator_str, NULL_PTR),
0, 0, NULL_PTR); 0, 0, NULL_PTR);
} }
tooldir_prefix = concat6 (standard_exec_prefix, spec_machine, tooldir_prefix = concat (standard_exec_prefix, spec_machine,
dir_separator_str, spec_version, dir_separator_str, spec_version,
dir_separator_str, tooldir_prefix); dir_separator_str, tooldir_prefix, NULL_PTR);
} }
add_prefix (&exec_prefixes, add_prefix (&exec_prefixes,
concat3 (tooldir_prefix, "bin", dir_separator_str), concat (tooldir_prefix, "bin", dir_separator_str, NULL_PTR),
0, 0, NULL_PTR); 0, 0, NULL_PTR);
add_prefix (&startfile_prefixes, add_prefix (&startfile_prefixes,
concat3 (tooldir_prefix, "lib", dir_separator_str), concat (tooldir_prefix, "lib", dir_separator_str, NULL_PTR),
0, 0, NULL_PTR); 0, 0, NULL_PTR);
/* More prefixes are enabled in main, after we read the specs file /* More prefixes are enabled in main, after we read the specs file
...@@ -3376,7 +3271,8 @@ do_spec_1 (spec, inswitch, soft_matched_part) ...@@ -3376,7 +3271,8 @@ do_spec_1 (spec, inswitch, soft_matched_part)
t->length = p - suffix; t->length = p - suffix;
t->suffix = save_string (suffix, p - suffix); t->suffix = save_string (suffix, p - suffix);
t->unique = (c != 'g'); t->unique = (c != 'g');
choose_temp_base (); temp_filename = choose_temp_base ();
temp_filename_length = strlen (temp_filename);
t->filename = temp_filename; t->filename = temp_filename;
t->filename_length = temp_filename_length; t->filename_length = temp_filename_length;
} }
...@@ -4245,12 +4141,12 @@ is_directory (path1, path2, linker) ...@@ -4245,12 +4141,12 @@ is_directory (path1, path2, linker)
/* Exclude directories that the linker is known to search. */ /* Exclude directories that the linker is known to search. */
if (linker if (linker
&& ((cp - path == 6 && ((cp - path == 6
&& strcmp (path, concat4 (dir_separator_str, "lib", && strcmp (path, concat (dir_separator_str, "lib",
dir_separator_str, ".")) == 0) dir_separator_str, ".", NULL_PTR)) == 0)
|| (cp - path == 10 || (cp - path == 10
&& strcmp (path, concat6 (dir_separator_str, "usr", && strcmp (path, concat (dir_separator_str, "usr",
dir_separator_str, "lib", dir_separator_str, "lib",
dir_separator_str, ".")) == 0))) dir_separator_str, ".", NULL_PTR)) == 0)))
return 0; return 0;
return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode)); return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
...@@ -4320,7 +4216,8 @@ main (argc, argv) ...@@ -4320,7 +4216,8 @@ main (argc, argv)
/* Choose directory for temp files. */ /* Choose directory for temp files. */
choose_temp_base (); temp_filename = choose_temp_base ();
temp_filename_length = strlen (temp_filename);
/* Make a table of what switches there are (switches, n_switches). /* Make a table of what switches there are (switches, n_switches).
Make a table of specified input files (infiles, n_infiles). Make a table of specified input files (infiles, n_infiles).
...@@ -4338,9 +4235,9 @@ main (argc, argv) ...@@ -4338,9 +4235,9 @@ main (argc, argv)
/* Read specs from a file if there is one. */ /* Read specs from a file if there is one. */
machine_suffix = concat4 (spec_machine, dir_separator_str, machine_suffix = concat (spec_machine, dir_separator_str,
spec_version, dir_separator_str); spec_version, dir_separator_str, NULL_PTR);
just_machine_suffix = concat (spec_machine, dir_separator_str); just_machine_suffix = concat (spec_machine, dir_separator_str, NULL_PTR);
specs_file = find_a_file (&startfile_prefixes, "specs", R_OK); specs_file = find_a_file (&startfile_prefixes, "specs", R_OK);
/* Read the specs file unless it is a default one. */ /* Read the specs file unless it is a default one. */
...@@ -4387,13 +4284,13 @@ main (argc, argv) ...@@ -4387,13 +4284,13 @@ main (argc, argv)
{ {
if (gcc_exec_prefix) if (gcc_exec_prefix)
add_prefix (&startfile_prefixes, add_prefix (&startfile_prefixes,
concat3 (gcc_exec_prefix, machine_suffix, concat (gcc_exec_prefix, machine_suffix,
standard_startfile_prefix), standard_startfile_prefix, NULL_PTR),
0, 0, NULL_PTR); 0, 0, NULL_PTR);
add_prefix (&startfile_prefixes, add_prefix (&startfile_prefixes,
concat3 (standard_exec_prefix, concat (standard_exec_prefix,
machine_suffix, machine_suffix,
standard_startfile_prefix), standard_startfile_prefix, NULL_PTR),
0, 0, NULL_PTR); 0, 0, NULL_PTR);
} }
...@@ -4409,8 +4306,8 @@ main (argc, argv) ...@@ -4409,8 +4306,8 @@ main (argc, argv)
{ {
if (*standard_startfile_prefix != DIR_SEPARATOR && gcc_exec_prefix) if (*standard_startfile_prefix != DIR_SEPARATOR && gcc_exec_prefix)
add_prefix (&startfile_prefixes, add_prefix (&startfile_prefixes,
concat3 (gcc_exec_prefix, machine_suffix, concat (gcc_exec_prefix, machine_suffix,
standard_startfile_prefix), standard_startfile_prefix, NULL_PTR),
0, 0, NULL_PTR); 0, 0, NULL_PTR);
} }
...@@ -4749,42 +4646,58 @@ xrealloc (ptr, size) ...@@ -4749,42 +4646,58 @@ xrealloc (ptr, size)
return value; return value;
} }
/* Return a newly-allocated string whose contents concatenate those of s1, s2 */ /* This function is based on the one in libiberty. */
static char * static char *
concat (s1, s2) concat VPROTO((char *first, ...))
char *s1, *s2;
{ {
int len1 = strlen (s1); register int length;
int len2 = strlen (s2); register char *newstr;
char *result = xmalloc (len1 + len2 + 1); register char *end;
register char *arg;
va_list args;
#ifndef __STDC__
char *first;
#endif
strcpy (result, s1); /* First compute the size of the result and get sufficient memory. */
strcpy (result + len1, s2);
*(result + len1 + len2) = 0;
return result; VA_START (args, first);
} #ifndef __STDC__
first = va_arg (args, char *);
#endif
static char * arg = first;
concat3 (s1, s2, s3) length = 0;
char *s1, *s2, *s3;
{
return concat (concat (s1, s2), s3);
}
static char * while (arg != 0)
concat4 (s1, s2, s3, s4) {
char *s1, *s2, *s3, *s4; length += strlen (arg);
{ arg = va_arg (args, char *);
return concat (concat (s1, s2), concat (s3, s4)); }
}
static char * newstr = (char *) xmalloc (length + 1);
concat6 (s1, s2, s3, s4, s5, s6) va_end (args);
char *s1, *s2, *s3, *s4, *s5, *s6;
{ /* Now copy the individual pieces to the result string. */
return concat3 (concat (s1, s2), concat (s3, s4), concat (s5, s6));
VA_START (args, first);
#ifndef __STDC__
first = va_arg (args, char *);
#endif
end = newstr;
arg = first;
while (arg != 0)
{
while (*arg)
*end++ = *arg++;
arg = va_arg (args, char *);
}
*end = '\000';
va_end (args);
return (newstr);
} }
static char * static char *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment