2 Proprietary Rand Corporation
, 1981.
3 Further distribution of
this software
4 subject to the terms of the Rand
17 m_edit(ed
, file
, use
, altmsg
)
18 char **ed
, *file
, *altmsg
;
21 /* Exec editor. Normal exit returns 0.
22 * To abort, returns -1. To try again, returns -2
34 if(!reedit
) { /* set initial editor */
35 if(!*ed
&& (*ed
= m_find("editor")) == NULL
)
38 if(!*ed
) { /* no explicit editor */
40 cp
= rindex(*ed
, '/');
43 cp
= concat(cp
, "-next", 0);
44 if((cp
= m_find(cp
)) != NULL
)
47 intr
= signal(SIGINT
, SIG_IGN
);
48 if((pid
= fork()) == 0) {
51 VOID
link(altmsg
, "@"); /* An easy handle on cur msg */
52 putenv("editalt", altmsg
);
56 VOID
signal(SIGINT
, intr
);
57 execlp(*ed
, r1bindex(*ed
, '/'), file
, 0);
58 fprintf(stderr
, "Can't exec the editor: ");
59 perror(*ed
); done(-1);
60 } else if(pid
== -1) {
61 fprintf(stderr
, "No forks!\n");
65 while((wpid
= wait(&status
)) != -1 && wpid
!= pid
) ;
66 VOID
signal(SIGINT
, intr
);
68 if((status
&0177400 == 0177400) || /* Can't exec editor */
69 (reedit
&& (status
&0377) == 0)) { /*2nd edit.Aborted by user*/
73 fprintf(stderr
, "[%s aborted--%s ", invo_name
, file
);
74 if(!use
&& (status
&017740)) { /* edit aborted by user */
76 fprintf(stderr
, "deleted]\n");
77 } else /* 'use' or system abort */
78 fprintf(stderr
, "preserved]\n");
84 if(altmsg
&& !mp
->msgflags
&READONLY
) {
85 VOID
stat("@", &stbuf
);
86 if(stbuf
.st_nlink
== 1) /*@'s been edited by Ned*/
87 if(unlink(altmsg
) == -1 || link("@", altmsg
) == -1){
88 fprintf(stderr
, "Can't update %s from @ file!\n",altmsg
);
96 VOID
unlink("@"); /* Remove this extra link */