#ifdef WINDOWS32
#include <windows.h>
-char *default_shell = "sh.exe";
+const char *default_shell = "sh.exe";
int no_default_sh_exe = 1;
int batch_mode_shell = 1;
HANDLE main_thread;
#elif defined (_AMIGA)
-char default_shell[] = "";
+const char *default_shell = "";
extern int MyExecute (char **);
int batch_mode_shell = 0;
says so. It is without an explicit path so we get a chance
to search the $PATH for it (since MSDOS doesn't have standard
directories we could trust). */
-char *default_shell = "command.com";
+const char *default_shell = "command.com";
int batch_mode_shell = 0;
#elif defined (__EMX__)
-char *default_shell = "/bin/sh";
+const char *default_shell = "/bin/sh";
int batch_mode_shell = 0;
#elif defined (VMS)
# include <descrip.h>
-char default_shell[] = "";
+const char *default_shell = "";
int batch_mode_shell = 0;
#elif defined (__riscos__)
-char default_shell[] = "";
+const char *default_shell = "";
int batch_mode_shell = 0;
#else
-char default_shell[] = "/bin/sh";
+const char *default_shell = "/bin/sh";
int batch_mode_shell = 0;
#endif
{
/* The file is not executable. Try it as a shell script. */
extern char *getenv ();
- char *shell;
+ const char *shell;
char **new_argv;
int argc;
int i=1;
# endif
new_argv = alloca ((1 + argc + 1) * sizeof (char *));
- new_argv[0] = shell;
+ new_argv[0] = (char *)shell;
# ifdef __EMX__
if (!unixy_shell)
#endif /* !VMS */
}
#else /* On Amiga */
-void exec_command (char **argv)
+void
+exec_command (char **argv)
{
MyExecute (argv);
}
avoid using a shell. This routine handles only ' quoting, and " quoting
when no backslash, $ or ' characters are seen in the quotes. Starting
quotes may be escaped with a backslash. If any of the characters in
- sh_chars[] is seen, or any of the builtin commands listed in sh_cmds[]
+ sh_chars is seen, or any of the builtin commands listed in sh_cmds
is the first word of a line, the shell is used.
If RESTP is not NULL, *RESTP is set to point to the first newline in LINE.
is overridden. */
static char **
-construct_command_argv_internal (char *line, char **restp, char *shell,
- char *shellflags, char *ifs, int flags,
- char **batch_filename UNUSED)
+construct_command_argv_internal (char *line, char **restp, const char *shell,
+ const char *shellflags, const char *ifs,
+ int flags, char **batch_filename UNUSED)
{
#ifdef __MSDOS__
/* MSDOS supports both the stock DOS shell and ports of Unixy shells.
DOS_CHARS also include characters special to 4DOS/NDOS, so we
won't have to tell one from another and have one more set of
commands and special characters. */
- static char sh_chars_dos[] = "*?[];|<>%^&()";
- static char *sh_cmds_dos[] = { "break", "call", "cd", "chcp", "chdir", "cls",
- "copy", "ctty", "date", "del", "dir", "echo",
- "erase", "exit", "for", "goto", "if", "md",
- "mkdir", "path", "pause", "prompt", "rd",
- "rmdir", "rem", "ren", "rename", "set",
- "shift", "time", "type", "ver", "verify",
- "vol", ":", 0 };
-
- static char sh_chars_sh[] = "#;\"*?[]&|<>(){}$`^";
- static char *sh_cmds_sh[] = { "cd", "echo", "eval", "exec", "exit", "login",
- "logout", "set", "umask", "wait", "while",
- "for", "case", "if", ":", ".", "break",
- "continue", "export", "read", "readonly",
- "shift", "times", "trap", "switch", "unset",
- "ulimit", 0 };
-
- char *sh_chars;
- char **sh_cmds;
+ static const char *sh_chars_dos = "*?[];|<>%^&()";
+ static const char *sh_cmds_dos[] =
+ { "break", "call", "cd", "chcp", "chdir", "cls", "copy", "ctty", "date",
+ "del", "dir", "echo", "erase", "exit", "for", "goto", "if", "md",
+ "mkdir", "path", "pause", "prompt", "rd", "rmdir", "rem", "ren",
+ "rename", "set", "shift", "time", "type", "ver", "verify", "vol", ":",
+ 0 };
+
+ static const char *sh_chars_sh = "#;\"*?[]&|<>(){}$`^";
+ static const char *sh_cmds_sh[] =
+ { "cd", "echo", "eval", "exec", "exit", "login", "logout", "set", "umask",
+ "wait", "while", "for", "case", "if", ":", ".", "break", "continue",
+ "export", "read", "readonly", "shift", "times", "trap", "switch",
+ "unset", "ulimit", 0 };
+
+ const char *sh_chars;
+ const char **sh_cmds;
+
#elif defined (__EMX__)
- static char sh_chars_dos[] = "*?[];|<>%^&()";
- static char *sh_cmds_dos[] = { "break", "call", "cd", "chcp", "chdir", "cls",
- "copy", "ctty", "date", "del", "dir", "echo",
- "erase", "exit", "for", "goto", "if", "md",
- "mkdir", "path", "pause", "prompt", "rd",
- "rmdir", "rem", "ren", "rename", "set",
- "shift", "time", "type", "ver", "verify",
- "vol", ":", 0 };
-
- static char sh_chars_os2[] = "*?[];|<>%^()\"'&";
- static char *sh_cmds_os2[] = { "call", "cd", "chcp", "chdir", "cls", "copy",
- "date", "del", "detach", "dir", "echo",
- "endlocal", "erase", "exit", "for", "goto", "if",
- "keys", "md", "mkdir", "move", "path", "pause",
- "prompt", "rd", "rem", "ren", "rename", "rmdir",
- "set", "setlocal", "shift", "start", "time",
- "type", "ver", "verify", "vol", ":", 0 };
-
- static char sh_chars_sh[] = "#;\"*?[]&|<>(){}$`^~'";
- static char *sh_cmds_sh[] = { "echo", "cd", "eval", "exec", "exit", "login",
- "logout", "set", "umask", "wait", "while",
- "for", "case", "if", ":", ".", "break",
- "continue", "export", "read", "readonly",
- "shift", "times", "trap", "switch", "unset",
- 0 };
- char *sh_chars;
- char **sh_cmds;
+ static const char *sh_chars_dos = "*?[];|<>%^&()";
+ static const char *sh_cmds_dos[] =
+ { "break", "call", "cd", "chcp", "chdir", "cls", "copy", "ctty", "date",
+ "del", "dir", "echo", "erase", "exit", "for", "goto", "if", "md",
+ "mkdir", "path", "pause", "prompt", "rd", "rmdir", "rem", "ren",
+ "rename", "set", "shift", "time", "type", "ver", "verify", "vol", ":",
+ 0 };
+
+ static const char *sh_chars_os2 = "*?[];|<>%^()\"'&";
+ static const char *sh_cmds_os2[] =
+ { "call", "cd", "chcp", "chdir", "cls", "copy", "date", "del", "detach",
+ "dir", "echo", "endlocal", "erase", "exit", "for", "goto", "if", "keys",
+ "md", "mkdir", "move", "path", "pause", "prompt", "rd", "rem", "ren",
+ "rename", "rmdir", "set", "setlocal", "shift", "start", "time", "type",
+ "ver", "verify", "vol", ":", 0 };
+
+ static const char *sh_chars_sh = "#;\"*?[]&|<>(){}$`^~'";
+ static const char *sh_cmds_sh[] =
+ { "echo", "cd", "eval", "exec", "exit", "login", "logout", "set", "umask",
+ "wait", "while", "for", "case", "if", ":", ".", "break", "continue",
+ "export", "read", "readonly", "shift", "times", "trap", "switch",
+ "unset", 0 };
+
+ const char *sh_chars;
+ const char **sh_cmds;
#elif defined (_AMIGA)
- static char sh_chars[] = "#;\"|<>()?*$`";
- static char *sh_cmds[] = { "cd", "eval", "if", "delete", "echo", "copy",
- "rename", "set", "setenv", "date", "makedir",
- "skip", "else", "endif", "path", "prompt",
- "unset", "unsetenv", "version",
- 0 };
+ static const char *sh_chars = "#;\"|<>()?*$`";
+ static const char *sh_cmds[] =
+ { "cd", "eval", "if", "delete", "echo", "copy", "rename", "set", "setenv",
+ "date", "makedir", "skip", "else", "endif", "path", "prompt", "unset",
+ "unsetenv", "version", 0 };
+
#elif defined (WINDOWS32)
/* We used to have a double quote (") in sh_chars_dos[] below, but
that caused any command line with quoted file names be run
can handle quoted file names just fine, removing the quote lifts
the limit from a very frequent use case, because using quoted
file names is commonplace on MS-Windows. */
- static char sh_chars_dos[] = "|&<>";
- static char *sh_cmds_dos[] = { "assoc", "break", "call", "cd", "chcp",
- "chdir", "cls", "color", "copy", "ctty",
- "date", "del", "dir", "echo", "echo.",
- "endlocal", "erase", "exit", "for", "ftype",
- "goto", "if", "if", "md", "mkdir", "move",
- "path", "pause", "prompt", "rd", "rem", "ren",
- "rename", "rmdir", "set", "setlocal",
- "shift", "time", "title", "type", "ver",
- "verify", "vol", ":", 0 };
- static char sh_chars_sh[] = "#;\"*?[]&|<>(){}$`^";
- static char *sh_cmds_sh[] = { "cd", "eval", "exec", "exit", "login",
- "logout", "set", "umask", "wait", "while", "for",
- "case", "if", ":", ".", "break", "continue",
- "export", "read", "readonly", "shift", "times",
- "trap", "switch", "test",
+ static const char *sh_chars_dos = "|&<>";
+ static const char *sh_cmds_dos[] =
+ { "assoc", "break", "call", "cd", "chcp", "chdir", "cls", "color", "copy",
+ "ctty", "date", "del", "dir", "echo", "echo.", "endlocal", "erase",
+ "exit", "for", "ftype", "goto", "if", "if", "md", "mkdir", "move",
+ "path", "pause", "prompt", "rd", "rem", "ren", "rename", "rmdir",
+ "set", "setlocal", "shift", "time", "title", "type", "ver", "verify",
+ "vol", ":", 0 };
+
+ static const char *sh_chars_sh = "#;\"*?[]&|<>(){}$`^";
+ static const char *sh_cmds_sh[] =
+ { "cd", "eval", "exec", "exit", "login", "logout", "set", "umask", "wait",
+ "while", "for", "case", "if", ":", ".", "break", "continue", "export",
+ "read", "readonly", "shift", "times", "trap", "switch", "test",
#ifdef BATCH_MODE_ONLY_SHELL
- "echo",
+ "echo",
#endif
- 0 };
- char* sh_chars;
- char** sh_cmds;
+ 0 };
+
+ const char *sh_chars;
+ const char **sh_cmds;
#elif defined(__riscos__)
- static char sh_chars[] = "";
- static char *sh_cmds[] = { 0 };
+ static const char *sh_chars = "";
+ static const char *sh_cmds[] = { 0 };
#else /* must be UNIX-ish */
- static char sh_chars[] = "#;\"*?[]&|<>(){}$`^~!";
- static char *sh_cmds[] = { ".", ":", "break", "case", "cd", "continue",
- "eval", "exec", "exit", "export", "for", "if",
- "login", "logout", "read", "readonly", "set",
- "shift", "switch", "test", "times", "trap",
- "ulimit", "umask", "unset", "wait", "while", 0 };
+ static const char *sh_chars = "#;\"*?[]&|<>(){}$`^~!";
+ static const char *sh_cmds[] =
+ { ".", ":", "break", "case", "cd", "continue", "eval", "exec", "exit",
+ "export", "for", "if", "login", "logout", "read", "readonly", "set",
+ "shift", "switch", "test", "times", "trap", "ulimit", "umask", "unset",
+ "wait", "while", 0 };
+
# ifdef HAVE_DOS_PATHS
/* This is required if the MSYS/Cygwin ports (which do not define
WINDOWS32) are compiled with HAVE_DOS_PATHS defined, which uses
- sh_chars_sh[] directly (see below). */
- static char *sh_chars_sh = sh_chars;
+ sh_chars_sh directly (see below). */
+ static const char *sh_chars_sh = sh_chars;
# endif /* HAVE_DOS_PATHS */
#endif
int i;
char *p;
- char *ap;
char *end;
+ char *ap;
+ const char *cap;
+ const char *cp;
int instring, word_has_equals, seen_nonequals, last_argument_was_empty;
char **new_argv = 0;
char *argstr = 0;
#endif /* !__MSDOS__ && !__EMX__ */
#endif /* not WINDOWS32 */
- if (ifs != 0)
- for (ap = ifs; *ap != '\0'; ++ap)
- if (*ap != ' ' && *ap != '\t' && *ap != '\n')
+ if (ifs)
+ for (cap = ifs; *cap != '\0'; ++cap)
+ if (*cap != ' ' && *cap != '\t' && *cap != '\n')
goto slow;
- if (shellflags != 0)
+ if (shellflags)
if (shellflags[0] != '-'
|| ((shellflags[1] != 'c' || shellflags[2] != '\0')
&& (shellflags[1] != 'e' || shellflags[2] != 'c' || shellflags[3] != '\0')))
we don't escape them, construct_command_argv_internal will
recursively call itself ad nauseam, or until stack overflow,
whichever happens first. */
- for (p = shell; *p != '\0'; ++p)
+ for (cp = shell; *cp != '\0'; ++cp)
{
- if (strchr (sh_chars, *p) != 0)
+ if (strchr (sh_chars, *cp) != 0)
*(ap++) = '\\';
- *(ap++) = *p;
+ *(ap++) = *cp;
}
*(ap++) = ' ';
if (shellflags)
avoid using a shell. This routine handles only ' quoting, and " quoting
when no backslash, $ or ' characters are seen in the quotes. Starting
quotes may be escaped with a backslash. If any of the characters in
- sh_chars[] is seen, or any of the builtin commands listed in sh_cmds[]
+ sh_chars is seen, or any of the builtin commands listed in sh_cmds
is the first word of a line, the shell is used.
If RESTP is not NULL, *RESTP is set to point to the first newline in LINE.
static void clean_jobserver (int status);
static void print_data_base (void);
static void print_version (void);
-static void decode_switches (int argc, char **argv, int env);
-static void decode_env_switches (char *envar, unsigned int len);
+static void decode_switches (int argc, const char **argv, int env);
+static void decode_env_switches (const char *envar, unsigned int len);
static struct variable *define_makeflags (int all, int makefile);
static char *quote_for_env (char *out, const char *in);
static void initialize_global_hash_tables (void);
const void *noarg_value; /* Pointer to value used if no arg given. */
const void *default_value; /* Pointer to default value. */
- char *long_name; /* Long option name. */
+ const char *long_name; /* Long option name. */
};
/* True if C is a switch value that corresponds to a short option. */
\f
/* The name we were invoked with. */
-char *program;
+const char *program;
/* Our current directory before processing any -C options. */
}
static const char *
-expand_command_line_file (char *name)
+expand_command_line_file (const char *name)
{
const char *cp;
char *expanded = 0;
if (name[0] == '~')
{
expanded = tilde_expand (name);
- if (expanded != 0)
+ if (expanded && expanded[0] != '\0')
name = expanded;
}
/* This is also done in parse_file_seq, so this is redundant
for names read from makefiles. It is here for names passed
on the command line. */
- while (name[0] == '.' && name[1] == '/' && name[2] != '\0')
+ while (name[0] == '.' && name[1] == '/')
{
name += 2;
- while (*name == '/')
+ while (name[0] == '/')
/* Skip following slashes: ".//foo" is "foo", not "/foo". */
++name;
}
- if (*name == '\0')
+ if (name[0] == '\0')
{
- /* It was all slashes! Move back to the dot and truncate
- it after the first slash, so it becomes just "./". */
- do
- --name;
- while (name[0] != '.');
- name[2] = '\0';
+ /* Nothing else but one or more "./", maybe plus slashes! */
+ name = "./";
}
cp = strcache_add (name);
- if (expanded)
- free (expanded);
+ free (expanded);
return cp;
}
{
int sh_found = 0;
char *atoken = 0;
- char *search_token;
+ const char *search_token;
char *tokend;
PATH_VAR(sh_path);
- extern char *default_shell;
+ extern const char *default_shell;
if (!token)
search_token = default_shell;
else
- atoken = search_token = xstrdup (token);
+ search_token = atoken = xstrdup (token);
/* If the user explicitly requests the DOS cmd shell, obey that request.
However, make sure that's what they really want by requiring the value
/* Figure out where this program lives. */
if (argv[0] == 0)
- argv[0] = "";
+ argv[0] = (char *)"";
if (argv[0][0] == '\0')
program = "make";
else
for (i = 0; envp[i] != 0; ++i)
{
struct variable *v;
- char *ep = envp[i];
+ const char *ep = envp[i];
/* By default, export all variables culled from the environment. */
enum variable_export export = v_export;
unsigned int len;
#ifndef __MSDOS__
export = v_noexport;
#endif
- shell_var.name = "SHELL";
+ shell_var.name = xstrdup ("SHELL");
shell_var.length = 5;
shell_var.value = xstrdup (ep);
}
decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS"));
#endif
- decode_switches (argc, argv, 0);
+ decode_switches (argc, (const char **)argv, 0);
/* Reset in case the switches changed our minds. */
syncing = (output_sync == OUTPUT_SYNC_LINE
and thus re-read the makefiles, we read standard input
into a temporary file and read from that. */
FILE *outfile;
- char *template, *tmpdir;
+ char *template;
+ const char *tmpdir;
if (stdin_nm)
O (fatal, NILF,
extern int _is_unixy_shell (const char *_path);
struct variable *shv = lookup_variable (STRING_SIZE_TUPLE ("SHELL"));
extern int unixy_shell;
- extern char *default_shell;
+ extern const char *default_shell;
if (shv && *shv->value)
{
FILE_TIMESTAMP *makefile_mtimes = 0;
unsigned int mm_idx = 0;
- char **nargv;
+ char **aargv = NULL;
+ const char **nargv;
int nargc;
int orig_db_level = db_level;
enum update_status status;
nargc = argc;
if (stdin_nm)
{
- nargv = xmalloc ((nargc + 2) * sizeof (char *));
- memcpy (nargv, argv, argc * sizeof (char *));
- nargv[nargc++] = xstrdup (concat (2, "-o", stdin_nm));
- nargv[nargc] = 0;
+ void *m = xmalloc ((nargc + 2) * sizeof (char *));
+ aargv = m;
+ memcpy (aargv, argv, argc * sizeof (char *));
+ aargv[nargc++] = xstrdup (concat (2, "-o", stdin_nm));
+ aargv[nargc] = 0;
+ nargv = m;
}
else
- nargv = argv;
+ nargv = (const char**)argv;
if (directories != 0 && directories->idx > 0)
{
if (ISDB (DB_BASIC))
{
- char **p;
+ const char **p;
printf (_("Re-executing[%u]:"), restarts);
for (p = nargv; *p != 0; ++p)
printf (" %s", *p);
exit (WIFEXITED(r) ? WEXITSTATUS(r) : EXIT_FAILURE);
}
#else
- exec_command (nargv, environ);
+ exec_command ((char **)nargv, environ);
#endif
+ free (aargv);
+ break;
}
db_level = orig_db_level;
/* Non-option argument. It might be a variable definition. */
static void
-handle_non_switch_argument (char *arg, int env)
+handle_non_switch_argument (const char *arg, int env)
{
struct variable *v;
They came from the environment if ENV is nonzero. */
static void
-decode_switches (int argc, char **argv, int env)
+decode_switches (int argc, const char **argv, int env)
{
int bad = 0;
register const struct command_switch *cs;
while (optind < argc)
{
+ const char *coptarg;
+
/* Parse the next argument. */
- c = getopt_long (argc, argv, options, long_options, (int *) 0);
+ c = getopt_long (argc, (char*const*)argv, options, long_options, NULL);
+ coptarg = optarg;
if (c == EOF)
/* End of arguments, or "--" marker seen. */
break;
else if (c == 1)
/* An argument not starting with a dash. */
- handle_non_switch_argument (optarg, env);
+ handle_non_switch_argument (coptarg, env);
else if (c == '?')
/* Bad option. We will print a usage message and die later.
But continue to parse the other options so the user can
if (!doit)
break;
- if (optarg == 0)
- optarg = xstrdup (cs->noarg_value);
- else if (*optarg == '\0')
+ if (! coptarg)
+ coptarg = xstrdup (cs->noarg_value);
+ else if (*coptarg == '\0')
{
char opt[2] = "c";
const char *op = opt;
char **val = (char **)cs->value_ptr;
if (*val)
free (*val);
- *val = xstrdup (optarg);
+ *val = xstrdup (coptarg);
break;
}
sl->max * sizeof (char *));
}
if (cs->type == filename)
- sl->list[sl->idx++] = expand_command_line_file (optarg);
+ sl->list[sl->idx++] = expand_command_line_file (coptarg);
else
- sl->list[sl->idx++] = xstrdup (optarg);
+ sl->list[sl->idx++] = xstrdup (coptarg);
sl->list[sl->idx] = 0;
break;
case positive_int:
/* See if we have an option argument; if we do require that
it's all digits, not something like "10foo". */
- if (optarg == 0 && argc > optind)
+ if (coptarg == 0 && argc > optind)
{
const char *cp;
for (cp=argv[optind]; ISDIGIT (cp[0]); ++cp)
;
if (cp[0] == '\0')
- optarg = argv[optind++];
+ coptarg = argv[optind++];
}
if (!doit)
break;
- if (optarg != 0)
+ if (coptarg)
{
- int i = atoi (optarg);
+ int i = atoi (coptarg);
const char *cp;
/* Yes, I realize we're repeating this in some cases. */
- for (cp = optarg; ISDIGIT (cp[0]); ++cp)
+ for (cp = coptarg; ISDIGIT (cp[0]); ++cp)
;
if (i < 1 || cp[0] != '\0')
#ifndef NO_FLOAT
case floating:
- if (optarg == 0 && optind < argc
+ if (coptarg == 0 && optind < argc
&& (ISDIGIT (argv[optind][0]) || argv[optind][0] == '.'))
- optarg = argv[optind++];
+ coptarg = argv[optind++];
if (doit)
*(double *) cs->value_ptr
- = (optarg != 0 ? atof (optarg)
+ = (coptarg != 0 ? atof (coptarg)
: *(double *) cs->noarg_value);
break;
decode_switches. */
static void
-decode_env_switches (char *envar, unsigned int len)
+decode_env_switches (const char *envar, unsigned int len)
{
char *varref = alloca (2 + len + 2);
char *value, *p, *buf;
int argc;
- char **argv;
+ const char **argv;
/* Get the variable's value. */
varref[0] = '$';
{
static int printed_version = 0;
- char *precede = print_data_base_flag ? "# " : "";
+ const char *precede = print_data_base_flag ? "# " : "";
if (printed_version)
/* Do it only once. */