X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/6c85fa2a4274975d27581c240a80c94c244756d5..435e8dffcf378b5a0513c17aabf4f32096c20da8:/usr/src/usr.bin/mail/cmd1.c diff --git a/usr/src/usr.bin/mail/cmd1.c b/usr/src/usr.bin/mail/cmd1.c index fa3a55e713..7f1af26717 100644 --- a/usr/src/usr.bin/mail/cmd1.c +++ b/usr/src/usr.bin/mail/cmd1.c @@ -1,6 +1,25 @@ -# +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef lint +static char sccsid[] = "@(#)cmd1.c 5.19 (Berkeley) %G%"; +#endif /* not lint */ + #include "rcv.h" -#include /* * Mail -- a mail program @@ -8,8 +27,6 @@ * User commands. */ -static char *SccsId = "@(#)cmd1.c 2.6 %G%"; - /* * Print the current active headings. * Don't change dot if invoker didn't give an argument. @@ -46,7 +63,6 @@ headers(msgvec) if (flag++ >= size) break; printhead(mesg); - sreset(); } if (flag == 0) { printf("No more mail.\n"); @@ -58,7 +74,6 @@ headers(msgvec) /* * Scroll to the next/previous screen */ - scroll(arg) char arg[]; { @@ -95,30 +110,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; + int s; + char *cp; - if ((cp = value("screen")) != NOSTR) { - s = atoi(cp); - if (s > 0) - return(s); - } - if (baud < B1200) - s = 5; - else if (baud == B1200) - s = 10; - else - s = 20; - return(s); + if ((cp = value("screen")) != NOSTR && (s = atoi(cp)) > 0) + return s; + return screenheight - 4; } /* @@ -131,10 +132,8 @@ from(msgvec) { register int *ip; - for (ip = msgvec; *ip != NULL; ip++) { + for (ip = msgvec; *ip != NULL; ip++) printhead(*ip); - sreset(); - } if (--ip >= msgvec) dot = &message[*ip - 1]; return(0); @@ -148,26 +147,18 @@ from(msgvec) printhead(mesg) { struct message *mp; - FILE *ibuf; - char headline[LINESIZE], wcount[10], *subjline, dispc, curind; + 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) + (void) readline(setinput(mp), headline, LINESIZE); + 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) @@ -181,18 +172,15 @@ printhead(mesg) if (mp->m_flag & MBOX) dispc = 'M'; parse(headline, &hl, pbuf); - sprintf(wcount, " %d/%d", 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); } /* @@ -231,58 +219,102 @@ pcmdlist() } /* - * Type out the messages requested. + * Paginate messages, honor ignored fields. */ +more(msgvec) + int *msgvec; +{ + return (type1(msgvec, 1, 1)); +} -jmp_buf pipestop; +/* + * Paginate messages, even printing ignored fields. + */ +More(msgvec) + int *msgvec; +{ + return (type1(msgvec, 0, 1)); +} + +/* + * Type out messages, honor ignored fields. + */ type(msgvec) int *msgvec; { + + return(type1(msgvec, 1, 0)); +} + +/* + * Type out messages, even printing ignored fields. + */ +Type(msgvec) + int *msgvec; +{ + + return(type1(msgvec, 0, 0)); +} + +/* + * Type out the messages requested. + */ +jmp_buf pipestop; + +type1(msgvec, doign, page) + int *msgvec; +{ register *ip; 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)) { if (obuf != stdout) { pipef = NULL; - pclose(obuf); + Pclose(obuf); } - sigset(SIGPIPE, SIG_DFL); + signal(SIGPIPE, SIG_DFL); return(0); } - if (intty && outtty && (cp = value("crt")) != NOSTR) { - for (ip = msgvec, nlines = 0; *ip && ip-msgvec < msgCount; ip++) - nlines += message[*ip - 1].m_lines; - if (nlines > atoi(cp)) { - obuf = popen(MORE, "w"); + if (value("interactive") != NOSTR && + (page || (cp = value("crt")) != NOSTR)) { + nlines = 0; + if (!page) { + for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) + nlines += message[*ip - 1].m_lines; + } + if (page || nlines > (*cp ? atoi(cp) : realscreenheight)) { + cp = value("PAGER"); + if (cp == NULL || *cp == '\0') + cp = _PATH_MORE; + obuf = Popen(cp, "w"); if (obuf == NULL) { - perror(MORE); + perror(cp); obuf = stdout; - } - else { + } else { pipef = obuf; - sigset(SIGPIPE, brokpipe); + signal(SIGPIPE, brokpipe); } } } - for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) { - mesg = *ip; - touch(mesg); - mp = &message[mesg-1]; + for (ip = msgvec; *ip && ip - msgvec < msgCount; ip++) { + mp = &message[*ip - 1]; + touch(mp); dot = mp; - print(mp, obuf); + if (value("quiet") == NOSTR) + fprintf(obuf, "Message %d:\n", *ip); + (void) send(mp, obuf, doign ? ignore : 0, NOSTR); } if (obuf != stdout) { pipef = NULL; - pclose(obuf); + Pclose(obuf); } - sigset(SIGPIPE, SIG_DFL); + signal(SIGPIPE, SIG_DFL); return(0); } @@ -293,29 +325,9 @@ type(msgvec) brokpipe() { -# ifdef VMUNIX - sigrelse(SIGPIPE); -# else - signal(SIGPIPE, brokpipe); -# endif longjmp(pipestop, 1); } -/* - * Print the indicated message on standard output. - */ - -print(mp, obuf) - 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); -} - /* * Print the top so many lines of each desired message. * The number of lines is taken from the variable "toplines" @@ -327,7 +339,6 @@ top(msgvec) { register int *ip; register struct message *mp; - register int mesg; int c, topl, lines, lineb; char *valtop, linebuf[LINESIZE]; FILE *ibuf; @@ -341,18 +352,17 @@ top(msgvec) } lineb = 1; for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) { - mesg = *ip; - touch(mesg); - mp = &message[mesg-1]; + mp = &message[*ip - 1]; + touch(mp); dot = mp; if (value("quiet") == NOSTR) - printf("Message %2d:\n", mesg); + printf("Message %d:\n", *ip); ibuf = setinput(mp); c = mp->m_lines; if (!lineb) printf("\n"); for (lines = 0; lines < c && lines <= topl; lines++) { - if (readline(ibuf, linebuf) <= 0) + if (readline(ibuf, linebuf, LINESIZE) < 0) break; puts(linebuf); lineb = blankline(linebuf); @@ -365,7 +375,6 @@ top(msgvec) * Touch all the given messages so that they will * get mboxed. */ - stouch(msgvec) int msgvec[]; { @@ -401,26 +410,15 @@ mboxit(msgvec) */ folders() { - char dirname[BUFSIZ], cmd[BUFSIZ]; - int pid, s, e; + char dirname[BUFSIZ]; + char *cmd; if (getfold(dirname) < 0) { printf("No value set for \"folder\"\n"); - return(-1); - } - switch ((pid = fork())) { - case 0: - execlp("ls", "ls", dirname, 0); - clrbuf(stdout); - exit(1); - - case -1: - perror("fork"); - return(-1); - - default: - while ((e = wait(&s)) != -1 && e != pid) - ; + return 1; } - return(0); + if ((cmd = value("LISTER")) == NOSTR) + cmd = "ls"; + (void) run_command(cmd, 0, -1, -1, dirname, NOSTR); + return 0; }