From ac67346d0fb5e5ea359d34c2c9215bd1892455f3 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Fri, 25 Apr 2014 17:10:47 -0400 Subject: * maintMakefile, various: Improve constification of the codebase. --- default.c | 10 +-- job.c | 210 +++++++++++++++++++++++++++++----------------------------- main.c | 114 ++++++++++++++++--------------- maintMakefile | 2 +- makeint.h | 2 +- read.c | 6 +- remake.c | 4 +- rule.c | 4 +- rule.h | 2 +- variable.c | 24 +++---- variable.h | 4 +- version.c | 4 +- 12 files changed, 193 insertions(+), 193 deletions(-) diff --git a/default.c b/default.c index d6c08a5..48b899d 100644 --- a/default.c +++ b/default.c @@ -108,7 +108,7 @@ static struct pspec default_terminal_rules[] = { 0, 0, 0 } }; -static char *default_suffix_rules[] = +static const char *default_suffix_rules[] = { #ifdef VMS ".obj.exe", @@ -548,8 +548,8 @@ set_default_suffixes (void) else { struct dep *d; - char *p = default_suffixes; - suffix_file->deps = enter_prereqs (PARSE_SIMPLE_SEQ (&p, struct dep), + const char *p = default_suffixes; + suffix_file->deps = enter_prereqs (PARSE_SIMPLE_SEQ ((char **)&p, struct dep), NULL); for (d = suffix_file->deps; d; d = d->next) d->file->builtin = 1; @@ -566,7 +566,7 @@ set_default_suffixes (void) void install_default_suffix_rules (void) { - char **s; + const char **s; if (no_builtin_rules_flag) return; @@ -578,7 +578,7 @@ install_default_suffix_rules (void) assert (f->cmds == 0); f->cmds = xmalloc (sizeof (struct commands)); f->cmds->fileinfo.filenm = 0; - f->cmds->commands = s[1]; + f->cmds->commands = xstrdup (s[1]); f->cmds->command_lines = 0; f->cmds->recipe_prefix = RECIPEPREFIX_DEFAULT; f->builtin = 1; diff --git a/job.c b/job.c index e4a40ac..1850fe1 100644 --- a/job.c +++ b/job.c @@ -31,14 +31,14 @@ this program. If not, see . */ #ifdef WINDOWS32 #include -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; @@ -48,28 +48,28 @@ 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 -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 @@ -2428,7 +2428,7 @@ exec_command (char **argv, char **envp) { /* 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; @@ -2456,7 +2456,7 @@ exec_command (char **argv, char **envp) # endif new_argv = alloca ((1 + argc + 1) * sizeof (char *)); - new_argv[0] = shell; + new_argv[0] = (char *)shell; # ifdef __EMX__ if (!unixy_shell) @@ -2509,7 +2509,8 @@ exec_command (char **argv, char **envp) #endif /* !VMS */ } #else /* On Amiga */ -void exec_command (char **argv) +void +exec_command (char **argv) { MyExecute (argv); } @@ -2526,7 +2527,7 @@ void clean_tmp (void) 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. @@ -2541,9 +2542,9 @@ void clean_tmp (void) 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. @@ -2568,61 +2569,58 @@ construct_command_argv_internal (char *line, char **restp, char *shell, 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 @@ -2631,49 +2629,51 @@ construct_command_argv_internal (char *line, char **restp, char *shell, 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; @@ -2758,12 +2758,12 @@ construct_command_argv_internal (char *line, char **restp, char *shell, #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'))) @@ -3251,11 +3251,11 @@ construct_command_argv_internal (char *line, char **restp, char *shell, 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) @@ -3480,7 +3480,7 @@ construct_command_argv_internal (char *line, char **restp, char *shell, 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. diff --git a/main.c b/main.c index 3a3d016..4659099 100644 --- a/main.c +++ b/main.c @@ -77,8 +77,8 @@ double atof (); 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); @@ -111,7 +111,7 @@ struct command_switch 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. */ @@ -480,7 +480,7 @@ static struct command_variable *command_variables; /* The name we were invoked with. */ -char *program; +const char *program; /* Our current directory before processing any -C options. */ @@ -639,7 +639,7 @@ initialize_stopchar_map () } static const char * -expand_command_line_file (char *name) +expand_command_line_file (const char *name) { const char *cp; char *expanded = 0; @@ -650,35 +650,30 @@ expand_command_line_file (char *name) 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; } @@ -888,15 +883,15 @@ find_and_set_default_shell (const char *token) { 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 @@ -1156,7 +1151,7 @@ main (int argc, char **argv, char **envp) /* Figure out where this program lives. */ if (argv[0] == 0) - argv[0] = ""; + argv[0] = (char *)""; if (argv[0][0] == '\0') program = "make"; else @@ -1278,7 +1273,7 @@ main (int argc, char **argv, char **envp) 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; @@ -1327,7 +1322,7 @@ main (int argc, char **argv, char **envp) #ifndef __MSDOS__ export = v_noexport; #endif - shell_var.name = "SHELL"; + shell_var.name = xstrdup ("SHELL"); shell_var.length = 5; shell_var.value = xstrdup (ep); } @@ -1396,7 +1391,7 @@ main (int argc, char **argv, char **envp) 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 @@ -1718,7 +1713,8 @@ main (int argc, char **argv, char **envp) 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, @@ -1889,7 +1885,7 @@ main (int argc, char **argv, char **envp) 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) { @@ -2104,7 +2100,8 @@ main (int argc, char **argv, char **envp) 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; @@ -2287,13 +2284,15 @@ main (int argc, char **argv, char **envp) 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) { @@ -2319,7 +2318,7 @@ main (int argc, char **argv, char **envp) if (ISDB (DB_BASIC)) { - char **p; + const char **p; printf (_("Re-executing[%u]:"), restarts); for (p = nargv; *p != 0; ++p) printf (" %s", *p); @@ -2398,8 +2397,10 @@ main (int argc, char **argv, char **envp) 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; @@ -2597,7 +2598,7 @@ init_switches (void) /* 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; @@ -2704,7 +2705,7 @@ print_usage (int bad) 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; @@ -2724,14 +2725,17 @@ decode_switches (int argc, char **argv, int env) 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 @@ -2767,9 +2771,9 @@ decode_switches (int argc, char **argv, int env) 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; @@ -2791,7 +2795,7 @@ decode_switches (int argc, char **argv, int env) char **val = (char **)cs->value_ptr; if (*val) free (*val); - *val = xstrdup (optarg); + *val = xstrdup (coptarg); break; } @@ -2812,34 +2816,34 @@ decode_switches (int argc, char **argv, int env) 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') @@ -2859,13 +2863,13 @@ decode_switches (int argc, char **argv, int env) #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; @@ -2901,12 +2905,12 @@ decode_switches (int argc, char **argv, int env) 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] = '$'; @@ -3234,7 +3238,7 @@ print_version (void) { 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. */ diff --git a/maintMakefile b/maintMakefile index cacab4c..69cb586 100644 --- a/maintMakefile +++ b/maintMakefile @@ -20,7 +20,7 @@ GNUWEBDIR ?= $(SRCROOTDIR)/gnu-www MAKEWEBDIR ?= $(SRCROOTDIR)/make/make-web # We like mondo-warnings! -AM_CFLAGS += -Wall -Wextra -Wdeclaration-after-statement -Wshadow -Wpointer-arith -Wbad-function-cast +AM_CFLAGS += -Wall -Wwrite-strings -Wextra -Wdeclaration-after-statement -Wshadow -Wpointer-arith -Wbad-function-cast MAKE_MAINTAINER_MODE := -DMAKE_MAINTAINER_MODE AM_CPPFLAGS += $(MAKE_MAINTAINER_MODE) diff --git a/makeint.h b/makeint.h index 7c695f5..45e63cb 100644 --- a/makeint.h +++ b/makeint.h @@ -609,7 +609,7 @@ extern double max_load_average; extern int max_load_average; #endif -extern char *program; +extern const char *program; extern char *starting_directory; extern unsigned int makelevel; extern char *version_string, *remote_description, *make_host; diff --git a/read.c b/read.c index b408c24..efacaf5 100644 --- a/read.c +++ b/read.c @@ -238,7 +238,7 @@ read_all_makefiles (const char **makefiles) if (num_makefiles == 0) { - static char *default_makefiles[] = + static const char *default_makefiles[] = #ifdef VMS /* all lower case since readdir() (the vms version) 'lowercasifies' */ { "makefile.vms", "gnumakefile.", "makefile.", 0 }; @@ -249,7 +249,7 @@ read_all_makefiles (const char **makefiles) { "GNUmakefile", "makefile", "Makefile", 0 }; #endif /* AMIGA */ #endif /* VMS */ - register char **p = default_makefiles; + const char **p = default_makefiles; while (*p != 0 && !file_exists_p (*p)) ++p; @@ -1572,7 +1572,7 @@ do_define (char *name, enum variable_origin origin, struct ebuffer *ebuf) static int conditional_line (char *line, int len, const gmk_floc *flocp) { - char *cmdname; + const char *cmdname; enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq, c_else, c_endif } cmdtype; unsigned int i; unsigned int o; diff --git a/remake.c b/remake.c index 01e83a7..acf7ca5 100644 --- a/remake.c +++ b/remake.c @@ -1546,7 +1546,7 @@ name_mtime (const char *name) static const char * library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr) { - static char *dirs[] = + static const char *dirs[] = { #ifndef _AMIGA "/lib", @@ -1576,7 +1576,7 @@ library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr) /* Information about the earliest (in the vpath sequence) match. */ unsigned int best_vpath = 0, best_path = 0; - char **dp; + const char **dp; libpatterns = xstrdup (variable_expand ("$(.LIBPATTERNS)")); diff --git a/rule.c b/rule.c index e5716c5..986ada7 100644 --- a/rule.c +++ b/rule.c @@ -357,7 +357,7 @@ void install_pattern_rule (struct pspec *p, int terminal) { struct rule *r; - char *ptr; + const char *ptr; r = xmalloc (sizeof (struct rule)); @@ -373,7 +373,7 @@ install_pattern_rule (struct pspec *p, int terminal) ++r->suffixes[0]; ptr = p->dep; - r->deps = PARSE_SIMPLE_SEQ (&ptr, struct dep); + r->deps = PARSE_SIMPLE_SEQ ((char **)&ptr, struct dep); if (new_pattern_rule (r, 0)) { diff --git a/rule.h b/rule.h index 3982639..3c9b21f 100644 --- a/rule.h +++ b/rule.h @@ -33,7 +33,7 @@ struct rule /* For calling install_pattern_rule. */ struct pspec { - char *target, *dep, *commands; + const char *target, *dep, *commands; }; diff --git a/variable.c b/variable.c index a782305..4df8d8d 100644 --- a/variable.c +++ b/variable.c @@ -785,12 +785,8 @@ merge_variable_set_lists (struct variable_set_list **setlist0, void define_automatic_variables (void) { -#if defined(WINDOWS32) || defined(__EMX__) - extern char* default_shell; -#else - extern char default_shell[]; -#endif - register struct variable *v; + extern const char* default_shell; + struct variable *v; char buf[200]; sprintf (buf, "%u", makelevel); @@ -1045,7 +1041,7 @@ target_environment (struct file *file) } } - makelevel_key.name = MAKELEVEL_NAME; + makelevel_key.name = xstrdup (MAKELEVEL_NAME); makelevel_key.length = MAKELEVEL_LENGTH; hash_delete (&table, &makelevel_key); @@ -1328,7 +1324,7 @@ do_variable_definition (const gmk_floc *flocp, const char *varname, if ((origin == o_file || origin == o_override || origin == o_command) && streq (varname, "SHELL")) { - extern char *default_shell; + extern const char *default_shell; /* Call shell locator function. If it returns TRUE, then set no_default_sh_exe to indicate sh was found and @@ -1537,7 +1533,7 @@ parse_variable_definition (const char *p, struct variable *var) returned. */ struct variable * -assign_variable_definition (struct variable *v, char *line) +assign_variable_definition (struct variable *v, const char *line) { char *name; @@ -1570,7 +1566,7 @@ assign_variable_definition (struct variable *v, char *line) returned. */ struct variable * -try_variable_definition (const gmk_floc *flocp, char *line, +try_variable_definition (const gmk_floc *flocp, const char *line, enum variable_origin origin, int target_var) { struct variable v; @@ -1690,11 +1686,11 @@ print_noauto_variable (const void *item, void *arg) /* Print all the variables in SET. PREFIX is printed before the actual variable definitions (everything else is comments). */ -void -print_variable_set (struct variable_set *set, char *prefix, int pauto) +static void +print_variable_set (struct variable_set *set, const char *prefix, int pauto) { hash_map_arg (&set->table, (pauto ? print_auto_variable : print_variable), - prefix); + (void *)prefix); fputs (_("# variable set hash-table stats:\n"), stdout); fputs ("# ", stdout); @@ -1721,7 +1717,7 @@ print_variable_data_base (void) { ++rules; printf ("\n%s :\n", p->target); - print_variable (&p->variable, "# "); + print_variable (&p->variable, (void *)"# "); } if (rules == 0) diff --git a/variable.h b/variable.h index eda2493..3e2328a 100644 --- a/variable.h +++ b/variable.h @@ -159,8 +159,8 @@ struct variable *do_variable_definition (const gmk_floc *flocp, int target_var); char *parse_variable_definition (const char *line, struct variable *v); -struct variable *assign_variable_definition (struct variable *v, char *line); -struct variable *try_variable_definition (const gmk_floc *flocp, char *line, +struct variable *assign_variable_definition (struct variable *v, const char *line); +struct variable *try_variable_definition (const gmk_floc *flocp, const char *line, enum variable_origin origin, int target_var); void init_hash_global_variable_set (void); diff --git a/version.c b/version.c index af461f7..f71cfca 100644 --- a/version.c +++ b/version.c @@ -23,8 +23,8 @@ this program. If not, see . */ # define MAKE_HOST "unknown" #endif -char *version_string = VERSION; -char *make_host = MAKE_HOST; +const char *version_string = VERSION; +const char *make_host = MAKE_HOST; /* Local variables: -- cgit v1.2.3