From 828615a1268b1799e4092fbbdf7b2e1a5ccceaf2 Mon Sep 17 00:00:00 2001 From: Edward Wang Date: Mon, 18 May 1987 19:29:02 -0800 Subject: [PATCH] major rework: made faster, cleaned up, obsolete code removed, the whole thing should be chucked and written from scratch SCCS-vsn: usr.bin/mail/list.c 5.5 SCCS-vsn: usr.bin/mail/lex.c 5.5 SCCS-vsn: usr.bin/mail/collect.c 5.3 SCCS-vsn: usr.bin/mail/main.c 5.4 SCCS-vsn: usr.bin/mail/names.c 5.4 SCCS-vsn: usr.bin/mail/cmd3.c 5.4 SCCS-vsn: usr.bin/mail/Makefile 5.4 SCCS-vsn: usr.bin/mail/cmdtab.c 5.4 SCCS-vsn: usr.bin/mail/def.h 5.3 SCCS-vsn: usr.bin/mail/glob.h 5.2 SCCS-vsn: usr.bin/mail/aux.c 5.6 SCCS-vsn: usr.bin/mail/pathnames.h 5.3 SCCS-vsn: usr.bin/mail/cmd1.c 5.4 SCCS-vsn: usr.bin/mail/popen.c 5.3 SCCS-vsn: usr.bin/mail/send.c 5.3 SCCS-vsn: usr.bin/mail/vars.c 5.3 SCCS-vsn: usr.bin/fmt/fmt.c 5.4 SCCS-vsn: usr.bin/mail/rcv.h 5.2 SCCS-vsn: usr.bin/mail/tty.c 5.3 SCCS-vsn: usr.bin/mail/getname.c 5.3 SCCS-vsn: usr.bin/mail/strings.c 5.4 SCCS-vsn: usr.bin/mail/temp.c 5.3 SCCS-vsn: usr.bin/mail/v7.local.c 5.3 SCCS-vsn: usr.bin/mail/cmd2.c 5.4 SCCS-vsn: usr.bin/mail/local.h 5.2 SCCS-vsn: usr.bin/mail/edit.c 5.3 SCCS-vsn: usr.bin/mail/fio.c 5.5 SCCS-vsn: usr.bin/mail/head.c 5.3 SCCS-vsn: usr.bin/mail/optim.c 5.7 --- usr/src/usr.bin/fmt/fmt.c | 8 +- usr/src/usr.bin/mail/Makefile | 2 +- usr/src/usr.bin/mail/aux.c | 375 ++++++++++----------------- usr/src/usr.bin/mail/cmd1.c | 120 +++------ usr/src/usr.bin/mail/cmd2.c | 25 +- usr/src/usr.bin/mail/cmd3.c | 73 +++--- usr/src/usr.bin/mail/cmdtab.c | 4 +- usr/src/usr.bin/mail/collect.c | 426 ++++++++++++------------------- usr/src/usr.bin/mail/def.h | 63 ++--- usr/src/usr.bin/mail/edit.c | 51 ++-- usr/src/usr.bin/mail/fio.c | 229 +++++++---------- usr/src/usr.bin/mail/getname.c | 15 +- usr/src/usr.bin/mail/glob.h | 5 +- usr/src/usr.bin/mail/head.c | 247 ++++++------------ usr/src/usr.bin/mail/lex.c | 70 ++--- usr/src/usr.bin/mail/list.c | 4 +- usr/src/usr.bin/mail/local.h | 24 +- usr/src/usr.bin/mail/main.c | 69 +++-- usr/src/usr.bin/mail/names.c | 43 ++-- usr/src/usr.bin/mail/optim.c | 60 +---- usr/src/usr.bin/mail/pathnames.h | 7 +- usr/src/usr.bin/mail/popen.c | 26 +- usr/src/usr.bin/mail/rcv.h | 5 +- usr/src/usr.bin/mail/send.c | 285 ++++++++++----------- usr/src/usr.bin/mail/strings.c | 2 +- usr/src/usr.bin/mail/temp.c | 30 +-- usr/src/usr.bin/mail/tty.c | 46 ++-- usr/src/usr.bin/mail/v7.local.c | 6 +- usr/src/usr.bin/mail/vars.c | 66 +++-- 29 files changed, 923 insertions(+), 1463 deletions(-) diff --git a/usr/src/usr.bin/fmt/fmt.c b/usr/src/usr.bin/fmt/fmt.c index f02338d949..97442cca3c 100644 --- a/usr/src/usr.bin/fmt/fmt.c +++ b/usr/src/usr.bin/fmt/fmt.c @@ -11,7 +11,7 @@ char *copyright = #endif not lint #ifndef lint -static char *sccsid = "@(#)fmt.c 5.3 (Berkeley) %G%"; +static char *sccsid = "@(#)fmt.c 5.4 (Berkeley) %G%"; #endif not lint #include @@ -38,7 +38,7 @@ int pfx; /* Current leading blank count */ int lineno; /* Current input line */ int mark; /* Last place we saw a head line */ -char *calloc(); /* for lint . . . */ +char *malloc(); /* for lint . . . */ char *headnames[] = {"To", "Subject", "Cc", 0}; /* @@ -412,12 +412,12 @@ savestr(str) { register char *top; - top = calloc(strlen(str) + 1, 1); + top = malloc(strlen(str) + 1); if (top == NOSTR) { fprintf(stderr, "fmt: Ran out of memory\n"); exit(1); } - copy(str, top); + strcpy(top, str); return (top); } diff --git a/usr/src/usr.bin/mail/Makefile b/usr/src/usr.bin/mail/Makefile index 50ba282378..73f55f16e0 100644 --- a/usr/src/usr.bin/mail/Makefile +++ b/usr/src/usr.bin/mail/Makefile @@ -3,7 +3,7 @@ # All rights reserved. The Berkeley software License Agreement # specifies the terms and conditions for redistribution. # -# @(#)Makefile 5.3 (Berkeley) %G% +# @(#)Makefile 5.4 (Berkeley) %G% # # Berkeley Mail # diff --git a/usr/src/usr.bin/mail/aux.c b/usr/src/usr.bin/mail/aux.c index d9765abc2a..84cd7daab1 100644 --- a/usr/src/usr.bin/mail/aux.c +++ b/usr/src/usr.bin/mail/aux.c @@ -5,13 +5,11 @@ */ #ifndef lint -static char *sccsid = "@(#)aux.c 5.5 (Berkeley) %G%"; +static char *sccsid = "@(#)aux.c 5.6 (Berkeley) %G%"; #endif not lint #include "rcv.h" #include -#include -#include /* * Mail -- a mail program @@ -40,62 +38,20 @@ savestr(str) return(top); } -/* - * Copy the name from the passed header line into the passed - * name buffer. Null pad the name buffer. - */ - -copyname(linebuf, nbuf) - char *linebuf, *nbuf; -{ - register char *cp, *cp2; - - for (cp = linebuf + 5, cp2 = nbuf; *cp != ' ' && cp2-nbuf < 8; cp++) - *cp2++ = *cp; - while (cp2-nbuf < 8) - *cp2++ = 0; -} - /* * Announce a fatal error and die. */ -panic(str) - char *str; +/*VARARGS1*/ +panic(fmt, a, b) + char *fmt; { - prs("panic: "); - prs(str); - prs("\n"); + fprintf(stderr, "panic: "); + fprintf(stderr, fmt, a, b); + putc('\n', stderr); exit(1); } -/* - * Catch stdio errors and report them more nicely. - */ - -_error(str) - char *str; -{ - prs("Stdio Error: "); - prs(str); - prs("\n"); - abort(); -} - -/* - * Print a string on diagnostic output. - */ - -prs(str) - char *str; -{ - register char *s; - - for (s = str; *s; s++) - ; - write(2, str, s-str); -} - /* * Touch the named message by setting its MTOUCH flag. * Touched messages have the effect of not being sent @@ -138,38 +94,9 @@ argcount(argv) { register char **ap; - for (ap = argv; *ap != NOSTR; ap++) + for (ap = argv; *ap++ != NOSTR;) ; - return(ap-argv); -} - -/* - * Given a file address, determine the - * block number it represents. - */ - -blockof(off) - off_t off; -{ - off_t a; - - a = off >> 9; - a &= 077777; - return((int) a); -} - -/* - * Take a file address, and determine - * its offset in the current block. - */ - -offsetof(off) - off_t off; -{ - off_t a; - - a = off & 0777; - return((int) a); + return ap - argv - 1; } /* @@ -185,156 +112,104 @@ hfield(field, mp) register FILE *ibuf; char linebuf[LINESIZE]; register int lc; + register char *hfield; + char *colon; ibuf = setinput(mp); - if ((lc = mp->m_lines) <= 0) - return(NOSTR); + if ((lc = mp->m_lines - 1) < 0) + return NOSTR; if (readline(ibuf, linebuf) < 0) - return(NOSTR); - lc--; - do { - lc = gethfield(ibuf, linebuf, lc); - if (lc == -1) - return(NOSTR); - if (ishfield(linebuf, field)) - return(savestr(hcontents(linebuf))); - } while (lc > 0); - return(NOSTR); + return NOSTR; + while (lc > 0) { + if ((lc = gethfield(ibuf, linebuf, lc, &colon)) < 0) + return NOSTR; + if (hfield = ishfield(linebuf, colon, field)) + return savestr(hfield); + } + return NOSTR; } /* * Return the next header field found in the given message. - * Return > 0 if something found, <= 0 elsewise. + * Return >= 0 if something found, < 0 elsewise. + * "colon" is set to point to the colon in the header. * Must deal with \ continuations & other such fraud. */ -gethfield(f, linebuf, rem) +gethfield(f, linebuf, rem, colon) register FILE *f; char linebuf[]; register int rem; + char **colon; { char line2[LINESIZE]; - long loc; register char *cp, *cp2; register int c; - for (;;) { - if (rem <= 0) - return(-1); - if (readline(f, linebuf) < 0) - return(-1); - rem--; - if (strlen(linebuf) == 0) - return(-1); - if (isspace(linebuf[0])) - continue; - if (linebuf[0] == '>') - continue; - cp = index(linebuf, ':'); - if (cp == NOSTR) + if (--rem < 0) + return -1; + if ((c = readline(f, linebuf)) <= 0) + return -1; + for (cp = linebuf; isprint(*cp) && *cp != ' ' && *cp != ':'; + cp++) + ; + if (*cp != ':' || cp == linebuf) continue; - for (cp2 = linebuf; cp2 < cp; cp2++) - if (isdigit(*cp2)) - continue; - /* * I guess we got a headline. * Handle wraparounding */ - + *colon = cp; + cp = linebuf + c; for (;;) { + while (--cp >= linebuf && (*cp == ' ' || *cp == '\t')) + ; + cp++; if (rem <= 0) break; -#ifdef CANTELL - loc = ftell(f); - if (readline(f, line2) < 0) - break; - rem--; - if (!isspace(line2[0])) { - fseek(f, loc, 0); - rem++; - break; - } -#else - c = getc(f); - ungetc(c, f); - if (!isspace(c) || c == '\n') + ungetc(c = getc(f), f); + if (c != ' ' && c != '\t') break; - if (readline(f, line2) < 0) + if ((c = readline(f, line2)) < 0) break; rem--; -#endif - cp2 = line2; - for (cp2 = line2; *cp2 != 0 && isspace(*cp2); cp2++) + for (cp2 = line2; *cp2 == ' ' || *cp2 == '\t'; cp2++) ; - if (strlen(linebuf) + strlen(cp2) >= LINESIZE-2) + c -= cp2 - line2; + if (cp + c >= linebuf + LINESIZE - 2) break; - cp = &linebuf[strlen(linebuf)]; - while (cp > linebuf && - (isspace(cp[-1]) || cp[-1] == '\\')) - cp--; *cp++ = ' '; - for (cp2 = line2; *cp2 != 0 && isspace(*cp2); cp2++) - ; - strcpy(cp, cp2); - } - if ((c = strlen(linebuf)) > 0) { - cp = &linebuf[c-1]; - while (cp > linebuf && isspace(*cp)) - cp--; - *++cp = 0; + bcopy(cp2, cp, c); + cp += c; } - return(rem); + *cp = 0; + return rem; } /* NOTREACHED */ } /* * Check whether the passed line is a header line of - * the desired breed. + * the desired breed. Return the field body, or 0. */ -ishfield(linebuf, field) +char* +ishfield(linebuf, colon, field) char linebuf[], field[]; + char *colon; { - register char *cp; - register int c; + register char *cp = colon; - if ((cp = index(linebuf, ':')) == NOSTR) - return(0); - if (cp == linebuf) - return(0); - cp--; - while (cp > linebuf && isspace(*cp)) - cp--; - c = *++cp; *cp = 0; - if (icequal(linebuf ,field)) { - *cp = c; - return(1); + if (!icequal(linebuf, field)) { + *cp = ':'; + return 0; } - *cp = c; - return(0); -} - -/* - * Extract the non label information from the given header field - * and return it. - */ - -char * -hcontents(hfield) - char hfield[]; -{ - register char *cp; - - if ((cp = index(hfield, ':')) == NOSTR) - return(NOSTR); - cp++; - while (*cp && isspace(*cp)) - cp++; - return(cp); + *cp = ':'; + for (cp++; *cp == ' ' || *cp == '\t'; cp++) + ; + return cp; } /* @@ -344,26 +219,35 @@ hcontents(hfield) icequal(s1, s2) register char *s1, *s2; { + register c1, c2; - while (raise(*s1++) == raise(*s2)) - if (*s2++ == 0) - return(1); - return(0); + for (;;) { + if ((c1 = (unsigned char)*s1++) != + (c2 = (unsigned char)*s2++)) { + if (isupper(c1)) + c1 = tolower(c1); + if (c1 != c2) + return 0; + } + if (c1 == 0) + return 1; + } + /*NOTREACHED*/ } /* * Copy a string, lowercasing it as we go. */ istrcpy(dest, src) - char *dest, *src; + register char *dest, *src; { - register char *cp, *cp2; - cp2 = dest; - cp = src; do { - *cp2++ = little(*cp); - } while (*cp++ != 0); + if (isupper(*src)) + *dest++ = tolower(*src); + else + *dest++ = *src; + } while (*src++ != 0); } /* @@ -412,21 +296,6 @@ source(name) return(0); } -/* - * Source a file, but do nothing if the file cannot be opened. - */ - -source1(name) - char name[]; -{ - register int f; - - if ((f = open(name, 0)) < 0) - return(0); - close(f); - source(name); -} - /* * Pop the current input back to the previous level. * Update the "sourcing" flag as appropriate. @@ -542,7 +411,7 @@ skin(name) if (name == NOSTR) return(NOSTR); if (index(name, '(') == NOSTR && index(name, '<') == NOSTR - && index(name, ' ') == NOSTR) + && index(name, ' ') == NOSTR) return(name); gotlt = 0; lastsp = 0; @@ -666,23 +535,23 @@ name1(mp, reptype) int first = 1; if ((cp = hfield("from", mp)) != NOSTR) - return(cp); + return cp; if (reptype == 0 && (cp = hfield("sender", mp)) != NOSTR) - return(cp); + return cp; ibuf = setinput(mp); - copy("", namebuf); - if (readline(ibuf, linebuf) <= 0) + namebuf[0] = 0; + if (readline(ibuf, linebuf) < 0) return(savestr(namebuf)); newname: - for (cp = linebuf; *cp != ' '; cp++) + for (cp = linebuf; *cp && *cp != ' '; cp++) ; - while (any(*cp, " \t")) - cp++; - for (cp2 = &namebuf[strlen(namebuf)]; *cp && !any(*cp, " \t") && - cp2-namebuf < LINESIZE-1; *cp2++ = *cp++) + for (; *cp == ' ' || *cp == '\t'; cp++) ; + for (cp2 = &namebuf[strlen(namebuf)]; + *cp && *cp != ' ' && *cp != '\t' && cp2 < namebuf + LINESIZE - 1;) + *cp2++ = *cp++; *cp2 = '\0'; - if (readline(ibuf, linebuf) <= 0) + if (readline(ibuf, linebuf) < 0) return(savestr(namebuf)); if ((cp = index(linebuf, 'F')) == NULL) return(savestr(namebuf)); @@ -698,7 +567,7 @@ newname: break; cp++; if (first) { - copy(cp, namebuf); + strcpy(namebuf, cp); first = 0; } else strcpy(rindex(namebuf, '!')+1, cp); @@ -726,33 +595,58 @@ charcount(str, c) } /* - * See if the string is a number. + * Are any of the characters in the two strings the same? */ -numeric(str) - char str[]; +anyof(s1, s2) + register char *s1, *s2; { - register char *cp = str; - while (*cp) - if (!isdigit(*cp++)) - return(0); - return(1); + while (*s1) + if (index(s2, *s1++)) + return 1; + return 0; } /* - * Are any of the characters in the two strings the same? + * Convert c to upper case */ -anyof(s1, s2) +raise(c) + register c; +{ + + if (islower(c)) + return toupper(c); + return c; +} + +/* + * Copy s1 to s2, return pointer to null in s2. + */ + +char * +copy(s1, s2) register char *s1, *s2; { - register int c; - while (c = *s1++) - if (any(c, s2)) - return(1); - return(0); + while (*s2++ = *s1++) + ; + return s2 - 1; +} + +/* + * Add a single character onto a string. + */ + +stradd(str, c) + register char *str; +{ + + while (*str++) + ; + str[-1] = c; + *str = 0; } /* @@ -768,7 +662,6 @@ isign(field) * will hash to the same place. */ istrcpy(realfld, field); - if (nretained > 0) return (!member(realfld, retain)); else @@ -777,13 +670,13 @@ isign(field) member(realfield, table) register char *realfield; - register struct ignore **table; + struct ignore **table; { register struct ignore *igp; for (igp = table[hash(realfield)]; igp != 0; igp = igp->i_link) - if (equal(igp->i_field, realfield)) + if (*igp->i_field == *realfield && + equal(igp->i_field, realfield)) return (1); - return (0); } diff --git a/usr/src/usr.bin/mail/cmd1.c b/usr/src/usr.bin/mail/cmd1.c index 50379b0a87..efe4104472 100644 --- a/usr/src/usr.bin/mail/cmd1.c +++ b/usr/src/usr.bin/mail/cmd1.c @@ -5,11 +5,12 @@ */ #ifndef lint -static char *sccsid = "@(#)cmd1.c 5.3 (Berkeley) %G%"; +static char *sccsid = "@(#)cmd1.c 5.4 (Berkeley) %G%"; #endif not lint #include "rcv.h" #include +#include /* * Mail -- a mail program @@ -82,9 +83,9 @@ local(namelist) } if (localnames != 0) cfree((char *) localnames); - localnames = (char **) calloc(c, sizeof (char *)); + localnames = (char **) calloc((unsigned) c, sizeof (char *)); for (ap = namelist, ap2 = localnames; *ap; ap++, ap2++) { - cp = (char *) calloc(strlen(*ap) + 1, sizeof (char)); + cp = (char *) calloc((unsigned) strlen(*ap) + 1, sizeof (char)); strcpy(cp, *ap); *ap2 = cp; } @@ -132,37 +133,16 @@ scroll(arg) } /* - * Compute what the screen size should be. - * We use the following algorithm: - * If user specifies with screen option, use that. - * If baud rate < 1200, use 5 - * If baud rate = 1200, use 10 - * If baud rate > 1200, use 20 + * Compute screen size. */ screensize() { - register char *cp; - register int s; -#ifdef TIOCGWINSZ - struct winsize ws; -#endif - - if ((cp = value("screen")) != NOSTR) { - s = atoi(cp); - if (s > 0) - return(s); - } - if (baud < B1200) - s = 5; - else if (baud == B1200) - s = 10; -#ifdef TIOCGWINSZ - else if (ioctl(fileno(stdout), TIOCGWINSZ, &ws) == 0 && ws.ws_row != 0) - s = ws.ws_row - 4; -#endif - else - s = 20; - return(s); + int s; + char *cp; + + if ((cp = value("screen")) != NOSTR && (s = atoi(cp)) > 0) + return s; + return screenheight - 4; } /* @@ -192,26 +172,18 @@ from(msgvec) printhead(mesg) { struct message *mp; - FILE *ibuf; char headline[LINESIZE], wcount[LINESIZE], *subjline, dispc, curind; char pbuf[BUFSIZ]; - int s; struct headline hl; - register char *cp; + int subjlen; mp = &message[mesg-1]; - ibuf = setinput(mp); - readline(ibuf, headline); - subjline = hfield("subject", mp); - if (subjline == NOSTR) + readline(setinput(mp), headline); + if ((subjline = hfield("subject", mp)) == NOSTR) subjline = hfield("subj", mp); - /* * Bletch! */ - - if (subjline != NOSTR && strlen(subjline) > 28) - subjline[29] = '\0'; curind = dot == mp ? '>' : ' '; dispc = ' '; if (mp->m_flag & MSAVED) @@ -225,18 +197,15 @@ printhead(mesg) if (mp->m_flag & MBOX) dispc = 'M'; parse(headline, &hl, pbuf); - sprintf(wcount, " %d/%ld", mp->m_lines, mp->m_size); - s = strlen(wcount); - cp = wcount + s; - while (s < 7) - s++, *cp++ = ' '; - *cp = '\0'; - if (subjline != NOSTR) - printf("%c%c%3d %-8s %16.16s %s \"%s\"\n", curind, dispc, mesg, - nameof(mp, 0), hl.l_date, wcount, subjline); + sprintf(wcount, "%3d/%-4ld", mp->m_lines, mp->m_size); + subjlen = screenwidth - 50 - strlen(wcount); + if (subjline == NOSTR || subjlen < 0) /* pretty pathetic */ + printf("%c%c%3d %-20.20s %16.16s %s\n", + curind, dispc, mesg, nameof(mp, 0), hl.l_date, wcount); else - printf("%c%c%3d %-8s %16.16s %s\n", curind, dispc, mesg, - nameof(mp, 0), hl.l_date, wcount); + printf("%c%c%3d %-20.20s %16.16s %s \"%.*s\"\n", + curind, dispc, mesg, nameof(mp, 0), hl.l_date, wcount, + subjlen, subjline); } /* @@ -325,9 +294,9 @@ type1(msgvec, doign, page) register struct message *mp; register int mesg; register char *cp; - int c, nlines; + int nlines; int brokpipe(); - FILE *ibuf, *obuf; + FILE *obuf; obuf = stdout; if (setjmp(pipestop)) { @@ -335,7 +304,7 @@ type1(msgvec, doign, page) pipef = NULL; pclose(obuf); } - sigset(SIGPIPE, SIG_DFL); + signal(SIGPIPE, SIG_DFL); return(0); } if (intty && outtty && (page || (cp = value("crt")) != NOSTR)) { @@ -352,25 +321,26 @@ type1(msgvec, doign, page) if (obuf == NULL) { perror(cp); obuf = stdout; - } - else { + } else { pipef = obuf; - sigset(SIGPIPE, brokpipe); + signal(SIGPIPE, brokpipe); } } } - for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) { + for (ip = msgvec; *ip && ip - msgvec < msgCount; ip++) { mesg = *ip; touch(mesg); mp = &message[mesg-1]; dot = mp; - print(mp, obuf, doign); + if (value("quiet") == NOSTR) + fprintf(obuf, "Message %d:\n", mesg); + send(mp, obuf, doign); } if (obuf != stdout) { pipef = NULL; pclose(obuf); } - sigset(SIGPIPE, SIG_DFL); + signal(SIGPIPE, SIG_DFL); return(0); } @@ -381,27 +351,9 @@ type1(msgvec, doign, page) brokpipe() { -# ifndef VMUNIX - signal(SIGPIPE, brokpipe); -# endif longjmp(pipestop, 1); } -/* - * Print the indicated message on standard output. - */ - -print(mp, obuf, doign) - register struct message *mp; - FILE *obuf; -{ - - if (value("quiet") == NOSTR) - fprintf(obuf, "Message %2d:\n", mp - &message[0] + 1); - touch(mp - &message[0] + 1); - send(mp, obuf, doign); -} - /* * Print the top so many lines of each desired message. * The number of lines is taken from the variable "toplines" @@ -438,7 +390,7 @@ top(msgvec) if (!lineb) printf("\n"); for (lines = 0; lines < c && lines <= topl; lines++) { - if (readline(ibuf, linebuf) <= 0) + if (readline(ibuf, linebuf) < 0) break; puts(linebuf); lineb = blankline(linebuf); @@ -487,8 +439,9 @@ mboxit(msgvec) */ folders() { - char dirname[BUFSIZ], cmd[BUFSIZ]; - int pid, s, e; + char dirname[BUFSIZ]; + int pid, e; + union wait s; if (getfold(dirname) < 0) { printf("No value set for \"folder\"\n"); @@ -496,7 +449,6 @@ folders() } switch ((pid = fork())) { case 0: - sigchild(); execlp("ls", "ls", dirname, 0); _exit(1); diff --git a/usr/src/usr.bin/mail/cmd2.c b/usr/src/usr.bin/mail/cmd2.c index 6f99a8753a..1bf02e11a5 100644 --- a/usr/src/usr.bin/mail/cmd2.c +++ b/usr/src/usr.bin/mail/cmd2.c @@ -5,11 +5,12 @@ */ #ifndef lint -static char *sccsid = "@(#)cmd2.c 5.3 (Berkeley) %G%"; +static char *sccsid = "@(#)cmd2.c 5.4 (Berkeley) %G%"; #endif not lint #include "rcv.h" #include +#include /* * Mail -- a mail program @@ -275,7 +276,7 @@ snarf(linebuf, flag) * Strip away trailing blanks. */ - while (*cp == ' ' && cp > linebuf) + while (cp > linebuf && isspace(*cp)) cp--; *++cp = 0; @@ -283,13 +284,13 @@ snarf(linebuf, flag) * Now search for the beginning of the file name. */ - while (cp > linebuf && !any(*cp, "\t ")) + while (cp > linebuf && !isspace(*cp)) cp--; if (*cp == '\0') { printf("No file specified.\n"); return(NOSTR); } - if (any(*cp, " \t")) + if (isspace(*cp)) *cp++ = 0; else *flag = 0; @@ -404,14 +405,13 @@ undelete(msgvec) core() { register int pid; - int status; + union wait status; if ((pid = vfork()) == -1) { perror("fork"); return(1); } if (pid == 0) { - sigchild(); abort(); _exit(1); } @@ -419,10 +419,11 @@ core() fflush(stdout); while (wait(&status) != pid) ; - if (status & 0200) + if (status.w_coredump) printf(" -- Core dumped\n"); else printf("\n"); + return 0; } /* @@ -477,7 +478,8 @@ retfield(list) h = hash(field); igp = (struct ignore *) calloc(1, sizeof (struct ignore)); - igp->i_field = calloc(strlen(field) + 1, sizeof (char)); + igp->i_field = calloc((unsigned) strlen(field) + 1, + sizeof (char)); strcpy(igp->i_field, field); igp->i_link = retain[h]; retain[h] = igp; @@ -510,7 +512,7 @@ retshow() for (igp = retain[h]; igp != 0; igp = igp->i_link) *ap++ = igp->i_field; *ap = 0; - qsort(ring, count, sizeof (char *), igcomp); + qsort((char *) ring, count, sizeof (char *), igcomp); for (ap = ring; *ap != 0; ap++) printf("%s\n", *ap); return(0); @@ -536,7 +538,8 @@ igfield(list) istrcpy(field, *ap); h = hash(field); igp = (struct ignore *) calloc(1, sizeof (struct ignore)); - igp->i_field = calloc(strlen(field) + 1, sizeof (char)); + igp->i_field = calloc((unsigned) strlen(field) + 1, + sizeof (char)); strcpy(igp->i_field, field); igp->i_link = ignore[h]; ignore[h] = igp; @@ -568,7 +571,7 @@ igshow() for (igp = ignore[h]; igp != 0; igp = igp->i_link) *ap++ = igp->i_field; *ap = 0; - qsort(ring, count, sizeof (char *), igcomp); + qsort((char *) ring, count, sizeof (char *), igcomp); for (ap = ring; *ap != 0; ap++) printf("%s\n", *ap); return(0); diff --git a/usr/src/usr.bin/mail/cmd3.c b/usr/src/usr.bin/mail/cmd3.c index 2aa78a6bf0..47739a167b 100644 --- a/usr/src/usr.bin/mail/cmd3.c +++ b/usr/src/usr.bin/mail/cmd3.c @@ -5,11 +5,12 @@ */ #ifndef lint -static char *sccsid = "@(#)cmd3.c 5.3 (Berkeley) %G%"; +static char *sccsid = "@(#)cmd3.c 5.4 (Berkeley) %G%"; #endif not lint #include "rcv.h" #include +#include /* * Mail -- a mail program @@ -25,7 +26,8 @@ static char *sccsid = "@(#)cmd3.c 5.3 (Berkeley) %G%"; shell(str) char *str; { - int (*sig[2])(), stat[1]; + int (*sigint)(), (*sigquit)(); + union wait stat; register int t; char *Shell; char cmd[BUFSIZ]; @@ -35,24 +37,24 @@ shell(str) return(-1); if ((Shell = value("SHELL")) == NOSTR) Shell = SHELL; - for (t = 2; t < 4; t++) - sig[t-2] = sigset(t, SIG_IGN); + sigint = signal(SIGINT, SIG_IGN); + sigquit = signal(SIGQUIT, SIG_IGN); t = vfork(); if (t == 0) { - sigchild(); - for (t = 2; t < 4; t++) - if (sig[t-2] != SIG_IGN) - sigsys(t, SIG_DFL); + if (sigint != SIG_IGN) + signal(SIGINT, SIG_DFL); + if (sigquit != SIG_IGN) + signal(SIGQUIT, SIG_DFL); execl(Shell, Shell, "-c", cmd, (char *)0); perror(Shell); _exit(1); } - while (wait(stat) != t) + while (wait(&stat) != t) ; if (t == -1) perror("fork"); - for (t = 2; t < 4; t++) - sigset(t, sig[t-2]); + signal(SIGINT, sigint); + signal(SIGQUIT, sigquit); printf("!\n"); return(0); } @@ -61,32 +63,35 @@ shell(str) * Fork an interactive shell. */ +/*ARGSUSED*/ dosh(str) char *str; { - int (*sig[2])(), stat[1]; + int (*sigint)(), (*sigquit)(); + union wait stat; register int t; char *Shell; + if ((Shell = value("SHELL")) == NOSTR) Shell = SHELL; - for (t = 2; t < 4; t++) - sig[t-2] = sigset(t, SIG_IGN); + sigint = signal(SIGINT, SIG_IGN); + sigquit = signal(SIGQUIT, SIG_IGN); t = vfork(); if (t == 0) { - sigchild(); - for (t = 2; t < 4; t++) - if (sig[t-2] != SIG_IGN) - sigsys(t, SIG_DFL); + if (sigint != SIG_IGN) + signal(SIGINT, SIG_DFL); + if (sigquit != SIG_IGN) + signal(SIGQUIT, SIG_DFL); execl(Shell, Shell, (char *)0); perror(Shell); _exit(1); } - while (wait(stat) != t) + while (wait(&stat) != t) ; if (t == -1) perror("fork"); - for (t = 2; t < 4; t++) - sigsys(t, sig[t-2]); + signal(SIGINT, sigint); + signal(SIGQUIT, sigquit); putchar('\n'); return(0); } @@ -205,7 +210,7 @@ _respond(msgvec) int *msgvec; { struct message *mp; - char *cp, *cp2, *cp3, *rcv, *replyto; + char *cp, *rcv, *replyto; char buf[2 * LINESIZE], **ap; struct name *np; struct header head; @@ -233,7 +238,6 @@ _respond(msgvec) strcpy(buf, cp); } np = elide(extract(buf, GTO)); - /* rcv = rename(rcv); */ mapf(np, rcv); /* * Delete my name from the reply list, @@ -265,7 +269,7 @@ _respond(msgvec) head.h_subject = reedit(head.h_subject); head.h_cc = NOSTR; if (replyto == NOSTR) { - cp = hfield("cc", mp); + cp = skin(hfield("cc", mp)); if (cp != NOSTR) { np = elide(extract(cp, GCC)); mapf(np, rcv); @@ -300,7 +304,7 @@ reedit(subj) if (icequal(sbuf, "re:")) return(subj); newsubj = salloc(strlen(subj) + 6); - sprintf(newsubj, "Re: %s", subj); + sprintf(newsubj, "Re: %s", subj); return(newsubj); } @@ -375,6 +379,7 @@ rexit(e) if (Tflag != NOSTR) close(creat(Tflag, 0600)); exit(e); + /*NOTREACHED*/ } /* @@ -433,7 +438,6 @@ unset(arglist) char **arglist; { register struct var *vp, *vp2; - register char *cp; int errs, h; char **ap; @@ -451,7 +455,7 @@ unset(arglist) variables[h] = variables[h]->v_link; vfree(vp2->v_name); vfree(vp2->v_value); - cfree(vp2); + cfree((char *)vp2); continue; } for (vp = variables[h]; vp->v_link != vp2; vp = vp->v_link) @@ -459,7 +463,7 @@ unset(arglist) vp->v_link = vp2->v_link; vfree(vp2->v_name); vfree(vp2->v_value); - cfree(vp2); + cfree((char *) vp2); } return(errs); } @@ -535,7 +539,7 @@ sort(list) ; if (ap-list < 2) return; - qsort(list, ap-list, sizeof *list, diction); + qsort((char *)list, ap-list, sizeof *list, diction); } /* @@ -553,9 +557,10 @@ diction(a, b) * The do nothing command for comments. */ +/*ARGSUSED*/ null(e) { - return(0); + return 0; } /* @@ -568,7 +573,6 @@ file(argv) char **argv; { register char *cp; - char fname[BUFSIZ]; int edit; if (argv[0] == NOSTR) { @@ -594,6 +598,7 @@ file(argv) return(-1); } announce(0); + return 0; } /* @@ -707,7 +712,7 @@ _Respond(msgvec) { struct header head; struct message *mp; - register int i, s, *ap; + register int s, *ap; register char *cp, *cp2, *subject; for (s = 0, ap = msgvec; *ap != 0; ap++) { @@ -840,9 +845,9 @@ alternates(namelist) } if (altnames != 0) cfree((char *) altnames); - altnames = (char **) calloc(c, sizeof (char *)); + altnames = (char **) calloc((unsigned) c, sizeof (char *)); for (ap = namelist, ap2 = altnames; *ap; ap++, ap2++) { - cp = (char *) calloc(strlen(*ap) + 1, sizeof (char)); + cp = (char *) calloc((unsigned) strlen(*ap) + 1, sizeof (char)); strcpy(cp, *ap); *ap2 = cp; } diff --git a/usr/src/usr.bin/mail/cmdtab.c b/usr/src/usr.bin/mail/cmdtab.c index 9442858123..10837a8286 100644 --- a/usr/src/usr.bin/mail/cmdtab.c +++ b/usr/src/usr.bin/mail/cmdtab.c @@ -5,7 +5,7 @@ */ #ifndef lint -static char *sccsid = "@(#)cmdtab.c 5.3 (Berkeley) %G%"; +static char *sccsid = "@(#)cmdtab.c 5.4 (Berkeley) %G%"; #endif not lint #include "def.h" @@ -17,7 +17,7 @@ static char *sccsid = "@(#)cmdtab.c 5.3 (Berkeley) %G%"; */ extern int type(), preserve(), delete(), undelete(), next(), shell(), schdir(); -extern int save(), help(), headers(), pdot(), strace(), respond(), editor(); +extern int save(), help(), headers(), pdot(), respond(), editor(); extern int edstop(), rexit(), pcmdlist(), sendmail(), from(), copycmd(); extern int messize(), psalloc(), deltype(), unset(), set(), source(); extern int pversion(), group(), top(), core(), null(), stouch(), visual(); diff --git a/usr/src/usr.bin/mail/collect.c b/usr/src/usr.bin/mail/collect.c index 954e31ca14..574875e204 100644 --- a/usr/src/usr.bin/mail/collect.c +++ b/usr/src/usr.bin/mail/collect.c @@ -5,7 +5,7 @@ */ #ifndef lint -static char *sccsid = "@(#)collect.c 5.2 (Berkeley) %G%"; +static char *sccsid = "@(#)collect.c 5.3 (Berkeley) %G%"; #endif not lint /* @@ -17,6 +17,7 @@ static char *sccsid = "@(#)collect.c 5.2 (Berkeley) %G%"; #include "rcv.h" #include +#include /* * Read a message from standard output and return a read file to it @@ -26,19 +27,13 @@ static char *sccsid = "@(#)collect.c 5.2 (Berkeley) %G%"; /* * The following hokiness with global variables is so that on * receipt of an interrupt signal, the partial message can be salted - * away on dead.letter. The output file must be available to flush, - * and the input to read. Several open files could be saved all through - * Mail if stdio allowed simultaneous read/write access. + * away on dead.letter. */ -static int (*savesig)(); /* Previous SIGINT value */ +static int (*saveint)(); /* Previous SIGINT value */ static int (*savehup)(); /* Previous SIGHUP value */ -# ifdef VMUNIX static int (*savecont)(); /* Previous SIGCONT value */ -# endif VMUNIX -static FILE *newi; /* File for saving away */ -static FILE *newo; /* Output side of same */ -static int hf; /* Ignore interrups */ +static FILE *collf; /* File for saving away */ static int hadintr; /* Have seen one SIGINT so far */ static jmp_buf coljmp; /* To get back to work */ @@ -47,46 +42,41 @@ FILE * collect(hp) struct header *hp; { - FILE *ibuf, *fbuf, *obuf; - int lc, cc, escape, collrub(), intack(), collhup, collcont(), eof; + FILE *fp, *fbuf; + int lc, cc, escape, eof; + int collrub(), intack(), collcont(); register int c, t; char linebuf[LINESIZE], *cp; extern char tempMail[]; int notify(); - extern collintsig(), collhupsig(); char getsub; + int omask; noreset++; - ibuf = obuf = NULL; - if (value("ignore") != NOSTR) - hf = 1; - else - hf = 0; - hadintr = 0; -# ifdef VMUNIX - if ((savesig = sigset(SIGINT, SIG_IGN)) != SIG_IGN) - sigset(SIGINT, hf ? intack : collrub), sigblock(sigmask(SIGINT)); - if ((savehup = sigset(SIGHUP, SIG_IGN)) != SIG_IGN) - sigset(SIGHUP, collrub), sigblock(sigmask(SIGHUP)); - savecont = sigset(SIGCONT, collcont); -# else VMUNIX - savesig = signal(SIGINT, SIG_IGN); - savehup = signal(SIGHUP, SIG_IGN); -# endif VMUNIX - newi = NULL; - newo = NULL; - if ((obuf = fopen(tempMail, "w")) == NULL) { - perror(tempMail); + fp = NULL; + collf = NULL; + + /* + * Start catching signals from here, but we're still die on interrupts + * until we're in the main loop. + */ + omask = sigblock(sigmask(SIGINT) | sigmask(SIGHUP)); + if ((saveint = signal(SIGINT, SIG_IGN)) != SIG_IGN) + signal(SIGINT, value("ignore") != NOSTR ? intack : collrub); + if ((savehup = signal(SIGHUP, SIG_IGN)) != SIG_IGN) + signal(SIGHUP, collrub); + savecont = signal(SIGCONT, SIG_DFL); + if (setjmp(coljmp)) { + remove(tempMail); goto err; } - newo = obuf; - if ((ibuf = fopen(tempMail, "r")) == NULL) { + sigsetmask(omask & ~(sigmask(SIGINT) | sigmask(SIGHUP))); + + if ((fp = fopen(tempMail, "w+")) == NULL) { perror(tempMail); - newo = NULL; - fclose(obuf); goto err; } - newi = ibuf; + collf = fp; remove(tempMail); /* @@ -94,7 +84,6 @@ collect(hp) * refrain from printing a newline after * the headers (since some people mind). */ - t = GTO|GSUBJECT|GCC|GNL; getsub = 0; if (intty && sflag == NOSTR && hp->h_subject == NOSTR && value("ask")) @@ -107,30 +96,38 @@ collect(hp) if ((cp = value("escape")) != NOSTR) escape = *cp; eof = 0; - for (;;) { - int omask = sigblock(0) &~ (sigmask(SIGINT)|sigmask(SIGHUP)); - - setjmp(coljmp); -# ifdef VMUNIX - sigsetmask(omask); -# else VMUNIX - if (savesig != SIG_IGN) - signal(SIGINT, hf ? intack : collintsig); - if (savehup != SIG_IGN) - signal(SIGHUP, collhupsig); -# endif VMUNIX - fflush(stdout); - if (getsub) { + hadintr = 0; + + /* + * We can put the setjmp here because register variable + * needs to be saved in the loop. + */ + if (!setjmp(coljmp)) { + signal(SIGCONT, collcont); + if (getsub) grabh(hp, GSUBJECT); - getsub = 0; - continue; + } else { + /* + * Come here for printing the after-signal message. + * Duplicate messages won't be printed because + * the write is aborted if we get a SIGTTOU. + */ +cont: + if (hadintr) { + fflush(stdout); + fprintf(stderr, + "\n(Interrupt -- one more to kill letter)\n"); + } else { + printf("(continue)\n"); + fflush(stdout); } - if (readline(stdin, linebuf) <= 0) { + } + for (;;) { + if (readline(stdin, linebuf) < 0) { if (intty && value("ignoreeof") != NOSTR) { if (++eof > 35) break; - printf("Use \".\" to terminate letter\n", - escape); + printf("Use \".\" to terminate letter\n"); continue; } break; @@ -141,7 +138,7 @@ collect(hp) (value("dot") != NOSTR || value("ignoreeof") != NOSTR)) break; if (linebuf[0] != escape || rflag != NOSTR) { - if ((t = putline(obuf, linebuf)) < 0) + if (putline(fp, linebuf) < 0) goto err; continue; } @@ -154,7 +151,7 @@ collect(hp) */ if (c == escape) { - if (putline(obuf, &linebuf[1]) < 0) + if (putline(fp, &linebuf[1]) < 0) goto err; else break; @@ -186,14 +183,13 @@ collect(hp) */ execute(&linebuf[2], 1); - printf("(continue)\n"); - break; + goto cont; case '.': /* * Simulate end of file on input. */ - goto eofl; + goto out; case 'q': case 'Q': @@ -215,8 +211,7 @@ collect(hp) break; } grabh(hp, GTO|GSUBJECT|GCC|GBCC); - printf("(continue)\n"); - break; + goto cont; case 't': /* @@ -233,7 +228,7 @@ collect(hp) */ cp = &linebuf[2]; - while (any(*cp, " \t")) + while (isspace(*cp)) cp++; hp->h_subject = savestr(cp); hp->h_seq++; @@ -257,18 +252,18 @@ collect(hp) break; case 'd': - copy(deadletter, &linebuf[2]); + strcpy(linebuf + 2, deadletter); /* fall into . . . */ case 'r': /* * Invoke a file: * Search for the file name, - * then open it and copy the contents to obuf. + * then open it and copy the contents to fp. */ cp = &linebuf[2]; - while (any(*cp, " \t")) + while (isspace(*cp)) cp++; if (*cp == '\0') { printf("Interpolate what file?\n"); @@ -278,7 +273,7 @@ collect(hp) if (cp == NOSTR) break; if (isdir(cp)) { - printf("%s: directory\n"); + printf("%s: Directory\n", cp); break; } if ((fbuf = fopen(cp, "r")) == NULL) { @@ -289,9 +284,9 @@ collect(hp) fflush(stdout); lc = 0; cc = 0; - while (readline(fbuf, linebuf) > 0) { + while (readline(fbuf, linebuf) >= 0) { lc++; - if ((t = putline(obuf, linebuf)) < 0) { + if ((t = putline(fp, linebuf)) < 0) { fclose(fbuf); goto err; } @@ -315,9 +310,8 @@ collect(hp) } if ((cp = expand(cp)) == NOSTR) break; - fflush(obuf); - rewind(ibuf); - exwrite(cp, ibuf, 1); + rewind(fp); + exwrite(cp, fp, 1); break; case 'm': @@ -336,21 +330,17 @@ collect(hp) cp = &linebuf[2]; while (any(*cp, " \t")) cp++; - if (forward(cp, obuf, c) < 0) + if (forward(cp, fp, c) < 0) goto err; - printf("(continue)\n"); - break; + goto cont; case '?': if ((fbuf = fopen(THELPFILE, "r")) == NULL) { perror(THELPFILE); break; } - t = getc(fbuf); - while (t != -1) { + while ((t = getc(fp)) != EOF) putchar(t); - t = getc(fbuf); - } fclose(fbuf); break; @@ -360,17 +350,12 @@ collect(hp) * message without altering anything. */ - fflush(obuf); - rewind(ibuf); + rewind(fp); printf("-------\nMessage contains:\n"); puthead(hp, stdout, GTO|GSUBJECT|GCC|GBCC|GNL); - t = getc(ibuf); - while (t != EOF) { + while ((t = getc(fp)) != EOF) putchar(t); - t = getc(ibuf); - } - printf("(continue)\n"); - break; + goto cont; case '^': case '|': @@ -379,12 +364,9 @@ collect(hp) * Collect output as new message. */ - obuf = mespipe(ibuf, obuf, &linebuf[2]); - newo = obuf; - ibuf = newi; - newi = ibuf; - printf("(continue)\n"); - break; + rewind(fp); + fp = mespipe(fp, &linebuf[2]); + goto cont; case 'v': case 'e': @@ -394,61 +376,36 @@ collect(hp) * 'v' means to use VISUAL */ - if ((obuf = mesedit(ibuf, obuf, c)) == NULL) + rewind(fp); + if ((fp = mesedit(fp, c)) == NULL) goto err; - newo = obuf; - ibuf = newi; - printf("(continue)\n"); - break; + goto cont; } } -eofl: - fclose(obuf); - rewind(ibuf); - sigset(SIGINT, savesig); - sigset(SIGHUP, savehup); -# ifdef VMUNIX - sigset(SIGCONT, savecont); - sigsetmask(0); -# endif VMUNIX - noreset = 0; - return(ibuf); - + goto out; err: - if (ibuf != NULL) - fclose(ibuf); - if (obuf != NULL) - fclose(obuf); - sigset(SIGINT, savesig); - sigset(SIGHUP, savehup); -# ifdef VMUNIX - sigset(SIGCONT, savecont); - sigsetmask(0); -# endif VMUNIX + if (fp != NULL) { + fclose(fp); + fp = NULL; + } +out: + if (fp != NULL) + rewind(fp); + signal(SIGINT, saveint); + signal(SIGHUP, savehup); + signal(SIGCONT, savecont); + sigsetmask(omask); noreset = 0; - return(NULL); -} - -/* - * Non destructively interrogate the value of the given signal. - */ - -psig(n) -{ - register (*wassig)(); - - wassig = sigset(n, SIG_IGN); - sigset(n, wassig); - return((int) wassig); + return(fp); } /* * Write a file, ex-like if f set. */ -exwrite(name, ibuf, f) +exwrite(name, fp, f) char name[]; - FILE *ibuf; + FILE *fp; { register FILE *of; register int c; @@ -463,7 +420,7 @@ exwrite(name, ibuf, f) if (stat(name, &junk) >= 0 && (junk.st_mode & S_IFMT) == S_IFREG) { if (!f) fprintf(stderr, "%s: ", name); - fprintf(stderr, "File exists\n", name); + fprintf(stderr, "File exists\n"); return(-1); } if ((of = fopen(name, "w")) == NULL) { @@ -472,7 +429,7 @@ exwrite(name, ibuf, f) } lc = 0; cc = 0; - while ((c = getc(ibuf)) != EOF) { + while ((c = getc(fp)) != EOF) { cc++; if (c == '\n') lc++; @@ -490,7 +447,7 @@ exwrite(name, ibuf, f) } /* - * Edit the message being collected on ibuf and obuf. + * Edit the message being collected on fp. * Write the message out onto some poorly-named temp file * and point an editor at it. * @@ -498,21 +455,20 @@ exwrite(name, ibuf, f) */ FILE * -mesedit(ibuf, obuf, c) - FILE *ibuf, *obuf; +mesedit(fp, c) + FILE *fp; { - int pid, s; + int pid; + union wait s; FILE *fbuf; register int t; - int (*sig)(), (*scont)(), signull(); + int (*sigint)(), (*sigcont)(); struct stat sbuf; extern char tempMail[], tempEdit[]; register char *edit; - sig = sigset(SIGINT, SIG_IGN); -# ifdef VMUNIX - scont = sigset(SIGCONT, signull); -# endif VMUNIX + sigint = signal(SIGINT, SIG_IGN); + sigcont = signal(SIGCONT, SIG_DFL); if (stat(tempEdit, &sbuf) >= 0) { printf("%s: file exists\n", tempEdit); goto out; @@ -522,13 +478,8 @@ mesedit(ibuf, obuf, c) perror(tempEdit); goto out; } - fflush(obuf); - rewind(ibuf); - t = getc(ibuf); - while (t != EOF) { + while ((t = getc(fp)) != EOF) putc(t, fbuf); - t = getc(ibuf); - } fflush(fbuf); if (ferror(fbuf)) { perror(tempEdit); @@ -540,9 +491,8 @@ mesedit(ibuf, obuf, c) edit = c == 'e' ? EDITOR : VISUAL; pid = vfork(); if (pid == 0) { - sigchild(); - if (sig != SIG_IGN) - sigsys(SIGINT, SIG_DFL); + if (sigint != SIG_IGN) + signal(SIGINT, SIG_DFL); execl(edit, edit, tempEdit, 0); perror(edit); _exit(1); @@ -554,7 +504,7 @@ mesedit(ibuf, obuf, c) } while (wait(&s) != pid) ; - if ((s & 0377) != 0) { + if (s.w_status != 0) { printf("Fatal error in \"%s\"\n", edit); remove(tempEdit); goto out; @@ -564,31 +514,22 @@ mesedit(ibuf, obuf, c) * Now switch to new file. */ - if ((fbuf = fopen(tempEdit, "a")) == NULL) { + if ((fbuf = fopen(tempEdit, "a+")) == NULL) { perror(tempEdit); remove(tempEdit); goto out; } - if ((ibuf = fopen(tempEdit, "r")) == NULL) { - perror(tempEdit); - fclose(fbuf); - remove(tempEdit); - goto out; - } remove(tempEdit); - fclose(obuf); - fclose(newi); - obuf = fbuf; + collf = fbuf; + fclose(fp); + fp = fbuf; goto out; fix: perror(tempEdit); out: -# ifdef VMUNIX - sigset(SIGCONT, scont); -# endif VMUNIX - sigset(SIGINT, sig); - newi = ibuf; - return(obuf); + signal(SIGCONT, sigcont); + signal(SIGINT, sigint); + return(fp); } /* @@ -599,30 +540,22 @@ out: */ FILE * -mespipe(ibuf, obuf, cmd) - FILE *ibuf, *obuf; +mespipe(fp, cmd) + FILE *fp; char cmd[]; { - register FILE *ni, *no; - int pid, s; - int (*savesig)(); + register FILE *nf; + int pid; + union wait s; + int (*saveint)(); char *Shell; - newi = ibuf; - if ((no = fopen(tempEdit, "w")) == NULL) { + if ((nf = fopen(tempEdit, "w+")) == NULL) { perror(tempEdit); - return(obuf); - } - if ((ni = fopen(tempEdit, "r")) == NULL) { - perror(tempEdit); - fclose(no); - remove(tempEdit); - return(obuf); + return(fp); } remove(tempEdit); - savesig = sigset(SIGINT, SIG_IGN); - fflush(obuf); - rewind(ibuf); + saveint = signal(SIGINT, SIG_IGN); if ((Shell = value("SHELL")) == NULL) Shell = "/bin/sh"; if ((pid = vfork()) == -1) { @@ -630,29 +563,29 @@ mespipe(ibuf, obuf, cmd) goto err; } if (pid == 0) { + int fd; /* * stdin = current message. * stdout = new message. */ - sigchild(); close(0); - dup(fileno(ibuf)); + dup(fileno(fp)); close(1); - dup(fileno(no)); - for (s = 4; s < 15; s++) - close(s); + dup(fileno(nf)); + for (fd = getdtablesize(); --fd > 2;) + close(fd); execl(Shell, Shell, "-c", cmd, 0); perror(Shell); _exit(1); } while (wait(&s) != pid) ; - if (s != 0 || pid == -1) { + if (s.w_status != 0 || pid == -1) { fprintf(stderr, "\"%s\" failed!?\n", cmd); goto err; } - if (fsize(ni) == 0) { + if (fsize(nf) == 0) { fprintf(stderr, "No bytes from \"%s\" !?\n", cmd); goto err; } @@ -661,17 +594,16 @@ mespipe(ibuf, obuf, cmd) * Take new files. */ - newi = ni; - fclose(ibuf); - fclose(obuf); - sigset(SIGINT, savesig); - return(no); + fseek(nf, 0L, 2); + collf = nf; + fclose(fp); + signal(SIGINT, saveint); + return(nf); err: - fclose(no); - fclose(ni); - sigset(SIGINT, savesig); - return(obuf); + fclose(nf); + signal(SIGINT, saveint); + return(fp); } /* @@ -682,9 +614,9 @@ err: * the message temporary. The flag argument is 'm' if we * should shift over and 'f' if not. */ -forward(ms, obuf, f) +forward(ms, fp, f) char ms[]; - FILE *obuf; + FILE *fp; { register int *msgvec, *ip; extern char tempMail[]; @@ -707,12 +639,12 @@ forward(ms, obuf, f) touch(*ip); printf(" %d", *ip); if (f == 'm') { - if (transmit(&message[*ip-1], obuf) < 0L) { + if (transmit(&message[*ip-1], fp) < 0L) { perror(tempMail); return(-1); } } else - if (send(&message[*ip-1], obuf, 0) < 0) { + if (send(&message[*ip-1], fp, 0) < 0) { perror(tempMail); return(-1); } @@ -729,9 +661,9 @@ forward(ms, obuf, f) */ long -transmit(mailp, obuf) +transmit(mailp, fp) struct message *mailp; - FILE *obuf; + FILE *fp; { register struct message *mp; register int ch; @@ -745,20 +677,16 @@ transmit(mailp, obuf) n = c; bol = 1; while (c-- > 0L) { - if (bol) { + ch = getc(ibuf); + if (ch == '\n') + bol = 1; + else if (bol) { bol = 0; - putc('\t', obuf); + putc('\t', fp); n++; - if (ferror(obuf)) { - perror("/tmp"); - return(-1L); - } } - ch = getc(ibuf); - if (ch == '\n') - bol++; - putc(ch, obuf); - if (ferror(obuf)) { + putc(ch, fp); + if (ferror(fp)) { perror("/tmp"); return(-1L); } @@ -769,11 +697,12 @@ transmit(mailp, obuf) /* * Print (continue) when continued after ^Z. */ +/*ARGSUSED*/ collcont(s) { - printf("(continue)\n"); - fflush(stdout); + hadintr = 0; + longjmp(coljmp, 1); } /* @@ -784,56 +713,36 @@ collcont(s) * were previously set anyway. */ -# ifndef VMUNIX -collintsig() -{ - signal(SIGINT, SIG_IGN); - collrub(SIGINT); -} - -collhupsig() -{ - signal(SIGHUP, SIG_IGN); - collrub(SIGHUP); -} -# endif VMUNIX - collrub(s) { register FILE *dbuf; register int c; if (s == SIGINT && hadintr == 0) { - hadintr++; - fflush(stdout); - fprintf(stderr, "\n(Interrupt -- one more to kill letter)\n"); + hadintr = 1; longjmp(coljmp, 1); } - fclose(newo); - rewind(newi); - if (s == SIGINT && value("nosave") != NOSTR || fsize(newi) == 0) + rewind(collf); + if (s == SIGINT && value("nosave") != NOSTR || fsize(collf) == 0) goto done; if ((dbuf = fopen(deadletter, "w")) == NULL) goto done; chmod(deadletter, 0600); - while ((c = getc(newi)) != EOF) + while ((c = getc(collf)) != EOF) putc(c, dbuf); fclose(dbuf); done: - fclose(newi); - sigset(SIGINT, savesig); - sigset(SIGHUP, savehup); -# ifdef VMUNIX - sigset(SIGCONT, savecont); -# endif VMUNIX + fclose(collf); + signal(SIGINT, saveint); + signal(SIGHUP, savehup); + signal(SIGCONT, savecont); if (rcvmode) { if (s == SIGHUP) hangup(SIGHUP); else stop(s); - } - else + } else exit(1); } @@ -841,9 +750,10 @@ done: * Acknowledge an interrupt signal from the tty by typing an @ */ +/*ARGSUSED*/ intack(s) { - + puts("@"); fflush(stdout); clearerr(stdin); diff --git a/usr/src/usr.bin/mail/def.h b/usr/src/usr.bin/mail/def.h index a597628d84..162c0bf5ce 100644 --- a/usr/src/usr.bin/mail/def.h +++ b/usr/src/usr.bin/mail/def.h @@ -3,34 +3,20 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)def.h 5.2 (Berkeley) %G% + * @(#)def.h 5.3 (Berkeley) %G% */ #include /* includes */ -#include +#include #include #include +#include +#include #include "local.h" -#undef isalpha -#undef isdigit - /* * Mail -- a mail program * - * Commands are: - * t print out these messages - * r reply to messages - * m mail to users (analogous to send) - * e edit messages - * c [directory] chdir to dir or home if none - * x exit quickly - * w file save messages in file - * q quit, save remaining stuff in mbox - * d delete messages - * u undelete messages - * h print message headers - * * Author: Kurt Shoens (UCB) March 25, 1978 */ @@ -46,6 +32,7 @@ #define MAXARGC 1024 /* Maximum list of raw strings */ #define NOSTR ((char *) 0) /* Null string pointer */ #define MAXEXP 25 /* Maximum expansion of aliases */ + #define equal(a, b) (strcmp(a,b)==0)/* A nice function to string compare */ struct message { @@ -72,6 +59,13 @@ struct message { #define MSTATUS (1<<9) /* message status has changed */ #define MBOX (1<<10) /* Send this to mbox, regardless */ +/* + * Given a file address, determine the block number it represents. + */ +#define blockof(off) ((int) ((off) / 4096)) +#define offsetof(off) ((int) ((off) % 4096)) +#define positionof(block, offset) ((off_t)(block) * 4096 + (offset)) + /* * Format of the command description table. * The actual table is declared and initialized @@ -237,26 +231,6 @@ struct ignore { #define setexit() setjmp(srbuf) #define reset(x) longjmp(srbuf, x) -/* - * VM/UNIX has a vfork system call which is faster than forking. If we - * don't have it, fork(2) will do . . . - */ - -#ifndef VMUNIX -#define vfork() fork() -#endif -#ifndef SIGRETRO -#define sigchild() -#endif - -/* - * 4.2bsd signal interface help... - */ -#ifdef VMUNIX -#define sigset(s, a) signal(s, a) -#define sigsys(s, a) signal(s, a) -#endif - /* * Truncate a file to the last character written. This is * useful just before closing an old file that was opened @@ -285,34 +259,28 @@ char *detract(); char *expand(); char *gets(); char *hfield(); -char *index(); char *name1(); char *nameof(); char *nextword(); char *getenv(); char *getfilename(); -char *hcontents(); +char *ishfield(); +char *malloc(); char *netmap(); char *netname(); char *readtty(); char *reedit(); -char *rename(); char *revarpa(); -char *rindex(); char *rpair(); char *salloc(); char *savestr(); char *skin(); char *snarf(); -char *strcat(); -char *strcpy(); +char *sprintf(); char *value(); char *vcopy(); char *yankword(); off_t fsize(); -#ifndef VMUNIX -int (*sigset())(); -#endif struct cmd *lex(); struct grouphead *findgroup(); struct name *cat(); @@ -328,4 +296,3 @@ struct name *verify(); struct var *lookup(); long transmit(); int icequal(); -int cmpdomain(); diff --git a/usr/src/usr.bin/mail/edit.c b/usr/src/usr.bin/mail/edit.c index 37ee0088bb..ab9b8c5024 100644 --- a/usr/src/usr.bin/mail/edit.c +++ b/usr/src/usr.bin/mail/edit.c @@ -5,12 +5,13 @@ */ #ifndef lint -static char *sccsid = "@(#)edit.c 5.2 (Berkeley) %G%"; +static char *sccsid = "@(#)edit.c 5.3 (Berkeley) %G%"; #endif not lint #include "rcv.h" #include #include +#include /* * Mail -- a mail program @@ -56,25 +57,24 @@ edit1(msgvec, ed) int *msgvec; char *ed; { - register char *cp, *cp2; register int c; - int *ip, pid, mesg, lines; - long ms; + int *ip, pid, mesg; int (*sigint)(), (*sigquit)(); FILE *ibuf, *obuf; char edname[15], nbuf[10]; - struct message *mp; + register struct message *mp; extern char tempEdit[]; off_t fsize(), size; struct stat statb; long modtime; + union wait status; /* * Set signals; locate editor. */ - sigint = sigset(SIGINT, SIG_IGN); - sigquit = sigset(SIGQUIT, SIG_IGN); + sigint = signal(SIGINT, SIG_IGN); + sigquit = signal(SIGQUIT, SIG_IGN); /* * Deal with each message to be edited . . . @@ -84,22 +84,15 @@ edit1(msgvec, ed) mesg = *ip; mp = &message[mesg-1]; mp->m_flag |= MODIFY; + touch(mesg); + dot = mp; /* * Make up a name for the edit file of the * form "Message%d" and make sure it doesn't * already exist. */ - - cp = &nbuf[10]; - *--cp = 0; - while (mesg) { - *--cp = mesg % 10 + '0'; - mesg /= 10; - } - cp2 = copy("Message", edname); - while (*cp2++ = *cp++) - ; + sprintf(edname, "Message%d", mesg); if (!access(edname, 2)) { printf("%s: file exists\n", edname); goto out; @@ -108,7 +101,6 @@ edit1(msgvec, ed) /* * Copy the message into the edit file. */ - close(creat(edname, 0600)); if ((obuf = fopen(edname, "w")) == NULL) { perror(edname); @@ -150,16 +142,15 @@ edit1(msgvec, ed) goto out; } if (pid == 0) { - sigchild(); if (sigint != SIG_IGN) - sigsys(SIGINT, SIG_DFL); + signal(SIGINT, SIG_DFL); if (sigquit != SIG_IGN) - sigsys(SIGQUIT, SIG_DFL); + signal(SIGQUIT, SIG_DFL); execl(ed, ed, edname, 0); perror(ed); _exit(1); } - while (wait(&mesg) != pid) + while (wait(&status) != pid) ; /* @@ -192,21 +183,18 @@ edit1(msgvec, ed) } remove(edname); fseek(otf, (long) 0, 2); - size = fsize(otf); + size = ftell(otf); mp->m_block = blockof(size); mp->m_offset = offsetof(size); - ms = 0L; - lines = 0; + mp->m_size = fsize(ibuf); + mp->m_lines = 0; while ((c = getc(ibuf)) != EOF) { if (c == '\n') - lines++; + mp->m_lines++; putc(c, otf); if (ferror(otf)) break; - ms++; } - mp->m_size = ms; - mp->m_lines = lines; if (ferror(otf)) perror("/tmp"); fclose(ibuf); @@ -217,6 +205,7 @@ edit1(msgvec, ed) */ out: - sigset(SIGINT, sigint); - sigset(SIGQUIT, sigquit); + signal(SIGINT, sigint); + signal(SIGQUIT, sigquit); + return 0; } diff --git a/usr/src/usr.bin/mail/fio.c b/usr/src/usr.bin/mail/fio.c index 78774646fb..c213cea008 100644 --- a/usr/src/usr.bin/mail/fio.c +++ b/usr/src/usr.bin/mail/fio.c @@ -5,13 +5,14 @@ */ #ifndef lint -static char *sccsid = "@(#)fio.c 5.4 (Berkeley) %G%"; +static char *sccsid = "@(#)fio.c 5.5 (Berkeley) %G%"; #endif not lint #include "rcv.h" #include +#include +#include #include -#include /* * Mail -- a mail program @@ -23,90 +24,86 @@ static char *sccsid = "@(#)fio.c 5.4 (Berkeley) %G%"; * Set up the input pointers while copying the mail file into * /tmp. */ - setptr(ibuf) - FILE *ibuf; + register FILE *ibuf; { - register int c; + register c; register char *cp, *cp2; - register int count, l; - long s; - off_t offset; + register count; char linebuf[LINESIZE]; - char wbuf[LINESIZE]; - int maybe, mestmp, flag, inhead; + int maybe, inhead; + FILE *mestmp; + off_t offset; struct message this; extern char tempSet[]; - if ((mestmp = opentemp(tempSet)) < 0) + if ((c = opentemp(tempSet)) < 0) exit(1); + if ((mestmp = fdopen(c, "r+")) == NULL) + panic("Can't open temporary"); msgCount = 0; - offset = 0; - s = 0L; - l = 0; maybe = 1; - flag = MUSED|MNEW; + inhead = 0; + offset = 0; + this.m_flag = MUSED|MNEW; + this.m_size = 0; + this.m_lines = 0; + this.m_block = 0; + this.m_offset = 0; for (;;) { if (fgets(linebuf, LINESIZE, ibuf) == NULL) { - this.m_flag = flag; - flag = MUSED|MNEW; - this.m_offset = offsetof(offset); - this.m_block = blockof(offset); - this.m_size = s; - this.m_lines = l; if (append(&this, mestmp)) { perror(tempSet); exit(1); } fclose(ibuf); makemessage(mestmp); - close(mestmp); return; } count = strlen(linebuf); - fputs(linebuf, otf); - cp = linebuf + (count - 1); - if (*cp == '\n') - *cp = 0; + fwrite(linebuf, sizeof *linebuf, count, otf); if (ferror(otf)) { perror("/tmp"); exit(1); } + linebuf[count - 1] = 0; if (maybe && linebuf[0] == 'F' && ishead(linebuf)) { msgCount++; - this.m_flag = flag; - flag = MUSED|MNEW; - inhead = 1; - this.m_block = blockof(offset); - this.m_offset = offsetof(offset); - this.m_size = s; - this.m_lines = l; - s = 0L; - l = 0; if (append(&this, mestmp)) { perror(tempSet); exit(1); } - } - if (linebuf[0] == 0) + this.m_flag = MUSED|MNEW; + this.m_size = 0; + this.m_lines = 0; + this.m_block = blockof(offset); + this.m_offset = offsetof(offset); + inhead = 1; + } else if (linebuf[0] == 0) { inhead = 0; - if (inhead && (cp = index(linebuf, ':'))) { - *cp = 0; - if (icequal(linebuf, "status")) { - ++cp; - if (index(cp, 'R')) - flag |= MREAD; - if (index(cp, 'O')) - flag &= ~MNEW; - inhead = 0; + } else if (inhead) { + for (cp = linebuf, cp2 = "status";; cp++) { + if ((c = *cp2++) == 0) { + while (isspace(*cp++)) + ; + if (cp[-1] != ':') + break; + while (c = *cp++) + if (c == 'R') + this.m_flag |= MREAD; + else if (c == 'O') + this.m_flag &= ~MNEW; + inhead = 0; + break; + } + if (*cp != c && *cp != toupper(c)) + break; } } offset += count; - s += (long) count; - l++; - maybe = 0; - if (linebuf[0] == 0) - maybe = 1; + this.m_size += count; + this.m_lines++; + maybe = linebuf[0] == 0; } } @@ -115,7 +112,6 @@ setptr(ibuf) * If a write error occurs, return -1, else the count of * characters written, including the newline. */ - putline(obuf, linebuf) FILE *obuf; char *linebuf; @@ -123,11 +119,11 @@ putline(obuf, linebuf) register int c; c = strlen(linebuf); - fputs(linebuf, obuf); + fwrite(linebuf, sizeof *linebuf, c, obuf); putc('\n', obuf); if (ferror(obuf)) - return(-1); - return(c+1); + return (-1); + return (c + 1); } /* @@ -135,7 +131,6 @@ putline(obuf, linebuf) * buffer. Return the number of characters read. Do not * include the newline at the end. */ - readline(ibuf, linebuf) FILE *ibuf; char *linebuf; @@ -144,84 +139,69 @@ readline(ibuf, linebuf) clearerr(ibuf); if (fgets(linebuf, LINESIZE, ibuf) == NULL) - return(0); + return -1; n = strlen(linebuf); - if (n >= 1 && linebuf[n-1] == '\n') - linebuf[n-1] = '\0'; - return(n); + if (n > 0 && linebuf[n - 1] == '\n') + linebuf[--n] = '\0'; + return n; } /* * Return a file buffer all ready to read up the * passed message pointer. */ - FILE * setinput(mp) register struct message *mp; { - off_t off; fflush(otf); - off = mp->m_block; - off <<= 9; - off += mp->m_offset; - if (fseek(itf, off, 0) < 0) { + if (fseek(itf, positionof(mp->m_block, mp->m_offset), 0) < 0) { perror("fseek"); panic("temporary file seek"); } - return(itf); + return (itf); } /* * Take the data out of the passed ghost file and toss it into * a dynamically allocated message structure. */ - makemessage(f) + FILE *f; { - register struct message *m; - register char *mp; - register count; + register size = (msgCount + 1) * sizeof (struct message); + off_t lseek(); - mp = calloc((unsigned) (msgCount + 1), sizeof *m); - if (mp == NOSTR) { - printf("Insufficient memory for %d messages\n", msgCount); - exit(1); - } - if (message != (struct message *) 0) - cfree((char *) message); - message = (struct message *) mp; + if (message != 0) + free((char *) message); + if ((message = (struct message *) malloc((unsigned) size)) == 0) + panic("Insufficient memory for %d messages", msgCount); dot = message; - lseek(f, 0L, 0); - while (count = read(f, mp, BUFSIZ)) - mp += count; - for (m = &message[0]; m < &message[msgCount]; m++) { - m->m_size = (m+1)->m_size; - m->m_lines = (m+1)->m_lines; - m->m_flag = (m+1)->m_flag; - } - message[msgCount].m_size = 0L; + size -= sizeof (struct message); + fflush(f); + lseek(fileno(f), (long) sizeof *message, 0); + if (read(fileno(f), (char *) message, size) != size) + panic("Message temporary file corrupted"); + message[msgCount].m_size = 0; message[msgCount].m_lines = 0; + fclose(f); } /* * Append the passed message descriptor onto the temp file. * If the write fails, return 1, else 0 */ - append(mp, f) struct message *mp; + FILE *f; { - if (write(f, (char *) mp, sizeof *mp) != sizeof *mp) - return(1); - return(0); + return fwrite((char *) mp, sizeof *mp, 1, f) != 1; } /* * Delete a file, but only if the file is a plain file. */ - remove(name) char name[]; { @@ -234,7 +214,7 @@ remove(name) errno = EISDIR; return(-1); } - return(unlink(name)); + return unlink(name); } /* @@ -248,7 +228,7 @@ edstop() FILE *obuf, *ibuf, *readstat; struct stat statb; char tempname[30], *id; - int (*sigs[3])(); + char *mktemp(); if (readonly) return; @@ -349,67 +329,53 @@ done: static int sigdepth = 0; /* depth of holdsigs() */ static int omask = 0; /* - * Hold signals SIGHUP - SIGQUIT. + * Hold signals SIGHUP, SIGINT, and SIGQUIT. */ holdsigs() { - register int i; if (sigdepth++ == 0) omask = sigblock(sigmask(SIGHUP)|sigmask(SIGINT)|sigmask(SIGQUIT)); } /* - * Release signals SIGHUP - SIGQUIT + * Release signals SIGHUP, SIGINT, and SIGQUIT. */ relsesigs() { - register int i; if (--sigdepth == 0) sigsetmask(omask); } /* - * Open a temp file by creating, closing, unlinking, and - * reopening. Return the open file descriptor. + * Open a temp file by creating and unlinking. + * Return the open file descriptor. */ - opentemp(file) char file[]; { - register int f; + int f; - if ((f = creat(file, 0600)) < 0) { + if ((f = open(file, O_CREAT|O_EXCL|O_RDWR, 0600)) < 0) perror(file); - return(-1); - } - close(f); - if ((f = open(file, 2)) < 0) { - perror(file); - remove(file); - return(-1); - } remove(file); - return(f); + return (f); } /* * Determine the size of the file possessed by * the passed buffer. */ - off_t fsize(iob) FILE *iob; { - register int f; struct stat sbuf; - f = fileno(iob); - if (fstat(f, &sbuf) < 0) - return(0); - return(sbuf.st_size); + if (fstat(fileno(iob), &sbuf) < 0) + return 0; + return sbuf.st_size; } /* @@ -417,17 +383,17 @@ fsize(iob) * in it and expand it by using "sh -c echo filename" * Return the file name as a dynamic string. */ - char * expand(name) char name[]; { char xname[BUFSIZ]; char cmdbuf[BUFSIZ]; - register int pid, l, rc; + register int pid, l; register char *cp, *Shell; - int s, pivec[2], (*sigint)(); + int pivec[2]; struct stat sbuf; + union wait s; if (name[0] == '+' && getfold(cmdbuf) >= 0) { sprintf(xname, "%s/%s", cmdbuf, name + 1); @@ -441,7 +407,6 @@ expand(name) } sprintf(cmdbuf, "echo %s", name); if ((pid = vfork()) == 0) { - sigchild(); Shell = value("SHELL"); if (Shell == NOSTR) Shell = SHELL; @@ -464,8 +429,7 @@ expand(name) close(pivec[0]); while (wait(&s) != pid); ; - s &= 0377; - if (s != 0 && s != SIGPIPE) { + if (s.w_status != 0 && s.w_termsig != SIGPIPE) { fprintf(stderr, "\"Echo\" failed\n"); goto err; } @@ -504,30 +468,27 @@ getfold(name) char *folder; if ((folder = value("folder")) == NOSTR) - return(-1); + return (-1); if (*folder == '/') strcpy(name, folder); else sprintf(name, "%s/%s", homedir, folder); - return(0); + return (0); } /* * A nicer version of Fdopen, which allows us to fclose * without losing the open file. */ - FILE * Fdopen(fildes, mode) char *mode; { - register int f; - FILE *fdopen(); + int f; - f = dup(fildes); - if (f < 0) { + if ((f = dup(fildes)) < 0) { perror("dup"); - return(NULL); + return (NULL); } - return(fdopen(f, mode)); + return fdopen(f, mode); } diff --git a/usr/src/usr.bin/mail/getname.c b/usr/src/usr.bin/mail/getname.c index a873b26264..5bf172914c 100644 --- a/usr/src/usr.bin/mail/getname.c +++ b/usr/src/usr.bin/mail/getname.c @@ -5,7 +5,7 @@ */ #ifndef lint -static char *sccsid = "@(#)getname.c 5.2 (Berkeley) %G%"; +static char *sccsid = "@(#)getname.c 5.3 (Berkeley) %G%"; #endif not lint #include @@ -21,7 +21,6 @@ static char *sccsid = "@(#)getname.c 5.2 (Berkeley) %G%"; /* * Search the passwd file for a uid. Return name through ref parameter * if found, indicating success with 0 return. Return -1 on error. - * If -1 is passed as the user id, close the passwd file. */ getname(uid, namebuf) @@ -29,18 +28,15 @@ getname(uid, namebuf) { struct passwd *pw; - if (uid == -1) { - return(0); - } if ((pw = getpwuid(uid)) == NULL) - return(-1); + return -1; strcpy(namebuf, pw->pw_name); return 0; } /* * Convert the passed name to a user id and return it. Return -1 - * on error. Iff the name passed is -1 (yech) close the pwfile. + * on error. */ getuserid(name) @@ -48,10 +44,7 @@ getuserid(name) { struct passwd *pw; - if (name == (char *) -1) { - return(0); - } if ((pw = getpwnam(name)) == NULL) - return 0; + return -1; return pw->pw_uid; } diff --git a/usr/src/usr.bin/mail/glob.h b/usr/src/usr.bin/mail/glob.h index 32535798be..2cadc52217 100644 --- a/usr/src/usr.bin/mail/glob.h +++ b/usr/src/usr.bin/mail/glob.h @@ -3,7 +3,7 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)glob.h 5.1 (Berkeley) %G% + * @(#)glob.h 5.2 (Berkeley) %G% */ /* @@ -27,7 +27,6 @@ int readonly; /* Will be unable to rewrite file */ int noreset; /* String resets suspended */ int sourcing; /* Currently reading variant file */ int loading; /* Loading user definitions */ -int shudann; /* Print headers when possible */ int cond; /* Current state of conditional exc. */ FILE *itf; /* Input temp file buffer */ FILE *otf; /* Output temp file buffer */ @@ -64,6 +63,8 @@ char **altnames; /* List of alternate names for user */ char **localnames; /* List of aliases for our local host */ int debug; /* Debug flag set */ int rmail; /* Being called as rmail */ +int screenwidth; /* Screen width, or best guess */ +int screenheight; /* Screen height, or best guess */ #include diff --git a/usr/src/usr.bin/mail/head.c b/usr/src/usr.bin/mail/head.c index 80cb5fdb6a..ca78f6e02f 100644 --- a/usr/src/usr.bin/mail/head.c +++ b/usr/src/usr.bin/mail/head.c @@ -5,7 +5,7 @@ */ #ifndef lint -static char *sccsid = "@(#)head.c 5.2 (Berkeley) %G%"; +static char *sccsid = "@(#)head.c 5.3 (Berkeley) %G%"; #endif not lint #include "rcv.h" @@ -21,7 +21,6 @@ static char *sccsid = "@(#)head.c 5.2 (Berkeley) %G%"; * Return true if yes. Note the extreme pains to * accomodate all funny formats. */ - ishead(linebuf) char linebuf[]; { @@ -30,32 +29,34 @@ ishead(linebuf) char parbuf[BUFSIZ]; cp = linebuf; - if (strncmp("From ", cp, 5) != 0) - return(0); - parse(cp, &hl, parbuf); + if (*cp++ != 'F' || *cp++ != 'r' || *cp++ != 'o' || *cp++ != 'm' || + *cp++ != ' ') + return (0); + parse(linebuf, &hl, parbuf); if (hl.l_from == NOSTR || hl.l_date == NOSTR) { fail(linebuf, "No from or date field"); - return(0); + return (0); } if (!isdate(hl.l_date)) { fail(linebuf, "Date field not legal date"); - return(0); + return (0); } - /* * I guess we got it! */ - - return(1); + return (1); } +/*ARGSUSED*/ fail(linebuf, reason) char linebuf[], reason[]; { - if (1 /*value("debug") == NOSTR*/) + /* + if (value("debug") == NOSTR) return; fprintf(stderr, "\"%s\"\nnot a header because %s\n", linebuf, reason); + */ } /* @@ -64,12 +65,11 @@ fail(linebuf, reason) * pointers into the copied line in the passed headline * structure. Actually, it scans. */ - parse(line, hl, pbuf) char line[], pbuf[]; - struct headline *hl; + register struct headline *hl; { - register char *cp, *dp; + register char *cp; char *sp; char word[LINESIZE]; @@ -78,25 +78,19 @@ parse(line, hl, pbuf) hl->l_date = NOSTR; cp = line; sp = pbuf; - /* - * Skip the first "word" of the line, which should be "From" - * anyway. + * Skip over "From" first. */ - cp = nextword(cp, word); - dp = nextword(cp, word); - if (!equal(word, "")) + cp = nextword(cp, word); + if (*word) hl->l_from = copyin(word, &sp); - if (strncmp(dp, "tty", 3) == 0) { - cp = nextword(dp, word); + if (cp != NOSTR && cp[0] == 't' && cp[1] == 't' && cp[2] == 'y') { + cp = nextword(cp, word); hl->l_tty = copyin(word, &sp); - if (cp != NOSTR) - hl->l_date = copyin(cp, &sp); } - else - if (dp != NOSTR) - hl->l_date = copyin(dp, &sp); + if (cp != NOSTR) + hl->l_date = copyin(cp, &sp); } /* @@ -105,22 +99,19 @@ parse(line, hl, pbuf) * Thus, dynamically allocate space in the right string, copying * the left string into it. */ - char * copyin(src, space) - char src[]; + register char *src; char **space; { - register char *cp, *top; - register int s; + register char *cp; + char *top; - s = strlen(src); - cp = *space; - top = cp; - strcpy(cp, src); - cp += s + 1; + top = cp = *space; + while (*cp++ = *src++) + ; *space = cp; - return(top); + return (top); } /* @@ -139,75 +130,62 @@ copyin(src, space) #define N 6 /* A new line */ #define U 7 /* An upper case char */ -char ctypes[] = {U,L,L,S,U,L,L,S,O,D,S,D,D,C,D,D,C,D,D,S,D,D,D,D,0}; -char tmztypes[] = {U,L,L,S,U,L,L,S,O,D,S,D,D,C,D,D,C,D,D,S,U,U,U,S,D,D,D,D,0}; +char ctypes[] = { U,L,L,S,U,L,L,S,O,D,S,D,D,C,D,D,C,D,D,S,D,D,D,D,0 }; +char tmztypes[] = { U,L,L,S,U,L,L,S,O,D,S,D,D,C,D,D,C,D,D,S,U,U,U,S,D,D,D,D,0 }; isdate(date) char date[]; { - register char *cp; - cp = date; - if (cmatch(cp, ctypes)) - return(1); - return(cmatch(cp, tmztypes)); + if (cmatch(date, ctypes)) + return (1); + return (cmatch(date, tmztypes)); } /* - * Match the given string against the given template. + * Match the given string (cp) against the given template (tp). * Return 1 if they match, 0 if they don't */ -cmatch(str, temp) - char str[], temp[]; -{ +cmatch(cp, tp) register char *cp, *tp; - register int c; +{ - cp = str; - tp = temp; - while (*cp != '\0' && *tp != 0) { - c = *cp++; + while (*cp && *tp) switch (*tp++) { case L: - if (c < 'a' || c > 'z') - return(0); + if (!islower(*cp++)) + return 0; break; - case U: - if (c < 'A' || c > 'Z') - return(0); + if (!isupper(*cp++)) + return 0; break; - case S: - if (c != ' ') - return(0); + if (*cp++ != ' ') + return 0; break; - case D: - if (!isdigit(c)) - return(0); + if (!isdigit(*cp++)) + return 0; break; - case O: - if (c != ' ' && !isdigit(c)) - return(0); + if (*cp != ' ' && !isdigit(*cp)) + return 0; + cp++; break; - case C: - if (c != ':') - return(0); + if (*cp++ != ':') + return 0; break; - case N: - if (c != '\n') - return(0); + if (*cp++ != '\n') + return 0; break; } - } - if (*cp != '\0' || *tp != 0) - return(0); - return(1); + if (*cp || *tp) + return 0; + return (1); } /* @@ -215,100 +193,45 @@ cmatch(str, temp) * passed. Also, return a pointer to the next word following that, * or NOSTR if none follow. */ - char * nextword(wp, wbuf) - char wp[], wbuf[]; + register char *wp, *wbuf; { - register char *cp, *cp2; + register c; - if ((cp = wp) == NOSTR) { - copy("", wbuf); - return(NOSTR); + if (wp == NOSTR) { + *wbuf = 0; + return (NOSTR); } - cp2 = wbuf; - while (!any(*cp, " \t") && *cp != '\0') - if (*cp == '"') { - *cp2++ = *cp++; - while (*cp != '\0' && *cp != '"') - *cp2++ = *cp++; - if (*cp == '"') - *cp2++ = *cp++; - } else - *cp2++ = *cp++; - *cp2 = '\0'; - while (any(*cp, " \t")) - cp++; - if (*cp == '\0') - return(NOSTR); - return(cp); -} - -/* - * Test to see if the character is an ascii alphabetic. - */ - -isalpha(c) -{ - register int ch; - - ch = raise(c); - return(ch >= 'A' && ch <= 'Z'); -} - -/* - * Test to see if the character is an ascii digit. - */ - -isdigit(c) -{ - return(c >= '0' && c <= '9'); -} - -/* - * Copy str1 to str2, return pointer to null in str2. - */ - -char * -copy(str1, str2) - char *str1, *str2; -{ - register char *s1, *s2; - - s1 = str1; - s2 = str2; - while (*s1) - *s2++ = *s1++; - *s2 = 0; - return(s2); + while ((c = *wp++) && c != ' ' && c != '\t') { + *wbuf++ = c; + if (c == '"') { + while ((c = *wp++) && c != '"') + *wbuf++ = c; + if (c == '"') + *wbuf++ = c; + else + wp--; + } + } + *wbuf = '\0'; + for (; c == ' ' || c == '\t'; c = *wp++) + ; + if (c == 0) + return (NOSTR); + return (wp - 1); } /* - * Is ch any of the characters in str? + * Is c contained in s? */ - -any(ch, str) - char *str; -{ - register char *f; +any(c, s) register c; - - f = str; - c = ch; - while (*f) - if (c == *f++) - return(1); - return(0); -} - -/* - * Convert lower case letters to upper case. - */ - -raise(c) - register int c; + register char *s; { - if (c >= 'a' && c <= 'z') - c += 'A' - 'a'; - return(c); + + while (*s) + if (*s++ == c) + return 1; + return 0; } diff --git a/usr/src/usr.bin/mail/lex.c b/usr/src/usr.bin/mail/lex.c index ec8d536220..a24a64af21 100644 --- a/usr/src/usr.bin/mail/lex.c +++ b/usr/src/usr.bin/mail/lex.c @@ -5,7 +5,7 @@ */ #ifndef lint -static char *sccsid = "@(#)lex.c 5.4 (Berkeley) %G%"; +static char *sccsid = "@(#)lex.c 5.5 (Berkeley) %G%"; #endif not lint #include "rcv.h" @@ -125,6 +125,7 @@ setfile(name, isedit) */ int *msgvec; +jmp_buf commjmp; commands() { @@ -133,14 +134,12 @@ commands() char linebuf[LINESIZE]; int hangup(), contin(); -# ifdef VMUNIX - sigset(SIGCONT, SIG_DFL); -# endif VMUNIX + signal(SIGCONT, SIG_DFL); if (rcvmode && !sourcing) { - if (sigset(SIGINT, SIG_IGN) != SIG_IGN) - sigset(SIGINT, stop); - if (sigset(SIGHUP, SIG_IGN) != SIG_IGN) - sigset(SIGHUP, hangup); + if (signal(SIGINT, SIG_IGN) != SIG_IGN) + signal(SIGINT, stop); + if (signal(SIGHUP, SIG_IGN) != SIG_IGN) + signal(SIGHUP, hangup); } shudprompt = intty && !sourcing; for (;;) { @@ -156,13 +155,11 @@ commands() eofloop = 0; top: if (shudprompt) { + setjmp(commjmp); + signal(SIGCONT, contin); printf(prompt); - fflush(stdout); -# ifdef VMUNIX - sigset(SIGCONT, contin); -# endif VMUNIX - } else - fflush(stdout); + } + fflush(stdout); sreset(); /* @@ -172,7 +169,7 @@ top: n = 0; for (;;) { - if (readline(input, &linebuf[n]) <= 0) { + if (readline(input, &linebuf[n]) < 0) { if (n != 0) break; if (loading) @@ -198,9 +195,7 @@ top: break; linebuf[n++] = ' '; } -# ifdef VMUNIX - sigset(SIGCONT, SIG_DFL); -# endif VMUNIX + signal(SIGCONT, SIG_DFL); if (execute(linebuf, 0)) return; more: ; @@ -234,9 +229,8 @@ execute(linebuf, contxt) * lexical conventions. */ - cp = linebuf; - while (any(*cp, " \t")) - cp++; + for (cp = linebuf; isspace(*cp); cp++) + ; if (*cp == '!') { if (sourcing) { printf("Can't \"!\" while sourcing\n"); @@ -259,7 +253,7 @@ execute(linebuf, contxt) * confusion. */ - if (sourcing && equal(word, "")) + if (sourcing && *word == '\0') return(0); com = lex(word); if (com == NONE) { @@ -293,7 +287,7 @@ execute(linebuf, contxt) return(0); } if (!edit && com->c_func == edstop) { - sigset(SIGINT, SIG_IGN); + signal(SIGINT, SIG_IGN); return(1); } @@ -378,7 +372,7 @@ execute(linebuf, contxt) * Just the straight string, with * leading blanks removed. */ - while (any(*cp, " \t")) + while (isspace(*cp)) cp++; e = (*com->c_func)(cp); break; @@ -440,17 +434,18 @@ execute(linebuf, contxt) /* * When we wake up after ^Z, reprint the prompt. */ +/*ARGSUSED*/ contin(s) { - printf(prompt); - fflush(stdout); + longjmp(commjmp, 1); } /* * Branch here on hangup signal and simulate quit. */ -hangup() +/*ARGSUSED*/ +hangup(s) { holdsigs(); @@ -472,8 +467,8 @@ hangup() setmsize(sz) { - if (msgvec != (int *) 0) - cfree(msgvec); + if (msgvec != 0) + cfree((char *) msgvec); msgvec = (int *) calloc((unsigned) (sz + 1), sizeof *msgvec); } @@ -514,12 +509,10 @@ isprefix(as1, as2) } /* - * The following gets called on receipt of a rubout. This is + * The following gets called on receipt of an interrupt. This is * to abort printout of a command, mainly. * Dispatching here when command() is inactive crashes rcv. * Close all open files except 0, 1, 2, and the temporary. - * The special call to getuserid() is needed so it won't get - * annoyed about losing its open file. * Also, unstack all source files. */ @@ -553,20 +546,16 @@ xclose(iop) } } +/*ARGSUSED*/ stop(s) { - register FILE *fp; -# ifndef VMUNIX - s = SIGINT; -# endif VMUNIX noreset = 0; if (!inithdr) sawcom++; inithdr = 0; while (sourcing) unstack(); - getuserid((char *) -1); /* * Walk through all the open FILEs, applying xclose() to them @@ -578,9 +567,6 @@ stop(s) image = -1; } fprintf(stderr, "Interrupt\n"); -# ifndef VMUNIX - signal(s, stop); -# endif reset(0); } @@ -668,14 +654,14 @@ newfileinfo() return(mdot); } -strace() {} - /* * Print the current version number. */ +/*ARGSUSED*/ pversion(e) { + printf("Version %s\n", version); return(0); } diff --git a/usr/src/usr.bin/mail/list.c b/usr/src/usr.bin/mail/list.c index 21fb5d7f34..71c07cbf84 100644 --- a/usr/src/usr.bin/mail/list.c +++ b/usr/src/usr.bin/mail/list.c @@ -5,7 +5,7 @@ */ #ifndef lint -static char *sccsid = "@(#)list.c 5.4 (Berkeley) %G%"; +static char *sccsid = "@(#)list.c 5.5 (Berkeley) %G%"; #endif not lint #include "rcv.h" @@ -414,7 +414,7 @@ scan(sp) int quotec; if (regretp >= 0) { - copy(stringstack[regretp], lexstring); + strcpy(lexstring, stringstack[regretp]); lexnumber = numberstack[regretp]; return(regretstack[regretp--]); } diff --git a/usr/src/usr.bin/mail/local.h b/usr/src/usr.bin/mail/local.h index 6719ee7a47..ebaaddc8e5 100644 --- a/usr/src/usr.bin/mail/local.h +++ b/usr/src/usr.bin/mail/local.h @@ -3,29 +3,7 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)local.h 5.1 (Berkeley) %G% + * @(#)local.h 5.2 (Berkeley) %G% */ -#ifdef V7 #include "v7.local.h" -#endif - -#ifdef CORY -#include "c.local.h" -#endif - -#ifdef INGRES -#include "ing.local.h" -#endif - -#ifdef V6 -#include "v6.local.h" -#endif - -#ifdef CC -#include "cc.local.h" -#endif - -#ifdef V40 -#include "40.local.h" -#endif diff --git a/usr/src/usr.bin/mail/main.c b/usr/src/usr.bin/mail/main.c index 218e3491d2..73bce5c37d 100644 --- a/usr/src/usr.bin/mail/main.c +++ b/usr/src/usr.bin/mail/main.c @@ -11,7 +11,7 @@ char *copyright = #endif not lint #ifndef lint -static char *sccsid = "@(#)main.c 5.3 (Berkeley) %G%"; +static char *sccsid = "@(#)main.c 5.4 (Berkeley) %G%"; #endif not lint #include "rcv.h" @@ -41,23 +41,15 @@ main(argc, argv) { register char *ef; register int i, argp; - int mustsend, uflag, hdrstop(), (*prevint)(), f; - FILE *ibuf, *ftat; + int mustsend, hdrstop(), (*prevint)(), f; struct sgttyb tbuf; -#ifdef signal - Siginit(); -#endif - /* - * Set up a reasonable environment. We clobber the last - * element of argument list for compatibility with version 6, - * figure out whether we are being run interactively, set up + * Set up a reasonable environment. + * Figure out whether we are being run interactively, set up * all the temporary files, buffer standard output, and so forth. */ - uflag = 0; - argv[argc] = (char *) -1; #ifdef GETHOST inithost(); #endif GETHOST @@ -67,8 +59,7 @@ main(argc, argv) if (outtty) { gtty(1, &tbuf); baud = tbuf.sg_ospeed; - } - else + } else baud = B9600; image = -1; @@ -134,7 +125,6 @@ main(argc, argv) /* * Next argument is person to pretend to be. */ - uflag++; if (i >= argc - 1) { fprintf(stderr, "Missing user name for -u\n"); exit(1); @@ -250,6 +240,7 @@ main(argc, argv) exit(1); } tinit(); + setscreensize(); input = stdin; rcvmode = argp == -1; if (!nosrc) @@ -277,7 +268,7 @@ main(argc, argv) edit++; ename = expand(ef); if (ename != ef) { - ef = (char *) calloc(1, strlen(ename) + 1); + ef = malloc((unsigned) strlen(ename) + 1); strcpy(ef, ename); } editfile = ef; @@ -292,11 +283,11 @@ main(argc, argv) } if (!noheader && value("noheader") == NOSTR) { if (setjmp(hdrjmp) == 0) { - if ((prevint = sigset(SIGINT, SIG_IGN)) != SIG_IGN) - sigset(SIGINT, hdrstop); + if ((prevint = signal(SIGINT, SIG_IGN)) != SIG_IGN) + signal(SIGINT, hdrstop); announce(!0); fflush(stdout); - sigset(SIGINT, prevint); + signal(SIGINT, prevint); } } if (!edit && msgCount == 0) { @@ -306,9 +297,9 @@ main(argc, argv) } commands(); if (!edit) { - sigset(SIGHUP, SIG_IGN); - sigset(SIGINT, SIG_IGN); - sigset(SIGQUIT, SIG_IGN); + signal(SIGHUP, SIG_IGN); + signal(SIGINT, SIG_IGN); + signal(SIGQUIT, SIG_IGN); quit(); } exit(0); @@ -324,3 +315,37 @@ hdrstop() fprintf(stderr, "\nInterrupt\n"); longjmp(hdrjmp, 1); } + +/* + * Compute what the screen size should be. + * We use the following algorithm for the height: + * If baud rate < 1200, use 9 + * If baud rate = 1200, use 14 + * If baud rate > 1200, use 24 or ws_row + * Width is either 80 or ws_col; + */ +setscreensize() +{ +#ifdef TIOCGWINSZ + struct winsize ws; + + if (ioctl(fileno(stdout), TIOCGWINSZ, (char *) &ws) < 0) + ws.ws_col = ws.ws_row = 0; +#endif + if (baud < B1200) + screenheight = 9; + else if (baud == B1200) + screenheight = 14; +#ifdef TIOCGWINSZ + else if (ws.ws_row != 0) + screenheight = ws.ws_row; +#endif + else + screenheight = 24; +#ifdef TIOCGWINSZ + if (ws.ws_col != 0) + screenwidth = ws.ws_col; + else +#endif + screenwidth = 80; +} diff --git a/usr/src/usr.bin/mail/names.c b/usr/src/usr.bin/mail/names.c index 9613701934..7631f4a458 100644 --- a/usr/src/usr.bin/mail/names.c +++ b/usr/src/usr.bin/mail/names.c @@ -5,7 +5,7 @@ */ #ifndef lint -static char *sccsid = "@(#)names.c 5.3 (Berkeley) %G%"; +static char *sccsid = "@(#)names.c 5.4 (Berkeley) %G%"; #endif not lint /* @@ -15,6 +15,7 @@ static char *sccsid = "@(#)names.c 5.3 (Berkeley) %G%"; */ #include "rcv.h" +#include /* * Allocate a single element of a name list, @@ -194,12 +195,13 @@ struct name * verify(names) struct name *names; { - register struct name *np, *top, *t, *x; - register char *cp; - #ifdef SENDMAIL + return(names); #else + register struct name *np, *top, *t, *x; + register char *cp; + top = names; np = names; while (np != NIL) { @@ -258,12 +260,16 @@ outof(names, fo, hp) struct header *hp; { register int c; - register struct name *np, *top, *t, *x; - long now; + register struct name *np, *top; +#ifdef CRAZYWOW + register struct name *t, *x; +#endif + time_t now, time(); char *date, *fname, *shell, *ctime(); FILE *fout, *fin; - int ispipe, s, pid; + int ispipe; extern char tempEdit[]; + union wait s; top = names; np = names; @@ -321,12 +327,11 @@ outof(names, fo, hp) if (ispipe) { wait(&s); - switch (pid = fork()) { + switch (fork()) { case 0: - sigchild(); - sigsys(SIGHUP, SIG_IGN); - sigsys(SIGINT, SIG_IGN); - sigsys(SIGQUIT, SIG_IGN); + signal(SIGHUP, SIG_IGN); + signal(SIGINT, SIG_IGN); + signal(SIGQUIT, SIG_IGN); close(0); dup(image); close(image); @@ -437,13 +442,11 @@ usermap(names) struct name *names; { register struct name *new, *np, *cp; - struct name *getto; struct grouphead *gh; register int metoo; new = NIL; np = names; - getto = NIL; metoo = (value("metoo") != NOSTR); while (np != NIL) { if (np->n_name[0] == '\\') { @@ -790,16 +793,6 @@ count(np) return(c); } -cmpdomain(name, dname) - register char *name, *dname; -{ - char buf[BUFSIZ]; - - strcpy(buf, dname); - buf[strlen(name)] = '\0'; - return(icequal(name, buf)); -} - /* * Delete the given name from a namelist, using the passed * function to compare the names. @@ -851,6 +844,7 @@ mapf(np, from) * Uncomment it if you need it. */ +/* prettyprint(name) struct name *name; { @@ -863,3 +857,4 @@ prettyprint(name) } fprintf(stderr, "\n"); } +*/ diff --git a/usr/src/usr.bin/mail/optim.c b/usr/src/usr.bin/mail/optim.c index 2ec41a4056..8fc9d96c0f 100644 --- a/usr/src/usr.bin/mail/optim.c +++ b/usr/src/usr.bin/mail/optim.c @@ -5,7 +5,7 @@ */ #ifndef lint -static char *sccsid = "@(#)optim.c 5.6 (Berkeley) %G%"; +static char *sccsid = "@(#)optim.c 5.7 (Berkeley) %G%"; #endif not lint /* @@ -16,8 +16,6 @@ static char *sccsid = "@(#)optim.c 5.6 (Berkeley) %G%"; #include "rcv.h" #include "configdefs.h" -#include -#include /* * Map a name into the correct network "view" of the @@ -55,43 +53,6 @@ netmap(name, from) return(name); } -/* - * Rename the given network path to use - * the kinds of names that we would right here. - */ - -char * -rename(str) - char str[]; -{ - register char *cp, *cp2; - char buf[BUFSIZ], path[BUFSIZ]; - register int c, host; - - cp = str; - strcpy(path, ""); - for (;;) { - if ((c = *cp++) == 0) - break; - cp2 = buf; - while (!any(c, metanet) && c != 0) { - *cp2++ = c; - c = *cp++; - } - *cp2 = 0; - if (c == 0) { - strcat(path, buf); - break; - } - host = netlook(buf, ntype(c)); - strcat(path, netname(host)); - stradd(path, c); - } - if (strcmp(str, path) != 0) - return(savestr(path)); - return(str); -} - /* * Turn a network machine name into a unique character */ @@ -191,7 +152,7 @@ arpafix(name, from) if (cp == NOSTR) cp = rindex(name, '%'); if (cp == NOSTR) { - fprintf(stderr, "Somethings amiss -- no @ or % in arpafix\n"); + fprintf(stderr, "Somethings amiss -- no @ or %% in arpafix\n"); return(name); } cp++; @@ -270,7 +231,6 @@ short midfree; /* Next free machine id */ minit() { register struct xtrahash *xp, **tp; - register int i; midfree = 0; tp = &xtab[0]; @@ -470,7 +430,7 @@ err: printf("Made up bad net name\n"); printf("Machine code %c (0%o)\n", cp[-1], cp[-1]); printf("Sorry -- dumping now. Alert K. Shoens\n"); - core(0); + core(); goto err; } strcat(name, cp2); @@ -872,17 +832,3 @@ yylex() yylval = dot; return(WORD); } - -/* - * Add a single character onto a string. - */ - -stradd(str, c) - register char *str; - register int c; -{ - - str += strlen(str); - *str++ = c; - *str = 0; -} diff --git a/usr/src/usr.bin/mail/pathnames.h b/usr/src/usr.bin/mail/pathnames.h index 1e5d86ecdd..ed6ed6e7f9 100644 --- a/usr/src/usr.bin/mail/pathnames.h +++ b/usr/src/usr.bin/mail/pathnames.h @@ -3,7 +3,7 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)pathnames.h 5.2 (Berkeley) %G% + * @(#)pathnames.h 5.3 (Berkeley) %G% */ /* @@ -32,12 +32,7 @@ #define POSTAGE "/usr/adm/maillog" /* Where to audit mail sending */ /* Name of casual tilde help */ -#define UIDMASK 0177777 /* Significant uid bits */ #define MASTER "/usr/lib/Mail.rc" #define APPEND /* New mail goes to end of mailbox */ #define CANLOCK /* Locking protocol actually works */ #define UTIME /* System implements utime(2) */ - -#ifndef VMUNIX -#include "sigretro.h" /* Retrofit signal defs */ -#endif VMUNIX diff --git a/usr/src/usr.bin/mail/popen.c b/usr/src/usr.bin/mail/popen.c index 966f6f618f..4e1af06fa6 100644 --- a/usr/src/usr.bin/mail/popen.c +++ b/usr/src/usr.bin/mail/popen.c @@ -5,24 +5,20 @@ */ #ifndef lint -static char *sccsid = "@(#)popen.c 5.2 (Berkeley) %G%"; +static char *sccsid = "@(#)popen.c 5.3 (Berkeley) %G%"; #endif not lint #include -#include +#include +#include +#include #include + #define tst(a,b) (*mode == 'r'? (b) : (a)) #define RDR 0 #define WTR 1 static int popen_pid[20]; -#ifndef VMUNIX -#define vfork fork -#endif VMUNIX -#ifndef SIGRETRO -#define sigchild() -#endif - FILE * popen(cmd,mode) char *cmd; @@ -37,7 +33,6 @@ char *mode; hisside = tst(p[RDR], p[WTR]); if((pid = vfork()) == 0) { /* myside and hisside reverse roles in child */ - sigchild(); close(myside); dup2(hisside, tst(0, 1)); close(hisside); @@ -55,20 +50,17 @@ pclose(ptr) FILE *ptr; { register f, r; - int status, omask; + int omask; + union wait status; extern int errno; f = fileno(ptr); fclose(ptr); -# ifdef VMUNIX omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP)); -# endif VMUNIX while((r = wait(&status)) != popen_pid[f] && r != -1 && errno != EINTR) ; if(r == -1) - status = -1; -# ifdef VMUNIX + status.w_status = -1; sigsetmask(omask); -# endif VMUNIX - return(status); + return (status.w_status); } diff --git a/usr/src/usr.bin/mail/rcv.h b/usr/src/usr.bin/mail/rcv.h index 4ca8d65de1..d581f9a7e5 100644 --- a/usr/src/usr.bin/mail/rcv.h +++ b/usr/src/usr.bin/mail/rcv.h @@ -3,7 +3,7 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)rcv.h 5.1 (Berkeley) %G% + * @(#)rcv.h 5.2 (Berkeley) %G% */ /* @@ -13,8 +13,5 @@ * globals and declarations. */ -#ifdef pdp11 -#include -#endif #include "def.h" #include "glob.h" diff --git a/usr/src/usr.bin/mail/send.c b/usr/src/usr.bin/mail/send.c index 69fb34573e..22a4d999f5 100644 --- a/usr/src/usr.bin/mail/send.c +++ b/usr/src/usr.bin/mail/send.c @@ -5,14 +5,11 @@ */ #ifndef lint -static char *sccsid = "@(#)send.c 5.2 (Berkeley) %G%"; +static char *sccsid = "@(#)send.c 5.3 (Berkeley) %G%"; #endif not lint #include "rcv.h" -#ifdef VMUNIX #include -#endif -#include #include /* @@ -27,154 +24,153 @@ static char *sccsid = "@(#)send.c 5.2 (Berkeley) %G%"; * the number of lines written. Adjust the status: field * if need be. If doign is set, suppress ignored header fields. */ -send(mailp, obuf, doign) - struct message *mailp; +send(mp, obuf, doign) + register struct message *mp; FILE *obuf; { - register struct message *mp; - register int t; - long c; - FILE *ibuf; - char line[LINESIZE], field[BUFSIZ]; - int lc, ishead, infld, fline, dostat; - char *cp, *cp2; - - mp = mailp; + long count; + register FILE *ibuf; + char line[LINESIZE]; + int lc, ishead, infld, ignoring, dostat; + register char *cp, *cp2; + register int c; + int length; + ibuf = setinput(mp); - c = mp->m_size; + count = mp->m_size; ishead = 1; - dostat = 1; + dostat = !doign || !isign("status"); infld = 0; - fline = 1; lc = 0; - while (c > 0L) { - fgets(line, LINESIZE, ibuf); - c -= (long) strlen(line); - lc++; - if (ishead) { + /* + * Process headers first + */ + while (count > 0 && ishead) { + if (fgets(line, LINESIZE, ibuf) == NULL) + break; + count -= length = strlen(line); + if (lc == 0) { /* * First line is the From line, so no headers * there to worry about */ - if (fline) { - fline = 0; - goto writeit; - } + ignoring = 0; + } else if (line[0] == '\n') { /* * If line is blank, we've reached end of * headers, so force out status: field * and note that we are no longer in header * fields */ - if (line[0] == '\n') { - if (dostat) { - statusput(mailp, obuf, doign); - dostat = 0; - } - ishead = 0; - goto writeit; + if (dostat) { + statusput(mp, obuf); + dostat = 0; } + ishead = 0; + ignoring = 0; + } else if (infld && (line[0] == ' ' || line[0] == '\t')) { /* * If this line is a continuation (via space or tab) * of a previous header field, just echo it * (unless the field should be ignored). + * In other words, nothing to do. */ - if (infld && (isspace(line[0]) || line[0] == '\t')) { - if (doign && isign(field)) continue; - goto writeit; - } - infld = 0; + } else { /* - * If we are no longer looking at real - * header lines, force out status: - * This happens in uucp style mail where - * there are no headers at all. + * Pick up the header field if we have one. */ - if (!headerp(line)) { + for (cp = line; (c = *cp++) && c != ':' && !isspace(c);) + ; + cp2 = --cp; + while (isspace(*cp++)) + ; + if (cp[-1] != ':') { + /* + * Not a header line, force out status: + * This happens in uucp style mail where + * there are no headers at all. + */ if (dostat) { - statusput(mailp, obuf, doign); + statusput(mp, obuf); dostat = 0; } - putc('\n', obuf); + putc('\n', obuf); /* add blank line */ + lc++; ishead = 0; - goto writeit; - } - infld++; - /* - * Pick up the header field. - * If it is an ignored field and - * we care about such things, skip it. - */ - cp = line; - cp2 = field; - while (*cp && *cp != ':' && !isspace(*cp)) - *cp2++ = *cp++; - *cp2 = 0; - if (doign && isign(field)) - continue; - /* - * If the field is "status," go compute and print the - * real Status: field - */ - if (icequal(field, "status")) { - if (dostat) { - statusput(mailp, obuf, doign); - dostat = 0; + ignoring = 0; + } else { + /* + * If it is an ignored field and + * we care about such things, skip it. + */ + *cp2 = 0; /* temporarily null terminate */ + if (doign && isign(line)) + ignoring = 1; + else if ((line[0] == 's' || line[0] == 'S') && + icequal(line, "status")) { + /* + * If the field is "status," go compute + * and print the real Status: field + */ + if (dostat) { + statusput(mp, obuf); + dostat = 0; + } + ignoring = 1; + } else { + ignoring = 0; + *cp2 = c; /* restore */ } - continue; + infld = 1; } } -writeit: - fputs(line, obuf); - if (ferror(obuf)) - return(-1); + if (!ignoring) { + fwrite(line, sizeof *line, length, obuf); + if (ferror(obuf)) + return -1; + lc++; + } } - if (ferror(obuf)) - return(-1); - if (ishead && (mailp->m_flag & MSTATUS)) + /* + * Copy out message body + */ + while (count > 0) { + cp = line; + c = count < LINESIZE ? count : LINESIZE; + if ((c = fread(cp, sizeof *cp, c, ibuf)) <= 0) + break; + if (fwrite(cp, sizeof *cp, c, obuf) != c) + return -1; + count -= c; + while (--c >= 0) + if (*cp++ == '\n') + lc++; + } + if (ishead && (mp->m_flag & MSTATUS)) printf("failed to fix up status field\n"); - return(lc); -} - -/* - * Test if the passed line is a header line, RFC 733 style. - */ -headerp(line) - register char *line; -{ - register char *cp = line; - - while (*cp && !isspace(*cp) && *cp != ':') - cp++; - while (*cp && isspace(*cp)) - cp++; - return(*cp == ':'); + return (lc); } /* * Output a reasonable looking status field. * But if "status" is ignored and doign, forget it. */ -statusput(mp, obuf, doign) +statusput(mp, obuf) register struct message *mp; - register FILE *obuf; + FILE *obuf; { char statout[3]; + register char *cp = statout; - if (doign && isign("status")) - return; - if ((mp->m_flag & (MNEW|MREAD)) == MNEW) - return; if (mp->m_flag & MREAD) - strcpy(statout, "R"); - else - strcpy(statout, ""); + *cp++ = 'R'; if ((mp->m_flag & MNEW) == 0) - strcat(statout, "O"); - fprintf(obuf, "Status: %s\n", statout); + *cp++ = 'O'; + *cp = 0; + if (statout[0]) + fprintf(obuf, "Status: %s\n", statout); } - /* * Interface between the argument list and the mail1 routine * which does all the dirty work. @@ -188,11 +184,11 @@ mail(people) char *buf, **ap; struct header head; - for (s = 0, ap = people; *ap != (char *) -1; ap++) + for (s = 0, ap = people; *ap != 0; ap++) s += strlen(*ap) + 1; buf = salloc(s+1); cp2 = buf; - for (ap = people; *ap != (char *) -1; ap++) { + for (ap = people; *ap != 0; ap++) { cp2 = copy(*ap, cp2); *cp2++ = ' '; } @@ -217,9 +213,6 @@ mail(people) sendmail(str) char *str; { - register char **ap; - char *bufp; - register int t; struct header head; if (blankline(str)) @@ -243,7 +236,8 @@ mail1(hp) struct header *hp; { register char *cp; - int pid, i, s, p, gotcha; + int pid, i, p, gotcha; + union wait s; char **namelist, *deliver; struct name *to, *np; struct stat sbuf; @@ -330,10 +324,10 @@ topdog: printf(" \"%s\"", *t); printf("\n"); fflush(stdout); - return; + return 0; } if ((cp = value("record")) != NOSTR) - savemail(expand(cp), hp, mtf); + savemail(expand(cp), mtf); /* * Wait, to absorb a potential zombie, then @@ -343,17 +337,8 @@ topdog: * wants to await the completion of mail. */ -#ifdef VMUNIX -#ifdef pdp11 - while (wait2(&s, WNOHANG) > 0) -#endif -#if defined(vax) || defined(sun) - while (wait3(&s, WNOHANG, 0) > 0) -#endif + while (wait3(&s, WNOHANG, (struct timeval *) 0) > 0) ; -#else - wait(&s); -#endif rewind(mtf); pid = fork(); if (pid == -1) { @@ -363,32 +348,26 @@ topdog: goto out; } if (pid == 0) { - sigchild(); #ifdef SIGTSTP if (remote == 0) { - sigset(SIGTSTP, SIG_IGN); - sigset(SIGTTIN, SIG_IGN); - sigset(SIGTTOU, SIG_IGN); + signal(SIGTSTP, SIG_IGN); + signal(SIGTTIN, SIG_IGN); + signal(SIGTTOU, SIG_IGN); } #endif - for (i = SIGHUP; i <= SIGQUIT; i++) - sigset(i, SIG_IGN); + signal(SIGHUP, SIG_IGN); + signal(SIGINT, SIG_IGN); + signal(SIGQUIT, SIG_IGN); if (!stat(POSTAGE, &sbuf)) if ((postage = fopen(POSTAGE, "a")) != NULL) { fprintf(postage, "%s %d %d\n", myname, count(to), fsize(mtf)); fclose(postage); } - s = fileno(mtf); - for (i = 3; i < 15; i++) - if (i != s) - close(i); close(0); - dup(s); - close(s); -#ifdef CC - submit(getpid()); -#endif CC + dup(fileno(mtf)); + for (i = getdtablesize(); --i > 2;) + close(i); #ifdef SENDMAIL if ((deliver = value("sendmail")) == NOSTR) deliver = SENDMAIL; @@ -403,7 +382,7 @@ out: if (remote || (value("verbose") != NOSTR)) { while ((p = wait(&s)) != pid && p != -1) ; - if (s != 0) + if (s.w_status != 0) senderr++; pid = 0; } @@ -422,7 +401,6 @@ fixhead(hp, tolist) struct header *hp; struct name *tolist; { - register struct name *nlist; register int f; register struct name *np; @@ -529,7 +507,7 @@ fmt(str, txt, fo) bl = 0; while (*bg) { pt++; - if (++col >72) { + if (++col > 72) { if (!bl) { bl = bg; while (*bl && !isspace(*bl)) @@ -559,32 +537,33 @@ finish: * Save the outgoing mail on the passed file. */ -savemail(name, hp, fi) +/*ARGSUSED*/ +savemail(name, fi) char name[]; - struct header *hp; - FILE *fi; + register FILE *fi; { register FILE *fo; - register int c; - long now; + char buf[BUFSIZ]; + register i; + time_t now, time(); char *n; + char *ctime(); if ((fo = fopen(name, "a")) == NULL) { perror(name); - return(-1); + return (-1); } time(&now); - n = rflag; - if (n == NOSTR) + if ((n = rflag) == NOSTR) n = myname; fprintf(fo, "From %s %s", n, ctime(&now)); rewind(fi); - for (c = getc(fi); c != EOF; c = getc(fi)) - putc(c, fo); - fprintf(fo, "\n"); + while ((i = fread(buf, 1, sizeof buf, fi)) > 0) + fwrite(buf, 1, i, fo); + putc('\n', fo); fflush(fo); if (ferror(fo)) perror(name); fclose(fo); - return(0); + return (0); } diff --git a/usr/src/usr.bin/mail/strings.c b/usr/src/usr.bin/mail/strings.c index c5b1e3d12c..48ba627855 100644 --- a/usr/src/usr.bin/mail/strings.c +++ b/usr/src/usr.bin/mail/strings.c @@ -5,7 +5,7 @@ */ #ifndef lint -static char *sccsid = "@(#)strings.c 5.3 (Berkeley) %G%"; +static char *sccsid = "@(#)strings.c 5.4 (Berkeley) %G%"; #endif not lint /* diff --git a/usr/src/usr.bin/mail/temp.c b/usr/src/usr.bin/mail/temp.c index 4f9d688b02..a18e7ad4f4 100644 --- a/usr/src/usr.bin/mail/temp.c +++ b/usr/src/usr.bin/mail/temp.c @@ -5,7 +5,7 @@ */ #ifndef lint -static char *sccsid = "@(#)temp.c 5.2 (Berkeley) %G%"; +static char *sccsid = "@(#)temp.c 5.3 (Berkeley) %G%"; #endif not lint #include "rcv.h" @@ -25,10 +25,10 @@ char tempMesg[14]; tinit() { - register char *cp, *cp2; + register char *cp; char uname[PATHSIZE]; - register int err = 0; register int pid; + uid_t getuid(); pid = getpid(); sprintf(tempMail, "/tmp/Rs%05d", pid); @@ -47,29 +47,23 @@ tinit() } } else { - uid = getuid() & UIDMASK; + uid = getuid(); if (username(uid, uname) < 0) { - copy("ubluit", myname); - err++; + strcpy(myname, "ubluit"); if (rcvmode) { printf("Who are you!?\n"); exit(1); } - } - else - copy(uname, myname); + } else + strcpy(myname, uname); } - cp = value("HOME"); - if (cp == NOSTR) + if ((cp = value("HOME")) == NOSTR) cp = "."; - copy(cp, homedir); + strcpy(homedir, cp); findmail(); - cp = copy(homedir, mbox); - copy("/mbox", cp); - cp = copy(homedir, mailrc); - copy("/.mailrc", cp); - cp = copy(homedir, deadletter); - copy("/dead.letter", cp); + strcpy(copy(homedir, mbox), "/mbox"); + strcpy(copy(homedir, mailrc), "/.mailrc"); + strcpy(copy(homedir, deadletter), "/dead.letter"); if (debug) { printf("uid = %d, user = %s, mailname = %s\n", uid, myname, mailname); diff --git a/usr/src/usr.bin/mail/tty.c b/usr/src/usr.bin/mail/tty.c index be56f7466f..94dd81d007 100644 --- a/usr/src/usr.bin/mail/tty.c +++ b/usr/src/usr.bin/mail/tty.c @@ -5,7 +5,7 @@ */ #ifndef lint -static char *sccsid = "@(#)tty.c 5.2 (Berkeley) %G%"; +static char *sccsid = "@(#)tty.c 5.3 (Berkeley) %G%"; #endif not lint /* @@ -32,17 +32,14 @@ grabh(hp, gflags) struct header *hp; { struct sgttyb ttybuf; - int ttycont(), signull(); + int ttycont(); #ifndef TIOCSTI - int (*savesigs[2])(); + int (*saveint)(), (*savequit)(); #endif int (*savecont)(); - register int s; int errs; -# ifdef VMUNIX - savecont = sigset(SIGCONT, signull); -# endif VMUNIX + savecont = signal(SIGCONT, SIG_DFL); errs = 0; #ifndef TIOCSTI ttyset = 0; @@ -56,9 +53,10 @@ grabh(hp, gflags) #ifndef TIOCSTI ttybuf.sg_erase = 0; ttybuf.sg_kill = 0; - for (s = SIGINT; s <= SIGQUIT; s++) - if ((savesigs[s-SIGINT] = sigset(s, SIG_IGN)) == SIG_DFL) - sigset(s, SIG_DFL); + if ((saveint = signal(SIGINT, SIG_IGN)) == SIG_DFL) + signal(SIGINT, SIG_DFL); + if ((savequit = signal(SIGQUIT, SIG_IGN)) == SIG_DFL) + signal(SIGQUIT, SIG_DFL); #endif if (gflags & GTO) { #ifndef TIOCSTI @@ -96,16 +94,14 @@ grabh(hp, gflags) if (hp->h_bcc != NOSTR) hp->h_seq++; } -# ifdef VMUNIX - sigset(SIGCONT, savecont); -# endif VMUNIX + signal(SIGCONT, savecont); #ifndef TIOCSTI ttybuf.sg_erase = c_erase; ttybuf.sg_kill = c_kill; if (ttyset) stty(fileno(stdin), &ttybuf); - for (s = SIGINT; s <= SIGQUIT; s++) - sigset(s, savesigs[s-SIGINT]); + signal(SIGINT, saveint); + signal(SIGQUIT, savequit); #endif return(errs); } @@ -122,7 +118,7 @@ readtty(pr, src) char pr[], src[]; { char ch, canonb[BUFSIZ]; - int c, signull(); + int c; register char *cp, *cp2; fputs(pr, stdout); @@ -157,9 +153,7 @@ readtty(pr, src) cp2 = cp; if (setjmp(rewrite)) goto redo; -# ifdef VMUNIX - sigset(SIGCONT, ttycont); -# endif VMUNIX + signal(SIGCONT, ttycont); clearerr(stdin); while (cp2 < canonb + BUFSIZ) { c = getc(stdin); @@ -168,9 +162,7 @@ readtty(pr, src) *cp2++ = c; } *cp2 = 0; -# ifdef VMUNIX - sigset(SIGCONT, signull); -# endif VMUNIX + signal(SIGCONT, SIG_DFL); if (c == EOF && ferror(stdin) && hadcont) { redo: hadcont = 0; @@ -215,21 +207,13 @@ redo: return(savestr(canonb)); } -# ifdef VMUNIX /* * Receipt continuation. */ +/*ARGSUSED*/ ttycont(s) { hadcont++; longjmp(rewrite, 1); } -# endif VMUNIX - -/* - * Null routine to satisfy - * silly system bug that denies us holding SIGCONT - */ -signull(s) -{} diff --git a/usr/src/usr.bin/mail/v7.local.c b/usr/src/usr.bin/mail/v7.local.c index 68d14add1f..24ed9b61d1 100644 --- a/usr/src/usr.bin/mail/v7.local.c +++ b/usr/src/usr.bin/mail/v7.local.c @@ -5,7 +5,7 @@ */ #ifndef lint -static char *sccsid = "@(#)v7.local.c 5.2 (Berkeley) %G%"; +static char *sccsid = "@(#)v7.local.c 5.3 (Berkeley) %G%"; #endif not lint /* @@ -25,10 +25,8 @@ static char *sccsid = "@(#)v7.local.c 5.2 (Berkeley) %G%"; findmail() { - register char *cp; - cp = copy("/usr/spool/mail/", mailname); - copy(myname, cp); + strcpy(copy("/usr/spool/mail/", mailname), myname); if (isdir(mailname)) { stradd(mailname, '/'); strcat(mailname, myname); diff --git a/usr/src/usr.bin/mail/vars.c b/usr/src/usr.bin/mail/vars.c index 3d82f73cbf..7df1f1b09d 100644 --- a/usr/src/usr.bin/mail/vars.c +++ b/usr/src/usr.bin/mail/vars.c @@ -5,7 +5,7 @@ */ #ifndef lint -static char *sccsid = "@(#)vars.c 5.2 (Berkeley) %G%"; +static char *sccsid = "@(#)vars.c 5.3 (Berkeley) %G%"; #endif not lint #include "rcv.h" @@ -46,10 +46,10 @@ assign(name, value) */ vfree(cp) - register char *cp; + char *cp; { - if (!equal(cp, "")) - cfree(cp); + if (*cp) + free(cp); } /* @@ -61,17 +61,16 @@ char * vcopy(str) char str[]; { - register char *top, *cp, *cp2; - - if (equal(str, "")) - return(""); - if ((top = calloc(strlen(str)+1, 1)) == NULL) - panic ("Out of memory"); - cp = top; - cp2 = str; - while (*cp++ = *cp2++) - ; - return(top); + char *new; + unsigned len; + + if (*str == '\0') + return ""; + len = strlen(str) + 1; + if ((new = malloc(len)) == NULL) + panic("Out of memory"); + bcopy(str, new, (int) len); + return new; } /* @@ -97,14 +96,12 @@ value(name) struct var * lookup(name) - char name[]; + register char name[]; { register struct var *vp; - register int h; - h = hash(name); - for (vp = variables[h]; vp != NOVAR; vp = vp->v_link) - if (equal(vp->v_name, name)) + for (vp = variables[hash(name)]; vp != NOVAR; vp = vp->v_link) + if (*vp->v_name == *name && equal(vp->v_name, name)) return(vp); return(NOVAR); } @@ -115,14 +112,12 @@ lookup(name) struct grouphead * findgroup(name) - char name[]; + register char name[]; { register struct grouphead *gh; - register int h; - h = hash(name); - for (gh = groups[h]; gh != NOGRP; gh = gh->g_link) - if (equal(gh->g_name, name)) + for (gh = groups[hash(name)]; gh != NOGRP; gh = gh->g_link) + if (*gh->g_name == *name && equal(gh->g_name, name)) return(gh); return(NOGRP); } @@ -144,7 +139,7 @@ printgroup(name) printf("%s\t", gh->g_name); for (gp = gh->g_list; gp != NOGE; gp = gp->ge_link) printf(" %s", gp->ge_name); - printf("\n"); + putchar('\n'); } /* @@ -153,16 +148,15 @@ printgroup(name) */ hash(name) - char name[]; + register char *name; { - register unsigned h; - register char *cp; - - for (cp = name, h = 0; *cp; h = (h << 2) + *cp++) - ; - if (h < 0) - h = -h; - if (h < 0) + register h = 0; + + while (*name) { + h <<= 2; + h += *name++; + } + if (h < 0 && (h = -h) < 0) h = 0; - return(h % HSHSIZE); + return (h % HSHSIZE); } -- 2.20.1