1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1980, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
2001-03-25 04:57:05 +00:00
|
|
|
#if 0
|
2001-12-18 20:52:09 +00:00
|
|
|
static char sccsid[] = "@(#)cmd3.c 8.2 (Berkeley) 4/20/95";
|
2001-03-25 04:57:05 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif /* not lint */
|
2002-06-30 05:25:07 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#include "rcv.h"
|
|
|
|
#include "extern.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mail -- a mail program
|
|
|
|
*
|
|
|
|
* Still more user commands.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process a shell escape by saving signals, ignoring signals,
|
|
|
|
* and forking a sh -c
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
shell(char *str)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
sig_t sigint = signal(SIGINT, SIG_IGN);
|
2001-05-27 20:26:22 +00:00
|
|
|
char *sh;
|
1994-05-27 12:33:43 +00:00
|
|
|
char cmd[BUFSIZ];
|
|
|
|
|
2001-03-25 04:57:05 +00:00
|
|
|
if (strlcpy(cmd, str, sizeof(cmd)) >= sizeof(cmd))
|
2001-05-27 20:26:22 +00:00
|
|
|
return (1);
|
2001-03-25 04:57:05 +00:00
|
|
|
if (bangexp(cmd, sizeof(cmd)) < 0)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (1);
|
|
|
|
if ((sh = value("SHELL")) == NULL)
|
|
|
|
sh = _PATH_CSHELL;
|
|
|
|
(void)run_command(sh, 0, -1, -1, "-c", cmd, NULL);
|
|
|
|
(void)signal(SIGINT, sigint);
|
1994-05-27 12:33:43 +00:00
|
|
|
printf("!\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fork an interactive shell.
|
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
dosh(char *str __unused)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
sig_t sigint = signal(SIGINT, SIG_IGN);
|
2001-05-27 20:26:22 +00:00
|
|
|
char *sh;
|
|
|
|
|
|
|
|
if ((sh = value("SHELL")) == NULL)
|
|
|
|
sh = _PATH_CSHELL;
|
|
|
|
(void)run_command(sh, 0, -1, -1, NULL, NULL, NULL);
|
|
|
|
(void)signal(SIGINT, sigint);
|
|
|
|
printf("\n");
|
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Expand the shell escape by expanding unescaped !'s into the
|
|
|
|
* last issued command where possible.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
bangexp(char *str, size_t strsize)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
char bangbuf[BUFSIZ];
|
2001-03-25 04:57:05 +00:00
|
|
|
static char lastbang[BUFSIZ];
|
2001-05-27 20:26:22 +00:00
|
|
|
char *cp, *cp2;
|
|
|
|
int n, changed = 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
cp = str;
|
|
|
|
cp2 = bangbuf;
|
2001-03-25 04:57:05 +00:00
|
|
|
n = sizeof(bangbuf);
|
2001-05-27 20:26:22 +00:00
|
|
|
while (*cp != '\0') {
|
1994-05-27 12:33:43 +00:00
|
|
|
if (*cp == '!') {
|
|
|
|
if (n < strlen(lastbang)) {
|
|
|
|
overf:
|
|
|
|
printf("Command buffer overflow\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
changed++;
|
2001-03-25 04:57:05 +00:00
|
|
|
if (strlcpy(cp2, lastbang, sizeof(bangbuf) - (cp2 - bangbuf))
|
|
|
|
>= sizeof(bangbuf) - (cp2 - bangbuf))
|
|
|
|
goto overf;
|
1994-05-27 12:33:43 +00:00
|
|
|
cp2 += strlen(lastbang);
|
|
|
|
n -= strlen(lastbang);
|
|
|
|
cp++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*cp == '\\' && cp[1] == '!') {
|
|
|
|
if (--n <= 1)
|
|
|
|
goto overf;
|
|
|
|
*cp2++ = '!';
|
|
|
|
cp += 2;
|
|
|
|
changed++;
|
|
|
|
}
|
|
|
|
if (--n <= 1)
|
|
|
|
goto overf;
|
|
|
|
*cp2++ = *cp++;
|
|
|
|
}
|
|
|
|
*cp2 = 0;
|
|
|
|
if (changed) {
|
|
|
|
printf("!%s\n", bangbuf);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)fflush(stdout);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-03-25 04:57:05 +00:00
|
|
|
if (strlcpy(str, bangbuf, strsize) >= strsize)
|
|
|
|
goto overf;
|
|
|
|
if (strlcpy(lastbang, bangbuf, sizeof(lastbang)) >= sizeof(lastbang))
|
|
|
|
goto overf;
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out a nice help message from some file or another.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
help(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
int c;
|
|
|
|
FILE *f;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if ((f = Fopen(_PATH_HELP, "r")) == NULL) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("%s", _PATH_HELP);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
while ((c = getc(f)) != EOF)
|
|
|
|
putchar(c);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(f);
|
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Change user's working directory.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
schdir(char **arglist)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
if (*arglist == NULL) {
|
|
|
|
if (homedir == NULL)
|
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
cp = homedir;
|
2001-03-25 04:57:05 +00:00
|
|
|
} else
|
2001-05-27 20:26:22 +00:00
|
|
|
if ((cp = expand(*arglist)) == NULL)
|
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (chdir(cp) < 0) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("%s", cp);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
respond(int *msgvec)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2002-06-25 05:34:27 +00:00
|
|
|
if (value("Replyall") == NULL && value("flipr") == NULL)
|
1998-01-02 16:44:13 +00:00
|
|
|
return (dorespond(msgvec));
|
1994-05-27 12:33:43 +00:00
|
|
|
else
|
1998-01-02 16:44:13 +00:00
|
|
|
return (doRespond(msgvec));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reply to a list of messages. Extract each name from the
|
|
|
|
* message header and send them off to mail1()
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
dorespond(int *msgvec)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
struct message *mp;
|
|
|
|
char *cp, *rcv, *replyto;
|
|
|
|
char **ap;
|
|
|
|
struct name *np;
|
|
|
|
struct header head;
|
|
|
|
|
|
|
|
if (msgvec[1] != 0) {
|
|
|
|
printf("Sorry, can't reply to multiple messages at once\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
mp = &message[msgvec[0] - 1];
|
|
|
|
touch(mp);
|
|
|
|
dot = mp;
|
2001-05-27 20:26:22 +00:00
|
|
|
if ((rcv = skin(hfield("from", mp))) == NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
rcv = skin(nameof(mp, 1));
|
2001-05-27 20:26:22 +00:00
|
|
|
if ((replyto = skin(hfield("reply-to", mp))) != NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
np = extract(replyto, GTO);
|
2001-05-27 20:26:22 +00:00
|
|
|
else if ((cp = skin(hfield("to", mp))) != NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
np = extract(cp, GTO);
|
|
|
|
else
|
2001-05-27 20:26:22 +00:00
|
|
|
np = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
np = elide(np);
|
|
|
|
/*
|
|
|
|
* Delete my name from the reply list,
|
|
|
|
* and with it, all my alternate names.
|
|
|
|
*/
|
|
|
|
np = delname(np, myname);
|
|
|
|
if (altnames)
|
2001-05-27 20:26:22 +00:00
|
|
|
for (ap = altnames; *ap != NULL; ap++)
|
1994-05-27 12:33:43 +00:00
|
|
|
np = delname(np, *ap);
|
2001-05-27 20:26:22 +00:00
|
|
|
if (np != NULL && replyto == NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
np = cat(np, extract(rcv, GTO));
|
2001-05-27 20:26:22 +00:00
|
|
|
else if (np == NULL) {
|
|
|
|
if (replyto != NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
printf("Empty reply-to field -- replying to author\n");
|
|
|
|
np = extract(rcv, GTO);
|
|
|
|
}
|
|
|
|
head.h_to = np;
|
2001-05-27 20:26:22 +00:00
|
|
|
if ((head.h_subject = hfield("subject", mp)) == NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
head.h_subject = hfield("subj", mp);
|
|
|
|
head.h_subject = reedit(head.h_subject);
|
2001-05-27 20:26:22 +00:00
|
|
|
if (replyto == NULL && (cp = skin(hfield("cc", mp))) != NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
np = elide(extract(cp, GCC));
|
|
|
|
np = delname(np, myname);
|
|
|
|
if (altnames != 0)
|
2001-05-27 20:26:22 +00:00
|
|
|
for (ap = altnames; *ap != NULL; ap++)
|
1994-05-27 12:33:43 +00:00
|
|
|
np = delname(np, *ap);
|
|
|
|
head.h_cc = np;
|
|
|
|
} else
|
2001-05-27 20:26:22 +00:00
|
|
|
head.h_cc = NULL;
|
|
|
|
head.h_bcc = NULL;
|
|
|
|
head.h_smopts = NULL;
|
2001-06-14 01:08:30 +00:00
|
|
|
head.h_replyto = value("REPLYTO");
|
1998-01-02 16:44:13 +00:00
|
|
|
head.h_inreplyto = skin(hfield("message-id", mp));
|
1994-05-27 12:33:43 +00:00
|
|
|
mail1(&head, 1);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modify the subject we are replying to to begin with Re: if
|
|
|
|
* it does not already.
|
|
|
|
*/
|
|
|
|
char *
|
2010-12-19 16:25:23 +00:00
|
|
|
reedit(char *subj)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
char *newsubj;
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
if (subj == NULL)
|
|
|
|
return (NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
if ((subj[0] == 'r' || subj[0] == 'R') &&
|
|
|
|
(subj[1] == 'e' || subj[1] == 'E') &&
|
|
|
|
subj[2] == ':')
|
2001-05-27 20:26:22 +00:00
|
|
|
return (subj);
|
1994-05-27 12:33:43 +00:00
|
|
|
newsubj = salloc(strlen(subj) + 5);
|
2001-03-25 04:57:05 +00:00
|
|
|
sprintf(newsubj, "Re: %s", subj);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (newsubj);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Preserve the named messages, so that they will be sent
|
|
|
|
* back to the system mailbox.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
preserve(int *msgvec)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
int *ip, mesg;
|
|
|
|
struct message *mp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (edit) {
|
|
|
|
printf("Cannot \"preserve\" in edit mode\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1997-09-18 14:08:40 +00:00
|
|
|
for (ip = msgvec; *ip != 0; ip++) {
|
1994-05-27 12:33:43 +00:00
|
|
|
mesg = *ip;
|
|
|
|
mp = &message[mesg-1];
|
|
|
|
mp->m_flag |= MPRESERVE;
|
|
|
|
mp->m_flag &= ~MBOX;
|
|
|
|
dot = mp;
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark all given messages as unread.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
unread(int msgvec[])
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
int *ip;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1997-09-18 14:08:40 +00:00
|
|
|
for (ip = msgvec; *ip != 0; ip++) {
|
1994-05-27 12:33:43 +00:00
|
|
|
dot = &message[*ip-1];
|
|
|
|
dot->m_flag &= ~(MREAD|MTOUCH);
|
|
|
|
dot->m_flag |= MSTATUS;
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print the size of each message.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
messize(int *msgvec)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
struct message *mp;
|
|
|
|
int *ip, mesg;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1997-09-18 14:08:40 +00:00
|
|
|
for (ip = msgvec; *ip != 0; ip++) {
|
1994-05-27 12:33:43 +00:00
|
|
|
mesg = *ip;
|
|
|
|
mp = &message[mesg-1];
|
1998-07-06 21:01:54 +00:00
|
|
|
printf("%d: %ld/%ld\n", mesg, mp->m_lines, mp->m_size);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Quit quickly. If we are sourcing, just pop the input level
|
|
|
|
* by returning an error.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
rexit(int e __unused)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
if (sourcing)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (1);
|
2001-12-18 20:52:09 +00:00
|
|
|
exit(0);
|
1994-05-27 12:33:43 +00:00
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set or display a variable value. Syntax is similar to that
|
|
|
|
* of csh.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
set(char **arglist)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
struct var *vp;
|
|
|
|
char *cp, *cp2;
|
1994-05-27 12:33:43 +00:00
|
|
|
char varbuf[BUFSIZ], **ap, **p;
|
|
|
|
int errs, h, s;
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
if (*arglist == NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
for (h = 0, s = 1; h < HSHSIZE; h++)
|
2001-05-27 20:26:22 +00:00
|
|
|
for (vp = variables[h]; vp != NULL; vp = vp->v_link)
|
1994-05-27 12:33:43 +00:00
|
|
|
s++;
|
2001-05-27 20:26:22 +00:00
|
|
|
ap = (char **)salloc(s * sizeof(*ap));
|
1994-05-27 12:33:43 +00:00
|
|
|
for (h = 0, p = ap; h < HSHSIZE; h++)
|
2001-05-27 20:26:22 +00:00
|
|
|
for (vp = variables[h]; vp != NULL; vp = vp->v_link)
|
1994-05-27 12:33:43 +00:00
|
|
|
*p++ = vp->v_name;
|
2001-05-27 20:26:22 +00:00
|
|
|
*p = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
sort(ap);
|
2001-05-27 20:26:22 +00:00
|
|
|
for (p = ap; *p != NULL; p++)
|
1994-05-27 12:33:43 +00:00
|
|
|
printf("%s\t%s\n", *p, value(*p));
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
errs = 0;
|
2001-05-27 20:26:22 +00:00
|
|
|
for (ap = arglist; *ap != NULL; ap++) {
|
1994-05-27 12:33:43 +00:00
|
|
|
cp = *ap;
|
|
|
|
cp2 = varbuf;
|
2001-03-25 04:57:05 +00:00
|
|
|
while (cp2 < varbuf + sizeof(varbuf) - 1 && *cp != '=' && *cp != '\0')
|
1994-05-27 12:33:43 +00:00
|
|
|
*cp2++ = *cp++;
|
|
|
|
*cp2 = '\0';
|
|
|
|
if (*cp == '\0')
|
|
|
|
cp = "";
|
|
|
|
else
|
|
|
|
cp++;
|
|
|
|
if (equal(varbuf, "")) {
|
|
|
|
printf("Non-null variable name required\n");
|
|
|
|
errs++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
assign(varbuf, cp);
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (errs);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unset a bunch of variable values.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
unset(char **arglist)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
struct var *vp, *vp2;
|
1994-05-27 12:33:43 +00:00
|
|
|
int errs, h;
|
|
|
|
char **ap;
|
|
|
|
|
|
|
|
errs = 0;
|
2001-05-27 20:26:22 +00:00
|
|
|
for (ap = arglist; *ap != NULL; ap++) {
|
|
|
|
if ((vp2 = lookup(*ap)) == NULL) {
|
2001-12-18 20:52:09 +00:00
|
|
|
if (getenv(*ap))
|
|
|
|
unsetenv(*ap);
|
|
|
|
else if (!sourcing) {
|
1994-05-27 12:33:43 +00:00
|
|
|
printf("\"%s\": undefined variable\n", *ap);
|
|
|
|
errs++;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
h = hash(*ap);
|
|
|
|
if (vp2 == variables[h]) {
|
|
|
|
variables[h] = variables[h]->v_link;
|
|
|
|
vfree(vp2->v_name);
|
|
|
|
vfree(vp2->v_value);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)free(vp2);
|
1994-05-27 12:33:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (vp = variables[h]; vp->v_link != vp2; vp = vp->v_link)
|
|
|
|
;
|
|
|
|
vp->v_link = vp2->v_link;
|
|
|
|
vfree(vp2->v_name);
|
|
|
|
vfree(vp2->v_value);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)free(vp2);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (errs);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Put add users to a group.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
group(char **argv)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
struct grouphead *gh;
|
|
|
|
struct group *gp;
|
1994-05-27 12:33:43 +00:00
|
|
|
char **ap, *gname, **p;
|
2001-05-27 20:26:22 +00:00
|
|
|
int h, s;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
if (*argv == NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
for (h = 0, s = 1; h < HSHSIZE; h++)
|
2001-05-27 20:26:22 +00:00
|
|
|
for (gh = groups[h]; gh != NULL; gh = gh->g_link)
|
1994-05-27 12:33:43 +00:00
|
|
|
s++;
|
2001-05-27 20:26:22 +00:00
|
|
|
ap = (char **)salloc(s * sizeof(*ap));
|
1994-05-27 12:33:43 +00:00
|
|
|
for (h = 0, p = ap; h < HSHSIZE; h++)
|
2001-05-27 20:26:22 +00:00
|
|
|
for (gh = groups[h]; gh != NULL; gh = gh->g_link)
|
1994-05-27 12:33:43 +00:00
|
|
|
*p++ = gh->g_name;
|
2001-05-27 20:26:22 +00:00
|
|
|
*p = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
sort(ap);
|
2001-05-27 20:26:22 +00:00
|
|
|
for (p = ap; *p != NULL; p++)
|
1994-05-27 12:33:43 +00:00
|
|
|
printgroup(*p);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
if (argv[1] == NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
printgroup(*argv);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
gname = *argv;
|
|
|
|
h = hash(gname);
|
2001-05-27 20:26:22 +00:00
|
|
|
if ((gh = findgroup(gname)) == NULL) {
|
2016-07-13 14:59:17 +00:00
|
|
|
if ((gh = calloc(1, sizeof(*gh))) == NULL)
|
|
|
|
err(1, "Out of memory");
|
1994-05-27 12:33:43 +00:00
|
|
|
gh->g_name = vcopy(gname);
|
2001-05-27 20:26:22 +00:00
|
|
|
gh->g_list = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
gh->g_link = groups[h];
|
|
|
|
groups[h] = gh;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Insert names from the command list into the group.
|
|
|
|
* Who cares if there are duplicates? They get tossed
|
|
|
|
* later anyway.
|
|
|
|
*/
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
for (ap = argv+1; *ap != NULL; ap++) {
|
2016-07-13 14:59:17 +00:00
|
|
|
if ((gp = calloc(1, sizeof(*gp))) == NULL)
|
|
|
|
err(1, "Out of memory");
|
1994-05-27 12:33:43 +00:00
|
|
|
gp->ge_name = vcopy(*ap);
|
|
|
|
gp->ge_link = gh->g_list;
|
|
|
|
gh->g_list = gp;
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sort the passed string vecotor into ascending dictionary
|
|
|
|
* order.
|
|
|
|
*/
|
|
|
|
void
|
2010-12-19 16:25:23 +00:00
|
|
|
sort(char **list)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
char **ap;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
for (ap = list; *ap != NULL; ap++)
|
1994-05-27 12:33:43 +00:00
|
|
|
;
|
|
|
|
if (ap-list < 2)
|
|
|
|
return;
|
|
|
|
qsort(list, ap-list, sizeof(*list), diction);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do a dictionary order comparison of the arguments from
|
|
|
|
* qsort.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
diction(const void *a, const void *b)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
return (strcmp(*(const char **)a, *(const char **)b));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The do nothing command for comments.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
null(int e __unused)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Change to another file. With no argument, print information about
|
|
|
|
* the current file.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
file(char **argv)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
if (argv[0] == NULL) {
|
2001-12-18 20:52:09 +00:00
|
|
|
newfileinfo(0);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
if (setfile(*argv) < 0)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
announce();
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Expand file names like echo
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
echo(char **argv)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
char **ap, *cp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
for (ap = argv; *ap != NULL; ap++) {
|
1994-05-27 12:33:43 +00:00
|
|
|
cp = *ap;
|
2001-05-27 20:26:22 +00:00
|
|
|
if ((cp = expand(cp)) != NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
if (ap != argv)
|
2001-05-27 20:26:22 +00:00
|
|
|
printf(" ");
|
1994-05-27 12:33:43 +00:00
|
|
|
printf("%s", cp);
|
|
|
|
}
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
printf("\n");
|
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
Respond(int *msgvec)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2002-06-25 05:34:27 +00:00
|
|
|
if (value("Replyall") == NULL && value("flipr") == NULL)
|
1998-01-02 16:44:13 +00:00
|
|
|
return (doRespond(msgvec));
|
1994-05-27 12:33:43 +00:00
|
|
|
else
|
1998-01-02 16:44:13 +00:00
|
|
|
return (dorespond(msgvec));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reply to a series of messages by simply mailing to the senders
|
|
|
|
* and not messing around with the To: and Cc: lists as in normal
|
|
|
|
* reply.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
doRespond(int msgvec[])
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
struct header head;
|
|
|
|
struct message *mp;
|
2001-05-27 20:26:22 +00:00
|
|
|
int *ap;
|
|
|
|
char *cp, *mid;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
head.h_to = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
for (ap = msgvec; *ap != 0; ap++) {
|
|
|
|
mp = &message[*ap - 1];
|
|
|
|
touch(mp);
|
|
|
|
dot = mp;
|
2001-05-27 20:26:22 +00:00
|
|
|
if ((cp = skin(hfield("from", mp))) == NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
cp = skin(nameof(mp, 2));
|
|
|
|
head.h_to = cat(head.h_to, extract(cp, GTO));
|
1998-01-02 16:44:13 +00:00
|
|
|
mid = skin(hfield("message-id", mp));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
if (head.h_to == NULL)
|
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
mp = &message[msgvec[0] - 1];
|
2001-05-27 20:26:22 +00:00
|
|
|
if ((head.h_subject = hfield("subject", mp)) == NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
head.h_subject = hfield("subj", mp);
|
|
|
|
head.h_subject = reedit(head.h_subject);
|
2001-05-27 20:26:22 +00:00
|
|
|
head.h_cc = NULL;
|
|
|
|
head.h_bcc = NULL;
|
|
|
|
head.h_smopts = NULL;
|
2001-06-14 01:08:30 +00:00
|
|
|
head.h_replyto = value("REPLYTO");
|
1998-01-02 16:44:13 +00:00
|
|
|
head.h_inreplyto = mid;
|
1994-05-27 12:33:43 +00:00
|
|
|
mail1(&head, 1);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Conditional commands. These allow one to parameterize one's
|
|
|
|
* .mailrc and do some things if sending, others if receiving.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
ifcmd(char **argv)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
char *cp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (cond != CANY) {
|
|
|
|
printf("Illegal nested \"if\"\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
cond = CANY;
|
|
|
|
cp = argv[0];
|
|
|
|
switch (*cp) {
|
|
|
|
case 'r': case 'R':
|
|
|
|
cond = CRCV;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 's': case 'S':
|
|
|
|
cond = CSEND;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("Unrecognized if-keyword: \"%s\"\n", cp);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implement 'else'. This is pretty simple -- we just
|
|
|
|
* flip over the conditional flag.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
elsecmd(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
switch (cond) {
|
|
|
|
case CANY:
|
|
|
|
printf("\"Else\" without matching \"if\"\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
case CSEND:
|
|
|
|
cond = CRCV;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CRCV:
|
|
|
|
cond = CSEND;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("Mail's idea of conditions is screwed up\n");
|
|
|
|
cond = CANY;
|
|
|
|
break;
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* End of if statement. Just set cond back to anything.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
endifcmd(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (cond == CANY) {
|
|
|
|
printf("\"Endif\" without matching \"if\"\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
cond = CANY;
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the list of alternate names.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
alternates(char **namelist)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
int c;
|
|
|
|
char **ap, **ap2, *cp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
c = argcount(namelist) + 1;
|
|
|
|
if (c == 1) {
|
|
|
|
if (altnames == 0)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
|
|
|
for (ap = altnames; *ap != NULL; ap++)
|
1994-05-27 12:33:43 +00:00
|
|
|
printf("%s ", *ap);
|
|
|
|
printf("\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
if (altnames != 0)
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)free(altnames);
|
2016-07-13 14:59:17 +00:00
|
|
|
if ((altnames = calloc((unsigned)c, sizeof(char *))) == NULL)
|
|
|
|
err(1, "Out of memory");
|
2001-05-27 20:26:22 +00:00
|
|
|
for (ap = namelist, ap2 = altnames; *ap != NULL; ap++, ap2++) {
|
|
|
|
cp = calloc((unsigned)strlen(*ap) + 1, sizeof(char));
|
1994-05-27 12:33:43 +00:00
|
|
|
strcpy(cp, *ap);
|
|
|
|
*ap2 = cp;
|
|
|
|
}
|
|
|
|
*ap2 = 0;
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|