* 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.10 (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.
int (*sigcont
)() = signal(SIGCONT
, SIG_DFL
);
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
);
(void) signal(SIGCONT
, sigcont
);
* 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 EDITOR, 'v' for VISUAL.
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 (ferror(nf
) || fclose(nf
) < 0) {
if ((edit
= value(type
== 'e' ? "EDITOR" : "VISUAL")) == NOSTR
)
edit
= type
== 'e' ? EDITOR
: VISUAL
;
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
) {