version 1.16, 2001/11/20 20:50:00 |
version 1.17, 2001/11/21 15:26:39 |
|
|
|
|
#ifndef lint |
#ifndef lint |
#if 0 |
#if 0 |
static char sccsid[] = "@(#)cmd3.c 8.2 (Berkeley) 4/20/95"; |
static const char sccsid[] = "@(#)cmd3.c 8.2 (Berkeley) 4/20/95"; |
#else |
#else |
static char rcsid[] = "$OpenBSD$"; |
static const char rcsid[] = "$OpenBSD$"; |
#endif |
#endif |
#endif /* not lint */ |
#endif /* not lint */ |
|
|
|
|
* |
* |
* Still more user commands. |
* Still more user commands. |
*/ |
*/ |
static int diction __P((const void *, const void *)); |
static int diction(const void *, const void *); |
|
|
/* |
/* |
* Process a shell escape by saving signals, ignoring signals, |
* Process a shell escape by saving signals, ignoring signals, |
* and forking a sh -c |
* and forking a sh -c |
*/ |
*/ |
int |
int |
shell(v) |
shell(void *v) |
void *v; |
|
{ |
{ |
char *str = v; |
char *str = v; |
char *shell; |
char *shell; |
|
|
*/ |
*/ |
/*ARGSUSED*/ |
/*ARGSUSED*/ |
int |
int |
dosh(v) |
dosh(void *v) |
void *v; |
|
{ |
{ |
char *shell; |
char *shell; |
struct sigaction oact; |
struct sigaction oact; |
|
|
* last issued command where possible. |
* last issued command where possible. |
*/ |
*/ |
int |
int |
bangexp(str, strsize) |
bangexp(char *str, size_t strsize) |
char *str; |
|
size_t strsize; |
|
{ |
{ |
char bangbuf[BUFSIZ]; |
char bangbuf[BUFSIZ]; |
static char lastbang[BUFSIZ]; |
static char lastbang[BUFSIZ]; |
|
|
return(-1); |
return(-1); |
} |
} |
changed++; |
changed++; |
strncpy(cp2, lastbang, sizeof(bangbuf) - (cp2 - bangbuf) - 1); |
strlcpy(cp2, lastbang, sizeof(bangbuf) - (cp2 - bangbuf)); |
bangbuf[sizeof(bangbuf) - 1] = '\0'; |
|
cp2 += strlen(lastbang); |
cp2 += strlen(lastbang); |
n -= strlen(lastbang); |
n -= strlen(lastbang); |
cp++; |
cp++; |
|
|
(void)printf("!%s\n", bangbuf); |
(void)printf("!%s\n", bangbuf); |
(void)fflush(stdout); |
(void)fflush(stdout); |
} |
} |
(void)strncpy(str, bangbuf, strsize - 1); |
(void)strlcpy(str, bangbuf, strsize); |
str[strsize - 1] = '\0'; |
(void)strlcpy(lastbang, bangbuf, sizeof(lastbang)); |
(void)strncpy(lastbang, bangbuf, sizeof(lastbang) - 1); |
|
lastbang[sizeof(lastbang) - 1] = '\0'; |
|
return(0); |
return(0); |
} |
} |
|
|
|
|
* Print out a nice help message from some file or another. |
* Print out a nice help message from some file or another. |
*/ |
*/ |
int |
int |
help(v) |
help(void *v) |
void *v; |
|
{ |
{ |
|
|
(void)run_command(value("PAGER"), 0, -1, -1, _PATH_HELP, NULL); |
(void)run_command(value("PAGER"), 0, -1, -1, _PATH_HELP, NULL); |
|
|
* Change user's working directory. |
* Change user's working directory. |
*/ |
*/ |
int |
int |
schdir(v) |
schdir(void *v) |
void *v; |
|
{ |
{ |
char **arglist = v; |
char **arglist = v; |
char *cp; |
char *cp; |
|
|
} |
} |
|
|
int |
int |
respond(v) |
respond(void *v) |
void *v; |
|
{ |
{ |
int *msgvec = v; |
int *msgvec = v; |
|
|
if (value("Replyall") == NULL) |
if (value("Replyall") == NULL) |
return(_respond(msgvec)); |
return(_respond(msgvec)); |
else |
else |
|
|
else if ((cp = skin(hfield("to", mp))) != NULL) |
else if ((cp = skin(hfield("to", mp))) != NULL) |
np = extract(cp, GTO); |
np = extract(cp, GTO); |
else |
else |
np = NIL; |
np = NULL; |
np = elide(np); |
np = elide(np); |
/* |
/* |
* Delete my name from the reply list, |
* Delete my name from the reply list, |
|
|
if (altnames) |
if (altnames) |
for (ap = altnames; *ap; ap++) |
for (ap = altnames; *ap; ap++) |
np = delname(np, *ap); |
np = delname(np, *ap); |
if (np != NIL && replyto == NULL) |
if (np != NULL && replyto == NULL) |
np = cat(np, extract(rcv, GTO)); |
np = cat(np, extract(rcv, GTO)); |
else if (np == NIL) { |
else if (np == NULL) { |
if (replyto != NULL) |
if (replyto != NULL) |
puts("Empty reply-to field -- replying to author"); |
puts("Empty reply-to field -- replying to author"); |
np = extract(rcv, GTO); |
np = extract(rcv, GTO); |
|
|
np = delname(np, *ap); |
np = delname(np, *ap); |
head.h_cc = np; |
head.h_cc = np; |
} else |
} else |
head.h_cc = NIL; |
head.h_cc = NULL; |
head.h_bcc = NIL; |
head.h_bcc = NULL; |
head.h_smopts = NIL; |
head.h_smopts = NULL; |
mail1(&head, 1); |
mail1(&head, 1); |
return(0); |
return(0); |
} |
} |
|
|
* it does not already. |
* it does not already. |
*/ |
*/ |
char * |
char * |
reedit(subj) |
reedit(char *subj) |
char *subj; |
|
{ |
{ |
char *newsubj; |
char *newsubj; |
|
|
|
|
* mailbox as unread. |
* mailbox as unread. |
*/ |
*/ |
int |
int |
marknew(v) |
marknew(void *v) |
void *v; |
|
{ |
{ |
int *msgvec = v; |
int *msgvec = v; |
int *ip; |
int *ip; |
|
|
* back to the system mailbox. |
* back to the system mailbox. |
*/ |
*/ |
int |
int |
preserve(v) |
preserve(void *v) |
void *v; |
|
{ |
{ |
int *msgvec = v; |
int *msgvec = v; |
int *ip, mesg; |
int *ip, mesg; |
|
|
* Mark all given messages as unread. |
* Mark all given messages as unread. |
*/ |
*/ |
int |
int |
unread(v) |
unread(void *v) |
void *v; |
|
{ |
{ |
int *msgvec = v; |
int *msgvec = v; |
int *ip; |
int *ip; |
|
|
* Print the size of each message. |
* Print the size of each message. |
*/ |
*/ |
int |
int |
messize(v) |
messize(void *v) |
void *v; |
|
{ |
{ |
int *msgvec = v; |
int *msgvec = v; |
struct message *mp; |
struct message *mp; |
|
|
* by returning an error. |
* by returning an error. |
*/ |
*/ |
int |
int |
rexit(v) |
rexit(void *v) |
void *v; |
|
{ |
{ |
|
|
if (sourcing) |
if (sourcing) |
return(1); |
return(1); |
exit(0); |
exit(0); |
|
|
* of csh. |
* of csh. |
*/ |
*/ |
int |
int |
set(v) |
set(void *v) |
void *v; |
|
{ |
{ |
char **arglist = v; |
char **arglist = v; |
struct var *vp; |
struct var *vp; |
|
|
|
|
if (*arglist == NULL) { |
if (*arglist == NULL) { |
for (h = 0, s = 1; h < HSHSIZE; h++) |
for (h = 0, s = 1; h < HSHSIZE; h++) |
for (vp = variables[h]; vp != NOVAR; vp = vp->v_link) |
for (vp = variables[h]; vp != NULL; vp = vp->v_link) |
s++; |
s++; |
ap = (char **)salloc(s * sizeof(*ap)); |
ap = (char **)salloc(s * sizeof(*ap)); |
for (h = 0, p = ap; h < HSHSIZE; h++) |
for (h = 0, p = ap; h < HSHSIZE; h++) |
for (vp = variables[h]; vp != NOVAR; vp = vp->v_link) |
for (vp = variables[h]; vp != NULL; vp = vp->v_link) |
*p++ = vp->v_name; |
*p++ = vp->v_name; |
*p = NULL; |
*p = NULL; |
sort(ap); |
sort(ap); |
|
|
* Unset a bunch of variable values. |
* Unset a bunch of variable values. |
*/ |
*/ |
int |
int |
unset(v) |
unset(void *v) |
void *v; |
|
{ |
{ |
char **arglist = v; |
char **arglist = v; |
struct var *vp, *vp2; |
struct var *vp, *vp2; |
|
|
|
|
errs = 0; |
errs = 0; |
for (ap = arglist; *ap != NULL; ap++) { |
for (ap = arglist; *ap != NULL; ap++) { |
if ((vp2 = lookup(*ap)) == NOVAR) { |
if ((vp2 = lookup(*ap)) == NULL) { |
if (!sourcing) { |
if (!sourcing) { |
printf("\"%s\": undefined variable\n", *ap); |
printf("\"%s\": undefined variable\n", *ap); |
errs++; |
errs++; |
|
|
* Put add users to a group. |
* Put add users to a group. |
*/ |
*/ |
int |
int |
group(v) |
group(void *v) |
void *v; |
|
{ |
{ |
char **argv = v; |
char **argv = v; |
struct grouphead *gh; |
struct grouphead *gh; |
|
|
|
|
if (*argv == NULL) { |
if (*argv == NULL) { |
for (h = 0, s = 1; h < HSHSIZE; h++) |
for (h = 0, s = 1; h < HSHSIZE; h++) |
for (gh = groups[h]; gh != NOGRP; gh = gh->g_link) |
for (gh = groups[h]; gh != NULL; gh = gh->g_link) |
s++; |
s++; |
ap = (char **)salloc(s * sizeof(*ap)); |
ap = (char **)salloc(s * sizeof(*ap)); |
for (h = 0, p = ap; h < HSHSIZE; h++) |
for (h = 0, p = ap; h < HSHSIZE; h++) |
for (gh = groups[h]; gh != NOGRP; gh = gh->g_link) |
for (gh = groups[h]; gh != NULL; gh = gh->g_link) |
*p++ = gh->g_name; |
*p++ = gh->g_name; |
*p = NULL; |
*p = NULL; |
sort(ap); |
sort(ap); |
|
|
} |
} |
gname = *argv; |
gname = *argv; |
h = hash(gname); |
h = hash(gname); |
if ((gh = findgroup(gname)) == NOGRP) { |
if ((gh = findgroup(gname)) == NULL) { |
gh = (struct grouphead *)calloc(sizeof(*gh), 1); |
gh = (struct grouphead *)calloc(sizeof(*gh), 1); |
gh->g_name = vcopy(gname); |
gh->g_name = vcopy(gname); |
gh->g_list = NOGE; |
gh->g_list = NULL; |
gh->g_link = groups[h]; |
gh->g_link = groups[h]; |
groups[h] = gh; |
groups[h] = gh; |
} |
} |
|
|
* order. |
* order. |
*/ |
*/ |
void |
void |
sort(list) |
sort(char **list) |
char **list; |
|
{ |
{ |
char **ap; |
char **ap; |
|
|
|
|
* qsort. |
* qsort. |
*/ |
*/ |
static int |
static int |
diction(a, b) |
diction(const void *a, const void *b) |
const void *a, *b; |
|
{ |
{ |
|
|
return(strcmp(*(char **)a, *(char **)b)); |
return(strcmp(*(char **)a, *(char **)b)); |
} |
} |
|
|
/* |
/* |
* The do nothing command for comments. |
* The do nothing command for comments. |
*/ |
*/ |
|
|
/*ARGSUSED*/ |
/*ARGSUSED*/ |
int |
int |
null(v) |
null(void *v) |
void *v; |
|
{ |
{ |
|
|
return(0); |
return(0); |
} |
} |
|
|
|
|
* the current file. |
* the current file. |
*/ |
*/ |
int |
int |
file(v) |
file(void *v) |
void *v; |
|
{ |
{ |
char **argv = v; |
char **argv = v; |
|
|
|
|
* Expand file names like echo |
* Expand file names like echo |
*/ |
*/ |
int |
int |
echo(v) |
echo(void *v) |
void *v; |
|
{ |
{ |
char **argv = v; |
char **argv = v; |
char **ap, *cp; |
char **ap, *cp; |
|
|
} |
} |
|
|
int |
int |
Respond(v) |
Respond(void *v) |
void *v; |
|
{ |
{ |
int *msgvec = v; |
int *msgvec = v; |
|
|
if (value("Replyall") == NULL) |
if (value("Replyall") == NULL) |
return(_Respond(msgvec)); |
return(_Respond(msgvec)); |
else |
else |
|
|
* reply. |
* reply. |
*/ |
*/ |
int |
int |
_Respond(msgvec) |
_Respond(int *msgvec) |
int msgvec[]; |
|
{ |
{ |
struct header head; |
struct header head; |
struct message *mp; |
struct message *mp; |
int *ap; |
int *ap; |
char *cp; |
char *cp; |
|
|
head.h_to = NIL; |
head.h_to = NULL; |
for (ap = msgvec; *ap != 0; ap++) { |
for (ap = msgvec; *ap != 0; ap++) { |
mp = &message[*ap - 1]; |
mp = &message[*ap - 1]; |
touch(mp); |
touch(mp); |
|
|
cp = skin(nameof(mp, 2)); |
cp = skin(nameof(mp, 2)); |
head.h_to = cat(head.h_to, extract(cp, GTO)); |
head.h_to = cat(head.h_to, extract(cp, GTO)); |
} |
} |
if (head.h_to == NIL) |
if (head.h_to == NULL) |
return(0); |
return(0); |
mp = &message[msgvec[0] - 1]; |
mp = &message[msgvec[0] - 1]; |
if ((head.h_subject = hfield("subject", mp)) == NULL) |
if ((head.h_subject = hfield("subject", mp)) == NULL) |
head.h_subject = hfield("subj", mp); |
head.h_subject = hfield("subj", mp); |
head.h_subject = reedit(head.h_subject); |
head.h_subject = reedit(head.h_subject); |
head.h_cc = NIL; |
head.h_cc = NULL; |
head.h_bcc = NIL; |
head.h_bcc = NULL; |
head.h_smopts = NIL; |
head.h_smopts = NULL; |
mail1(&head, 1); |
mail1(&head, 1); |
return(0); |
return(0); |
} |
} |
|
|
* .mailrc and do some things if sending, others if receiving. |
* .mailrc and do some things if sending, others if receiving. |
*/ |
*/ |
int |
int |
ifcmd(v) |
ifcmd(void *v) |
void *v; |
|
{ |
{ |
char **argv = v; |
char **argv = v; |
char *cp; |
char *cp; |
|
|
* flip over the conditional flag. |
* flip over the conditional flag. |
*/ |
*/ |
int |
int |
elsecmd(v) |
elsecmd(void *v) |
void *v; |
|
{ |
{ |
|
|
switch (cond) { |
switch (cond) { |
|
|
* End of if statement. Just set cond back to anything. |
* End of if statement. Just set cond back to anything. |
*/ |
*/ |
int |
int |
endifcmd(v) |
endifcmd(void *v) |
void *v; |
|
{ |
{ |
|
|
if (cond == CANY) { |
if (cond == CANY) { |
|
|
* Set the list of alternate names. |
* Set the list of alternate names. |
*/ |
*/ |
int |
int |
alternates(v) |
alternates(void *v) |
void *v; |
|
{ |
{ |
char **namelist = v; |
char **namelist = v; |
char **ap, **ap2, *cp; |
char **ap, **ap2, *cp; |