Date: Thu, 24 Dec 2009 18:41:14 +0000 (UTC) From: Jilles Tjoelker <jilles@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r200956 - head/bin/sh Message-ID: <200912241841.nBOIfEpb038062@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jilles Date: Thu Dec 24 18:41:14 2009 New Revision: 200956 URL: http://svn.freebsd.org/changeset/base/200956 Log: sh: Constify various strings. Most of this is adding const keywords, but setvar() in var.c had to be changed somewhat more. Modified: head/bin/sh/alias.c head/bin/sh/alias.h head/bin/sh/arith.h head/bin/sh/arith.y head/bin/sh/cd.c head/bin/sh/exec.c head/bin/sh/exec.h head/bin/sh/expand.c head/bin/sh/expand.h head/bin/sh/histedit.c head/bin/sh/input.c head/bin/sh/input.h head/bin/sh/mail.c head/bin/sh/main.c head/bin/sh/main.h head/bin/sh/memalloc.c head/bin/sh/memalloc.h head/bin/sh/myhistedit.h head/bin/sh/options.c head/bin/sh/options.h head/bin/sh/output.c head/bin/sh/output.h head/bin/sh/parser.c head/bin/sh/parser.h head/bin/sh/show.c head/bin/sh/show.h head/bin/sh/var.c head/bin/sh/var.h Modified: head/bin/sh/alias.c ============================================================================== --- head/bin/sh/alias.c Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/alias.c Thu Dec 24 18:41:14 2009 (r200956) @@ -52,13 +52,13 @@ __FBSDID("$FreeBSD$"); STATIC struct alias *atab[ATABSIZE]; STATIC int aliases; -STATIC void setalias(char *, char *); +STATIC void setalias(const char *, const char *); STATIC int unalias(const char *); STATIC struct alias **hashalias(const char *); STATIC void -setalias(char *name, char *val) +setalias(const char *name, const char *val) { struct alias *ap, **app; @@ -176,7 +176,7 @@ rmaliases(void) } struct alias * -lookupalias(char *name, int check) +lookupalias(const char *name, int check) { struct alias *ap = *hashalias(name); Modified: head/bin/sh/alias.h ============================================================================== --- head/bin/sh/alias.h Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/alias.h Thu Dec 24 18:41:14 2009 (r200956) @@ -42,7 +42,7 @@ struct alias { int flag; }; -struct alias *lookupalias(char *, int); +struct alias *lookupalias(const char *, int); int aliascmd(int, char **); int unaliascmd(int, char **); void rmaliases(void); Modified: head/bin/sh/arith.h ============================================================================== --- head/bin/sh/arith.h Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/arith.h Thu Dec 24 18:41:14 2009 (r200956) @@ -34,8 +34,8 @@ #define DIGITS(var) (3 + (2 + CHAR_BIT * sizeof((var))) / 3) -extern char *arith_buf, *arith_startbuf; +extern const char *arith_buf, *arith_startbuf; -arith_t arith(char *); +arith_t arith(const char *); void arith_lex_reset(void); int expcmd(int, char **); Modified: head/bin/sh/arith.y ============================================================================== --- head/bin/sh/arith.y Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/arith.y Thu Dec 24 18:41:14 2009 (r200956) @@ -265,7 +265,7 @@ expr: #define YYPARSE_PARAM_TYPE arith_t * #define YYPARSE_PARAM result -char *arith_buf, *arith_startbuf; +const char *arith_buf, *arith_startbuf; int yylex(void); int yyparse(YYPARSE_PARAM_TYPE); @@ -284,7 +284,7 @@ arith_assign(char *name, arith_t value) } arith_t -arith(char *s) +arith(const char *s) { arith_t result; @@ -299,7 +299,7 @@ arith(char *s) } static void -yyerror(char *s) +yyerror(const char *s) { yyerrok; @@ -354,7 +354,7 @@ main(int argc, char *argv[]) printf("%d\n", exp(argv[1])); } -error(char *s) +error(const char *s) { fprintf(stderr, "exp: %s\n", s); exit(1); Modified: head/bin/sh/cd.c ============================================================================== --- head/bin/sh/cd.c Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/cd.c Thu Dec 24 18:41:14 2009 (r200956) @@ -80,7 +80,7 @@ int cdcmd(int argc, char **argv) { char *dest; - char *path; + const char *path; char *p; struct stat statb; int ch, phys, print = 0; Modified: head/bin/sh/exec.c ============================================================================== --- head/bin/sh/exec.c Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/exec.c Thu Dec 24 18:41:14 2009 (r200956) @@ -98,7 +98,7 @@ int exerrno = 0; /* Last exec error */ STATIC void tryexec(char *, char **, char **); STATIC void printentry(struct tblentry *, int); -STATIC struct tblentry *cmdlookup(char *, int); +STATIC struct tblentry *cmdlookup(const char *, int); STATIC void delete_cmd_entry(void); @@ -109,7 +109,7 @@ STATIC void delete_cmd_entry(void); */ void -shellexec(char **argv, char **envp, char *path, int index) +shellexec(char **argv, char **envp, const char *path, int index) { char *cmdname; int e; @@ -175,13 +175,13 @@ tryexec(char *cmd, char **argv, char **e * NULL. */ -char *pathopt; +const char *pathopt; char * -padvance(char **path, char *name) +padvance(const char **path, const char *name) { - char *p, *q; - char *start; + const char *p, *start; + char *q; int len; if (*path == NULL) @@ -269,7 +269,7 @@ STATIC void printentry(struct tblentry *cmdp, int verbose) { int index; - char *path; + const char *path; char *name; if (cmdp->cmdtype == CMDNORMAL) { @@ -310,7 +310,8 @@ printentry(struct tblentry *cmdp, int ve */ void -find_command(char *name, struct cmdentry *entry, int printerr, char *path) +find_command(const char *name, struct cmdentry *entry, int printerr, + const char *path) { struct tblentry *cmdp; int index; @@ -446,7 +447,7 @@ success: */ int -find_builtin(char *name, int *special) +find_builtin(const char *name, int *special) { const struct builtincmd *bp; @@ -608,10 +609,10 @@ STATIC struct tblentry **lastcmdentry; STATIC struct tblentry * -cmdlookup(char *name, int add) +cmdlookup(const char *name, int add) { int hashval; - char *p; + const char *p; struct tblentry *cmdp; struct tblentry **pp; @@ -664,7 +665,7 @@ delete_cmd_entry(void) */ void -addcmdentry(char *name, struct cmdentry *entry) +addcmdentry(const char *name, struct cmdentry *entry) { struct tblentry *cmdp; @@ -684,7 +685,7 @@ addcmdentry(char *name, struct cmdentry */ void -defun(char *name, union node *func) +defun(const char *name, union node *func) { struct cmdentry entry; @@ -701,7 +702,7 @@ defun(char *name, union node *func) */ int -unsetfunc(char *name) +unsetfunc(const char *name) { struct tblentry *cmdp; @@ -767,7 +768,8 @@ typecmd_impl(int argc, char **argv, int switch (entry.cmdtype) { case CMDNORMAL: { if (strchr(argv[i], '/') == NULL) { - char *path = pathval(), *name; + const char *path = pathval(); + char *name; int j = entry.u.index; do { name = padvance(&path, argv[i]); Modified: head/bin/sh/exec.h ============================================================================== --- head/bin/sh/exec.h Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/exec.h Thu Dec 24 18:41:14 2009 (r200956) @@ -57,20 +57,20 @@ struct cmdentry { }; -extern char *pathopt; /* set by padvance */ +extern const char *pathopt; /* set by padvance */ extern int exerrno; /* last exec error */ -void shellexec(char **, char **, char *, int); -char *padvance(char **, char *); +void shellexec(char **, char **, const char *, int); +char *padvance(const char **, const char *); int hashcmd(int, char **); -void find_command(char *, struct cmdentry *, int, char *); -int find_builtin(char *, int *); +void find_command(const char *, struct cmdentry *, int, const char *); +int find_builtin(const char *, int *); void hashcd(void); void changepath(const char *); void deletefuncs(void); -void addcmdentry(char *, struct cmdentry *); -void defun(char *, union node *); -int unsetfunc(char *); +void addcmdentry(const char *, struct cmdentry *); +void defun(const char *, union node *); +int unsetfunc(const char *); int typecmd_impl(int, char **, int); int typecmd(int, char **); void clearcmdentry(int); Modified: head/bin/sh/expand.c ============================================================================== --- head/bin/sh/expand.c Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/expand.c Thu Dec 24 18:41:14 2009 (r200956) @@ -107,7 +107,7 @@ STATIC void expmeta(char *, char *); STATIC void addfname(char *); STATIC struct strlist *expsort(struct strlist *); STATIC struct strlist *msort(struct strlist *, int); -STATIC int pmatch(char *, char *, int); +STATIC int pmatch(const char *, const char *, int); STATIC char *cvtnum(int, char *); STATIC int collate_range_cmp(int, int); @@ -1338,7 +1338,7 @@ msort(struct strlist *list, int len) */ int -patmatch(char *pattern, char *string, int squoted) +patmatch(const char *pattern, const char *string, int squoted) { #ifdef notdef if (pattern[0] == '!' && pattern[1] == '!') @@ -1350,9 +1350,9 @@ patmatch(char *pattern, char *string, in STATIC int -pmatch(char *pattern, char *string, int squoted) +pmatch(const char *pattern, const char *string, int squoted) { - char *p, *q; + const char *p, *q; char c; p = pattern; @@ -1400,7 +1400,7 @@ pmatch(char *pattern, char *string, int } while (*q++ != '\0'); return 0; case '[': { - char *endp; + const char *endp; int invert, found; char chr; @@ -1504,7 +1504,7 @@ rmescapes(char *str) */ int -casematch(union node *pattern, char *val) +casematch(union node *pattern, const char *val) { struct stackmark smark; int result; Modified: head/bin/sh/expand.h ============================================================================== --- head/bin/sh/expand.h Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/expand.h Thu Dec 24 18:41:14 2009 (r200956) @@ -58,7 +58,7 @@ union node; void expandhere(union node *, int); void expandarg(union node *, struct arglist *, int); void expari(int); -int patmatch(char *, char *, int); +int patmatch(const char *, const char *, int); void rmescapes(char *); -int casematch(union node *, char *); +int casematch(union node *, const char *); int wordexpcmd(int, char **); Modified: head/bin/sh/histedit.c ============================================================================== --- head/bin/sh/histedit.c Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/histedit.c Thu Dec 24 18:41:14 2009 (r200956) @@ -406,7 +406,7 @@ fc_replace(const char *s, char *p, char } int -not_fcnumber(char *s) +not_fcnumber(const char *s) { if (s == NULL) return (0); @@ -416,10 +416,10 @@ not_fcnumber(char *s) } int -str_to_event(char *str, int last) +str_to_event(const char *str, int last) { HistEvent he; - char *s = str; + const char *s = str; int relative = 0; int i, retval; Modified: head/bin/sh/input.c ============================================================================== --- head/bin/sh/input.c Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/input.c Thu Dec 24 18:41:14 2009 (r200956) @@ -401,7 +401,7 @@ popstring(void) */ void -setinputfile(char *fname, int push) +setinputfile(const char *fname, int push) { int fd; int fd2; Modified: head/bin/sh/input.h ============================================================================== --- head/bin/sh/input.h Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/input.h Thu Dec 24 18:41:14 2009 (r200956) @@ -54,7 +54,7 @@ int preadateof(void); void pungetc(void); void pushstring(char *, int, void *); void popstring(void); -void setinputfile(char *, int); +void setinputfile(const char *, int); void setinputfd(int, int); void setinputstring(char *, int); void popfile(void); Modified: head/bin/sh/mail.c ============================================================================== --- head/bin/sh/mail.c Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/mail.c Thu Dec 24 18:41:14 2009 (r200956) @@ -72,7 +72,7 @@ void chkmail(int silent) { int i; - char *mpath; + const char *mpath; char *p; char *q; struct stackmark smark; Modified: head/bin/sh/main.c ============================================================================== --- head/bin/sh/main.c Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/main.c Thu Dec 24 18:41:14 2009 (r200956) @@ -269,7 +269,7 @@ read_profile(char *name) */ void -readcmdfile(char *name) +readcmdfile(const char *name) { int fd; @@ -296,7 +296,7 @@ find_dot_file(char *basename) { static char localname[FILENAME_MAX+1]; char *fullname; - char *path = pathval(); + const char *path = pathval(); struct stat statb; /* don't try this for absolute or relative paths */ Modified: head/bin/sh/main.h ============================================================================== --- head/bin/sh/main.h Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/main.h Thu Dec 24 18:41:14 2009 (r200956) @@ -36,7 +36,7 @@ extern int rootpid; /* pid of main shell */ extern int rootshell; /* true if we aren't a child of the main shell */ -void readcmdfile(char *); +void readcmdfile(const char *); void cmdloop(int); int dotcmd(int, char **); int exitcmd(int, char **); Modified: head/bin/sh/memalloc.c ============================================================================== --- head/bin/sh/memalloc.c Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/memalloc.c Thu Dec 24 18:41:14 2009 (r200956) @@ -95,7 +95,7 @@ ckfree(pointer p) */ char * -savestr(char *s) +savestr(const char *s) { char *p; Modified: head/bin/sh/memalloc.h ============================================================================== --- head/bin/sh/memalloc.h Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/memalloc.h Thu Dec 24 18:41:14 2009 (r200956) @@ -51,7 +51,7 @@ extern int herefd; pointer ckmalloc(size_t); pointer ckrealloc(pointer, int); void ckfree(pointer); -char *savestr(char *); +char *savestr(const char *); pointer stalloc(int); void stunalloc(pointer); void setstackmark(struct stackmark *); Modified: head/bin/sh/myhistedit.h ============================================================================== --- head/bin/sh/myhistedit.h Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/myhistedit.h Thu Dec 24 18:41:14 2009 (r200956) @@ -39,7 +39,7 @@ extern int displayhist; void histedit(void); void sethistsize(const char *); int histcmd(int, char **); -int not_fcnumber(char *); -int str_to_event(char *, int); +int not_fcnumber(const char *); +int str_to_event(const char *, int); int bindcmd(int, char **); Modified: head/bin/sh/options.c ============================================================================== --- head/bin/sh/options.c Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/options.c Thu Dec 24 18:41:14 2009 (r200956) @@ -554,9 +554,10 @@ out: */ int -nextopt(char *optstring) +nextopt(const char *optstring) { - char *p, *q; + char *p; + const char *q; char c; if ((p = optptr) == NULL || *p == '\0') { Modified: head/bin/sh/options.h ============================================================================== --- head/bin/sh/options.h Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/options.h Thu Dec 24 18:41:14 2009 (r200956) @@ -111,5 +111,5 @@ void freeparam(struct shparam *); int shiftcmd(int, char **); int setcmd(int, char **); int getoptscmd(int, char **); -int nextopt(char *); +int nextopt(const char *); void getoptsreset(const char *); Modified: head/bin/sh/output.c ============================================================================== --- head/bin/sh/output.c Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/output.c Thu Dec 24 18:41:14 2009 (r200956) @@ -314,7 +314,7 @@ doformat(struct output *dest, const char */ int -xwrite(int fd, char *buf, int nbytes) +xwrite(int fd, const char *buf, int nbytes) { int ntry; int i; Modified: head/bin/sh/output.h ============================================================================== --- head/bin/sh/output.h Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/output.h Thu Dec 24 18:41:14 2009 (r200956) @@ -68,7 +68,7 @@ void out1fmt(const char *, ...) __printf void out2fmt_flush(const char *, ...) __printflike(1, 2); void fmtstr(char *, int, const char *, ...) __printflike(3, 4); void doformat(struct output *, const char *, va_list) __printflike(2, 0); -int xwrite(int, char *, int); +int xwrite(int, const char *, int); #define outc(c, file) (--(file)->nleft < 0? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c))) #define out1c(c) outc(c, out1); Modified: head/bin/sh/parser.c ============================================================================== --- head/bin/sh/parser.c Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/parser.c Thu Dec 24 18:41:14 2009 (r200956) @@ -1510,9 +1510,9 @@ noexpand(char *text) */ int -goodname(char *name) +goodname(const char *name) { - char *p; + const char *p; p = name; if (! is_name(*p)) Modified: head/bin/sh/parser.h ============================================================================== --- head/bin/sh/parser.h Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/parser.h Thu Dec 24 18:41:14 2009 (r200956) @@ -77,5 +77,5 @@ extern int whichprompt; /* 1 == PS1, 2 union node *parsecmd(int); void fixredir(union node *, const char *, int); -int goodname(char *); +int goodname(const char *); char *getprompt(void *); Modified: head/bin/sh/show.c ============================================================================== --- head/bin/sh/show.c Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/show.c Thu Dec 24 18:41:14 2009 (r200956) @@ -307,7 +307,7 @@ sh_trace(const char *fmt, ...) void -trputs(char *s) +trputs(const char *s) { if (tracefile == NULL) return; Modified: head/bin/sh/show.h ============================================================================== --- head/bin/sh/show.h Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/show.h Thu Dec 24 18:41:14 2009 (r200956) @@ -35,6 +35,6 @@ void showtree(union node *); void sh_trace(const char *, ...) __printflike(1, 2); void trargs(char **); void trputc(int); -void trputs(char *); +void trputs(const char *); void opentrace(void); #endif Modified: head/bin/sh/var.c ============================================================================== --- head/bin/sh/var.c Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/var.c Thu Dec 24 18:41:14 2009 (r200956) @@ -122,9 +122,9 @@ STATIC const struct varinit varinit[] = STATIC struct var *vartab[VTABSIZE]; -STATIC struct var **hashvar(char *); -STATIC int varequal(char *, char *); -STATIC int localevar(char *); +STATIC struct var **hashvar(const char *); +STATIC int varequal(const char *, const char *); +STATIC int localevar(const char *); /* * Initialize the variable symbol tables and import the environment. @@ -190,7 +190,7 @@ initvar(void) */ int -setvarsafe(char *name, char *val, int flags) +setvarsafe(const char *name, const char *val, int flags) { struct jmploc jmploc; struct jmploc *const savehandler = handler; @@ -215,9 +215,9 @@ setvarsafe(char *name, char *val, int fl */ void -setvar(char *name, char *val, int flags) +setvar(const char *name, const char *val, int flags) { - char *p, *q; + const char *p; int len; int namelen; char *nameeq; @@ -245,19 +245,18 @@ setvar(char *name, char *val, int flags) } else { len += strlen(val); } - p = nameeq = ckmalloc(len); - q = name; - while (--namelen >= 0) - *p++ = *q++; - *p++ = '='; - *p = '\0'; + nameeq = ckmalloc(len); + memcpy(nameeq, name, namelen); + nameeq[namelen] = '='; if (val) - scopy(val, p); + scopy(val, nameeq + namelen + 1); + else + nameeq[namelen + 1] = '\0'; setvareq(nameeq, flags); } STATIC int -localevar(char *s) +localevar(const char *s) { static char *lnames[7] = { "ALL", "COLLATE", "CTYPE", "MONETARY", @@ -283,7 +282,7 @@ localevar(char *s) * pointer into environ where the string should not be manipulated. */ static void -change_env(char *s, int set) +change_env(const char *s, int set) { char *eqp; char *ss; @@ -389,7 +388,7 @@ listsetvar(struct strlist *list) */ char * -lookupvar(char *name) +lookupvar(const char *name) { struct var *v; @@ -412,7 +411,7 @@ lookupvar(char *name) */ char * -bltinlookup(char *name, int doall) +bltinlookup(const char *name, int doall) { struct strlist *sp; struct var *v; @@ -796,7 +795,7 @@ unsetcmd(int argc __unused, char **argv */ int -unsetvar(char *s) +unsetvar(const char *s) { struct var **vpp; struct var *vp; @@ -836,7 +835,7 @@ unsetvar(char *s) */ STATIC struct var ** -hashvar(char *p) +hashvar(const char *p) { unsigned int hashval; @@ -855,7 +854,7 @@ hashvar(char *p) */ STATIC int -varequal(char *p, char *q) +varequal(const char *p, const char *q) { while (*p == *q++) { if (*p++ == '=') Modified: head/bin/sh/var.h ============================================================================== --- head/bin/sh/var.h Thu Dec 24 18:17:53 2009 (r200955) +++ head/bin/sh/var.h Thu Dec 24 18:41:14 2009 (r200956) @@ -101,12 +101,12 @@ extern struct var vhistsize; #define mpathset() ((vmpath.flags & VUNSET) == 0) void initvar(void); -void setvar(char *, char *, int); +void setvar(const char *, const char *, int); void setvareq(char *, int); struct strlist; void listsetvar(struct strlist *); -char *lookupvar(char *); -char *bltinlookup(char *, int); +char *lookupvar(const char *); +char *bltinlookup(const char *, int); char **environment(void); void shprocvar(void); int showvarscmd(int, char **); @@ -116,5 +116,5 @@ void mklocal(char *); void poplocalvars(void); int setvarcmd(int, char **); int unsetcmd(int, char **); -int unsetvar(char *); -int setvarsafe(char *, char *, int); +int unsetvar(const char *); +int setvarsafe(const char *, const char *, int);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200912241841.nBOIfEpb038062>