From: Peter Avalos Date: Thu, 28 Sep 2006 22:29:44 +0000 (+0000) Subject: Fix most compiler warnings. The last warnings at WARNS6 will need to be X-Git-Tag: v2.0.1~4336 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/934863d78677417ae0ccb1fbe80b6240bbff1e35 Fix most compiler warnings. The last warnings at WARNS6 will need to be fixed in usr.bin/printf. Remove nested externs. Rename local variables shadowing globals. Some changes taken from NetBSD. --- diff --git a/bin/sh/Makefile b/bin/sh/Makefile index e26b2edcd9..a27b7ff497 100644 --- a/bin/sh/Makefile +++ b/bin/sh/Makefile @@ -1,8 +1,8 @@ # @(#)Makefile 8.4 (Berkeley) 5/5/95 # $FreeBSD: src/bin/sh/Makefile,v 1.30.2.1 2001/12/15 10:05:18 knu Exp $ -# $DragonFly: src/bin/sh/Makefile,v 1.6 2006/09/28 04:24:05 pavalos Exp $ +# $DragonFly: src/bin/sh/Makefile,v 1.7 2006/09/28 22:29:44 pavalos Exp $ -WARNS?= 3 # Not yet +WARNS?= 5 # Not yet PROG= sh SHSRCS= alias.c arith.y arith_lex.l cd.c echo.c error.c eval.c exec.c expand.c \ diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 1628676bb5..3cd8965a40 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -35,7 +35,7 @@ * * @(#)eval.c 8.9 (Berkeley) 6/8/95 * $FreeBSD: src/bin/sh/eval.c,v 1.27.2.5 2002/08/27 01:36:28 tjr Exp $ - * $DragonFly: src/bin/sh/eval.c,v 1.8 2006/07/20 17:01:22 corecode Exp $ + * $DragonFly: src/bin/sh/eval.c,v 1.9 2006/09/28 22:29:44 pavalos Exp $ */ #include /* For WIFSIGNALED(status) */ @@ -79,7 +79,7 @@ #define EV_TESTED 02 /* exit status is checked; ignore -e flag */ #define EV_BACKCMD 04 /* command executing within back quotes */ -MKINIT int evalskip; /* set if we are skipping commands */ +int evalskip; /* set if we are skipping commands */ STATIC int skipcount; /* number of levels to skip */ MKINIT int loopnest; /* current loop nesting level */ int funcnest; /* depth of function calls */ @@ -772,7 +772,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) INTON; if (setjmp(jmploc.loc)) { if (exception == EXSHELLPROC) - freeparam((struct shparam *)&saveparam); + freeparam(&saveparam); else { freeparam(&shellparam); shellparam = saveparam; diff --git a/bin/sh/exec.c b/bin/sh/exec.c index 9b8941ed82..b995f61799 100644 --- a/bin/sh/exec.c +++ b/bin/sh/exec.c @@ -35,7 +35,7 @@ * * @(#)exec.c 8.4 (Berkeley) 6/8/95 * $FreeBSD: src/bin/sh/exec.c,v 1.14.2.4 2002/08/27 01:36:28 tjr Exp $ - * $DragonFly: src/bin/sh/exec.c,v 1.7 2006/06/19 12:06:07 corecode Exp $ + * $DragonFly: src/bin/sh/exec.c,v 1.8 2006/09/28 22:29:44 pavalos Exp $ */ #include @@ -100,7 +100,7 @@ STATIC void printentry(struct tblentry *, int); STATIC struct tblentry *cmdlookup(char *, int); STATIC void delete_cmd_entry(void); - +extern const char *const parsekwd[]; /* * Exec a program. Never returns. If you change this routine, you may @@ -108,7 +108,7 @@ STATIC void delete_cmd_entry(void); */ void -shellexec(char **argv, char **envp, const char *path, int index) +shellexec(char **argv, char **envp, const char *path, int idx) { char *cmdname; int e; @@ -119,7 +119,7 @@ shellexec(char **argv, char **envp, const char *path, int index) } else { e = ENOENT; while ((cmdname = padvance(&path, argv[0])) != NULL) { - if (--index < 0 && pathopt == NULL) { + if (--idx < 0 && pathopt == NULL) { tryexec(cmdname, argv, envp); if (errno != ENOENT && errno != ENOTDIR) e = errno; @@ -265,17 +265,17 @@ hashcmd(int argc __unused, char **argv __unused) STATIC void printentry(struct tblentry *cmdp, int verbose) { - int index; + int idx; const char *path; char *name; if (cmdp->cmdtype == CMDNORMAL) { - index = cmdp->param.index; + idx = cmdp->param.index; path = pathval(); do { name = padvance(&path, cmdp->cmdname); stunalloc(name); - } while (--index >= 0); + } while (--idx >= 0); out1str(name); } else if (cmdp->cmdtype == CMDBUILTIN) { out1fmt("builtin %s", cmdp->cmdname); @@ -310,7 +310,7 @@ void find_command(char *name, struct cmdentry *entry, int printerr, const char *path) { struct tblentry *cmdp; - int index; + int idx; int prev; char *fullname; struct stat statb; @@ -348,11 +348,11 @@ find_command(char *name, struct cmdentry *entry, int printerr, const char *path) } e = ENOENT; - index = -1; + idx = -1; loop: while ((fullname = padvance(&path, name)) != NULL) { stunalloc(fullname); - index++; + idx++; if (pathopt) { if (prefix("builtin", pathopt)) { if ((i = find_builtin(name)) < 0) @@ -370,8 +370,8 @@ loop: } } /* if rehash, don't redo absolute path names */ - if (fullname[0] == '/' && index <= prev) { - if (index < prev) + if (fullname[0] == '/' && idx <= prev) { + if (idx < prev) goto loop; TRACE(("searchexec \"%s\": no change\n", name)); goto success; @@ -408,7 +408,7 @@ loop: INTOFF; cmdp = cmdlookup(name, 1); cmdp->cmdtype = CMDNORMAL; - cmdp->param.index = index; + cmdp->param.index = idx; INTON; goto success; } @@ -482,18 +482,18 @@ void changepath(const char *newval) { const char *old, *new; - int index; + int idx; int firstchange; int bltin; old = pathval(); new = newval; firstchange = 9999; /* assume no change */ - index = 0; + idx = 0; bltin = -1; for (;;) { if (*old != *new) { - firstchange = index; + firstchange = idx; if ((*old == '\0' && *new == ':') || (*old == ':' && *new == '\0')) firstchange++; @@ -502,9 +502,9 @@ changepath(const char *newval) if (*new == '\0') break; if (*new == '%' && bltin < 0 && prefix("builtin", new + 1)) - bltin = index; + bltin = idx; if (*new == ':') { - index++; + idx++; } new++, old++; } @@ -713,8 +713,7 @@ typecmd(int argc, char **argv) const char * const *pp; struct alias *ap; int i; - int error = 0; - extern const char *const parsekwd[]; + int err = 0; for (i = 1; i < argc; i++) { out1str(argv[i]); @@ -762,7 +761,7 @@ typecmd(int argc, char **argv) } else { out1fmt(": %s\n", strerror(errno)); - error |= 127; + err |= 127; } } break; @@ -777,9 +776,9 @@ typecmd(int argc, char **argv) default: out1str(": not found\n"); - error |= 127; + err |= 127; break; } } - return error; + return err; } diff --git a/bin/sh/expand.c b/bin/sh/expand.c index fee2cfb6ab..2bc389af0f 100644 --- a/bin/sh/expand.c +++ b/bin/sh/expand.c @@ -35,7 +35,7 @@ * * @(#)expand.c 8.5 (Berkeley) 5/15/95 * $FreeBSD: src/bin/sh/expand.c,v 1.31.2.5 2003/01/17 07:44:01 tjr Exp $ - * $DragonFly: src/bin/sh/expand.c,v 1.6 2005/07/03 14:03:24 corecode Exp $ + * $DragonFly: src/bin/sh/expand.c,v 1.7 2006/09/28 22:29:44 pavalos Exp $ */ #include @@ -127,6 +127,8 @@ collate_range_cmp (int c1, int c2) return (c1 - c2); } +extern int oexitstatus; + /* * Expand shell variables and backquotes inside a here document. * union node *arg the document @@ -839,7 +841,6 @@ varvalue(char *name, int quoted, int allow_split) int num; char *p; int i; - extern int oexitstatus; char sep; char **ap; char const *syntax; diff --git a/bin/sh/histedit.c b/bin/sh/histedit.c index 6b6cf78a65..f65a2d3897 100644 --- a/bin/sh/histedit.c +++ b/bin/sh/histedit.c @@ -35,7 +35,7 @@ * * @(#)histedit.c 8.2 (Berkeley) 5/4/95 * $FreeBSD: src/bin/sh/histedit.c,v 1.13.2.4 2002/08/27 01:36:28 tjr Exp $ - * $DragonFly: src/bin/sh/histedit.c,v 1.8 2006/06/05 15:55:13 dillon Exp $ + * $DragonFly: src/bin/sh/histedit.c,v 1.9 2006/09/28 22:29:44 pavalos Exp $ */ #include @@ -357,14 +357,14 @@ histcmd(int argc, char **argv) out1fmt("%5d ", he.num); out1str(he.str); } else { - char *s = pat ? - fc_replace(he.str, pat, repl) : (char *)he.str; + const char *s = pat ? + fc_replace(he.str, pat, repl) : he.str; if (sflg) { if (displayhist) { out2str(s); } - evalstring(s); + evalstring(strcpy(stalloc(strlen(s) + 1), s)); if (displayhist && hist) { /* * XXX what about recursive and diff --git a/bin/sh/input.c b/bin/sh/input.c index afaac776c2..de36e3e5e8 100644 --- a/bin/sh/input.c +++ b/bin/sh/input.c @@ -35,7 +35,7 @@ * * @(#)input.c 8.3 (Berkeley) 6/9/95 * $FreeBSD: src/bin/sh/input.c,v 1.14.2.2 2002/08/27 01:36:28 tjr Exp $ - * $DragonFly: src/bin/sh/input.c,v 1.6 2005/11/13 11:58:30 corecode Exp $ + * $DragonFly: src/bin/sh/input.c,v 1.7 2006/09/28 22:29:44 pavalos Exp $ */ #include /* defines BUFSIZ */ @@ -93,11 +93,11 @@ struct parsefile { int plinno = 1; /* input line number */ -MKINIT int parsenleft; /* copy of parsefile->nleft */ +int parsenleft; /* copy of parsefile->nleft */ MKINIT int parselleft; /* copy of parsefile->lleft */ char *parsenextc; /* copy of parsefile->nextc */ MKINIT struct parsefile basepf; /* top level input file */ -char basebuf[BUFSIZ]; /* buffer for top level input file */ +MKINIT char basebuf[BUFSIZ]; /* buffer for top level input file */ STATIC struct parsefile *parsefile = &basepf; /* current input file */ int init_editline = 0; /* editline library initialized? */ int whichprompt; /* 1 == PS1, 2 == PS2 */ @@ -108,12 +108,11 @@ STATIC void pushfile(void); static int preadfd(void); #ifdef mkinit +INCLUDE INCLUDE "input.h" INCLUDE "error.h" INIT { - extern char basebuf[]; - basepf.nextc = basepf.buf = basebuf; } diff --git a/bin/sh/main.c b/bin/sh/main.c index 23d3191de9..5a8006df50 100644 --- a/bin/sh/main.c +++ b/bin/sh/main.c @@ -36,7 +36,7 @@ * @(#) Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. * @(#)main.c 8.6 (Berkeley) 5/28/95 * $FreeBSD: src/bin/sh/main.c,v 1.18.2.3 2002/07/19 04:38:51 tjr Exp $ - * $DragonFly: src/bin/sh/main.c,v 1.5 2004/11/07 20:54:52 eirikn Exp $ + * $DragonFly: src/bin/sh/main.c,v 1.6 2006/09/28 22:29:44 pavalos Exp $ */ #include @@ -80,6 +80,8 @@ extern int etext(); STATIC void read_profile(const char *); STATIC const char *find_dot_file(const char *); +extern int oexitstatus; + /* * Main routine. We initialize things, parse the arguments, execute * profiles if we're a login shell, and then call cmdloop to execute @@ -341,8 +343,6 @@ dotcmd(int argc, char **argv) int exitcmd(int argc, char **argv) { - extern int oexitstatus; - if (stoppedjobs()) return 0; if (argc > 1) diff --git a/bin/sh/options.c b/bin/sh/options.c index 0095c9b30d..84df06cd5f 100644 --- a/bin/sh/options.c +++ b/bin/sh/options.c @@ -35,7 +35,7 @@ * * @(#)options.c 8.2 (Berkeley) 5/4/95 * $FreeBSD: src/bin/sh/options.c,v 1.15.2.2 2002/07/19 04:38:52 tjr Exp $ - * $DragonFly: src/bin/sh/options.c,v 1.4 2004/11/07 20:54:52 eirikn Exp $ + * $DragonFly: src/bin/sh/options.c,v 1.5 2006/09/28 22:29:44 pavalos Exp $ */ #include @@ -299,7 +299,7 @@ setparam(char **argv) */ void -freeparam(struct shparam *param) +freeparam(volatile struct shparam *param) { char **ap; @@ -402,7 +402,7 @@ getoptscmd(int argc, char **argv) STATIC int getopts(char *optstr, char *optvar, char **optfirst, char ***optnext, - char **optptr) + char **optp) { char *p, *q; char c = '?'; @@ -411,7 +411,7 @@ getopts(char *optstr, char *optvar, char **optfirst, char ***optnext, int err = 0; char s[10]; - if ((p = *optptr) == NULL || *p == '\0') { + if ((p = *optp) == NULL || *p == '\0') { /* Current word is done, advance */ if (*optnext == NULL) return 1; @@ -479,7 +479,7 @@ bad: *optnext = NULL; p = NULL; out: - *optptr = p; + *optp = p; fmtstr(s, sizeof(s), "%d", ind); err |= setvarsafe("OPTIND", s, VNOFUNC); s[0] = c; @@ -487,7 +487,7 @@ out: err |= setvarsafe(optvar, s, 0); if (err) { *optnext = NULL; - *optptr = NULL; + *optp = NULL; flushall(); exraise(EXERROR); } diff --git a/bin/sh/options.h b/bin/sh/options.h index b661ef6d8a..3ca1c99627 100644 --- a/bin/sh/options.h +++ b/bin/sh/options.h @@ -35,7 +35,7 @@ * * @(#)options.h 8.2 (Berkeley) 5/4/95 * $FreeBSD: src/bin/sh/options.h,v 1.9.2.3 2002/08/27 01:36:28 tjr Exp $ - * $DragonFly: src/bin/sh/options.h,v 1.3 2004/03/19 18:39:41 cpressey Exp $ + * $DragonFly: src/bin/sh/options.h,v 1.4 2006/09/28 22:29:44 pavalos Exp $ */ struct shparam { @@ -112,7 +112,7 @@ extern const char *optptr; /* used by nextopt */ void procargs(int, char **); void optschanged(void); void setparam(char **); -void freeparam(struct shparam *); +void freeparam(volatile struct shparam *); int shiftcmd(int, char **); int setcmd(int, char **); int getoptscmd(int, char **); diff --git a/bin/sh/parser.c b/bin/sh/parser.c index d263cb1ae6..fb0a51e9ec 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -35,7 +35,7 @@ * * @(#)parser.c 8.7 (Berkeley) 5/16/95 * $FreeBSD: src/bin/sh/parser.c,v 1.29.2.9 2002/10/18 11:24:04 tjr Exp $ - * $DragonFly: src/bin/sh/parser.c,v 1.7 2006/09/28 04:19:40 pavalos Exp $ + * $DragonFly: src/bin/sh/parser.c,v 1.8 2006/09/28 22:29:44 pavalos Exp $ */ #include @@ -97,13 +97,6 @@ STATIC int startlinno; /* line # where last token started */ /* XXX When 'noaliases' is set to one, no alias expansion takes place. */ static int noaliases = 0; -#define GDB_HACK 1 /* avoid local declarations which gdb can't handle */ -#ifdef GDB_HACK -static const char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE, '@', '=', '\0'}; -static const char types[] = "}-+?="; -#endif - - STATIC union node *list(int); STATIC union node *andor(void); STATIC union node *pipeline(void); @@ -380,13 +373,10 @@ TRACE(("expecting DO got %s %s\n", tokname[got], got == TWORD ? wordtext : "")); if (lasttoken != TNL && lasttoken != TSEMI) synexpect(-1); } else { -#ifndef GDB_HACK - static const char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE, - '@', '=', '\0'}; -#endif + static char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE, '@', '=', '\0'}; n2 = (union node *)stalloc(sizeof (struct narg)); n2->type = NARG; - n2->narg.text = (char *)argvars; + n2->narg.text = argvars; n2->narg.backquote = NULL; n2->narg.next = NULL; n1->nfor.args = n2; @@ -1183,9 +1173,7 @@ parsesub: { int typeloc; int flags; char *p; -#ifndef GDB_HACK static const char types[] = "}-+?="; -#endif int bracketed_name = 0; /* used to handle ${[0-9]*} variables */ c = pgetc(); @@ -1322,24 +1310,24 @@ parsebackq: { /* We must read until the closing backquote, giving special treatment to some slashes, and then push the string and reread it as input, interpreting it normally. */ - char *out; - int c; - int savelen; - char *str; + char *pout; + int pc; + int psavelen; + char *pstr; - STARTSTACKSTR(out); + STARTSTACKSTR(pout); for (;;) { if (needprompt) { setprompt(2); needprompt = 0; } - switch (c = pgetc()) { + switch (pc = pgetc()) { case '`': goto done; case '\\': - if ((c = pgetc()) == '\n') { + if ((pc = pgetc()) == '\n') { plinno++; if (doprompt) setprompt(2); @@ -1353,9 +1341,9 @@ parsebackq: { */ continue; } - if (c != '\\' && c != '`' && c != '$' - && (!dblquote || c != '"')) - STPUTC('\\', out); + if (pc != '\\' && pc != '`' && pc != '$' + && (!dblquote || pc != '"')) + STPUTC('\\', pout); break; case '\n': @@ -1371,15 +1359,15 @@ parsebackq: { default: break; } - STPUTC(c, out); + STPUTC(pc, pout); } done: - STPUTC('\0', out); - savelen = out - stackblock(); - if (savelen > 0) { - str = ckmalloc(savelen); - memcpy(str, stackblock(), savelen); - setinputstring(str, 1); + STPUTC('\0', pout); + psavelen = pout - stackblock(); + if (psavelen > 0) { + pstr = ckmalloc(psavelen); + memcpy(pstr, stackblock(), psavelen); + setinputstring(pstr, 1); } } nlpp = &bqlist; diff --git a/bin/sh/var.c b/bin/sh/var.c index 6976bbd561..31b7480653 100644 --- a/bin/sh/var.c +++ b/bin/sh/var.c @@ -35,7 +35,7 @@ * * @(#)var.c 8.3 (Berkeley) 5/4/95 * $FreeBSD: src/bin/sh/var.c,v 1.15.2.2 2002/08/27 01:36:28 tjr Exp $ - * $DragonFly: src/bin/sh/var.c,v 1.11 2006/01/12 13:43:10 corecode Exp $ + * $DragonFly: src/bin/sh/var.c,v 1.12 2006/09/28 22:29:44 pavalos Exp $ */ #include @@ -72,7 +72,7 @@ struct varinit { struct var *var; int flags; - char *text; + const char *text; void (*func)(const char *); }; @@ -128,9 +128,9 @@ STATIC int localevar(const char *); #ifdef mkinit INCLUDE "var.h" +MKINIT char **environ; INIT { char **envp; - extern char **environ; initvar(); for (envp = environ ; *envp ; envp++) { @@ -160,7 +160,7 @@ initvar(void) vpp = hashvar(ip->text); vp->next = *vpp; *vpp = vp; - vp->text = ip->text; + vp->text = strdup(ip->text); vp->flags = ip->flags; vp->func = ip->func; } @@ -172,7 +172,7 @@ initvar(void) vpp = hashvar("PS1="); vps1.next = *vpp; *vpp = &vps1; - vps1.text = geteuid() ? "PS1=$ " : "PS1=# "; + vps1.text = strdup(geteuid() ? "PS1=$ " : "PS1=# "); vps1.flags = VSTRFIXED|VTEXTFIXED; } if ((vppid.flags & VEXPORT) == 0) { @@ -447,7 +447,7 @@ environment(void) */ #ifdef mkinit -MKINIT void shprocvar(void); +void shprocvar(void); SHELLPROC { shprocvar();