* Copyright (c) 1980, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)cmd2.c 8.1 (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.
return save1(str
, 1, "save", saveignore
);
* Copy a message to a file without affected its saved-ness
return save1(str
, 0, "copy", saveignore
);
* Save/copy the indicated messages at the end of the passed file name.
* If mark is true, mark the message "saved."
save1(str
, mark
, cmd
, ignore
)
struct ignoretab
*ignore
;
register struct message
*mp
;
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 (access(file
, 0) >= 0)
if ((obuf
= Fopen(file
, "a")) == NULL
) {
for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++) {
if (send(mp
, obuf
, ignore
, NOSTR
) < 0) {
* Write the indicated messages at the end of the passed
* file name, minus header and trailing blank line.
return save1(str
, 1, "write", ignoreall
);
* 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
> linebuf
&& isspace(*cp
))
* Now search for the beginning of the file name.
while (cp
> linebuf
&& !isspace(*cp
))
printf("No file specified.\n");
* Delete messages, then type the new dot.
lastdot
= dot
- &message
[0] + 1;
list
[0] = dot
- &message
[0] + 1;
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
&& ip
-msgvec
< msgCount
; ip
++) {
* Interactively dump core on "core"
extern union wait wait_status
;
if (wait_status
.w_coredump
)
printf(" -- Core dumped.\n");
printf(" -- Can't dump core.\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.
return ignore1(list
, ignore
+ 1, "retained");
* Add the given header fields to the ignored list.
* If no arguments, print the current list of ignored fields.
return ignore1(list
, ignore
, "ignored");
return ignore1(list
, saveignore
+ 1, "retained");
return ignore1(list
, saveignore
, "ignored");
ignore1(list
, tab
, which
)
register struct ignore
*igp
;
return igshow(tab
, which
);
for (ap
= list
; *ap
!= 0; ap
++) {
igp
= (struct ignore
*) calloc(1, sizeof (struct ignore
));
igp
->i_field
= calloc((unsigned) strlen(field
) + 1,
strcpy(igp
->i_field
, field
);
igp
->i_link
= tab
->i_head
[h
];
* Print out all currently retained fields.
printf("No fields currently being %s.\n", which
);
ring
= (char **) salloc((tab
->i_count
+ 1) * sizeof (char *));
for (h
= 0; h
< HSHSIZE
; h
++)
for (igp
= tab
->i_head
[h
]; igp
!= 0; igp
= igp
->i_link
)
qsort(ring
, tab
->i_count
, sizeof (char *), igcomp
);
for (ap
= ring
; *ap
!= 0; ap
++)
* Compare two names for sorting ignored field list.
return (strcmp(*(char **)l
, *(char **)r
));