diff options
Diffstat (limited to 'usr.bin/mail/cmd3.c')
-rw-r--r-- | usr.bin/mail/cmd3.c | 301 |
1 files changed, 148 insertions, 153 deletions
diff --git a/usr.bin/mail/cmd3.c b/usr.bin/mail/cmd3.c index 36e42674..6cb5c1d 100644 --- a/usr.bin/mail/cmd3.c +++ b/usr.bin/mail/cmd3.c @@ -57,19 +57,19 @@ shell(str) char *str; { sig_t sigint = signal(SIGINT, SIG_IGN); - char *shell; + char *sh; char cmd[BUFSIZ]; if (strlcpy(cmd, str, sizeof(cmd)) >= sizeof(cmd)) - return 1; + return (1); if (bangexp(cmd, sizeof(cmd)) < 0) - return 1; - if ((shell = value("SHELL")) == NOSTR) - shell = _PATH_CSHELL; - (void) run_command(shell, 0, -1, -1, "-c", cmd, NOSTR); - (void) signal(SIGINT, sigint); + return (1); + if ((sh = value("SHELL")) == NULL) + sh = _PATH_CSHELL; + (void)run_command(sh, 0, -1, -1, "-c", cmd, NULL); + (void)signal(SIGINT, sigint); printf("!\n"); - return 0; + return (0); } /* @@ -81,14 +81,14 @@ dosh(str) char *str; { sig_t sigint = signal(SIGINT, SIG_IGN); - char *shell; - - if ((shell = value("SHELL")) == NOSTR) - shell = _PATH_CSHELL; - (void) run_command(shell, 0, -1, -1, NOSTR, NOSTR, NOSTR); - (void) signal(SIGINT, sigint); - putchar('\n'); - return 0; + char *sh; + + if ((sh = value("SHELL")) == NULL) + sh = _PATH_CSHELL; + (void)run_command(sh, 0, -1, -1, NULL, NULL, NULL); + (void)signal(SIGINT, sigint); + printf("\n"); + return (0); } /* @@ -102,19 +102,18 @@ bangexp(str, strsize) { char bangbuf[BUFSIZ]; static char lastbang[BUFSIZ]; - register char *cp, *cp2; - register int n; - int changed = 0; + char *cp, *cp2; + int n, changed = 0; cp = str; cp2 = bangbuf; n = sizeof(bangbuf); - while (*cp) { + while (*cp != '\0') { if (*cp == '!') { if (n < strlen(lastbang)) { overf: printf("Command buffer overflow\n"); - return(-1); + return (-1); } changed++; if (strlcpy(cp2, lastbang, sizeof(bangbuf) - (cp2 - bangbuf)) @@ -139,13 +138,13 @@ overf: *cp2 = 0; if (changed) { printf("!%s\n", bangbuf); - fflush(stdout); + (void)fflush(stdout); } if (strlcpy(str, bangbuf, strsize) >= strsize) goto overf; if (strlcpy(lastbang, bangbuf, sizeof(lastbang)) >= sizeof(lastbang)) goto overf; - return(0); + return (0); } /* @@ -155,17 +154,17 @@ overf: int help() { - register c; - register FILE *f; + int c; + FILE *f; if ((f = Fopen(_PATH_HELP, "r")) == NULL) { warn("%s", _PATH_HELP); - return(1); + return (1); } while ((c = getc(f)) != EOF) putchar(c); - Fclose(f); - return(0); + (void)Fclose(f); + return (0); } /* @@ -177,25 +176,25 @@ schdir(arglist) { char *cp; - if (*arglist == NOSTR) { - if (homedir == NOSTR) - return(1); + if (*arglist == NULL) { + if (homedir == NULL) + return (1); cp = homedir; } else - if ((cp = expand(*arglist)) == NOSTR) - return(1); + if ((cp = expand(*arglist)) == NULL) + return (1); if (chdir(cp) < 0) { warn("%s", cp); - return(1); + return (1); } - return 0; + return (0); } int respond(msgvec) int *msgvec; { - if (value("Replyall") == NOSTR) + if (value("Replyall") == NULL) return (dorespond(msgvec)); else return (doRespond(msgvec)); @@ -217,19 +216,19 @@ dorespond(msgvec) if (msgvec[1] != 0) { printf("Sorry, can't reply to multiple messages at once\n"); - return(1); + return (1); } mp = &message[msgvec[0] - 1]; touch(mp); dot = mp; - if ((rcv = skin(hfield("from", mp))) == NOSTR) + if ((rcv = skin(hfield("from", mp))) == NULL) rcv = skin(nameof(mp, 1)); - if ((replyto = skin(hfield("reply-to", mp))) != NOSTR) + if ((replyto = skin(hfield("reply-to", mp))) != NULL) np = extract(replyto, GTO); - else if ((cp = skin(hfield("to", mp))) != NOSTR) + else if ((cp = skin(hfield("to", mp))) != NULL) np = extract(cp, GTO); else - np = NIL; + np = NULL; np = elide(np); /* * Delete my name from the reply list, @@ -237,35 +236,35 @@ dorespond(msgvec) */ np = delname(np, myname); if (altnames) - for (ap = altnames; *ap; ap++) + for (ap = altnames; *ap != NULL; ap++) np = delname(np, *ap); - if (np != NIL && replyto == NOSTR) + if (np != NULL && replyto == NULL) np = cat(np, extract(rcv, GTO)); - else if (np == NIL) { - if (replyto != NOSTR) + else if (np == NULL) { + if (replyto != NULL) printf("Empty reply-to field -- replying to author\n"); np = extract(rcv, GTO); } head.h_to = np; - if ((head.h_subject = hfield("subject", mp)) == NOSTR) + if ((head.h_subject = hfield("subject", mp)) == NULL) head.h_subject = hfield("subj", mp); head.h_subject = reedit(head.h_subject); - if (replyto == NOSTR && (cp = skin(hfield("cc", mp))) != NOSTR) { + if (replyto == NULL && (cp = skin(hfield("cc", mp))) != NULL) { np = elide(extract(cp, GCC)); np = delname(np, myname); if (altnames != 0) - for (ap = altnames; *ap; ap++) + for (ap = altnames; *ap != NULL; ap++) np = delname(np, *ap); head.h_cc = np; } else - head.h_cc = NIL; - head.h_bcc = NIL; - head.h_smopts = NIL; + head.h_cc = NULL; + head.h_bcc = NULL; + head.h_smopts = NULL; if ((head.h_replyto = getenv("REPLYTO")) == NULL) - head.h_replyto = NOSTR; + head.h_replyto = NULL; head.h_inreplyto = skin(hfield("message-id", mp)); mail1(&head, 1); - return(0); + return (0); } /* @@ -274,19 +273,19 @@ dorespond(msgvec) */ char * reedit(subj) - register char *subj; + char *subj; { char *newsubj; - if (subj == NOSTR) - return NOSTR; + if (subj == NULL) + return (NULL); if ((subj[0] == 'r' || subj[0] == 'R') && (subj[1] == 'e' || subj[1] == 'E') && subj[2] == ':') - return subj; + return (subj); newsubj = salloc(strlen(subj) + 5); sprintf(newsubj, "Re: %s", subj); - return newsubj; + return (newsubj); } /* @@ -297,12 +296,12 @@ int preserve(msgvec) int *msgvec; { - register struct message *mp; - register int *ip, mesg; + int *ip, mesg; + struct message *mp; if (edit) { printf("Cannot \"preserve\" in edit mode\n"); - return(1); + return (1); } for (ip = msgvec; *ip != 0; ip++) { mesg = *ip; @@ -311,7 +310,7 @@ preserve(msgvec) mp->m_flag &= ~MBOX; dot = mp; } - return(0); + return (0); } /* @@ -321,14 +320,14 @@ int unread(msgvec) int msgvec[]; { - register int *ip; + int *ip; for (ip = msgvec; *ip != 0; ip++) { dot = &message[*ip-1]; dot->m_flag &= ~(MREAD|MTOUCH); dot->m_flag |= MSTATUS; } - return(0); + return (0); } /* @@ -338,15 +337,15 @@ int messize(msgvec) int *msgvec; { - register struct message *mp; - register int *ip, mesg; + struct message *mp; + int *ip, mesg; for (ip = msgvec; *ip != 0; ip++) { mesg = *ip; mp = &message[mesg-1]; printf("%d: %ld/%ld\n", mesg, mp->m_lines, mp->m_size); } - return(0); + return (0); } /* @@ -358,7 +357,7 @@ rexit(e) int e; { if (sourcing) - return(1); + return (1); exit(e); /*NOTREACHED*/ } @@ -371,27 +370,27 @@ int set(arglist) char **arglist; { - register struct var *vp; - register char *cp, *cp2; + struct var *vp; + char *cp, *cp2; char varbuf[BUFSIZ], **ap, **p; int errs, h, s; - if (*arglist == NOSTR) { + if (*arglist == NULL) { for (h = 0, s = 1; h < HSHSIZE; h++) - for (vp = variables[h]; vp != NOVAR; vp = vp->v_link) + for (vp = variables[h]; vp != NULL; vp = vp->v_link) s++; - ap = (char **) salloc(s * sizeof *ap); + ap = (char **)salloc(s * sizeof(*ap)); for (h = 0, p = ap; h < HSHSIZE; h++) - for (vp = variables[h]; vp != NOVAR; vp = vp->v_link) + for (vp = variables[h]; vp != NULL; vp = vp->v_link) *p++ = vp->v_name; - *p = NOSTR; + *p = NULL; sort(ap); - for (p = ap; *p != NOSTR; p++) + for (p = ap; *p != NULL; p++) printf("%s\t%s\n", *p, value(*p)); - return(0); + return (0); } errs = 0; - for (ap = arglist; *ap != NOSTR; ap++) { + for (ap = arglist; *ap != NULL; ap++) { cp = *ap; cp2 = varbuf; while (cp2 < varbuf + sizeof(varbuf) - 1 && *cp != '=' && *cp != '\0') @@ -408,7 +407,7 @@ set(arglist) } assign(varbuf, cp); } - return(errs); + return (errs); } /* @@ -418,13 +417,13 @@ int unset(arglist) char **arglist; { - register struct var *vp, *vp2; + struct var *vp, *vp2; int errs, h; char **ap; errs = 0; - for (ap = arglist; *ap != NOSTR; ap++) { - if ((vp2 = lookup(*ap)) == NOVAR) { + for (ap = arglist; *ap != NULL; ap++) { + if ((vp2 = lookup(*ap)) == NULL) { if (!sourcing) { printf("\"%s\": undefined variable\n", *ap); errs++; @@ -436,7 +435,7 @@ unset(arglist) variables[h] = variables[h]->v_link; vfree(vp2->v_name); vfree(vp2->v_value); - free((char *)vp2); + (void)free(vp2); continue; } for (vp = variables[h]; vp->v_link != vp2; vp = vp->v_link) @@ -444,9 +443,9 @@ unset(arglist) vp->v_link = vp2->v_link; vfree(vp2->v_name); vfree(vp2->v_value); - free((char *) vp2); + (void)free(vp2); } - return(errs); + return (errs); } /* @@ -456,36 +455,35 @@ int group(argv) char **argv; { - register struct grouphead *gh; - register struct group *gp; - register int h; - int s; + struct grouphead *gh; + struct group *gp; char **ap, *gname, **p; + int h, s; - if (*argv == NOSTR) { + if (*argv == NULL) { for (h = 0, s = 1; h < HSHSIZE; h++) - for (gh = groups[h]; gh != NOGRP; gh = gh->g_link) + for (gh = groups[h]; gh != NULL; gh = gh->g_link) s++; - ap = (char **) salloc(s * sizeof *ap); + ap = (char **)salloc(s * sizeof(*ap)); for (h = 0, p = ap; h < HSHSIZE; h++) - for (gh = groups[h]; gh != NOGRP; gh = gh->g_link) + for (gh = groups[h]; gh != NULL; gh = gh->g_link) *p++ = gh->g_name; - *p = NOSTR; + *p = NULL; sort(ap); - for (p = ap; *p != NOSTR; p++) + for (p = ap; *p != NULL; p++) printgroup(*p); - return(0); + return (0); } - if (argv[1] == NOSTR) { + if (argv[1] == NULL) { printgroup(*argv); - return(0); + return (0); } gname = *argv; h = hash(gname); - if ((gh = findgroup(gname)) == NOGRP) { - gh = (struct grouphead *) calloc(sizeof *gh, 1); + if ((gh = findgroup(gname)) == NULL) { + gh = calloc(sizeof(*gh), 1); gh->g_name = vcopy(gname); - gh->g_list = NOGE; + gh->g_list = NULL; gh->g_link = groups[h]; groups[h] = gh; } @@ -496,13 +494,13 @@ group(argv) * later anyway. */ - for (ap = argv+1; *ap != NOSTR; ap++) { - gp = (struct group *) calloc(sizeof *gp, 1); + for (ap = argv+1; *ap != NULL; ap++) { + gp = calloc(sizeof(*gp), 1); gp->ge_name = vcopy(*ap); gp->ge_link = gh->g_list; gh->g_list = gp; } - return(0); + return (0); } /* @@ -513,10 +511,9 @@ void sort(list) char **list; { - register char **ap; - int diction(); + char **ap; - for (ap = list; *ap != NOSTR; ap++) + for (ap = list; *ap != NULL; ap++) ; if (ap-list < 2) return; @@ -531,7 +528,7 @@ int diction(a, b) const void *a, *b; { - return(strcmp(*(char **)a, *(char **)b)); + return (strcmp(*(const char **)a, *(const char **)b)); } /* @@ -543,7 +540,7 @@ int null(e) int e; { - return 0; + return (0); } /* @@ -552,17 +549,17 @@ null(e) */ int file(argv) - register char **argv; + char **argv; { - if (argv[0] == NOSTR) { + if (argv[0] == NULL) { newfileinfo(); - return 0; + return (0); } if (setfile(*argv) < 0) - return 1; + return (1); announce(); - return 0; + return (0); } /* @@ -572,26 +569,25 @@ int echo(argv) char **argv; { - register char **ap; - register char *cp; + char **ap, *cp; - for (ap = argv; *ap != NOSTR; ap++) { + for (ap = argv; *ap != NULL; ap++) { cp = *ap; - if ((cp = expand(cp)) != NOSTR) { + if ((cp = expand(cp)) != NULL) { if (ap != argv) - putchar(' '); + printf(" "); printf("%s", cp); } } - putchar('\n'); - return 0; + printf("\n"); + return (0); } int Respond(msgvec) int *msgvec; { - if (value("Replyall") == NOSTR) + if (value("Replyall") == NULL) return (doRespond(msgvec)); else return (dorespond(msgvec)); @@ -608,34 +604,33 @@ doRespond(msgvec) { struct header head; struct message *mp; - register int *ap; - register char *cp; - char *mid; + int *ap; + char *cp, *mid; - head.h_to = NIL; + head.h_to = NULL; for (ap = msgvec; *ap != 0; ap++) { mp = &message[*ap - 1]; touch(mp); dot = mp; - if ((cp = skin(hfield("from", mp))) == NOSTR) + if ((cp = skin(hfield("from", mp))) == NULL) cp = skin(nameof(mp, 2)); head.h_to = cat(head.h_to, extract(cp, GTO)); mid = skin(hfield("message-id", mp)); } - if (head.h_to == NIL) - return 0; + if (head.h_to == NULL) + return (0); mp = &message[msgvec[0] - 1]; - if ((head.h_subject = hfield("subject", mp)) == NOSTR) + if ((head.h_subject = hfield("subject", mp)) == NULL) head.h_subject = hfield("subj", mp); head.h_subject = reedit(head.h_subject); - head.h_cc = NIL; - head.h_bcc = NIL; - head.h_smopts = NIL; + head.h_cc = NULL; + head.h_bcc = NULL; + head.h_smopts = NULL; if ((head.h_replyto = getenv("REPLYTO")) == NULL) - head.h_replyto = NOSTR; + head.h_replyto = NULL; head.h_inreplyto = mid; mail1(&head, 1); - return 0; + return (0); } /* @@ -646,11 +641,11 @@ int ifcmd(argv) char **argv; { - register char *cp; + char *cp; if (cond != CANY) { printf("Illegal nested \"if\"\n"); - return(1); + return (1); } cond = CANY; cp = argv[0]; @@ -665,9 +660,9 @@ ifcmd(argv) default: printf("Unrecognized if-keyword: \"%s\"\n", cp); - return(1); + return (1); } - return(0); + return (0); } /* @@ -681,7 +676,7 @@ elsecmd() switch (cond) { case CANY: printf("\"Else\" without matching \"if\"\n"); - return(1); + return (1); case CSEND: cond = CRCV; @@ -696,7 +691,7 @@ elsecmd() cond = CANY; break; } - return(0); + return (0); } /* @@ -708,10 +703,10 @@ endifcmd() if (cond == CANY) { printf("\"Endif\" without matching \"if\"\n"); - return(1); + return (1); } cond = CANY; - return(0); + return (0); } /* @@ -721,26 +716,26 @@ int alternates(namelist) char **namelist; { - register int c; - register char **ap, **ap2, *cp; + int c; + char **ap, **ap2, *cp; c = argcount(namelist) + 1; if (c == 1) { if (altnames == 0) - return(0); - for (ap = altnames; *ap; ap++) + return (0); + for (ap = altnames; *ap != NULL; ap++) printf("%s ", *ap); printf("\n"); - return(0); + return (0); } if (altnames != 0) - free((char *) altnames); - altnames = (char **) calloc((unsigned) c, sizeof (char *)); - for (ap = namelist, ap2 = altnames; *ap; ap++, ap2++) { - cp = (char *) calloc((unsigned) strlen(*ap) + 1, sizeof (char)); + (void)free(altnames); + altnames = calloc((unsigned)c, sizeof(char *)); + for (ap = namelist, ap2 = altnames; *ap != NULL; ap++, ap2++) { + cp = calloc((unsigned)strlen(*ap) + 1, sizeof(char)); strcpy(cp, *ap); *ap2 = cp; } *ap2 = 0; - return(0); + return (0); } |