* Still more user commands.
static char *SccsId
= "@(#)cmd3.c 1.1 %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", str
, 0);
* Fork an interactive shell.
int (*sig
[2])(), stat
[1];
if ((Shell
= value("SHELL")) == NOSTR
)
sig
[t
-2] = signal(t
, SIG_IGN
);
* 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 editting.
* Otherwise, print the name of the person who's mail
printf("Reading \"%s\"\n", editfile
);
printf("Reading %s's mail\n", rindex(mailname
, '/') + 1);
* 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
;