]>
diplodocus.org Git - nmh/blob - docs/historical/mh-nov-1983/subs/m_edit.c
12 m_edit(ed
, file
, use
, altmsg
)
13 char **ed
, *file
, *altmsg
;
16 /* Exec editor. Normal exit returns 0.
17 * To abort, returns -1. To try again, returns -2
28 struct {char lobyte
, hibyte
;} statby
;
31 if(!reedit
) { /* set initial editor */
32 if(!*ed
&& (*ed
= m_find("editor")) == NULL
)
35 if(!*ed
) { /* no explicit editor */
37 cp
= rindex(*ed
, '/');
40 cp
= concat(cp
, "-next", 0);
41 if((cp
= m_find(cp
)) != NULL
)
44 intr
= (int) signal(SIGINT
, SIG_IGN
);
45 if((pid
= fork()) == 0) {
48 link(altmsg
, "@"); /* An easy handle on cur msg */
52 signal(SIGINT
, (int (*)()) intr
);
53 execlp(*ed
, *ed
, file
, 0);
54 fprintf(stderr
, "Can't exec the editor: ");
55 perror(*ed
); done(-1);
56 } else if(pid
== -1) {
57 fprintf(stderr
, "No forks!\n");
61 while((wpid
= wait(&status
)) != -1 && wpid
!= pid
) ;
62 signal(SIGINT
, (int (*)()) intr
);
64 if((status
.statby
.hibyte
== -1) || /* Can't exec editor */
65 (reedit
&& !status
.statby
.lobyte
)) { /*2nd edit.Aborted by user*/
69 fprintf(stderr
, "[%s aborted--%s ", invo_name(), file
);
70 if(!use
&& status
.statby
.hibyte
) { /* edit aborted by user */
72 fprintf(stderr
, "deleted]\n");
73 } else /* 'use' or system abort */
74 fprintf(stderr
, "preserved]\n");
80 if(altmsg
&& !mp
->msgflags
&READONLY
) {
82 if(stbuf
.st_nlink
== 1) /*@'s been edited by Ned*/
83 if(unlink(altmsg
) == -1 || link("@", altmsg
) == -1){
84 fprintf(stderr
, "Can't update %s from @ file!\n",altmsg
);
92 unlink("@"); /* Remove this extra link */