* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)edit.c 5.7 (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 (i
= 0; msgvec
[i
] && i
< msgCount
; i
++) {
mp
= &message
[msgvec
[i
] - 1];
* Copy the message into the edit file.
* If we are in read only mode, make the
* temporary message file readonly as well.
if ((c
= creat(edname
, readonly
? 0400 : 0600)) < 0) {
if ((fp
= fdopen(c
, "w")) == NULL
) {
if (send(mp
, fp
, 0) < 0) {
if (fstat(fileno(fp
), &statb
) < 0)
modtime
= statb
.st_mtime
;
* Fork/execl the editor on the edit file.
(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 ((fp
= fopen(edname
, "r")) == NULL
) {
(void) fseek(otf
, (long) 0, 2);
mp
->m_block
= blockof(size
);
mp
->m_offset
= offsetof(size
);
while ((c
= getc(fp
)) != EOF
) {
* Restore signals and return.
(void) signal(SIGINT
, sigint
);
(void) signal(SIGQUIT
, sigquit
);