* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)edit.c 5.15 (Berkeley) 6/25/90";
* 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
) {