ebd97a727b6196db40ed3c78512420deca37e0ef
* Still more user commands.
static char *SccsId
= "@(#)cmd3.c 1.5 %G%";
* Process a shell escape by saving signals, ignoring signals,
int (*sig
[2])(), stat
[1];
if ((Shell
= value("SHELL")) == NOSTR
)
sig
[t
-2] = signal(t
, SIG_IGN
);
execl(Shell
, Shell
, "-c", cmd
, 0);
* Fork an interactive shell.
int (*sig
[2])(), stat
[1];
if ((Shell
= value("SHELL")) == NOSTR
)
sig
[t
-2] = signal(t
, SIG_IGN
);
* 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(HELPFILE
, "r")) == NULL
) {
printf("No help just now.\n");
while ((c
= getc(f
)) != EOF
)
* Change user's working directory.
for (cp
= str
; *cp
== ' '; cp
++)
if ((cp
= expand(cp
)) == NOSTR
)
* Reply to a list of messages. Extract each name from the
* message header and send them off to mail1()
char *cp
, buf
[2 * LINESIZE
], *rcv
;
printf("Sorry, can't reply to multiple messages at once\n");
mp
= &message
[msgvec
[0] - 1];
np
= elide(extract(buf
, GTO
));
np
= delname(np
, myname
);
head
.h_subject
= hfield("subject", mp
);
if (head
.h_subject
== NOSTR
)
head
.h_subject
= hfield("subj", mp
);
np
= elide(extract(cp
, GCC
));
np
= delname(np
, myname
);
head
.h_cc
= detract(np
, 0);
* 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
++) {
* Print the size of each message.
register struct message
*mp
;
for (ip
= msgvec
; *ip
!= NULL
; ip
++) {
printf("%d: %d\n", mesg
, msize(mp
));
* 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
;
if (argcount(arglist
) == 0) {
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
;
if (argcount(argv
) == 0) {
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 (argcount(argv
) == 1) {
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(list
, ap
-list
, sizeof *list
, diction
);
* Do a dictionary order comparison of the arguments from
* The do nothing command for comments.
* Print out the current edit file, if we are editing.
* Otherwise, print the name of the person who's mail
printf("Reading \"%s\"", editfile
);
printf("Reading %s's mail",
rindex(mailname
, '/') + 1);
printf("; %d message(s)\n", msgCount
);
* Acker's! Must switch to the new file.
* We use a funny interpretation --
* # -- gets the previous file
* % -- gets the invoker's post office box
* %user -- gets someone else's post office box
* & -- gets invoker's mbox file
* string -- reads the given file
cp
= getfilename(argv
[0]);
* Evaluate the string given as a new mailbox name.
* Ultimately, we want this to support a number of meta characters.
* % -- for my system mail box
* %user -- for user's system mail box
* & -- get's invoker's mbox file
* file name -- for any other file
strcpy(prevfile
, mailname
);
strcpy(savename
, myname
);
strncpy(myname
, name
+1, PATHSIZE
-1);
strcpy(myname
, savename
);
printf("No previous file\n");
strcpy(savename
, prevfile
);
strcpy(prevfile
, mailname
);
strcpy(mailname
, savename
);
strcpy(prevfile
, mailname
);
strcpy(prevfile
, mailname
);
* Expand file names like echo
for (ap
= argv
; *ap
!= NOSTR
; ap
++) {
if ((cp
= expand(cp
)) != NOSTR
)
* 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
register char *cp
, *subject
;
for (s
= 0, ap
= msgvec
; *ap
!= 0; ap
++) {
s
+= strlen(nameof(mp
)) + 1;
for (ap
= msgvec
; *ap
!= 0; ap
++) {
cp
= copy(nameof(mp
), cp
);
mp
= &message
[msgvec
[0] - 1];
subject
= hfield("subject", mp
);
subject
= hfield("subj", mp
);
head
.h_subject
= 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");