From 3d42469030526b96a1a7b64b818e55286fb7286e Mon Sep 17 00:00:00 2001 From: christos Date: Fri, 9 Jul 1999 03:05:49 +0000 Subject: [PATCH] compile with WARNS = 2 --- bin/sh/Makefile | 3 ++- bin/sh/arith.y | 14 +++++----- bin/sh/cd.c | 8 +++--- bin/sh/error.c | 25 ++++++++--------- bin/sh/error.h | 8 +++--- bin/sh/eval.c | 13 ++++----- bin/sh/exec.c | 64 +++++++++++++++++++++++--------------------- bin/sh/exec.h | 11 ++++---- bin/sh/expand.c | 20 +++++++------- bin/sh/expand.h | 4 +-- bin/sh/histedit.c | 25 +++++++++-------- bin/sh/input.c | 13 ++++----- bin/sh/input.h | 4 +-- bin/sh/jobs.c | 15 ++++++----- bin/sh/mail.c | 6 ++--- bin/sh/main.c | 10 +++---- bin/sh/mkbuiltins | 4 +-- bin/sh/mktokens | 7 ++--- bin/sh/myhistedit.h | 4 +-- bin/sh/mystring.c | 6 ++--- bin/sh/options.c | 21 ++++++++------- bin/sh/options.h | 6 ++--- bin/sh/parser.c | 65 +++++++++++++++++++-------------------------- bin/sh/parser.h | 4 +-- bin/sh/var.c | 52 +++++++++++++++++++----------------- bin/sh/var.h | 12 ++++----- 26 files changed, 215 insertions(+), 209 deletions(-) diff --git a/bin/sh/Makefile b/bin/sh/Makefile index e7e05ada3d47..2424f0599e69 100644 --- a/bin/sh/Makefile +++ b/bin/sh/Makefile @@ -1,6 +1,7 @@ -# $NetBSD: Makefile,v 1.48 1999/02/05 22:19:47 tron Exp $ +# $NetBSD: Makefile,v 1.49 1999/07/09 03:05:49 christos Exp $ # @(#)Makefile 8.4 (Berkeley) 5/5/95 +WARNS=2 YHEADER=1 PROG= sh SHSRCS= alias.c cd.c echo.c error.c eval.c exec.c expand.c \ diff --git a/bin/sh/arith.y b/bin/sh/arith.y index 7e0eeddb43b6..c34ee46bae58 100644 --- a/bin/sh/arith.y +++ b/bin/sh/arith.y @@ -1,5 +1,5 @@ %{ -/* $NetBSD: arith.y,v 1.12 1999/02/05 07:52:52 christos Exp $ */ +/* $NetBSD: arith.y,v 1.13 1999/07/09 03:05:49 christos Exp $ */ /*- * Copyright (c) 1993 @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)arith.y 8.3 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: arith.y,v 1.12 1999/02/05 07:52:52 christos Exp $"); +__RCSID("$NetBSD: arith.y,v 1.13 1999/07/09 03:05:49 christos Exp $"); #endif #endif /* not lint */ @@ -53,9 +53,9 @@ __RCSID("$NetBSD: arith.y,v 1.12 1999/02/05 07:52:52 christos Exp $"); #include "output.h" #include "memalloc.h" -char *arith_buf, *arith_startbuf; +const char *arith_buf, *arith_startbuf; -void yyerror __P((char *)); +void yyerror __P((const char *)); int yyparse __P((void)); #ifdef TESTARITH int main __P((int , char *[])); @@ -64,7 +64,7 @@ int error __P((char *)); int arith(s) - char *s; + const char *s; { long result; @@ -87,7 +87,7 @@ expcmd(argc, argv) int argc; char **argv; { - char *p; + const char *p; char *concat; char **ap; long i; @@ -192,7 +192,7 @@ expr: ARITH_LPAREN expr ARITH_RPAREN = { $$ = $2; } %% void yyerror(s) - char *s; + const char *s; { yyerrok; diff --git a/bin/sh/cd.c b/bin/sh/cd.c index fce4806419bd..60006a8e78ec 100644 --- a/bin/sh/cd.c +++ b/bin/sh/cd.c @@ -1,4 +1,4 @@ -/* $NetBSD: cd.c,v 1.26 1998/07/28 11:41:52 mycroft Exp $ */ +/* $NetBSD: cd.c,v 1.27 1999/07/09 03:05:49 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)cd.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: cd.c,v 1.26 1998/07/28 11:41:52 mycroft Exp $"); +__RCSID("$NetBSD: cd.c,v 1.27 1999/07/09 03:05:49 christos Exp $"); #endif #endif /* not lint */ @@ -83,8 +83,8 @@ cdcmd(argc, argv) int argc; char **argv; { - char *dest; - char *path; + const char *dest; + const char *path; char *p; struct stat statb; int print = 0; diff --git a/bin/sh/error.c b/bin/sh/error.c index 9d07f69ce4d7..8db49bd932f2 100644 --- a/bin/sh/error.c +++ b/bin/sh/error.c @@ -1,4 +1,4 @@ -/* $NetBSD: error.c,v 1.21 1999/04/05 15:00:28 mycroft Exp $ */ +/* $NetBSD: error.c,v 1.22 1999/07/09 03:05:49 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)error.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: error.c,v 1.21 1999/04/05 15:00:28 mycroft Exp $"); +__RCSID("$NetBSD: error.c,v 1.22 1999/07/09 03:05:49 christos Exp $"); #endif #endif /* not lint */ @@ -72,7 +72,8 @@ volatile int intpending; char *commandname; -static void exverror __P((int, char *, va_list)) __attribute__((__noreturn__)); +static void exverror __P((int, const char *, va_list)) + __attribute__((__noreturn__)); /* * Called to raise an exception. Since C doesn't include exceptions, we @@ -130,7 +131,7 @@ onint() { static void exverror(cond, msg, ap) int cond; - char *msg; + const char *msg; va_list ap; { CLEAR_PENDING_INT; @@ -156,7 +157,7 @@ exverror(cond, msg, ap) #ifdef __STDC__ void -error(char *msg, ...) +error(const char *msg, ...) #else void error(va_alist) @@ -164,14 +165,14 @@ error(va_alist) #endif { #ifndef __STDC__ - char *msg; + const char *msg; #endif va_list ap; #ifdef __STDC__ va_start(ap, msg); #else va_start(ap); - msg = va_arg(ap, char *); + msg = va_arg(ap, const char *); #endif exverror(EXERROR, msg, ap); /* NOTREACHED */ @@ -181,7 +182,7 @@ error(va_alist) #ifdef __STDC__ void -exerror(int cond, char *msg, ...) +exerror(int cond, const char *msg, ...) #else void exerror(va_alist) @@ -190,7 +191,7 @@ exerror(va_alist) { #ifndef __STDC__ int cond; - char *msg; + const char *msg; #endif va_list ap; #ifdef __STDC__ @@ -198,7 +199,7 @@ exerror(va_alist) #else va_start(ap); cond = va_arg(ap, int); - msg = va_arg(ap, char *); + msg = va_arg(ap, const char *); #endif exverror(cond, msg, ap); /* NOTREACHED */ @@ -214,7 +215,7 @@ exerror(va_alist) struct errname { short errcode; /* error number */ short action; /* operation which encountered the error */ - char *msg; /* text describing the error */ + const char *msg; /* text describing the error */ }; @@ -281,7 +282,7 @@ STATIC const struct errname errormsg[] = { * Action describes the operation that got the error. */ -char * +const char * errmsg(e, action) int e; int action; diff --git a/bin/sh/error.h b/bin/sh/error.h index 2bb65b3294ed..4b2a1d2cc396 100644 --- a/bin/sh/error.h +++ b/bin/sh/error.h @@ -1,4 +1,4 @@ -/* $NetBSD: error.h,v 1.12 1998/07/28 11:41:53 mycroft Exp $ */ +/* $NetBSD: error.h,v 1.13 1999/07/09 03:05:49 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -92,9 +92,9 @@ extern char *commandname; /* name of command--printed on error */ void exraise __P((int)) __attribute__((__noreturn__)); void onint __P((void)); -void error __P((char *, ...)) __attribute__((__noreturn__)); -void exerror __P((int, char *, ...)) __attribute__((__noreturn__)); -char *errmsg __P((int, int)); +void error __P((const char *, ...)) __attribute__((__noreturn__)); +void exerror __P((int, const char *, ...)) __attribute__((__noreturn__)); +const char *errmsg __P((int, int)); /* diff --git a/bin/sh/eval.c b/bin/sh/eval.c index e8a198517c6f..8d42398568c7 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -1,4 +1,4 @@ -/* $NetBSD: eval.c,v 1.46 1999/06/26 16:31:47 christos Exp $ */ +/* $NetBSD: eval.c,v 1.47 1999/07/09 03:05:49 christos Exp $ */ /*- * Copyright (c) 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95"; #else -__RCSID("$NetBSD: eval.c,v 1.46 1999/06/26 16:31:47 christos Exp $"); +__RCSID("$NetBSD: eval.c,v 1.47 1999/07/09 03:05:49 christos Exp $"); #endif #endif /* not lint */ @@ -684,7 +684,7 @@ evalcommand(cmd, flags, backcmd) cmdentry.u.index = BLTINCMD; } else { static const char PATH[] = "PATH="; - char *path = pathval(); + const char *path = pathval(); /* * Modify the command lookup path, if a PATH= assignment @@ -764,9 +764,10 @@ evalcommand(cmd, flags, backcmd) localvars = NULL; INTON; if (setjmp(jmploc.loc)) { - if (exception == EXSHELLPROC) - freeparam((struct shparam *)&saveparam); - else { + if (exception == EXSHELLPROC) { + freeparam((volatile struct shparam *) + &saveparam); + } else { freeparam(&shellparam); shellparam = saveparam; } diff --git a/bin/sh/exec.c b/bin/sh/exec.c index b848fbcbea0f..59ebb0b1f8a6 100644 --- a/bin/sh/exec.c +++ b/bin/sh/exec.c @@ -1,4 +1,4 @@ -/* $NetBSD: exec.c,v 1.26 1998/07/28 11:41:54 mycroft Exp $ */ +/* $NetBSD: exec.c,v 1.27 1999/07/09 03:05:49 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95"; #else -__RCSID("$NetBSD: exec.c,v 1.26 1998/07/28 11:41:54 mycroft Exp $"); +__RCSID("$NetBSD: exec.c,v 1.27 1999/07/09 03:05:49 christos Exp $"); #endif #endif /* not lint */ @@ -117,10 +117,10 @@ STATIC void delete_cmd_entry __P((void)); */ void -shellexec(argv, envp, path, index) +shellexec(argv, envp, path, idx) char **argv, **envp; - char *path; - int index; + const char *path; + int idx; { char *cmdname; int e; @@ -131,7 +131,7 @@ shellexec(argv, envp, path, 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; @@ -285,15 +285,16 @@ break2:; * NULL. */ -char *pathopt; +const char *pathopt; char * padvance(path, name) - char **path; - char *name; + const char **path; + const char *name; { - char *p, *q; - char *start; + const char *p; + char *q; + const char *start; int len; if (*path == NULL) @@ -379,17 +380,17 @@ printentry(cmdp, verbose) struct tblentry *cmdp; int verbose; { - int index; - char *path; + 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); @@ -425,10 +426,10 @@ find_command(name, entry, act, path) char *name; struct cmdentry *entry; int act; - char *path; + const char *path; { struct tblentry *cmdp; - int index; + int idx; int prev; char *fullname; struct stat statb; @@ -482,11 +483,11 @@ find_command(name, entry, act, 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) @@ -504,8 +505,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; @@ -546,7 +547,7 @@ loop: INTOFF; cmdp = cmdlookup(name, 1); cmdp->cmdtype = CMDNORMAL; - cmdp->param.index = index; + cmdp->param.index = idx; INTON; goto success; } @@ -618,18 +619,18 @@ changepath(newval) 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++; @@ -638,9 +639,9 @@ changepath(newval) if (*new == '\0') break; if (*new == '%' && bltin < 0 && prefix("builtin", new + 1)) - bltin = index; + bltin = idx; if (*new == ':') { - index++; + idx++; } new++, old++; } @@ -877,7 +878,7 @@ typecmd(argc, argv) char **pp; struct alias *ap; int i; - int error = 0; + int err = 0; extern char *const parsekwd[]; for (i = 1; i < argc; i++) { @@ -911,7 +912,8 @@ typecmd(argc, argv) switch (entry.cmdtype) { case CMDNORMAL: { int j = entry.u.index; - char *path = pathval(), *name; + const char *path = pathval(); + char *name; if (j == -1) name = argv[i]; else { @@ -934,9 +936,9 @@ typecmd(argc, argv) default: out1str(" not found\n"); - error |= 127; + err |= 127; break; } } - return error; + return err; } diff --git a/bin/sh/exec.h b/bin/sh/exec.h index 29760db23818..3c0394951a42 100644 --- a/bin/sh/exec.h +++ b/bin/sh/exec.h @@ -1,4 +1,4 @@ -/* $NetBSD: exec.h,v 1.14 1998/07/28 11:41:54 mycroft Exp $ */ +/* $NetBSD: exec.h,v 1.15 1999/07/09 03:05:50 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -57,13 +57,14 @@ struct cmdentry { #define DO_ERR 1 /* find_command prints errors */ #define DO_ABS 2 /* find_command checks absolute paths */ -extern char *pathopt; /* set by padvance */ +extern const char *pathopt; /* set by padvance */ extern int exerrno; /* last exec error */ -void shellexec __P((char **, char **, char *, int)) __attribute__((noreturn)); -char *padvance __P((char **, char *)); +void shellexec __P((char **, char **, const char *, int)) + __attribute__((noreturn)); +char *padvance __P((const char **, const char *)); int hashcmd __P((int, char **)); -void find_command __P((char *, struct cmdentry *, int, char *)); +void find_command __P((char *, struct cmdentry *, int, const char *)); int find_builtin __P((char *)); void hashcd __P((void)); void changepath __P((const char *)); diff --git a/bin/sh/expand.c b/bin/sh/expand.c index 09da2229a580..29d5e23009c7 100644 --- a/bin/sh/expand.c +++ b/bin/sh/expand.c @@ -1,4 +1,4 @@ -/* $NetBSD: expand.c,v 1.47 1999/04/30 17:54:17 he Exp $ */ +/* $NetBSD: expand.c,v 1.48 1999/07/09 03:05:50 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95"; #else -__RCSID("$NetBSD: expand.c,v 1.47 1999/04/30 17:54:17 he Exp $"); +__RCSID("$NetBSD: expand.c,v 1.48 1999/07/09 03:05:50 christos Exp $"); #endif #endif /* not lint */ @@ -954,7 +954,7 @@ ifsbreakup(string, arglist) char *start; char *p; char *q; - char *ifs; + const char *ifs; int ifsspc; int nulonly; @@ -1119,6 +1119,7 @@ expmeta(enddir, name) char *name; { char *p; + const char *cp; char *q; char *start; char *endname; @@ -1192,14 +1193,14 @@ expmeta(enddir, name) } } if (enddir == expdir) { - p = "."; + cp = "."; } else if (enddir == expdir + 1 && *expdir == '/') { - p = "/"; + cp = "/"; } else { - p = expdir; + cp = expdir; enddir[-1] = '\0'; } - if ((dirp = opendir(p)) == NULL) + if ((dirp = opendir(cp)) == NULL) return; if (enddir != expdir) enddir[-1] = '/'; @@ -1225,9 +1226,8 @@ expmeta(enddir, name) scopy(dp->d_name, enddir); addfname(expdir); } else { - char *q; - for (p = enddir, q = dp->d_name; - (*p++ = *q++) != '\0';) + for (p = enddir, cp = dp->d_name; + (*p++ = *cp++) != '\0';) continue; p[-1] = '/'; expmeta(p, endname); diff --git a/bin/sh/expand.h b/bin/sh/expand.h index 3b15fb65d37b..cde5cef2e417 100644 --- a/bin/sh/expand.h +++ b/bin/sh/expand.h @@ -1,4 +1,4 @@ -/* $NetBSD: expand.h,v 1.11 1999/03/26 15:49:34 christos Exp $ */ +/* $NetBSD: expand.h,v 1.12 1999/07/09 03:05:50 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -69,7 +69,7 @@ void rmescapes __P((char *)); int casematch __P((union node *, char *)); /* From arith.y */ -int arith __P((char *)); +int arith __P((const char *)); int expcmd __P((int , char **)); void arith_lex_reset __P((void)); int yylex __P((void)); diff --git a/bin/sh/histedit.c b/bin/sh/histedit.c index 9409f49daae9..15a30f6cb845 100644 --- a/bin/sh/histedit.c +++ b/bin/sh/histedit.c @@ -1,4 +1,4 @@ -/* $NetBSD: histedit.c,v 1.20 1998/07/28 11:41:55 mycroft Exp $ */ +/* $NetBSD: histedit.c,v 1.21 1999/07/09 03:05:50 christos Exp $ */ /*- * Copyright (c) 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)histedit.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: histedit.c,v 1.20 1998/07/28 11:41:55 mycroft Exp $"); +__RCSID("$NetBSD: histedit.c,v 1.21 1999/07/09 03:05:50 christos Exp $"); #endif #endif /* not lint */ @@ -74,7 +74,7 @@ EditLine *el; /* editline cookie */ int displayhist; static FILE *el_in, *el_out; -STATIC char *fc_replace __P((const char *, char *, char *)); +STATIC const char *fc_replace __P((const char *, char *, char *)); /* * Set history and editing status. Called whenever the status may @@ -186,11 +186,11 @@ histcmd(argc, argv) extern char *optarg; extern int optind, optopt, optreset; int ch; - char *editor = NULL; + const char *editor = NULL; HistEvent he; int lflg = 0, nflg = 0, rflg = 0, sflg = 0; int i, retval; - char *firststr, *laststr; + const char *firststr, *laststr; int first, last, direction; char *pat = NULL, *repl; /* ksh "fc old=new" crap */ static int active = 0; @@ -366,14 +366,17 @@ histcmd(argc, 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; + char *sp; if (sflg) { if (displayhist) { out2str(s); } - evalstring(s); + + evalstring(strcpy(stalloc(strlen(s) + 1), s)); + free(sp); if (displayhist && hist) { /* * XXX what about recursive and @@ -410,7 +413,7 @@ histcmd(argc, argv) return 0; } -STATIC char * +STATIC const char * fc_replace(s, p, r) const char *s; char *p, *r; @@ -447,11 +450,11 @@ not_fcnumber(s) int str_to_event(str, last) - char *str; + const char *str; int last; { HistEvent he; - char *s = str; + const char *s = str; int relative = 0; int i, retval; diff --git a/bin/sh/input.c b/bin/sh/input.c index f38605dc3840..f119f1ac9138 100644 --- a/bin/sh/input.c +++ b/bin/sh/input.c @@ -1,4 +1,4 @@ -/* $NetBSD: input.c,v 1.31 1998/05/20 01:36:14 christos Exp $ */ +/* $NetBSD: input.c,v 1.32 1999/07/09 03:05:50 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)input.c 8.3 (Berkeley) 6/9/95"; #else -__RCSID("$NetBSD: input.c,v 1.31 1998/05/20 01:36:14 christos Exp $"); +__RCSID("$NetBSD: input.c,v 1.32 1999/07/09 03:05:50 christos Exp $"); #endif #endif /* not lint */ @@ -181,7 +181,8 @@ static int preadfd() { int nr; - parsenextc = parsefile->buf; + char *buf = parsefile->buf; + parsenextc = buf; retry: #ifndef SMALL @@ -193,11 +194,11 @@ retry: nr = 0; else { /* XXX - BUFSIZE should redesign so not necessary */ - (void) strcpy(parsenextc, rl_cp); + (void) strcpy(buf, rl_cp); } } else #endif - nr = read(parsefile->fd, parsenextc, BUFSIZ - 1); + nr = read(parsefile->fd, buf, BUFSIZ - 1); if (nr <= 0) { @@ -381,7 +382,7 @@ popstring() void setinputfile(fname, push) - char *fname; + const char *fname; int push; { int fd; diff --git a/bin/sh/input.h b/bin/sh/input.h index 99a5a2c2938e..93f9ecfcf8e6 100644 --- a/bin/sh/input.h +++ b/bin/sh/input.h @@ -1,4 +1,4 @@ -/* $NetBSD: input.h,v 1.9 1996/10/16 15:45:09 christos Exp $ */ +/* $NetBSD: input.h,v 1.10 1999/07/09 03:05:50 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -56,7 +56,7 @@ int preadbuffer __P((void)); void pungetc __P((void)); void pushstring __P((char *, int, void *)); void popstring __P((void)); -void setinputfile __P((char *, int)); +void setinputfile __P((const char *, int)); void setinputfd __P((int, int)); void setinputstring __P((char *, int)); void popfile __P((void)); diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c index bddf1c8a9d5b..57532a688947 100644 --- a/bin/sh/jobs.c +++ b/bin/sh/jobs.c @@ -1,4 +1,4 @@ -/* $NetBSD: jobs.c,v 1.30 1999/04/05 14:59:35 mycroft Exp $ */ +/* $NetBSD: jobs.c,v 1.31 1999/07/09 03:05:50 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: jobs.c,v 1.30 1999/04/05 14:59:35 mycroft Exp $"); +__RCSID("$NetBSD: jobs.c,v 1.31 1999/07/09 03:05:50 christos Exp $"); #endif #endif /* not lint */ @@ -100,7 +100,7 @@ STATIC int dowait __P((int, struct job *)); STATIC int onsigchild __P((void)); STATIC int waitproc __P((int, int *)); STATIC void cmdtxt __P((union node *)); -STATIC void cmdputs __P((char *)); +STATIC void cmdputs __P((const char *)); /* @@ -575,7 +575,7 @@ forkshell(jp, n, mode) int pid; int pgrp; const char *devnull = _PATH_DEVNULL; - /* const */ char *nullerr = "Can't open %s"; + const char *nullerr = "Can't open %s"; TRACE(("forkshell(%%%d, 0x%lx, %d) called\n", jp - jobtab, (long)n, mode)); @@ -975,7 +975,7 @@ cmdtxt(n) { union node *np; struct nodelist *lp; - char *p; + const char *p; int i; char s[2]; @@ -1100,9 +1100,10 @@ redir: STATIC void cmdputs(s) - char *s; + const char *s; { - char *p, *q; + const char *p; + char *q; char c; int subtype = 0; diff --git a/bin/sh/mail.c b/bin/sh/mail.c index ea25fdc3e328..b43f48628e67 100644 --- a/bin/sh/mail.c +++ b/bin/sh/mail.c @@ -1,4 +1,4 @@ -/* $NetBSD: mail.c,v 1.12 1998/01/31 12:36:17 christos Exp $ */ +/* $NetBSD: mail.c,v 1.13 1999/07/09 03:05:50 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)mail.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: mail.c,v 1.12 1998/01/31 12:36:17 christos Exp $"); +__RCSID("$NetBSD: mail.c,v 1.13 1999/07/09 03:05:50 christos Exp $"); #endif #endif /* not lint */ @@ -79,7 +79,7 @@ chkmail(silent) int silent; { int i; - char *mpath; + const char *mpath; char *p; char *q; struct stackmark smark; diff --git a/bin/sh/main.c b/bin/sh/main.c index 63fa099f8627..af681bcfed49 100644 --- a/bin/sh/main.c +++ b/bin/sh/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.33 1999/03/27 13:46:19 christos Exp $ */ +/* $NetBSD: main.c,v 1.34 1999/07/09 03:05:50 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -46,7 +46,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 1993\n\ #if 0 static char sccsid[] = "@(#)main.c 8.7 (Berkeley) 7/19/95"; #else -__RCSID("$NetBSD: main.c,v 1.33 1999/03/27 13:46:19 christos Exp $"); +__RCSID("$NetBSD: main.c,v 1.34 1999/07/09 03:05:50 christos Exp $"); #endif #endif /* not lint */ @@ -90,7 +90,7 @@ short profile_buf[16384]; extern int etext(); #endif -STATIC void read_profile __P((char *)); +STATIC void read_profile __P((const char *)); STATIC char *find_dot_file __P((char *)); int main __P((int, char **)); @@ -282,7 +282,7 @@ cmdloop(top) STATIC void read_profile(name) - char *name; + const char *name; { int fd; int xflag_set = 0; @@ -346,7 +346,7 @@ find_dot_file(basename) char *basename; { char *fullname; - char *path = pathval(); + const char *path = pathval(); struct stat statb; /* don't try this for absolute or relative paths */ diff --git a/bin/sh/mkbuiltins b/bin/sh/mkbuiltins index 8fd1286c8fb3..377985daace7 100644 --- a/bin/sh/mkbuiltins +++ b/bin/sh/mkbuiltins @@ -1,5 +1,5 @@ #!/bin/sh - -# $NetBSD: mkbuiltins,v 1.14 1998/03/29 09:27:41 christos Exp $ +# $NetBSD: mkbuiltins,v 1.15 1999/07/09 03:05:50 christos Exp $ # # Copyright (c) 1991, 1993 # The Regents of the University of California. All rights reserved. @@ -91,7 +91,7 @@ tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ < $temp | awk '{ printf "#define %s %d\n", $1, NR-1}' echo ' struct builtincmd { - char *name; + const char *name; int code; }; diff --git a/bin/sh/mktokens b/bin/sh/mktokens index b7c9e19014d2..9c3e255f896c 100644 --- a/bin/sh/mktokens +++ b/bin/sh/mktokens @@ -1,5 +1,5 @@ #!/bin/sh - -# $NetBSD: mktokens,v 1.8 1996/10/16 14:47:49 christos Exp $ +# $NetBSD: mktokens,v 1.9 1999/07/09 03:05:50 christos Exp $ # # Copyright (c) 1991, 1993 # The Regents of the University of California. All rights reserved. @@ -80,14 +80,15 @@ const char tokendlist[] = {' awk '{print "\t" $2 ","}' /tmp/ka$$ echo '}; -char *const tokname[] = {' +const char *const tokname[] = {' sed -e 's/"/\\"/g' \ -e 's/[^ ]*[ ][ ]*[^ ]*[ ][ ]*\(.*\)/ "\1",/' \ /tmp/ka$$ echo '}; ' sed 's/"//g' /tmp/ka$$ | awk ' -/TIF/{print "#define KWDOFFSET " NR-1; print ""; print "char *const parsekwd[] = {"} +/TIF/{print "#define KWDOFFSET " NR-1; print ""; + print "const char *const parsekwd[] = {"} /TIF/,/neverfound/{print " \"" $3 "\","}' echo ' 0 };' diff --git a/bin/sh/myhistedit.h b/bin/sh/myhistedit.h index 257b4a278531..807c1997869b 100644 --- a/bin/sh/myhistedit.h +++ b/bin/sh/myhistedit.h @@ -1,4 +1,4 @@ -/* $NetBSD: myhistedit.h,v 1.6 1997/04/11 22:45:40 christos Exp $ */ +/* $NetBSD: myhistedit.h,v 1.7 1999/07/09 03:05:50 christos Exp $ */ /*- * Copyright (c) 1993 @@ -46,5 +46,5 @@ void sethistsize __P((const char *)); void setterm __P((const char *)); int histcmd __P((int, char **)); int not_fcnumber __P((char *)); -int str_to_event __P((char *, int)); +int str_to_event __P((const char *, int)); diff --git a/bin/sh/mystring.c b/bin/sh/mystring.c index 2ca62bd9bd21..8829a63069b4 100644 --- a/bin/sh/mystring.c +++ b/bin/sh/mystring.c @@ -1,4 +1,4 @@ -/* $NetBSD: mystring.c,v 1.13 1997/07/04 21:02:15 christos Exp $ */ +/* $NetBSD: mystring.c,v 1.14 1999/07/09 03:05:50 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)mystring.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: mystring.c,v 1.13 1997/07/04 21:02:15 christos Exp $"); +__RCSID("$NetBSD: mystring.c,v 1.14 1999/07/09 03:05:50 christos Exp $"); #endif #endif /* not lint */ @@ -122,7 +122,7 @@ number(s) { if (! is_number(s)) - error("Illegal number: %s", (char *)s); + error("Illegal number: %s", s); return atoi(s); } diff --git a/bin/sh/options.c b/bin/sh/options.c index f2aefee87157..5537000d90ef 100644 --- a/bin/sh/options.c +++ b/bin/sh/options.c @@ -1,4 +1,4 @@ -/* $NetBSD: options.c,v 1.28 1998/07/28 11:41:57 mycroft Exp $ */ +/* $NetBSD: options.c,v 1.29 1999/07/09 03:05:50 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: options.c,v 1.28 1998/07/28 11:41:57 mycroft Exp $"); +__RCSID("$NetBSD: options.c,v 1.29 1999/07/09 03:05:50 christos Exp $"); #endif #endif /* not lint */ @@ -292,7 +292,7 @@ setparam(argv) void freeparam(param) - struct shparam *param; + volatile struct shparam *param; { char **ap; @@ -401,12 +401,12 @@ getoptscmd(argc, argv) } STATIC int -getopts(optstr, optvar, optfirst, optnext, optptr) +getopts(optstr, optvar, optfirst, optnext, optpptr) char *optstr; char *optvar; char **optfirst; char ***optnext; - char **optptr; + char **optpptr; { char *p, *q; char c = '?'; @@ -415,7 +415,7 @@ getopts(optstr, optvar, optfirst, optnext, optptr) int err = 0; char s[10]; - if ((p = *optptr) == NULL || *p == '\0') { + if ((p = *optpptr) == NULL || *p == '\0') { /* Current word is done, advance */ if (*optnext == NULL) return 1; @@ -483,7 +483,7 @@ bad: *optnext = NULL; p = NULL; out: - *optptr = p; + *optpptr = p; fmtstr(s, sizeof(s), "%d", ind); err |= setvarsafe("OPTIND", s, VNOFUNC); s[0] = c; @@ -491,7 +491,7 @@ out: err |= setvarsafe(optvar, s, 0); if (err) { *optnext = NULL; - *optptr = NULL; + *optpptr = NULL; flushall(); exraise(EXERROR); } @@ -511,9 +511,10 @@ out: int nextopt(optstring) - char *optstring; + const char *optstring; { - char *p, *q; + char *p; + const char *q; char c; if ((p = optptr) == NULL || *p == '\0') { diff --git a/bin/sh/options.h b/bin/sh/options.h index 2813e6fbcf3c..0698467aa8bf 100644 --- a/bin/sh/options.h +++ b/bin/sh/options.h @@ -1,4 +1,4 @@ -/* $NetBSD: options.h,v 1.12 1999/02/04 00:27:07 cjs Exp $ */ +/* $NetBSD: options.h,v 1.13 1999/07/09 03:05:50 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -108,9 +108,9 @@ extern char *optptr; /* used by nextopt */ void procargs __P((int, char **)); void optschanged __P((void)); void setparam __P((char **)); -void freeparam __P((struct shparam *)); +void freeparam __P((volatile struct shparam *)); int shiftcmd __P((int, char **)); int setcmd __P((int, char **)); int getoptscmd __P((int, char **)); -int nextopt __P((char *)); +int nextopt __P((const char *)); void getoptsreset __P((const char *)); diff --git a/bin/sh/parser.c b/bin/sh/parser.c index 46a08ad68dfb..124001c815ab 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -1,4 +1,4 @@ -/* $NetBSD: parser.c,v 1.42 1999/02/04 16:17:39 christos Exp $ */ +/* $NetBSD: parser.c,v 1.43 1999/07/09 03:05:50 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95"; #else -__RCSID("$NetBSD: parser.c,v 1.42 1999/02/04 16:17:39 christos Exp $"); +__RCSID("$NetBSD: parser.c,v 1.43 1999/07/09 03:05:50 christos Exp $"); #endif #endif /* not lint */ @@ -101,14 +101,6 @@ int quoteflag; /* set if (part of) last token was quoted */ int startlinno; /* line # where last token started */ -#define GDB_HACK 1 /* avoid local declarations which gdb can't handle */ -#ifdef GDB_HACK -static const char argvars[5] = {(char)CTLVAR, (char)(VSNORMAL|VSQUOTE), - '@', '=', '\0'}; -static const char types[] = "}-+?="; -#endif - - STATIC union node *list __P((int)); STATIC union node *andor __P((void)); STATIC union node *pipeline __P((void)); @@ -123,7 +115,7 @@ STATIC int xxreadtoken __P((void)); STATIC int readtoken1 __P((int, char const *, char *, int)); STATIC int noexpand __P((char *)); STATIC void synexpect __P((int)) __attribute__((noreturn)); -STATIC void synerror __P((char *)) __attribute__((noreturn)); +STATIC void synerror __P((const char *)) __attribute__((noreturn)); STATIC void setprompt __P((int)); @@ -372,13 +364,11 @@ 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, + static char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE, '@', '=', '\0'}; -#endif 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; @@ -728,12 +718,13 @@ readtoken() { */ if (t == TWORD && !quoteflag) { - char * const *pp; + const char *const *pp; - for (pp = (char **)parsekwd; *pp; pp++) { + for (pp = parsekwd; *pp; pp++) { if (**pp == *wordtext && equal(*pp, wordtext)) { - lasttoken = t = pp - parsekwd + KWDOFFSET; + lasttoken = t = pp - + parsekwd + KWDOFFSET; TRACE(("keyword %s recognized\n", tokname[t])); goto out; } @@ -1181,9 +1172,7 @@ parsesub: { int typeloc; int flags; char *p; -#ifndef GDB_HACK static const char types[] = "}-+?="; -#endif c = pgetc(); if (c != '(' && c != '{' && !is_name(c) && !is_special(c)) { @@ -1313,24 +1302,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); @@ -1344,9 +1333,9 @@ parsebackq: { */ continue; } - if (c != '\\' && c != '`' && c != '$' - && (!dblquote || c != '"')) - STPUTC('\\', out); + if (pc != '\\' && pc != '`' && pc != '$' + && (!dblquote || pc != '"')) + STPUTC('\\', pout); break; case '\n': @@ -1362,14 +1351,14 @@ parsebackq: { default: break; } - STPUTC(c, out); + STPUTC(pc, pout); } done: - STPUTC('\0', out); - savelen = out - stackblock(); - if (savelen > 0) { - str = grabstackstr(out); - setinputstring(str, 1); + STPUTC('\0', pout); + psavelen = pout - stackblock(); + if (psavelen > 0) { + pstr = grabstackstr(pout); + setinputstring(pstr, 1); } } nlpp = &bqlist; @@ -1531,7 +1520,7 @@ synexpect(token) STATIC void synerror(msg) - char *msg; + const char *msg; { if (commandname) outfmt(&errout, "%s: %d: ", commandname, startlinno); @@ -1556,7 +1545,7 @@ setprompt(which) * called by editline -- any expansions to the prompt * should be added here. */ -char * +const char * getprompt(unused) void *unused; { diff --git a/bin/sh/parser.h b/bin/sh/parser.h index 6eb68f461455..45a39bea728d 100644 --- a/bin/sh/parser.h +++ b/bin/sh/parser.h @@ -1,4 +1,4 @@ -/* $NetBSD: parser.h,v 1.12 1999/01/25 14:20:56 mycroft Exp $ */ +/* $NetBSD: parser.h,v 1.13 1999/07/09 03:05:50 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -80,4 +80,4 @@ extern int whichprompt; /* 1 == PS1, 2 == PS2 */ union node *parsecmd __P((int)); void fixredir __P((union node *, const char *, int)); int goodname __P((char *)); -char *getprompt __P((void *)); +const char *getprompt __P((void *)); diff --git a/bin/sh/var.c b/bin/sh/var.c index 7c4507d62f2a..3781c855521e 100644 --- a/bin/sh/var.c +++ b/bin/sh/var.c @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.22 1999/01/28 18:11:51 kleink Exp $ */ +/* $NetBSD: var.c,v 1.23 1999/07/09 03:05:50 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: var.c,v 1.22 1999/01/28 18:11:51 kleink Exp $"); +__RCSID("$NetBSD: var.c,v 1.23 1999/07/09 03:05:50 christos Exp $"); #endif #endif /* not lint */ @@ -78,7 +78,7 @@ __RCSID("$NetBSD: var.c,v 1.22 1999/01/28 18:11:51 kleink Exp $"); struct varinit { struct var *var; int flags; - char *text; + const char *text; void (*func) __P((const char *)); }; @@ -133,8 +133,8 @@ const struct varinit varinit[] = { struct var *vartab[VTABSIZE]; -STATIC struct var **hashvar __P((char *)); -STATIC int varequal __P((char *, char *)); +STATIC struct var **hashvar __P((const char *)); +STATIC int varequal __P((const char *, const char *)); /* * Initialize the varable symbol tables and import the environment @@ -172,7 +172,7 @@ initvar() { 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; } @@ -184,7 +184,7 @@ initvar() { vpp = hashvar("PS1="); vps1.next = *vpp; *vpp = &vps1; - vps1.text = geteuid() ? "PS1=$ " : "PS1=# "; + vps1.text = strdup(geteuid() ? "PS1=$ " : "PS1=# "); vps1.flags = VSTRFIXED|VTEXTFIXED; } } @@ -195,7 +195,7 @@ initvar() { int setvarsafe(name, val, flags) - char *name, *val; + const char *name, *val; int flags; { struct jmploc jmploc; @@ -222,10 +222,12 @@ setvarsafe(name, val, flags) void setvar(name, val, flags) - char *name, *val; + const char *name, *val; int flags; { - char *p, *q; + const char *p; + const char *q; + char *d; int len; int namelen; char *nameeq; @@ -253,14 +255,14 @@ setvar(name, val, flags) } else { len += strlen(val); } - p = nameeq = ckmalloc(len); + d = nameeq = ckmalloc(len); q = name; while (--namelen >= 0) - *p++ = *q++; - *p++ = '='; - *p = '\0'; + *d++ = *q++; + *d++ = '='; + *d = '\0'; if (val) - scopy(val, p); + scopy(val, d); setvareq(nameeq, flags); } @@ -345,7 +347,7 @@ listsetvar(list) char * lookupvar(name) - char *name; + const char *name; { struct var *v; @@ -369,7 +371,7 @@ lookupvar(name) char * bltinlookup(name, doall) - char *name; + const char *name; int doall; { struct strlist *sp; @@ -402,7 +404,8 @@ environment() { int nenv; struct var **vpp; struct var *vp; - char **env, **ep; + char **env; + char **ep; nenv = 0; for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) { @@ -499,7 +502,7 @@ exportcmd(argc, argv) struct var **vpp; struct var *vp; char *name; - char *p; + const char *p; int flag = argv[0][0] == 'r'? VREADONLY : VEXPORT; int pflag; @@ -578,8 +581,9 @@ mklocal(name) INTOFF; lvp = ckmalloc(sizeof (struct localvar)); if (name[0] == '-' && name[1] == '\0') { - lvp->text = ckmalloc(sizeof optlist); - memcpy(lvp->text, optlist, sizeof optlist); + char *p; + p = ckmalloc(sizeof optlist); + lvp->text = memcpy(p, optlist, sizeof optlist); vp = NULL; } else { vpp = hashvar(name); @@ -692,7 +696,7 @@ unsetcmd(argc, argv) int unsetvar(s) - char *s; + const char *s; { struct var **vpp; struct var *vp; @@ -729,7 +733,7 @@ unsetvar(s) STATIC struct var ** hashvar(p) - char *p; + const char *p; { unsigned int hashval; @@ -749,7 +753,7 @@ hashvar(p) STATIC int varequal(p, q) - char *p, *q; + const char *p, *q; { while (*p == *q++) { if (*p++ == '=') diff --git a/bin/sh/var.h b/bin/sh/var.h index 7e9b960f4fdf..f041ec7fd225 100644 --- a/bin/sh/var.h +++ b/bin/sh/var.h @@ -1,4 +1,4 @@ -/* $NetBSD: var.h,v 1.15 1999/01/25 14:20:56 mycroft Exp $ */ +/* $NetBSD: var.h,v 1.16 1999/07/09 03:05:50 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -112,12 +112,12 @@ extern struct var vhistsize; #define mpathset() ((vmpath.flags & VUNSET) == 0) void initvar __P((void)); -void setvar __P((char *, char *, int)); +void setvar __P((const char *, const char *, int)); void setvareq __P((char *, int)); struct strlist; void listsetvar __P((struct strlist *)); -char *lookupvar __P((char *)); -char *bltinlookup __P((char *, int)); +char *lookupvar __P((const char *)); +char *bltinlookup __P((const char *, int)); char **environment __P((void)); void shprocvar __P((void)); int showvarscmd __P((int, char **)); @@ -127,5 +127,5 @@ void mklocal __P((char *)); void poplocalvars __P((void)); int setvarcmd __P((int, char **)); int unsetcmd __P((int, char **)); -int unsetvar __P((char *)); -int setvarsafe __P((char *, char *, int)); +int unsetvar __P((const char *)); +int setvarsafe __P((const char *, const char *, int));