* 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
= "@(#)edit.c 5.4 (Berkeley) %G%";
* Perform message editing functions.
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 (*sigint
)(), (*sigquit
)();
register struct message
*mp
;
* Set signals; locate editor.
sigint
= signal(SIGINT
, SIG_IGN
);
sigquit
= signal(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
(void) sprintf(edname
, "Message%d", mesg
);
if (!access(edname
, 2)) {
printf("%s: file exists\n", edname
);
* Copy the message into the edit file.
(void) 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.
(void) chmod(edname
, 0400);
* Fork/execl the editor on the edit file.
if (stat(edname
, &statb
) < 0)
modtime
= statb
.st_mtime
;
(void) signal(SIGINT
, SIG_DFL
);
(void) signal(SIGQUIT
, SIG_DFL
);
execl(ed
, ed
, edname
, 0);
while (wait(&status
) != 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
) {
(void) fseek(otf
, (long) 0, 2);
mp
->m_block
= blockof(size
);
mp
->m_offset
= offsetof(size
);
mp
->m_size
= fsize(ibuf
);
while ((c
= getc(ibuf
)) != EOF
) {
* Restore signals and return.
(void) signal(SIGINT
, sigint
);
(void) signal(SIGQUIT
, sigquit
);