* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char *sccsid
= "@(#)cmd2.c 5.3 (Berkeley) %G%";
* If any arguments were given, go to the next applicable argument
* following dot, otherwise, go to the next applicable message.
* If given as first command with no arguments, print first message.
register struct message
*mp
;
* If some messages were supplied, find the
* first applicable one following dot using
mdot
= dot
- &message
[0] + 1;
* Find the first message in the supplied
* message list which follows dot.
for (ip
= msgvec
; *ip
!= NULL
; ip
++)
if ((mp
->m_flag
& MDELETED
) == 0) {
printf("No messages applicable\n");
* If this is the first command, select message 1.
* Note that this must exist for us to get here at all.
* Just find the next good message after dot, no
for (mp
= dot
+1; mp
< &message
[msgCount
]; mp
++)
if ((mp
->m_flag
& (MDELETED
|MSAVED
)) == 0)
if (mp
>= &message
[msgCount
]) {
list
[0] = dot
- &message
[0] + 1;
* Save a message in a file. Mark the message as saved
* so we can discard when the user quits.
* Copy a message to a file without affected its saved-ness
* Save/copy the indicated messages at the end of the passed file name.
* If mark is true, mark the message "saved."
register struct message
*mp
;
cmd
= mark
? "save" : "copy";
msgvec
= (int *) salloc((msgCount
+ 2) * sizeof *msgvec
);
if ((file
= snarf(str
, &f
)) == NOSTR
)
*msgvec
= first(0, MMNORM
);
printf("No messages to %s.\n", cmd
);
if (f
&& getmsglist(str
, msgvec
, 0) < 0)
if ((file
= expand(file
)) == NOSTR
)
if (stat(file
, &statb
) >= 0)
if ((obuf
= fopen(file
, "a")) == NULL
) {
for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++) {
if ((t
= send(mp
, obuf
, 0)) < 0) {
printf("%s %d/%ld\n", disp
, lc
, cc
);
* Write the indicated messages at the end of the passed
* file name, minus header and trailing blank line.
register struct message
*mp
;
register char *file
, *disp
;
int f
, *msgvec
, lc
, cc
, t
;
msgvec
= (int *) salloc((msgCount
+ 2) * sizeof *msgvec
);
if ((file
= snarf(str
, &f
)) == NOSTR
)
if ((file
= expand(file
)) == NOSTR
)
*msgvec
= first(0, MMNORM
);
printf("No messages to write.\n");
if (f
&& getmsglist(str
, msgvec
, 0) < 0)
if (stat(file
, &statb
) >= 0)
if ((obuf
= fopen(file
, "a")) == NULL
) {
for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++) {
fgets(linebuf
, BUFSIZ
, mesf
);
printf("%s %d/%d\n", disp
, lc
, cc
);
* Snarf the file from the end of the command line and
* return a pointer to it. If there is no file attached,
* just return NOSTR. Put a null in front of the file
* name so that the message list processing won't see it,
* unless the file name is the only thing on the line, in
* which case, return 0 in the reference flag variable.
cp
= strlen(linebuf
) + linebuf
- 1;
* Strip away trailing blanks.
while (*cp
== ' ' && cp
> linebuf
)
* Now search for the beginning of the file name.
while (cp
> linebuf
&& !any(*cp
, "\t "))
printf("No file specified.\n");
* Delete messages, then type the new dot.
lastdot
= dot
- &message
[0] + 1;
list
[0] = dot
- &message
[0];
printf("No more messages\n");
* Delete the indicated messages.
* Set dot to some nice place afterwards.
register struct message
*mp
;
for (ip
= msgvec
; *ip
!= NULL
; ip
++) {
mp
->m_flag
|= MDELETED
|MTOUCH
;
mp
->m_flag
&= ~(MPRESERVE
|MSAVED
|MBOX
);
last
= first(0, MDELETED
);
* Following can't happen -- it keeps lint happy
* Undelete the indicated messages.
register struct message
*mp
;
for (ip
= msgvec
; ip
-msgvec
< msgCount
; ip
++) {
* Interactively dump core on "core"
if ((pid
= vfork()) == -1) {
while (wait(&status
) != pid
)
printf(" -- Core dumped\n");
* Clobber as many bytes of stack as the user requests.
times
= (atoi(argv
[0]) + 511) / 512;
for (cp
= buf
; cp
< &buf
[512]; *cp
++ = 0xFF)
* Add the given header fields to the retained list.
* If no arguments, print the current list of retained fields.
register struct ignore
*igp
;
for (ap
= list
; *ap
!= 0; ap
++) {
if (member(field
, retain
))
igp
= (struct ignore
*) calloc(1, sizeof (struct ignore
));
igp
->i_field
= calloc(strlen(field
) + 1, sizeof (char));
strcpy(igp
->i_field
, field
);
* Print out all currently retained fields.
for (h
= 0; h
< HSHSIZE
; h
++)
for (igp
= retain
[h
]; igp
!= 0; igp
= igp
->i_link
)
printf("No fields currently being retained.\n");
ring
= (char **) salloc((count
+ 1) * sizeof (char *));
for (h
= 0; h
< HSHSIZE
; h
++)
for (igp
= retain
[h
]; igp
!= 0; igp
= igp
->i_link
)
qsort(ring
, count
, sizeof (char *), igcomp
);
for (ap
= ring
; *ap
!= 0; ap
++)
* Add the given header fields to the ignored list.
* If no arguments, print the current list of ignored fields.
register struct ignore
*igp
;
for (ap
= list
; *ap
!= 0; ap
++) {
igp
= (struct ignore
*) calloc(1, sizeof (struct ignore
));
igp
->i_field
= calloc(strlen(field
) + 1, sizeof (char));
strcpy(igp
->i_field
, field
);
* Print out all currently ignored fields.
for (h
= 0; h
< HSHSIZE
; h
++)
for (igp
= ignore
[h
]; igp
!= 0; igp
= igp
->i_link
)
printf("No fields currently being ignored.\n");
ring
= (char **) salloc((count
+ 1) * sizeof (char *));
for (h
= 0; h
< HSHSIZE
; h
++)
for (igp
= ignore
[h
]; igp
!= 0; igp
= igp
->i_link
)
qsort(ring
, count
, sizeof (char *), igcomp
);
for (ap
= ring
; *ap
!= 0; ap
++)
* Compare two names for sorting ignored field list.