4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1996 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
32 * University Copyright- Copyright (c) 1982, 1986, 1988
33 * The Regents of the University of California
36 * University Acknowledgment- Portions of this document are derived from
37 * software developed by the University of California, Berkeley, and its
41 #pragma ident "%Z%%M% %I% %E% SMI"
48 * mailx -- a modified version of a University of California at Berkeley
51 * Perform message editing functions.
54 static void edit1(int *msgvec
, char *ed
);
57 * Edit a message list.
65 if ((edname
= value("EDITOR")) == NOSTR
|| *edname
== '\0')
67 edit1(msgvec
, edname
);
72 * Invoke the visual editor on a message list.
80 if ((edname
= value("VISUAL")) == NOSTR
|| *edname
== '\0')
82 edit1(msgvec
, edname
);
87 * Edit a message by writing the message into a funnily-named file
88 * (which should not exist) and forking an editor on it.
89 * We get the editor from the stuff above.
93 edit1(int *msgvec
, char *ed
)
95 register int c
, lastc
= '\n';
97 int *ip
, mesg
, blank
= 1;
99 void (*sigint
)(int), (*sigquit
)(int);
108 * Set signals; locate editor.
111 sigint
= sigset(SIGINT
, SIG_IGN
);
112 sigquit
= sigset(SIGQUIT
, SIG_IGN
);
116 * Deal with each message to be edited . . .
119 for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++) {
122 mp
= &message
[mesg
-1];
125 if (!access(tempZedit
, 2)) {
126 printf(gettext("%s: file exists\n"), tempZedit
);
131 * Copy the message into the edit file.
134 if ((fd
= open(tempZedit
, O_RDWR
|O_CREAT
|
135 O_EXCL
, 0600)) < 0 ||
136 (obuf
= fdopen(fd
, "w")) == NULL
) {
140 if (msend(mp
, obuf
, 0, fputs
) < 0) {
143 removefile(tempZedit
);
150 removefile(tempZedit
);
156 * If we are in read only mode, make the
157 * temporary message file readonly as well.
161 chmod(tempZedit
, 0400);
164 * Fork/execl the editor on the edit file.
167 if (stat(tempZedit
, &statb
) < 0)
170 modtime
= statb
.st_mtime
;
172 if (pid
== (pid_t
)-1) {
174 removefile(tempZedit
);
179 if (sigint
!= SIG_IGN
)
180 sigset(SIGINT
, SIG_DFL
);
181 if (sigquit
!= SIG_IGN
)
182 sigset(SIGQUIT
, SIG_DFL
);
183 execlp(ed
, ed
, tempZedit
, (char *)0);
187 while (wait(&mesg
) != pid
)
191 * If in read only mode, just remove the editor
192 * temporary and return.
196 removefile(tempZedit
);
201 * Now copy the message to the end of the
205 if (stat(tempZedit
, &statb
) < 0) {
209 if (modtime
== statb
.st_mtime
) {
210 removefile(tempZedit
);
213 if ((ibuf
= fopen(tempZedit
, "r")) == NULL
) {
215 removefile(tempZedit
);
218 removefile(tempZedit
);
219 fseek(otf
, (long) 0, 2);
221 mp
->m_flag
|= MODIFY
;
225 while ((c
= getc(ibuf
)) != EOF
) {
228 blank
= lastc
== '\n';
249 printf("\n%s\n", gettext(
250 "*** Message content is not printable: pipe to command or save to a file ***"));
255 * Restore signals and return.
259 sigset(SIGINT
, sigint
);
260 sigset(SIGQUIT
, sigquit
);