* Copyright (c) 1980 Regents of the University of California.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)edit.c 5.15 (Berkeley) %G%";
* Perform message editing functions.
return edit1(msgvec
, 'e');
* Invoke the visual editor on a message list.
return edit1(msgvec
, 'v');
* 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.
register struct message
*mp
;
* Deal with each message to be edited . . .
for (i
= 0; msgvec
[i
] && i
< msgCount
; i
++) {
printf("Edit message %d [ynq]? ", msgvec
[i
]);
if (fgets(buf
, sizeof buf
, stdin
) == 0)
for (p
= buf
; *p
== ' ' || *p
== '\t'; p
++)
dot
= mp
= &message
[msgvec
[i
] - 1];
sigint
= signal(SIGINT
, SIG_IGN
);
fp
= run_editor(setinput(mp
), mp
->m_size
, type
, readonly
);
(void) fseek(otf
, (long) 0, 2);
mp
->m_block
= blockof(size
);
mp
->m_offset
= offsetof(size
);
while ((c
= getc(fp
)) != EOF
) {
(void) signal(SIGINT
, sigint
);
* Run an editor on the file at "fpp" of "size" bytes,
* and return a new file pointer.
* Signals must be handled by the caller.
* "Type" is 'e' for _PATH_EX, 'v' for _PATH_VI.
run_editor(fp
, size
, type
, readonly
)
register FILE *nf
= NULL
;
if ((t
= creat(tempEdit
, readonly
? 0400 : 0600)) < 0) {
if ((nf
= Fdopen(t
, "w")) == NULL
) {
while (--size
>= 0 && (t
= getc(fp
)) != EOF
)
while ((t
= getc(fp
)) != EOF
)
if (fstat(fileno(nf
), &statb
) < 0)
modtime
= statb
.st_mtime
;
if ((edit
= value(type
== 'e' ? "EDITOR" : "VISUAL")) == NOSTR
)
edit
= type
== 'e' ? _PATH_EX
: _PATH_VI
;
if (run_command(edit
, 0, -1, -1, tempEdit
, NOSTR
) < 0) {
* If in read only mode or file unchanged, just remove the editor
if (stat(tempEdit
, &statb
) < 0) {
if (modtime
== statb
.st_mtime
) {
* Now switch to new file.
if ((nf
= Fopen(tempEdit
, "a+")) == NULL
) {