* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted provided
* that: (1) source distributions retain this entire copyright notice and
* comment, and (2) distributions including binaries display the following
* acknowledgement: ``This product includes software developed by the
* University of California, Berkeley and its contributors'' in the
* documentation or other materials provided with the distribution and in
* all advertising materials mentioning features or use of this software.
* 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)cmd3.c 5.24 (Berkeley) 6/25/90";
* Still more user commands.
* Process a shell escape by saving signals, ignoring signals,
sig_t sigint
= signal(SIGINT
, SIG_IGN
);
if ((shell
= value("SHELL")) == NOSTR
)
(void) run_command(shell
, 0, -1, -1, "-c", cmd
, NOSTR
);
(void) signal(SIGINT
, sigint
);
* Fork an interactive shell.
sig_t sigint
= signal(SIGINT
, SIG_IGN
);
if ((shell
= value("SHELL")) == NOSTR
)
(void) run_command(shell
, 0, -1, -1, NOSTR
);
(void) signal(SIGINT
, sigint
);
* Expand the shell escape by expanding unescaped !'s into the
* last issued command where possible.
if (n
< strlen(lastbang
)) {
printf("Command buffer overflow\n");
if (*cp
== '\\' && cp
[1] == '!') {
printf("!%s\n", bangbuf
);
strncpy(lastbang
, bangbuf
, 128);
* Print out a nice help message from some file or another.
if ((f
= Fopen(_PATH_HELP
, "r")) == NULL
) {
while ((c
= getc(f
)) != EOF
)
* Change user's working directory.
if ((cp
= expand(*arglist
)) == NOSTR
)
if (value("Replyall") == NOSTR
)
return (_respond(msgvec
));
return (_Respond(msgvec
));
* Reply to a list of messages. Extract each name from the
* message header and send them off to mail1()
char *cp
, *rcv
, *replyto
;
printf("Sorry, can't reply to multiple messages at once\n");
mp
= &message
[msgvec
[0] - 1];
if ((rcv
= skin(hfield("from", mp
))) == NOSTR
)
rcv
= skin(nameof(mp
, 1));
if ((replyto
= skin(hfield("reply-to", mp
))) != NOSTR
)
np
= extract(replyto
, GTO
);
else if ((cp
= skin(hfield("to", mp
))) != NOSTR
)
* Delete my name from the reply list,
* and with it, all my alternate names.
np
= delname(np
, myname
);
for (ap
= altnames
; *ap
; ap
++)
if (np
!= NIL
&& replyto
== NOSTR
)
np
= cat(np
, extract(rcv
, GTO
));
printf("Empty reply-to field -- replying to author\n");
if ((head
.h_subject
= hfield("subject", mp
)) == NOSTR
)
head
.h_subject
= hfield("subj", mp
);
head
.h_subject
= reedit(head
.h_subject
);
if (replyto
== NOSTR
&& (cp
= skin(hfield("cc", mp
))) != NOSTR
) {
np
= elide(extract(cp
, GCC
));
np
= delname(np
, myname
);
for (ap
= altnames
; *ap
; ap
++)
* Modify the subject we are replying to to begin with Re: if
if ((subj
[0] == 'r' || subj
[0] == 'R') &&
(subj
[1] == 'e' || subj
[1] == 'E') &&
newsubj
= salloc(strlen(subj
) + 5);
strcpy(newsubj
+ 4, subj
);
* Preserve the named messages, so that they will be sent
* back to the system mailbox.
register struct message
*mp
;
printf("Cannot \"preserve\" in edit mode\n");
for (ip
= msgvec
; *ip
!= NULL
; ip
++) {
* Mark all given messages as unread.
for (ip
= msgvec
; *ip
!= NULL
; ip
++) {
dot
->m_flag
&= ~(MREAD
|MTOUCH
);
* Print the size of each message.
register struct message
*mp
;
for (ip
= msgvec
; *ip
!= NULL
; ip
++) {
printf("%d: %d/%ld\n", mesg
, mp
->m_lines
, mp
->m_size
);
* Quit quickly. If we are sourcing, just pop the input level
* Set or display a variable value. Syntax is similar to that
char varbuf
[BUFSIZ
], **ap
, **p
;
for (h
= 0, s
= 1; h
< HSHSIZE
; h
++)
for (vp
= variables
[h
]; vp
!= NOVAR
; vp
= vp
->v_link
)
ap
= (char **) salloc(s
* sizeof *ap
);
for (h
= 0, p
= ap
; h
< HSHSIZE
; h
++)
for (vp
= variables
[h
]; vp
!= NOVAR
; vp
= vp
->v_link
)
for (p
= ap
; *p
!= NOSTR
; p
++)
printf("%s\t%s\n", *p
, value(*p
));
for (ap
= arglist
; *ap
!= NOSTR
; ap
++) {
while (*cp
!= '=' && *cp
!= '\0')
printf("Non-null variable name required\n");
* Unset a bunch of variable values.
register struct var
*vp
, *vp2
;
for (ap
= arglist
; *ap
!= NOSTR
; ap
++) {
if ((vp2
= lookup(*ap
)) == NOVAR
) {
printf("\"%s\": undefined variable\n", *ap
);
if (vp2
== variables
[h
]) {
variables
[h
] = variables
[h
]->v_link
;
for (vp
= variables
[h
]; vp
->v_link
!= vp2
; vp
= vp
->v_link
)
vp
->v_link
= vp2
->v_link
;
* Put add users to a group.
register struct grouphead
*gh
;
register struct group
*gp
;
for (h
= 0, s
= 1; h
< HSHSIZE
; h
++)
for (gh
= groups
[h
]; gh
!= NOGRP
; gh
= gh
->g_link
)
ap
= (char **) salloc(s
* sizeof *ap
);
for (h
= 0, p
= ap
; h
< HSHSIZE
; h
++)
for (gh
= groups
[h
]; gh
!= NOGRP
; gh
= gh
->g_link
)
for (p
= ap
; *p
!= NOSTR
; p
++)
if ((gh
= findgroup(gname
)) == NOGRP
) {
gh
= (struct grouphead
*) calloc(sizeof *gh
, 1);
gh
->g_name
= vcopy(gname
);
* Insert names from the command list into the group.
* Who cares if there are duplicates? They get tossed
for (ap
= argv
+1; *ap
!= NOSTR
; ap
++) {
gp
= (struct group
*) calloc(sizeof *gp
, 1);
gp
->ge_name
= vcopy(*ap
);
gp
->ge_link
= gh
->g_list
;
* Sort the passed string vecotor into ascending dictionary
for (ap
= list
; *ap
!= NOSTR
; ap
++)
qsort((char *)list
, ap
-list
, sizeof *list
, diction
);
* Do a dictionary order comparison of the arguments from
* The do nothing command for comments.
* Change to another file. With no argument, print information about
* Expand file names like echo
for (ap
= argv
; *ap
!= NOSTR
; ap
++) {
if ((cp
= expand(cp
)) != NOSTR
) {
if (value("Replyall") == NOSTR
)
return (_Respond(msgvec
));
return (_respond(msgvec
));
* 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
for (ap
= msgvec
; *ap
!= 0; ap
++) {
if ((cp
= skin(hfield("from", mp
))) == NOSTR
)
cp
= skin(nameof(mp
, 2));
head
.h_to
= cat(head
.h_to
, extract(cp
, GTO
));
mp
= &message
[msgvec
[0] - 1];
if ((head
.h_subject
= hfield("subject", mp
)) == NOSTR
)
head
.h_subject
= hfield("subj", mp
);
head
.h_subject
= reedit(head
.h_subject
);
* Conditional commands. These allow one to parameterize one's
* .mailrc and do some things if sending, others if receiving.
printf("Illegal nested \"if\"\n");
printf("Unrecognized if-keyword: \"%s\"\n", cp
);
* Implement 'else'. This is pretty simple -- we just
* flip over the conditional flag.
printf("\"Else\" without matching \"if\"\n");
printf("Mail's idea of conditions is screwed up\n");
* End of if statement. Just set cond back to anything.
printf("\"Endif\" without matching \"if\"\n");
* Set the list of alternate names.
register char **ap
, **ap2
, *cp
;
c
= argcount(namelist
) + 1;
for (ap
= altnames
; *ap
; ap
++)
cfree((char *) altnames
);
altnames
= (char **) calloc((unsigned) c
, sizeof (char *));
for (ap
= namelist
, ap2
= altnames
; *ap
; ap
++, ap2
++) {
cp
= (char *) calloc((unsigned) strlen(*ap
) + 1, sizeof (char));