* Perform message editing functions.
static char *SccsId
= "@(#)edit.c 2.4 %G%";
if ((edname
= value("EDITOR")) == NOSTR
)
return(edit1(msgvec
, edname
));
* Invoke the visual editor on a message list.
if ((edname
= value("VISUAL")) == NOSTR
)
return(edit1(msgvec
, edname
));
* Edit a message by writing the message into a funnily-named file
* (which should not exist) and forking an editor on it.
* We get the editor from the stuff above.
int *ip
, pid
, mesg
, lines
;
int (*sigint
)(), (*sigquit
)();
char edname
[15], nbuf
[10];
* Set signals; locate editor.
sigint
= sigset(SIGINT
, SIG_IGN
);
sigquit
= sigset(SIGQUIT
, SIG_IGN
);
* Deal with each message to be edited . . .
for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++) {
* Make up a name for the edit file of the
* form "Message%d" and make sure it doesn't
cp2
= copy("Message", edname
);
if (!access(edname
, 2)) {
printf("%s: file exists\n", edname
);
* Copy the message into the edit file.
close(creat(edname
, 0600));
if ((obuf
= fopen(edname
, "w")) == NULL
) {
if (send(mp
, obuf
, 0) < 0) {
* If we are in read only mode, make the
* temporary message file readonly as well.
* Fork/execl the editor on the edit file.
if (stat(edname
, &statb
) < 0)
modtime
= statb
.st_mtime
;
sigsys(SIGQUIT
, SIG_DFL
);
execl(ed
, ed
, edname
, 0);
while (wait(&mesg
) != pid
)
* If in read only mode, just remove the editor
* Now copy the message to the end of the
if (stat(edname
, &statb
) < 0) {
if (modtime
== statb
.st_mtime
) {
if ((ibuf
= fopen(edname
, "r")) == NULL
) {
mp
->m_block
= blockof(size
);
mp
->m_offset
= offsetof(size
);
while ((c
= getc(ibuf
)) != EOF
) {
* Restore signals and return.
sigset(SIGQUIT
, sigquit
);