-#
+/*
+ * 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.15 (Berkeley) %G%";
+#endif /* not lint */
+
#include "rcv.h"
-#include <sys/stat.h>
/*
* Mail -- a mail program
* User commands.
*/
-static char *SccsId = "@(#)cmd1.c 2.10 %G%";
-
/*
* Print the current active headings.
* Don't change dot if invoker didn't give an argument.
if (flag++ >= size)
break;
printhead(mesg);
- sreset();
}
if (flag == 0) {
printf("No more mail.\n");
return(0);
}
-/*
- * Set the list of alternate names for out host.
- */
-local(namelist)
- char **namelist;
-{
- register int c;
- register char **ap, **ap2, *cp;
-
- c = argcount(namelist) + 1;
- if (c == 1) {
- if (localnames == 0)
- return(0);
- for (ap = localnames; *ap; ap++)
- printf("%s ", *ap);
- printf("\n");
- return(0);
- }
- if (localnames != 0)
- cfree((char *) localnames);
- localnames = (char **) calloc(c, sizeof (char *));
- for (ap = namelist, ap2 = localnames; *ap; ap++, ap2++) {
- cp = (char *) calloc(strlen(*ap) + 1, sizeof (char));
- strcpy(cp, *ap);
- *ap2 = cp;
- }
- *ap2 = 0;
- return(0);
-}
-
/*
* Scroll to the next/previous screen
*/
-
scroll(arg)
char 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;
}
/*
{
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);
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)
+ 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)
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);
}
/*
return(0);
}
+/*
+ * Paginate messages, honor ignored fields.
+ */
+more(msgvec)
+ int *msgvec;
+{
+ return (type1(msgvec, 1, 1));
+}
+
+/*
+ * Paginate messages, even printing ignored fields.
+ */
+More(msgvec)
+ int *msgvec;
+{
+
+ return (type1(msgvec, 0, 1));
+}
+
/*
* Type out messages, honor ignored fields.
*/
int *msgvec;
{
- return(type1(msgvec, 1));
+ return(type1(msgvec, 1, 0));
}
/*
int *msgvec;
{
- return(type1(msgvec, 0));
+ return(type1(msgvec, 0, 0));
}
/*
*/
jmp_buf pipestop;
-type1(msgvec, doign)
+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 = 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++) {
+ 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);
+ (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);
}
brokpipe()
{
-# ifdef VMUNIX
- sigrelse(SIGPIPE);
-# else
- 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"
mp = &message[mesg-1];
dot = mp;
if (value("quiet") == NOSTR)
- printf("Message %2d:\n", mesg);
+ printf("Message %d:\n", mesg);
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) < 0)
break;
puts(linebuf);
lineb = blankline(linebuf);
*/
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);
+ return -1;
}
- switch ((pid = fork())) {
- case 0:
- sigchild();
- execlp("ls", "ls", dirname, 0);
- clrbuf(stdout);
- exit(1);
-
- case -1:
- perror("fork");
- return(-1);
-
- default:
- while ((e = wait(&s)) != -1 && e != pid)
- ;
- }
- return(0);
+ if ((cmd = value("LISTER")) == NOSTR)
+ cmd = "ls";
+ (void) run_command(cmd, 0, -1, -1, dirname, NOSTR);
+ return 0;
}