From 83394f684ab0b5451c351e37411e8cab3c4ed42a Mon Sep 17 00:00:00 2001 From: Siteshwar Vashisht Date: Sun, 30 Jul 2017 16:03:51 +0200 Subject: [PATCH] Cleanup compiler warnings --- array.c | 1 - arrayfunc.c | 6 +--- bashline.c | 39 +++++++++------------ braces.c | 10 +++--- builtins/bind.def | 1 - builtins/cd.def | 14 ++++++-- builtins/command.def | 5 ++- builtins/declare.def | 5 ++- builtins/evalfile.c | 2 +- builtins/help.def | 9 +++-- builtins/history.def | 6 +++- builtins/mapfile.def | 3 +- builtins/setattr.def | 2 +- builtins/shopt.def | 2 +- builtins/ulimit.def | 5 ++- execute_cmd.c | 20 +++++------ expr.c | 8 +++-- general.c | 19 +--------- jobs.c | 17 ++++----- locale.c | 13 +++---- parse.y | 56 +++++++++++++++--------------- pathexp.c | 5 ++- pcomplete.c | 3 +- print_cmd.c | 10 +++--- redir.c | 16 ++++++--- shell.c | 7 ++-- subst.c | 98 ++++++++++++++++++++++++---------------------------- support/man2html.c | 76 ++++++++++++++++++++-------------------- trap.c | 6 ++-- variables.c | 23 +++++------- xmalloc.c | 2 ++ 31 files changed, 234 insertions(+), 255 deletions(-) diff --git a/array.c b/array.c index 34f022e..5f7d72f 100644 --- a/array.c +++ b/array.c @@ -384,7 +384,6 @@ array_remove_quoted_nulls(array) ARRAY *array; { ARRAY_ELEMENT *a; - char *t; if (array == 0 || array_head(array) == 0 || array_empty(array)) return (ARRAY *)NULL; diff --git a/arrayfunc.c b/arrayfunc.c index ac4884f..5b41f86 100644 --- a/arrayfunc.c +++ b/arrayfunc.c @@ -262,9 +262,6 @@ bind_assoc_variable (entry, name, key, value, flags) char *value; int flags; { - SHELL_VAR *dentry; - char *newval; - if ((readonly_p (entry) && (flags&ASS_FORCE) == 0) || noassign_p (entry)) { if (readonly_p (entry)) @@ -285,7 +282,7 @@ assign_array_element (name, value, flags) { char *sub, *vname; int sublen; - SHELL_VAR *entry, *nv; + SHELL_VAR *entry; vname = array_variable_name (name, (flags & ASS_NOEXPAND) != 0, &sub, &sublen); @@ -458,7 +455,6 @@ expand_compound_array_assignment (var, value, flags) int flags; { WORD_LIST *list, *nlist; - WORD_LIST *hd, *tl, *t, *n; char *val; int ni; diff --git a/bashline.c b/bashline.c index e156ef8..fb01e22 100644 --- a/bashline.c +++ b/bashline.c @@ -175,11 +175,14 @@ static char *quote_word_break_chars __P((char *)); static void set_filename_bstab __P((const char *)); static char *bash_quote_filename __P((char *, int, char *)); +#ifdef INCLUDE_UNUSED #ifdef _MINIX static void putx __P((int)); #else static int putx __P((int)); #endif +#endif + static int bash_execute_unix_command __P((int, int)); static void init_unix_command_map __P((void)); static int isolate_sequence __P((char *, int, int, int *)); @@ -1049,7 +1052,7 @@ bash_forward_shellword (count, key) int count, key; { size_t slen; - int sindex, c, p; + int c, p; DECLARE_MBSTATE; if (count < 0) @@ -1158,7 +1161,7 @@ bash_backward_shellword (count, key) int count, key; { size_t slen; - int sindex, c, p; + int c, p; DECLARE_MBSTATE; if (count < 0) @@ -1416,7 +1419,7 @@ attempt_shell_completion (text, start, end) const char *text; int start, end; { - int in_command_position, ti, saveti, qc, dflags; + int in_command_position, ti, qc, dflags; char **matches, *command_separator_chars; #if defined (PROGRAMMABLE_COMPLETION) int have_progcomps, was_assignment; @@ -1438,7 +1441,7 @@ attempt_shell_completion (text, start, end) appears after a character that separates commands. It cannot be a command word if we aren't at the top-level prompt. */ ti = start - 1; - saveti = qc = -1; + qc = -1; while ((ti > -1) && (whitespace (rl_line_buffer[ti]))) ti--; @@ -1449,7 +1452,7 @@ attempt_shell_completion (text, start, end) if (ti >= 0 && (rl_line_buffer[ti] == '"' || rl_line_buffer[ti] == '\'')) { qc = rl_line_buffer[ti]; - saveti = ti--; + ti--; while (ti > -1 && (whitespace (rl_line_buffer[ti]))) ti--; } @@ -1799,7 +1802,7 @@ command_word_completion_function (hint_text, state) static char *dequoted_hint = (char *)NULL; static char *directory_part = (char *)NULL; static char **glob_matches = (char **)NULL; - static int path_index, hint_len, dequoted_len, istate, igncase; + static int path_index, hint_len, istate, igncase; static int mapping_over, local_index, searching_path, hint_is_dir; static int old_glob_ignore_case, globpat; static SHELL_VAR **varlist = (SHELL_VAR **)NULL; @@ -1877,7 +1880,7 @@ command_word_completion_function (hint_text, state) free (hint); hint = dequoted_hint; } - dequoted_len = hint_len = strlen (hint); + hint_len = strlen (hint); if (filename_hint) free (filename_hint); @@ -1905,12 +1908,11 @@ command_word_completion_function (hint_text, state) } dequoted_hint = hint = savestring (hint_text); - dequoted_len = hint_len = strlen (hint); + hint_len = strlen (hint); if (rl_completion_found_quote && rl_completion_quote_character == 0) { dequoted_hint = bash_dequote_filename (hint, 0); - dequoted_len = strlen (dequoted_hint); } path = get_string_value ("PATH"); @@ -2300,7 +2302,6 @@ variable_completion_function (text, state) static char **varlist = (char **)NULL; static int varlist_index; static char *varname = (char *)NULL; - static int namelen; static int first_char, first_char_loc; if (!state) @@ -2319,7 +2320,6 @@ variable_completion_function (text, state) varname = savestring (text + first_char_loc); - namelen = strlen (varname); if (varlist) strvec_dispose (varlist); @@ -2407,7 +2407,7 @@ bash_servicename_completion_function (text, state) #else static char *sname = (char *)NULL; static struct servent *srvent; - static int snamelen, firstc; + static int snamelen; char *value; char **alist, *aentry; int afound; @@ -2415,7 +2415,6 @@ bash_servicename_completion_function (text, state) if (state == 0) { FREE (sname); - firstc = *text; sname = savestring (text); snamelen = strlen (sname); @@ -3145,7 +3144,6 @@ bash_filename_stat_hook (dirname) int should_expand_dirname, return_value; int global_nounset; WORD_LIST *wl; - struct stat sb; local_dirname = *dirname; should_expand_dirname = return_value = 0; @@ -3223,10 +3221,8 @@ bash_directory_completion_hook (dirname) char **dirname; { char *local_dirname, *new_dirname, *t; - int return_value, should_expand_dirname, nextch, closer, changed; - size_t local_dirlen; + int return_value, should_expand_dirname, nextch, closer; WORD_LIST *wl; - struct stat sb; return_value = should_expand_dirname = nextch = closer = 0; local_dirname = *dirname; @@ -3962,7 +3958,7 @@ set_filename_bstab (string) memset (filename_bstab, 0, sizeof (filename_bstab)); for (s = string; s && *s; s++) - filename_bstab[*s] = 1; + filename_bstab[(int)*s] = 1; } /* Quote a filename using double quotes, single quotes, or backslashes @@ -4070,6 +4066,7 @@ bash_quote_filename (s, rtype, qcp) /* Support for binding readline key sequences to Unix commands. */ static Keymap cmd_xmap; +#ifdef INCLUDE_UNUSED #ifdef _MINIX static void #else @@ -4084,15 +4081,13 @@ putx(c) return x; #endif } - +#endif + static int bash_execute_unix_command (count, key) int count; /* ignored */ int key; { - Keymap ckmap; /* current keymap */ - Keymap xkmap; /* unix command executing keymap */ - rl_command_func_t *func; int type; register int i, r; intmax_t mi; diff --git a/braces.c b/braces.c index 1339b32..192ac64 100644 --- a/braces.c +++ b/braces.c @@ -385,7 +385,7 @@ mkseq (start, end, incr, type, width) int type, width; { intmax_t n, prevn; - int i, j, nelem; + int i, nelem; char **result, *t; if (incr == 0) @@ -447,9 +447,9 @@ mkseq (start, end, incr, type, width) result[i++] = t = itos (n); else if (type == ST_ZINT) { - int len, arg; + int arg; arg = n; - len = asprintf (&t, "%0*d", width, arg); + asprintf (&t, "%0*d", width, arg); result[i++] = t; } else @@ -496,7 +496,7 @@ expand_seqterm (text, tlen) size_t tlen; { char *t, *lhs, *rhs; - int i, lhs_t, rhs_t, lhs_l, rhs_l, width; + int lhs_t, rhs_t, lhs_l, rhs_l, width; intmax_t lhs_v, rhs_v, incr; intmax_t tl, tr; char **result, *ep, *oep; @@ -745,6 +745,7 @@ comsub: return (c); } +#ifdef INCLUDE_UNUSED /* Return 1 if ARR has any non-empty-string members. Used to short-circuit in array_concat() below. */ static int @@ -758,6 +759,7 @@ degenerate_array (arr) return 0; return 1; } +#endif /* Return a new array of strings which is the result of appending each string in ARR2 to each string in ARR1. The resultant array is diff --git a/builtins/bind.def b/builtins/bind.def index 5fc8d34..2b18873 100644 --- a/builtins/bind.def +++ b/builtins/bind.def @@ -115,7 +115,6 @@ bind_builtin (list) Keymap kmap, saved_keymap; int flags, opt; char *initfile, *map_name, *fun_name, *unbind_name, *remove_seq, *cmd_seq, *t; - rl_command_func_t *func; if (no_line_editing) { diff --git a/builtins/cd.def b/builtins/cd.def index 45bcf1d..58cb5d9 100644 --- a/builtins/cd.def +++ b/builtins/cd.def @@ -61,7 +61,10 @@ static int setpwd __P((char *)); static char *resetpwd __P((char *)); static int change_to_directory __P((char *, int, int)); +#if defined (O_XATTR) static int cdxattr __P((char *, char **)); +#endif + static void resetxattr __P((void)); /* Change this to 1 to get cd spelling correction by default. */ @@ -186,6 +189,7 @@ resetpwd (caller) return (tdir); } +#if defined (O_XATTR) static int cdxattr (dir, ndirp) char *dir; /* don't assume we can always free DIR */ @@ -230,6 +234,7 @@ cdxattr (dir, ndirp) return -1; #endif } +#endif /* Clean up the O_XATTR baggage. Currently only closes xattrfd */ static void @@ -544,8 +549,12 @@ change_to_directory (newdir, nolinks, xattr) char *newdir; int nolinks, xattr; { - char *t, *tdir, *ndir; - int err, canon_failed, r, ndlen, dlen; + char *t, *tdir; + int err, canon_failed, r, ndlen; + +#if defined (O_XATTR) + char *ndir; +#endif tdir = (char *)NULL; @@ -564,7 +573,6 @@ change_to_directory (newdir, nolinks, xattr) : sh_canonpath (t, PATH_CHECKDOTDOT|PATH_CHECKEXISTS); ndlen = strlen (newdir); - dlen = strlen (t); /* Use the canonicalized version of NEWDIR, or, if canonicalization failed, use the non-canonical form. */ diff --git a/builtins/command.def b/builtins/command.def index ce694d8..affd120 100644 --- a/builtins/command.def +++ b/builtins/command.def @@ -60,7 +60,9 @@ $END extern size_t confstr __P((int, char *, size_t)); #endif +#ifdef INCLUDE_UNUSED static void restore_path __P((char *)); +#endif /* Run the commands mentioned in LIST without paying attention to shell functions. */ @@ -69,7 +71,6 @@ command_builtin (list) WORD_LIST *list; { int result, verbose, use_standard_path, opt; - char *old_path, *standard_path; COMMAND *command; verbose = use_standard_path = 0; @@ -143,6 +144,7 @@ command_builtin (list) return (result); } +#ifdef INCLUDE_UNUSED /* Restore the value of the $PATH variable after replacing it when executing `command -p'. */ static void @@ -159,3 +161,4 @@ restore_path (var) stupidly_hack_special_variables ("PATH"); } +#endif diff --git a/builtins/declare.def b/builtins/declare.def index cb944fe..e67b72c 100644 --- a/builtins/declare.def +++ b/builtins/declare.def @@ -295,7 +295,7 @@ declare_internal (list, local_var) int assoc_noexpand; #if defined (ARRAY_VARS) int making_array_special, compound_array_assign, simple_array_assign; - int var_exists, array_exists, creating_array, array_subscript_assignment; + int array_exists, creating_array, array_subscript_assignment; #endif name = savestring (list->word->word); @@ -369,7 +369,7 @@ declare_internal (list, local_var) restart_new_var_name: #if defined (ARRAY_VARS) - var_exists = array_exists = creating_array = 0; + array_exists = creating_array = 0; compound_array_assign = simple_array_assign = 0; array_subscript_assignment = 0; subscript_start = (char *)NULL; @@ -655,7 +655,6 @@ restart_new_var_name: var = mkglobal ? find_global_variable (name) : find_variable (name); #if defined (ARRAY_VARS) - var_exists = var != 0; array_exists = var && (array_p (var) || assoc_p (var)); creating_array = flags_on & (att_array|att_assoc); #endif diff --git a/builtins/evalfile.c b/builtins/evalfile.c index 4539b63..4da8f52 100644 --- a/builtins/evalfile.c +++ b/builtins/evalfile.c @@ -86,7 +86,7 @@ _evalfile (filename, flags) size_t file_size; sh_vmsg_func_t *errfunc; #if defined (ARRAY_VARS) - SHELL_VAR *funcname_v, *nfv, *bash_source_v, *bash_lineno_v; + SHELL_VAR *funcname_v, *bash_source_v, *bash_lineno_v; ARRAY *funcname_a, *bash_source_a, *bash_lineno_a; struct func_array_state *fa; # if defined (DEBUGGER) diff --git a/builtins/help.def b/builtins/help.def index 3528948..8903e3e 100644 --- a/builtins/help.def +++ b/builtins/help.def @@ -258,7 +258,7 @@ show_desc (name, i) char *name; int i; { - register int j, r; + register int j; char **doc, *line; int fd, usefile; @@ -270,7 +270,7 @@ show_desc (name, i) fd = open_helpfile (doc[0]); if (fd < 0) return; - r = zmapfd (fd, &line, doc[0]); + zmapfd (fd, &line, doc[0]); close (fd); /* XXX - handle errors if zmapfd returns < 0 */ } @@ -420,7 +420,6 @@ wdispcolumn (i, buf, bufsize, width, height) char *helpdoc; wchar_t *wcstr; size_t slen, n; - int wclen; /* first column */ helpdoc = _(shell_builtins[i].short_doc); @@ -517,9 +516,9 @@ wdispcolumn (i, buf, bufsize, width, height) static void show_builtin_command_help () { - int i, j; + int i; int height, width; - char *t, blurb[128]; + char blurb[128]; printf ( _("These shell commands are defined internally. Type `help' to see this list.\n\ diff --git a/builtins/history.def b/builtins/history.def index 7d92d2f..92216ea 100644 --- a/builtins/history.def +++ b/builtins/history.def @@ -104,9 +104,13 @@ history_builtin (list) WORD_LIST *list; { int flags, opt, result, old_history_lines, obase, ind; - char *filename, *delete_arg, *range; + char *filename, *delete_arg; intmax_t delete_offset; +#if defined (BASH_50) + char *range; +#endif + flags = 0; reset_internal_getopt (); while ((opt = internal_getopt (list, "acd:npsrw")) != -1) diff --git a/builtins/mapfile.def b/builtins/mapfile.def index 0ac445b..995d34a 100644 --- a/builtins/mapfile.def +++ b/builtins/mapfile.def @@ -244,12 +244,11 @@ int mapfile_builtin (list) WORD_LIST *list; { - int opt, code, fd, clear_array, flags; + int opt, code, fd, flags; intmax_t intval; long lines, origin, nskip, callback_quantum; char *array_name, *callback; - clear_array = 1; fd = 0; lines = origin = nskip = 0; flags = MAPF_CLEARARRAY; diff --git a/builtins/setattr.def b/builtins/setattr.def index 6eb6105..916515f 100644 --- a/builtins/setattr.def +++ b/builtins/setattr.def @@ -537,7 +537,7 @@ set_var_attribute (name, attribute, undo) int attribute, undo; { SHELL_VAR *var, *tv, *v, *refvar; - char *tvalue, *refname; + char *tvalue; if (undo) var = find_variable (name); diff --git a/builtins/shopt.def b/builtins/shopt.def index 2106893..b56a656 100644 --- a/builtins/shopt.def +++ b/builtins/shopt.def @@ -759,7 +759,7 @@ set_bashopts () { char *value; char tflag[N_SHOPT_OPTIONS]; - int vsize, i, vptr, *ip, exported; + int vsize, i, vptr, exported; SHELL_VAR *v; for (vsize = i = 0; shopt_vars[i].name; i++) diff --git a/builtins/ulimit.def b/builtins/ulimit.def index 9b88c8c..6bf0796 100644 --- a/builtins/ulimit.def +++ b/builtins/ulimit.def @@ -213,7 +213,9 @@ static int set_limit __P((int, RLIMTYPE, int)); static void printone __P((int, RLIMTYPE, int)); static void print_all_limits __P((int)); +#ifdef NOTYET static int set_all_limits __P((int, RLIMTYPE)); +#endif static int filesize __P((RLIMTYPE *)); static int pipesize __P((RLIMTYPE *)); @@ -753,6 +755,7 @@ printone (limind, curlim, pdesc) print_rlimtype ((curlim / factor), 1); } +#ifdef NOTYET /* Set all limits to NEWLIM. NEWLIM currently must be RLIM_INFINITY, which causes all limits to be set as high as possible depending on mode (like csh `unlimit'). Returns -1 if NEWLIM is invalid, 0 if all limits @@ -765,7 +768,6 @@ printone (limind, curlim, pdesc) To attempt to raise all soft and hard limits to infinity, use ulimit -a unlimited */ - static int set_all_limits (mode, newlim) int mode; @@ -792,5 +794,6 @@ set_all_limits (mode, newlim) } return retval; } +#endif #endif /* !_MINIX */ diff --git a/execute_cmd.c b/execute_cmd.c index 4d71932..e664f94 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -271,8 +271,6 @@ static int function_line_number; report the correct line number. Kind of a hack. */ static int showing_function_line; -static int connection_count; - /* $LINENO ($BASH_LINENO) for use by an ERR trap. Global so parse_and_execute can save and restore it. */ int line_number_for_err_trap; @@ -560,7 +558,6 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out, int exec_result, user_subshell, invert, ignore_return, was_error_trap; REDIRECT *my_undo_list, *exec_undo_list; char *tcmd; - volatile int last_pid; volatile int save_line_number; #if defined (PROCESS_SUBSTITUTION) volatile int ofifo, nfifo, osize, saved_fifo; @@ -799,7 +796,6 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out, #if defined (RECYCLES_PIDS) last_made_pid = NO_PID; #endif - last_pid = last_made_pid; was_error_trap = signal_is_trapped (ERROR_TRAP) && signal_is_ignored (ERROR_TRAP) == 0; if (ignore_return && command->value.Simple) @@ -1669,6 +1665,7 @@ typedef struct cplist } cplist_t; +#ifdef INCLUDE_UNUSED static struct cpelement *cpe_alloc __P((struct coproc *)); static void cpe_dispose __P((struct cpelement *)); static struct cpelement *cpl_add __P((struct coproc *)); @@ -1679,8 +1676,8 @@ static void cpl_closeall __P((void)); static struct cpelement *cpl_search __P((pid_t)); static struct cpelement *cpl_searchbyname __P((const char *)); static void cpl_prune __P((void)); - static void coproc_free __P((struct coproc *)); +#endif /* Will go away when there is fully-implemented support for multiple coprocs. */ Coproc sh_coproc = { 0, NO_PID, -1, -1, 0, 0, 0, 0, 0 }; @@ -1689,6 +1686,7 @@ cplist_t coproc_list = {0, 0, 0}; /* Functions to manage the list of coprocs */ +#ifdef INCLUDE_UNUSED static struct cpelement * cpe_alloc (cp) Coproc *cp; @@ -1887,7 +1885,6 @@ cpl_firstactive () return (pid_t)NO_PID; } -#if 0 static void cpl_prune () { @@ -1971,12 +1968,14 @@ coproc_alloc (name, pid) return (cp); } +#ifdef INCLUDE_UNUSED static void coproc_free (cp) struct coproc *cp; { free (cp); } +#endif void coproc_dispose (cp) @@ -3046,7 +3045,7 @@ execute_arith_for_command (arith_for_command) #endif #if defined (SELECT_COMMAND) -static int LINES, COLS, tabsize; +static int COLS, tabsize; #define RP_SPACE ") " #define RP_SPACE_LEN 2 @@ -3183,11 +3182,12 @@ select_query (list, list_len, prompt, print_menu) int max_elem_len, indices_len, len; intmax_t reply; WORD_LIST *l; - char *repl_string, *t; + char *repl_string; COLS = default_columns (); #if 0 + char *t; t = get_string_value ("TABSIZE"); tabsize = (t && *t) ? atoi (t) : 8; if (tabsize <= 0) @@ -4509,7 +4509,7 @@ execute_builtin (builtin, words, flags, subshell) WORD_LIST *words; int flags, subshell; { - int result, eval_unwind, ignexit_flag, old_e_flag; + int result, eval_unwind, ignexit_flag; int isbltinenv; char *error_trap; @@ -4635,8 +4635,6 @@ static void maybe_restore_getopt_state (gs) sh_getopt_state_t *gs; { - SHELL_VAR *v; - /* If we have a local copy of OPTIND and it's at the right (current) context, then we restore getopt's internal state. If not, we just let it go. We know there is a local OPTIND if gs->gs_flags & 1. diff --git a/expr.c b/expr.c index c51240f..b584052 100644 --- a/expr.c +++ b/expr.c @@ -185,8 +185,11 @@ static int _is_arithop __P((int)); static void readtok __P((void)); /* lexical analyzer */ static void init_lvalue __P((struct lvalue *)); + +#if 0 static struct lvalue *alloc_lvalue __P((void)); static void free_lvalue __P((struct lvalue *)); +#endif static intmax_t expr_streval __P((char *, int, struct lvalue *)); static intmax_t strlong __P((char *)); @@ -933,7 +936,7 @@ ipow (base, exp) static intmax_t exppower () { - register intmax_t val1, val2, c; + register intmax_t val1, val2; val1 = exp1 (); while (curtok == POWER) @@ -1092,6 +1095,7 @@ init_lvalue (lv) lv->tokval = lv->ind = -1; } +#if 0 static struct lvalue * alloc_lvalue () { @@ -1108,6 +1112,7 @@ free_lvalue (lv) { free (lv); /* should be inlined */ } +#endif static intmax_t expr_streval (tok, e, lvalue) @@ -1277,7 +1282,6 @@ readtok () register char *cp, *xp; register unsigned char c, c1; register int e; - struct lvalue lval; /* Skip leading whitespace. */ cp = tp; diff --git a/general.c b/general.c index adef2d8..24c7a3d 100644 --- a/general.c +++ b/general.c @@ -1112,21 +1112,9 @@ bash_tilde_expand (s, assign_p) const char *s; int assign_p; { - int old_immed, old_term, r; + int r; char *ret; -#if 0 - old_immed = interrupt_immediately; - old_term = terminate_immediately; - /* We want to be able to interrupt tilde expansion. Ordinarily, we can just - jump to top_level, but we don't want to run any trap commands in a signal - handler context. We might be able to get away with just checking for - things like SIGINT and SIGQUIT. */ - if (any_signals_trapped () < 0) - interrupt_immediately = 1; - terminate_immediately = 1; -#endif - tilde_additional_prefixes = assign_p == 0 ? (char **)0 : (assign_p == 2 ? bash_tilde_prefixes2 : bash_tilde_prefixes); if (assign_p == 2) @@ -1135,11 +1123,6 @@ bash_tilde_expand (s, assign_p) r = (*s == '~') ? unquoted_tilde_word (s) : 1; ret = r ? tilde_expand (s) : savestring (s); -#if 0 - interrupt_immediately = old_immed; - terminate_immediately = old_term; -#endif - QUIT; return (ret); diff --git a/jobs.c b/jobs.c index 079e096..e4c1794 100644 --- a/jobs.c +++ b/jobs.c @@ -768,8 +768,6 @@ bgp_resize () static ps_index_t bgp_getindex () { - ps_index_t psi; - if (bgpids.nalloc < js.c_childmax || bgpids.head >= bgpids.nalloc) bgp_resize (); @@ -2423,11 +2421,11 @@ void wait_for_background_pids () { register int i, r; - int any_stopped, check_async; + int any_stopped; sigset_t set, oset; pid_t pid; - for (any_stopped = 0, check_async = 1;;) + for (any_stopped = 0;;) { BLOCK_CHILD (set, oset); @@ -2462,7 +2460,6 @@ wait_for_background_pids () if (r == -1 && errno == ECHILD) { /* If we're mistaken about job state, compensate. */ - check_async = 0; mark_all_jobs_as_dead (); } } @@ -3057,8 +3054,7 @@ int wait_for_any_job (flags) int flags; { - pid_t pid; - int i, r, waited_for; + int i, r; sigset_t set, oset; if (jobs_list_frozen) @@ -3085,7 +3081,7 @@ return_job: /* At this point, we have no dead jobs in the jobs table. Wait until we get one, even if it takes multiple pids exiting. */ - for (waited_for = 0;;) + for (;;) { /* Make sure there is a background job to wait for */ BLOCK_CHILD (set, oset); @@ -3509,14 +3505,13 @@ static sighandler sigchld_handler (sig) int sig; { - int n, oerrno; + int oerrno; oerrno = errno; REINSTALL_SIGCHLD_HANDLER; sigchld++; - n = 0; if (queue_sigchld == 0) - n = waitchld (-1, 0); + waitchld (-1, 0); errno = oerrno; SIGRETURN (n); } diff --git a/locale.c b/locale.c index c42046b..8c0cead 100644 --- a/locale.c +++ b/locale.c @@ -340,7 +340,7 @@ get_locale_var (var) static int reset_locale_vars () { - char *t, *x; + char *x; #if defined (HAVE_SETLOCALE) if (lang == 0 || *lang == '\0') maybe_make_export_env (); /* trust that this will change environment for setlocale */ @@ -352,16 +352,16 @@ reset_locale_vars () x = setlocale (LC_CTYPE, get_locale_var ("LC_CTYPE")); # endif # if defined (LC_COLLATE) - t = setlocale (LC_COLLATE, get_locale_var ("LC_COLLATE")); + setlocale (LC_COLLATE, get_locale_var ("LC_COLLATE")); # endif # if defined (LC_MESSAGES) - t = setlocale (LC_MESSAGES, get_locale_var ("LC_MESSAGES")); + setlocale (LC_MESSAGES, get_locale_var ("LC_MESSAGES")); # endif # if defined (LC_NUMERIC) - t = setlocale (LC_NUMERIC, get_locale_var ("LC_NUMERIC")); + setlocale (LC_NUMERIC, get_locale_var ("LC_NUMERIC")); # endif # if defined (LC_TIME) - t = setlocale (LC_TIME, get_locale_var ("LC_TIME")); + setlocale (LC_TIME, get_locale_var ("LC_TIME")); # endif locale_setblanks (); @@ -570,7 +570,7 @@ static int locale_isutf8 (lspec) char *lspec; { - char *cp, *encoding; + char *cp; #if HAVE_LANGINFO_CODESET cp = nl_langinfo (CODESET); @@ -579,6 +579,7 @@ locale_isutf8 (lspec) cp = locale_charset (); return (STREQ (cp, "UTF-8") || STREQ (cp, "utf8")); #else + char encoding; /* Take a shot */ for (cp = lspec; *cp && *cp != '@' && *cp != '+' && *cp != ','; cp++) { diff --git a/parse.y b/parse.y index 92da96b..ff74e9c 100644 --- a/parse.y +++ b/parse.y @@ -129,8 +129,10 @@ extern int errno; /* **************************************************************** */ #ifdef DEBUG +#ifdef INCLUDE_UNUSED static void debug_parser __P((int)); #endif +#endif static int yy_getc __P((void)); static int yy_ungetc __P((int)); @@ -190,7 +192,10 @@ static int token_is_assignment __P((char *, int)); static int token_is_ident __P((char *, int)); #endif static int read_token_word __P((int)); + +#ifdef INCLUDE_UNUSED static void discard_parser_constructs __P((int)); +#endif static char *error_token_from_token __P((int)); static char *error_token_from_text __P((void)); @@ -319,8 +324,10 @@ static WORD_DESC *word_desc_to_read; static REDIRECTEE source; static REDIRECTEE redir; +#ifdef INCLUDE_UNUSED static FILE *yyoutstream; static FILE *yyerrstream; +#endif %} %union { @@ -1322,19 +1329,6 @@ timespec: TIME /* Global var is non-zero when end of file has been reached. */ int EOF_Reached = 0; -#ifdef DEBUG -static void -debug_parser (i) - int i; -{ -#if YYDEBUG != 0 - yydebug = i; - yyoutstream = stdout; - yyerrstream = stderr; -#endif -} -#endif - /* yy_getc () returns the next available character from input or EOF. yy_ungetc (c) makes `c' the next character to read. init_yy_io (get, unget, type, location) makes the function GET the @@ -2071,7 +2065,6 @@ read_secondary_line (remove_quoted_newline) int remove_quoted_newline; { char *ret; - int n, c; prompt_string_pointer = &ps2_prompt; if (SHOULD_PROMPT()) @@ -3409,7 +3402,7 @@ parse_matched_pair (qc, open, close, lenp, flags) int open, close; int *lenp, flags; { - int count, ch, prevch, tflags; + int count, ch, tflags; int nestlen, ttranslen, start_lineno; char *ret, *nestret, *ttrans; int retind, retsize, rflags; @@ -3434,7 +3427,6 @@ parse_matched_pair (qc, open, close, lenp, flags) ch = EOF; /* just in case */ while (count) { - prevch = ch; ch = shell_getc (qc != '\'' && (tflags & (LEX_PASSNEXT)) == 0); if (ch == EOF) @@ -3685,6 +3677,19 @@ parse_dollar_word: } #if defined (DEBUG) +#ifdef INCLUDE_UNUSED + +static void +debug_parser (i) + int i; +{ +#if YYDEBUG != 0 + yydebug = i; + yyoutstream = stdout; + yyerrstream = stderr; +#endif +} + static void dump_tflags (flags) int flags; @@ -3758,6 +3763,7 @@ dump_tflags (flags) fflush (stderr); } #endif +#endif /* Parse a $(...) command substitution. This is messier than I'd like, and reproduces a lot more of the token-reading code than I'd like. */ @@ -3802,7 +3808,6 @@ parse_comsub (qc, open, close, lenp, flags) while (count) { -comsub_readchar: ch = shell_getc (qc != '\'' && (tflags & (LEX_INCOMMENT|LEX_PASSNEXT|LEX_QUOTEDDOC)) == 0); if (ch == EOF) @@ -4283,7 +4288,7 @@ xparse_dolparen (base, string, indp, flags) sh_parser_state_t ps; sh_input_line_state_t ls; int orig_ind, nc, sflags, orig_eof_token; - char *ret, *s, *ep, *ostring; + char *ret, *ep, *ostring; #if defined (ALIAS) || defined (DPAREN_ARITHMETIC) STRING_SAVER *saved_pushed_strings; #endif @@ -4395,7 +4400,7 @@ static int parse_dparen (c) int c; { - int cmdtyp, sline; + int cmdtyp; char *wval; WORD_DESC *wd; @@ -4419,8 +4424,6 @@ parse_dparen (c) #if defined (DPAREN_ARITHMETIC) if (reserved_word_acceptable (last_read_token)) { - sline = line_number; - cmdtyp = parse_arith_cmd (&wval, 0); if (cmdtyp == 1) /* arithmetic command */ { @@ -4456,11 +4459,10 @@ parse_arith_cmd (ep, adddq) char **ep; int adddq; { - int exp_lineno, rval, c; + int rval, c; char *ttok, *tokstr; int ttoklen; - exp_lineno = line_number; ttok = parse_matched_pair (0, '(', ')', &ttoklen, 0); rval = 1; if (ttok == &matched_pair_error) @@ -6184,6 +6186,7 @@ report_syntax_error (message) last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE; } +#ifdef INCLUDE_UNUSED /* ??? Needed function. ??? We have to be able to discard the constructs created during parsing. In the case of error, we want to return allocated objects to the memory pool. In the case of no error, we want @@ -6194,6 +6197,7 @@ discard_parser_constructs (error_p) int error_p; { } +#endif /************************************************ * * @@ -6453,8 +6457,6 @@ sh_parser_state_t * save_parser_state (ps) sh_parser_state_t *ps; { - int i; - if (ps == 0) ps = (sh_parser_state_t *)xmalloc (sizeof (sh_parser_state_t)); if (ps == 0) @@ -6491,6 +6493,7 @@ save_parser_state (ps) ps->here_doc_first_line = here_doc_first_line; #if 0 + int i; for (i = 0; i < HEREDOC_MAX; i++) ps->redir_stack[i] = redir_stack[i]; #else @@ -6513,8 +6516,6 @@ void restore_parser_state (ps) sh_parser_state_t *ps; { - int i; - if (ps == 0) return; @@ -6553,6 +6554,7 @@ restore_parser_state (ps) here_doc_first_line = ps->here_doc_first_line; #if 0 + int i; for (i = 0; i < HEREDOC_MAX; i++) redir_stack[i] = ps->redir_stack[i]; #else diff --git a/pathexp.c b/pathexp.c index f88ed5b..d7bec2f 100644 --- a/pathexp.c +++ b/pathexp.c @@ -183,7 +183,7 @@ quote_string_for_globbing (pathname, qflags) { char *temp; register int i, j; - int brack, cclass, collsym, equiv, c, last_was_backslash; + int cclass, collsym, equiv, c, last_was_backslash; int savei, savej; temp = (char *)xmalloc (2 * strlen (pathname) + 1); @@ -194,7 +194,7 @@ quote_string_for_globbing (pathname, qflags) return temp; } - brack = cclass = collsym = equiv = last_was_backslash = 0; + cclass = collsym = equiv = last_was_backslash = 0; for (i = j = 0; pathname[i]; i++) { /* Fix for CTLESC at the end of the string? */ @@ -225,7 +225,6 @@ quote_string_for_globbing (pathname, qflags) } else if ((qflags & QGLOB_REGEXP) && (i == 0 || pathname[i-1] != CTLESC) && pathname[i] == '[') /*]*/ { - brack = 1; temp[j++] = pathname[i++]; /* open bracket */ savej = j; savei = i; diff --git a/pcomplete.c b/pcomplete.c index fb9efa9..310a69f 100644 --- a/pcomplete.c +++ b/pcomplete.c @@ -726,7 +726,6 @@ pcomp_filename_completion_function (text, state) int state; { static char *dfn; /* dequoted filename */ - int qc; int iscompgen, iscompleting; if (state == 0) @@ -1616,7 +1615,7 @@ programmable_completions (cmd, word, start, end, foundp) const char *word; int start, end, *foundp; { - COMPSPEC *cs, *lastcs; + COMPSPEC *lastcs; STRINGLIST *ret; char **rmatches, *t; int found, retry, count; diff --git a/print_cmd.c b/print_cmd.c index b09bdf8..326358b 100644 --- a/print_cmd.c +++ b/print_cmd.c @@ -79,9 +79,11 @@ static void print_redirection_list __P((REDIRECT *)); static void print_redirection __P((REDIRECT *)); static void print_heredoc_header __P((REDIRECT *)); static void print_heredoc_body __P((REDIRECT *)); -static void print_heredocs __P((REDIRECT *)); static void print_heredoc_bodies __P((REDIRECT *)); static void print_deferred_heredocs __P((const char *)); +#ifdef INCLUDE_UNUSED +static void print_heredocs __P((REDIRECT *)); +#endif static void print_for_command __P((FOR_COM *)); #if defined (ARITH_FOR_COMMAND) @@ -168,7 +170,7 @@ make_command_string_internal (command) char s[3]; if (command == 0) - cprintf (""); + cprintf ("%s", ""); else { if (skip_this_indent) @@ -963,6 +965,7 @@ print_simple_command (simple_command) } } +#ifdef INCLUDE_UNUSED static void print_heredocs (heredocs) REDIRECT *heredocs; @@ -977,6 +980,7 @@ print_heredocs (heredocs) } was_heredoc = 1; } +#endif static void print_heredoc_bodies (heredocs) @@ -1004,8 +1008,6 @@ static void print_deferred_heredocs (cstring) const char *cstring; { - REDIRECT *hdtail; - /* We now print the heredoc headers in print_redirection_list */ if (cstring && cstring[0] && (cstring[0] != ';' || cstring[1])) cprintf ("%s", cstring); diff --git a/redir.c b/redir.c index 68741db..c5a57ec 100644 --- a/redir.c +++ b/redir.c @@ -71,9 +71,13 @@ static int add_undo_redirect __P((int, enum r_instruction, int)); static int add_undo_close_redirect __P((int)); static int expandable_redirection_filename __P((REDIRECT *)); static int stdin_redirection __P((enum r_instruction, int)); -static int undoablefd __P((int)); static int do_redirection_internal __P((REDIRECT *, int)); +#ifdef INCLUDE_UNUSED +static int undoablefd __P((int)); +#endif + + static int write_here_document __P((int, WORD_DESC *)); static int write_here_string __P((int, WORD_DESC *)); static int here_document_to_fd __P((WORD_DESC *, enum r_instruction)); @@ -154,7 +158,6 @@ redirection_error (temp, error) #endif else if (expandable_redirection_filename (temp)) { -expandable_filename: oflags = temp->redirectee.filename->flags; if (posixly_correct && interactive_shell == 0) temp->redirectee.filename->flags |= W_NOGLOB; @@ -694,6 +697,7 @@ redir_open (filename, flags, mode, ri) return fd; } +#ifdef INCLUDE_UNUSED static int undoablefd (fd) int fd; @@ -705,6 +709,7 @@ undoablefd (fd) return 0; return 1; } +#endif /* Do the specific redirection requested. Returns errno or one of the special redirection errors (*_REDIRECT) in case of error, 0 on success. @@ -772,6 +777,8 @@ do_redirection_internal (redirect, flags) case r_move_output_word: new_redirect = make_redirection (sd, r_move_output, rd, 0); break; + default: + break; } } else if (ri == r_duplicating_output_word && (redirect->rflags & REDIR_VARASSIGN) == 0 && redirector == 1) @@ -1164,8 +1171,7 @@ do_redirection_internal (redirect, flags) } break; - case r_duplicating_input_word: - case r_duplicating_output_word: + default: break; } return (0); @@ -1325,9 +1331,9 @@ stdin_redirection (ri, redirector) case r_append_err_and_out: case r_output_force: case r_duplicating_output_word: + default: return (0); } - return (0); } /* Return non-zero if any of the redirections in REDIRS alter the standard diff --git a/shell.c b/shell.c index 013fece..aaf14ba 100644 --- a/shell.c +++ b/shell.c @@ -1280,15 +1280,12 @@ uidget () void disable_priv_mode () { - int e; - if (setuid (current_user.uid) < 0) { - e = errno; sys_error (_("cannot set uid to %d: effective uid %d"), current_user.uid, current_user.euid); #if defined (EXIT_ON_SETUID_FAILURE) - if (e == EAGAIN) - exit (e); + if (errno == EAGAIN) + exit (errno); #endif } if (setgid (current_user.gid) < 0) diff --git a/subst.c b/subst.c index 0bea6c2..944fc9c 100644 --- a/subst.c +++ b/subst.c @@ -213,7 +213,7 @@ static WORD_LIST *cached_quoted_dollar_at = 0; /* Distinguished error values to return from expansion functions */ static WORD_LIST expand_word_error, expand_word_fatal; static WORD_DESC expand_wdesc_error, expand_wdesc_fatal; -static char expand_param_error, expand_param_fatal, expand_param_unset; +static char expand_param_error, expand_param_fatal; static char extract_string_error, extract_string_fatal; /* Set by expand_word_unsplit and several of the expand_string_XXX functions; @@ -227,9 +227,15 @@ static int expand_no_split_dollar_star = 0; without any leading variable assignments. */ static WORD_LIST *garglist = (WORD_LIST *)NULL; +#ifdef INCLUDE_UNUSED static char *quoted_substring __P((char *, int, int)); static int quoted_strlen __P((char *)); static char *quoted_strchr __P((char *, int, int)); +static int unquoted_substring __P((char *, char *)); +static int unquoted_member __P((int, char *)); +static WORD_LIST *list_dequote_escapes __P((WORD_LIST *)); +#endif + static char *expand_string_if_necessary __P((char *, int, EXPFUNC *)); static inline char *expand_string_to_string_internal __P((char *, int, EXPFUNC *)); @@ -240,13 +246,10 @@ static WORD_LIST *expand_string_for_rhs __P((char *, int, int, int *, int *)); static WORD_LIST *expand_string_for_pat __P((char *, int, int *, int *)); static WORD_LIST *list_quote_escapes __P((WORD_LIST *)); -static WORD_LIST *list_dequote_escapes __P((WORD_LIST *)); static char *make_quoted_char __P((int)); static WORD_LIST *quote_list __P((WORD_LIST *)); -static int unquoted_substring __P((char *, char *)); -static int unquoted_member __P((int, char *)); #if defined (ARRAY_VARS) static SHELL_VAR *do_compound_assignment __P((char *, char *, int)); @@ -265,7 +268,9 @@ static int skip_matched_pair __P((const char *, int, int, int, int)); static char *pos_params __P((char *, int, int, int)); +#ifdef INCLUDE_UNUSED static unsigned char *mb_getcharlens __P((char *, int)); +#endif static char *remove_upattern __P((char *, char *, int)); #if defined (HANDLE_MULTIBYTE) @@ -280,7 +285,9 @@ static int match_wpattern __P((wchar_t *, char **, size_t, wchar_t *, int, char static int match_pattern __P((char *, char *, int, char **, char **)); static int getpatspec __P((int, char *)); static char *getpattern __P((char *, int, int)); +#ifdef INCLUDE_UNUSED static char *variable_remove_pattern __P((char *, char *, int, int)); +#endif static char *list_remove_pattern __P((WORD_LIST *, char *, int, int, int)); static char *parameter_list_remove_pattern __P((int, char *, int, int)); #ifdef ARRAY_VARS @@ -328,13 +335,13 @@ static int get_var_and_type __P((char *, char *, arrayind_t, int, int, SHELL_VAR static char *mb_substring __P((char *, int, int)); static char *parameter_brace_substring __P((char *, char *, int, char *, int, int, int)); +#ifdef INCLUDE_UNUSED static int shouldexp_replacement __P((char *)); - static char *pos_params_pat_subst __P((char *, char *, char *, int)); +#endif static char *parameter_brace_patsub __P((char *, char *, int, char *, int, int, int)); -static char *pos_params_casemod __P((char *, char *, int, int)); static char *parameter_brace_casemod __P((char *, char *, int, int, char *, int, int, int)); static WORD_DESC *parameter_brace_expand __P((char *, int *, int, int, int *, int *)); @@ -588,7 +595,6 @@ quoted_strlen (s) return i; } -#endif /* Find the first occurrence of character C in string S, obeying shell quoting rules. If (FLAGS & ST_BACKSL) is non-zero, backslash-escaped @@ -617,7 +623,6 @@ quoted_strchr (s, c, flags) return ((char *)NULL); } -#if defined (INCLUDE_UNUSED) /* Return 1 if CHARACTER appears in an unquoted portion of STRING. Return 0 otherwise. CHARACTER must be a single-byte character. */ static int @@ -1005,7 +1010,6 @@ skip_double_quoted (string, slen, sind, flags) int flags; { int c, i; - char *ret; int pass_next, backquote, si; DECLARE_MBSTATE; @@ -1042,9 +1046,9 @@ skip_double_quoted (string, slen, sind, flags) { si = i + 2; if (string[i + 1] == LPAREN) - ret = extract_command_subst (string, &si, SX_NOALLOC|(flags&SX_COMPLETE)); + extract_command_subst (string, &si, SX_NOALLOC|(flags&SX_COMPLETE)); else - ret = extract_dollar_brace_string (string, &si, Q_DOUBLE_QUOTES, SX_NOALLOC); + extract_dollar_brace_string (string, &si, Q_DOUBLE_QUOTES, SX_NOALLOC); /* These can consume the entire string if they are unterminated */ CHECK_STRING_OVERRUN (i, si, slen, c); @@ -1134,7 +1138,6 @@ string_extract_verbatim (string, slen, sindex, charlist, flags) { register int i; #if defined (HANDLE_MULTIBYTE) - size_t clen; wchar_t *wcharlist; #endif int c; @@ -1150,7 +1153,6 @@ string_extract_verbatim (string, slen, sindex, charlist, flags) i = *sindex; #if defined (HANDLE_MULTIBYTE) - clen = strlen (charlist); wcharlist = 0; #endif while (c = string[i]) @@ -1313,7 +1315,7 @@ extract_delimited_string (string, sindex, opener, alt_opener, closer, flags) { int i, c, si; size_t slen; - char *t, *result; + char *result; int pass_character, nesting_level, in_comment; int len_closer, len_opener, len_alt_opener; DECLARE_MBSTATE; @@ -1380,7 +1382,7 @@ extract_delimited_string (string, sindex, opener, alt_opener, closer, flags) if ((flags & SX_COMMAND) && string[i] == '$' && string[i+1] == LPAREN) { si = i + 2; - t = extract_command_subst (string, &si, flags|SX_NOALLOC); + extract_command_subst (string, &si, flags|SX_NOALLOC); CHECK_STRING_OVERRUN (i, si, slen, c); i = si + 1; continue; @@ -1390,7 +1392,7 @@ extract_delimited_string (string, sindex, opener, alt_opener, closer, flags) if (STREQN (string + i, opener, len_opener)) { si = i + len_opener; - t = extract_delimited_string (string, &si, opener, alt_opener, closer, flags|SX_NOALLOC); + extract_delimited_string (string, &si, opener, alt_opener, closer, flags|SX_NOALLOC); CHECK_STRING_OVERRUN (i, si, slen, c); i = si + 1; continue; @@ -1400,7 +1402,7 @@ extract_delimited_string (string, sindex, opener, alt_opener, closer, flags) if (len_alt_opener && STREQN (string + i, alt_opener, len_alt_opener)) { si = i + len_alt_opener; - t = extract_delimited_string (string, &si, alt_opener, alt_opener, closer, flags|SX_NOALLOC); + extract_delimited_string (string, &si, alt_opener, alt_opener, closer, flags|SX_NOALLOC); CHECK_STRING_OVERRUN (i, si, slen, c); i = si + 1; continue; @@ -1420,7 +1422,7 @@ extract_delimited_string (string, sindex, opener, alt_opener, closer, flags) if (c == '`') { si = i + 1; - t = string_extract (string, &si, "`", flags|SX_NOALLOC); + string_extract (string, &si, "`", flags|SX_NOALLOC); CHECK_STRING_OVERRUN (i, si, slen, c); i = si + 1; continue; @@ -1484,7 +1486,7 @@ extract_dollar_brace_string (string, sindex, quoted, flags) register int i, c; size_t slen; int pass_character, nesting_level, si, dolbrace_state; - char *result, *t; + char *result; DECLARE_MBSTATE; pass_character = 0; @@ -1538,7 +1540,7 @@ extract_dollar_brace_string (string, sindex, quoted, flags) if (c == '`') { si = i + 1; - t = string_extract (string, &si, "`", flags|SX_NOALLOC); + string_extract (string, &si, "`", flags|SX_NOALLOC); CHECK_STRING_OVERRUN (i, si, slen, c); @@ -1551,7 +1553,7 @@ extract_dollar_brace_string (string, sindex, quoted, flags) if (string[i] == '$' && string[i+1] == LPAREN) { si = i + 2; - t = extract_command_subst (string, &si, flags|SX_NOALLOC); + extract_command_subst (string, &si, flags|SX_NOALLOC); CHECK_STRING_OVERRUN (i, si, slen, c); @@ -1564,7 +1566,7 @@ extract_dollar_brace_string (string, sindex, quoted, flags) if ((string[i] == '<' || string[i] == '>') && string[i+1] == LPAREN) { si = i + 2; - t = extract_process_subst (string, (string[i] == '<' ? "<(" : ">)"), &si, flags|SX_NOALLOC); + extract_process_subst (string, (string[i] == '<' ? "<(" : ">)"), &si, flags|SX_NOALLOC); CHECK_STRING_OVERRUN (i, si, slen, c); @@ -1722,7 +1724,7 @@ skip_matched_pair (string, start, open, close, flags) { int i, pass_next, backq, si, c, count, oldjmp; size_t slen; - char *temp, *ss; + char *ss; DECLARE_MBSTATE; slen = strlen (string + start) + start; @@ -1790,9 +1792,9 @@ skip_matched_pair (string, start, open, close, flags) /* XXX - extract_command_subst here? */ if (string[i+1] == LPAREN) - temp = extract_delimited_string (ss, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */ + extract_delimited_string (ss, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */ else - temp = extract_dollar_brace_string (ss, &si, 0, SX_NOALLOC); + extract_dollar_brace_string (ss, &si, 0, SX_NOALLOC); CHECK_STRING_OVERRUN (i, si, slen, c); @@ -1836,7 +1838,7 @@ skip_to_delim (string, start, delims, flags) int invert, skipquote, skipcmd, noprocsub, completeflag; int arithexp, skipcol; size_t slen; - char *temp, open[3]; + char open[3]; DECLARE_MBSTATE; slen = strlen (string + start) + start; @@ -1919,7 +1921,7 @@ skip_to_delim (string, start, delims, flags) if (string[si] == '\0') CQ_RETURN(si); - temp = extract_delimited_string (string, &si, "(", "(", ")", SX_NOALLOC); /* ) */ + extract_delimited_string (string, &si, "(", "(", ")", SX_NOALLOC); /* ) */ i = si; if (string[i] == '\0') /* don't increment i past EOS in loop */ break; @@ -1933,9 +1935,9 @@ skip_to_delim (string, start, delims, flags) CQ_RETURN(si); if (string[i+1] == LPAREN) - temp = extract_delimited_string (string, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */ + extract_delimited_string (string, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */ else - temp = extract_dollar_brace_string (string, &si, 0, SX_NOALLOC); + extract_dollar_brace_string (string, &si, 0, SX_NOALLOC); CHECK_STRING_OVERRUN (i, si, slen, c); i = si; if (string[i] == '\0') /* don't increment i past EOS in loop */ @@ -1950,7 +1952,7 @@ skip_to_delim (string, start, delims, flags) if (string[si] == '\0') CQ_RETURN(si); - temp = extract_delimited_string (string, &si, (c == '<') ? "<(" : ">(", "(", ")", SX_COMMAND|SX_NOALLOC); /* )) */ + extract_delimited_string (string, &si, (c == '<') ? "<(" : ">(", "(", ")", SX_COMMAND|SX_NOALLOC); /* )) */ CHECK_STRING_OVERRUN (i, si, slen, c); i = si; if (string[i] == '\0') @@ -1969,7 +1971,7 @@ skip_to_delim (string, start, delims, flags) open[0] = c; open[1] = LPAREN; open[2] = '\0'; - temp = extract_delimited_string (string, &si, open, "(", ")", SX_NOALLOC); /* ) */ + extract_delimited_string (string, &si, open, "(", ")", SX_NOALLOC); /* ) */ CHECK_STRING_OVERRUN (i, si, slen, c); i = si; @@ -1985,7 +1987,7 @@ skip_to_delim (string, start, delims, flags) if (string[si] == '\0') CQ_RETURN(si); - temp = extract_delimited_string (string, &si, "[", "[", "]", SX_NOALLOC); /* ] */ + extract_delimited_string (string, &si, "[", "[", "]", SX_NOALLOC); /* ] */ i = si; if (string[i] == '\0') /* don't increment i past EOS in loop */ @@ -2014,10 +2016,9 @@ skip_to_histexp (string, start, delims, flags) char *delims; int flags; { - int i, pass_next, backq, dquote, si, c, oldjmp; + int i, pass_next, backq, dquote, c, oldjmp; int histexp_comsub, histexp_backq, old_dquote; size_t slen; - char *temp, open[3]; DECLARE_MBSTATE; slen = strlen (string + start) + start; @@ -4090,6 +4091,7 @@ dequote_escapes (string) return result; } +#ifdef INCLUDE_UNUSED static WORD_LIST * list_dequote_escapes (list) WORD_LIST *list; @@ -4105,6 +4107,7 @@ list_dequote_escapes (list) } return list; } +#endif /* Return a new string with the quoted representation of character C. This turns "" into QUOTED_NULL, so the W_HASQUOTEDNULL flag needs to be @@ -4287,7 +4290,7 @@ remove_quoted_ifs (string) char *string; { register size_t slen; - register int i, j, prev_i; + register int i, j; char *ret, *send; DECLARE_MBSTATE; @@ -4645,7 +4648,6 @@ match_upattern (string, pat, mtype, sp, ep) size_t len; register char *p, *p1, *npat; char *end; - int n1; /* If the pattern doesn't match anywhere in the string, go ahead and short-circuit right away. A minor optimization, saves a bunch of @@ -4946,7 +4948,6 @@ match_pattern (string, pat, mtype, sp, ep) size_t n; wchar_t *wstring, *wpat; char **indices; - size_t slen, plen, mslen, mplen; #endif if (string == 0 || pat == 0 || *pat == 0) @@ -5144,7 +5145,7 @@ parameter_brace_remove_pattern (varname, value, ind, patstr, rtype, quoted, flag char *patstr; int rtype, quoted, flags; { - int vtype, patspec, starsub; + int vtype, patspec; char *temp1, *val, *pattern, *oname; SHELL_VAR *v; @@ -5161,7 +5162,6 @@ parameter_brace_remove_pattern (varname, value, ind, patstr, rtype, quoted, flag return ((char *)NULL); } - starsub = vtype & VT_STARSUB; vtype &= ~VT_STARSUB; patspec = getpatspec (rtype, patstr); @@ -5789,7 +5789,7 @@ read_comsub (fd, quoted, flags, rflag) int fd, quoted, flags; int *rflag; { - char *istring, buf[128], *bufp, *s; + char *istring, buf[128], *bufp; int istring_index, istring_size, c, tflag, skip_ctlesc, skip_ctlnul; ssize_t bufn; int nullbyte; @@ -6531,7 +6531,7 @@ parameter_brace_expand_indir (name, var_is_special, quoted, quoted_dollar_atp, c int var_is_special, quoted; int *quoted_dollar_atp, *contains_dollar_at; { - char *temp, *t; + char *t; WORD_DESC *w; SHELL_VAR *v; @@ -7066,7 +7066,6 @@ get_var_and_type (varname, value, ind, quoted, flags, varp, valp) { int vtype, want_indir; char *temp, *vname; - WORD_DESC *wd; SHELL_VAR *v; arrayind_t lind; @@ -7608,7 +7607,7 @@ parameter_brace_substring (varname, value, ind, substr, quoted, pflags, flags) /* */ /****************************************************************/ -#if 0 /* Unused */ +#ifdef INCLUDE_UNUSED /* Unused */ static int shouldexp_replacement (s) char *s; @@ -9402,7 +9401,6 @@ expand_word_internal (word, quoted, isexp, contains_dollar_at, expanded_somethin int has_quoted_ifs; /* did we add a quoted $IFS character here? */ int has_dollar_at, temp_has_dollar_at; int split_on_spaces; - int local_expanded; int tflag; int pflags; /* flags passed to param_expand */ int mb_cur_max; @@ -9644,7 +9642,6 @@ add_string: case '$': if (expanded_something) *expanded_something = 1; - local_expanded = 1; temp_has_dollar_at = 0; pflags = (word->flags & W_NOCOMSUB) ? PF_NOCOMSUB : 0; @@ -9711,7 +9708,6 @@ add_string: if (expanded_something) *expanded_something = 1; - local_expanded = 1; if (word->flags & W_NOCOMSUB) /* sindex + 1 because string[sindex] == '`' */ @@ -9891,7 +9887,6 @@ add_twochars: *contains_dollar_at = 1; if (expanded_something) *expanded_something = 1; - local_expanded = 1; } } else @@ -10144,7 +10139,6 @@ finished_with_string: else { char *ifs_chars; - char *tstring; ifs_chars = (quoted_dollar_at || has_dollar_at) ? ifs_value : (char *)NULL; @@ -10861,7 +10855,6 @@ shell_expand_word_list (tlist, eflags) { WORD_LIST *expanded, *orig_list, *new_list, *next, *temp_list, *wcmd; int expanded_something, has_dollar_at; - char *temp_string; /* We do tilde expansion all the time. This is what 1003.2 says. */ new_list = (WORD_LIST *)NULL; @@ -10871,8 +10864,6 @@ shell_expand_word_list (tlist, eflags) for (orig_list = tlist; tlist; tlist = next) { - temp_string = tlist->word->word; - next = tlist->next; #if defined (ARRAY_VARS) @@ -10885,7 +10876,8 @@ shell_expand_word_list (tlist, eflags) if ((tlist->word->flags & (W_COMPASSIGN|W_ASSIGNARG)) == (W_COMPASSIGN|W_ASSIGNARG)) { int t; - char opts[16], opti; + char opts[16]; + int opti; opti = 0; if (tlist->word->flags & (W_ASSIGNASSOC|W_ASSNGLOBAL|W_ASSIGNARRAY)) @@ -10932,7 +10924,7 @@ shell_expand_word_list (tlist, eflags) case 'l': case 'u': case 'c': - omap[l->word->word[oind]] = 1; + omap[(int)l->word->word[oind]] = 1; if (opti == 0) opts[opti++] = '-'; break; diff --git a/support/man2html.c b/support/man2html.c index 6ba5061..dfd1f43 100644 --- a/support/man2html.c +++ b/support/man2html.c @@ -101,8 +101,6 @@ #define EXIT_USAGE 2 #endif -static char location_base[NULL_TERMINATED(MED_STR_MAX)] = ""; - static char th_page_and_sec[128] = { '\0' }; static char th_datestr[128] = { '\0' }; static char th_version[128] = { '\0' }; @@ -145,18 +143,6 @@ strerror(int e) #endif /* !HAVE_STRERROR */ static char * -strgrow(char *old, int len) -{ - char *new = realloc(old, (strlen(old) + len + 1) * sizeof(char)); - - if (!new) { - fprintf(stderr, "man2html: out of memory"); - exit(EXIT_FAILURE); - } - return new; -} - -static char * stralloc(int len) { /* allocate enough for len + NULL */ @@ -182,6 +168,30 @@ xmalloc (size_t size) return ret; } +/* Assumes space for n plus a null */ +static char * +strmaxcpy(char *to, char *from, int n) +{ + int len = strlen(from); + + strncpy(to, from, n); + to[(len <= n) ? len : n] = '\0'; + return to; +} + +#ifdef INCLUDE_UNUSED +static char * +strgrow(char *old, int len) +{ + char *new = realloc(old, (strlen(old) + len + 1) * sizeof(char)); + + if (!new) { + fprintf(stderr, "man2html: out of memory"); + exit(EXIT_FAILURE); + } + return new; +} + /* * Some systems don't have strdup so lets use our own - which can also * check for out of memory. @@ -195,17 +205,6 @@ strduplicate(char *from) return new; } -/* Assumes space for n plus a null */ -static char * -strmaxcpy(char *to, char *from, int n) -{ - int len = strlen(from); - - strncpy(to, from, n); - to[(len <= n) ? len : n] = '\0'; - return to; -} - static char * strmaxcat(char *to, char *from, int n) { @@ -220,6 +219,7 @@ strmaxcat(char *to, char *from, int n) } return to; } +#endif /* Assumes space for limit plus a null */ static char * @@ -232,6 +232,7 @@ strlimitcpy(char *to, char *from, int n, int limit) return to; } +#ifdef INCLUDE_UNUSED /* * takes string and escapes all metacharacters. should be used before * including string in system() or similar call. @@ -261,6 +262,7 @@ escape_input(char *str) new[j] = '\0'; return new; } +#endif static void usage(void) @@ -295,8 +297,11 @@ static char idxlabel[6] = "ixAAA"; #define INDEXFILE "/tmp/manindex.list" + +#ifdef MAKEINDEX static char *fname; static FILE *idxfile; +#endif static STRDEF *chardef, *strdef, *defdef; static INTDEF *intdef; @@ -425,7 +430,6 @@ static STRDEF standardchar[] = { /* default: print code */ -static char eqndelimopen = 0, eqndelimclose = 0; static char escapesym = '\\', nobreaksym = '\'', controlsym = '.', fieldsym = 0, padsym = 0; static char *buffer = NULL; @@ -505,7 +509,6 @@ static char * read_man_page(char *filename) { char *man_buf = NULL; - int i; FILE *man_stream = NULL; struct stat stbuf; int buf_size; @@ -933,7 +936,6 @@ change_to_size(int nr) return sizebuf; } -static int asint = 0; static int intresult = 0; #define SKIPEOL while (*c && *c++!='\n') @@ -1435,12 +1437,12 @@ static char itemreset[20] = "\\fR\\s0"; static char * scan_table(char *c) { - char *t, *h, *g; + char *h, *g; int center = 0, expand = 0, box = 0, border = 0, linesize = 1; int i, j, maxcol = 0, finished = 0; int oldfont, oldsize, oldfillout; char itemsep = '\t'; - TABLEROW *layout = NULL, *currow, *ftable; + TABLEROW *layout = NULL, *currow; TABLEITEM *curfield; while (*c++ != '\n'); @@ -1770,7 +1772,7 @@ scan_table(char *c) static char * scan_expression(char *c, int *result) { - int value = 0, value2, j = 0, sign = 1, opex = 0; + int value = 0, value2, sign = 1, opex = 0; char oper = 'c'; if (*c == '!') { @@ -2239,7 +2241,6 @@ scan_request(char *c) case V('d', 'i'): { STRDEF *de; - int oldcurpos = curpos; c = c + j; i = V(c[0], c[1]); @@ -2536,7 +2537,6 @@ scan_request(char *c) break; case V('s', 'o'): { - FILE *f; struct stat stbuf; int l = 0; char *buf; @@ -3744,10 +3744,12 @@ scan_request(char *c) return c; } +#ifdef INCLUDE_UNUSED static void flush(void) { } +#endif static int contained_tab = 0; static int mandoc_line = 0; /* Signals whether to look for embedded @@ -3760,7 +3762,6 @@ scan_troff(char *c, int san, char **result) char *h; char intbuff[NULL_TERMINATED(MED_STR_MAX)]; int ibp = 0; - int i; char *exbuffer; int exbuffpos, exbuffmax, exscaninbuff, exnewline_for_fun; int usenbsp = 0; @@ -3819,8 +3820,6 @@ scan_troff(char *c, int san, char **result) if (san && h[-1] == '\n') h--; } else { - int mx; - if (h[-1] == '\n' && still_dd && isalnum(*h)) { /* * sometimes a .HP request is not followed by @@ -3989,11 +3988,10 @@ scan_troff_mandoc(char *c, int san, char **result) int main(int argc, char **argv) { - FILE *f; char *t; - int l, i; + int i; char *buf; - char *h, *fullname; + char *h; STRDEF *stdf; t = NULL; diff --git a/trap.c b/trap.c index 28013e8..a533693 100644 --- a/trap.c +++ b/trap.c @@ -186,6 +186,7 @@ initialize_traps () } #ifdef DEBUG +#ifdef INCLUDE_UNUSED /* Return a printable representation of the trap handler for SIG. */ static char * trap_handler_string (sig) @@ -203,6 +204,7 @@ trap_handler_string (sig) return "NULL"; } #endif +#endif /* Return the print name of this signal. */ char * @@ -934,8 +936,8 @@ _run_trap_internal (sig, tag) char *tag; { char *trap_command, *old_trap; - int trap_exit_value, *token_state; - volatile int save_return_catch_flag, function_code, top_level_code, old_int; + int trap_exit_value; + volatile int save_return_catch_flag, function_code, old_int; int flags; procenv_t save_return_catch; WORD_LIST *save_subst_varlist; diff --git a/variables.c b/variables.c index a08313d..f09fa1b 100644 --- a/variables.c +++ b/variables.c @@ -649,13 +649,11 @@ initialize_shell_variables (env, privmode) static void set_machine_vars () { - SHELL_VAR *temp_var; - - temp_var = set_if_not ("HOSTTYPE", HOSTTYPE); - temp_var = set_if_not ("OSTYPE", OSTYPE); - temp_var = set_if_not ("MACHTYPE", MACHTYPE); + set_if_not ("HOSTTYPE", HOSTTYPE); + set_if_not ("OSTYPE", OSTYPE); + set_if_not ("MACHTYPE", MACHTYPE); - temp_var = set_if_not ("HOSTNAME", current_host_name); + set_if_not ("HOSTNAME", current_host_name); } /* Set $HOME to the information in the password file if we didn't get @@ -1970,7 +1968,7 @@ find_variable_nameref (v) SHELL_VAR *v; { int level, flags; - char *newname, *t; + char *newname; SHELL_VAR *orig, *oldv; level = 0; @@ -2068,7 +2066,6 @@ find_nameref_at_context (v, vc) VAR_CONTEXT *vc; { SHELL_VAR *nv, *nv2; - VAR_CONTEXT *nvc; char *newname; int level; @@ -3012,7 +3009,6 @@ bind_variable (name, value, flags) { SHELL_VAR *v, *nv; VAR_CONTEXT *vc, *nvc; - int level; if (shell_variables == 0) create_variable_tables (); @@ -3090,10 +3086,6 @@ bind_global_variable (name, value, flags) char *value; int flags; { - SHELL_VAR *v, *nv; - VAR_CONTEXT *vc, *nvc; - int level; - if (shell_variables == 0) create_variable_tables (); @@ -4397,6 +4389,7 @@ mk_env_string (name, value, isfunc) #ifdef DEBUG /* Debugging */ +#ifdef INCLUDE_UNUSED static int valid_exportstr (v) SHELL_VAR *v; @@ -4432,6 +4425,7 @@ valid_exportstr (v) return (1); } #endif +#endif static char ** make_env_array_from_var_list (vars) @@ -5741,13 +5735,12 @@ ARRAY * save_pipestatus_array () { SHELL_VAR *v; - ARRAY *a, *a2; + ARRAY *a2; v = find_variable ("PIPESTATUS"); if (v == 0 || array_p (v) == 0 || array_cell (v) == 0) return ((ARRAY *)NULL); - a = array_cell (v); a2 = array_copy (array_cell (v)); return a2; diff --git a/xmalloc.c b/xmalloc.c index b32c068..ca297dc 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -51,9 +51,11 @@ extern char *sbrk(); #endif +#if defined (HAVE_SBRK) && defined (USING_BASH_MALLOC) static PTR_T lbreak; static int brkfound; static size_t allocated; +#endif /* **************************************************************** */ /* */ -- 2.9.4