1 /* ELLE - Copyright 1982, 1985, 1987 by Ken Harrenstien, SRI International
2 * This software is quasi-public; it may be used freely with
3 * like software, but may NOT be sold or made part of licensed
4 * products without permission of the author.
6 /* EEMAKE - IMAGEN configuration functions for interfacing to "make".
7 * Written by (I think) Chris Ryland at IMAGEN, who also
8 * wrote other functions scattered through ELLE. These are either
9 * conditionalized or are commented as being derived from the IMAGEN
12 * KLH: An attempt has been made to keep these routines updated as ELLE
13 * changed, but their workings cannot be guaranteed.
18 * eemake: "make" (and other program) support
20 * Next-error depends on programs writing error messages of the form:
21 * "file", line n: message
22 * which is a de facto standard, at least in some worlds.
27 #if !(IMAGEN) /* Only with IMAGEN config for now */
35 struct buffer
*exec_buf
; /* Ptr to "Execution" buffer */
36 /* Only external ref is from e_buff.c */
38 #define MSGLENGTH (scr_wid - 11) /* Max length of message */
39 int fresh_make
= 1; /* Fresh Execution buffer contents */
40 chroff last_error_BOL
; /* Dot for last-error's BOL */
42 /* EFUN: "Execute Unix Command" */
48 /* EFUN: "Execute Make" */
54 /* EFUN: "Find Next Error" */
57 register struct sbstr
*sb
;
60 char file
[64], line
[32];
70 { e_go(last_error_BOL
);
76 last_error_BOL
= e_dot();
79 /* Looking for `"file", line n: msg' */
80 if (! e_search("\", line ", 8, 0))
83 e_gobol(); /* Found something, get to BOL */
85 goto failed
; /* Insist on beginning "file" */
86 cp
= file
; /* Pick up filename */
87 while ((c
= e_getc()) != '"')
90 e_go(linedot
); /* Back to after "line " */
92 while ((c
= e_getc()) >= '0' && c
<= '9')
95 lineno
= atoi(line
); /* Pick up line number */
97 cp
= msg
; /* Now get rest of line to msg */
98 len
= 0; /* But keep length <= MSGLENGTH */
99 e_getc(); /* Go past purported space */
100 while ((c
= e_getc()) != LF
&& c
!= EOF
&& len
<= MSGLENGTH
)
102 len
= (len
+ 8) & ~07;
103 else if (c
< ' ' || c
> 0176)
124 #else /* -ONEWINDOW */
125 f_begline(); /* Get to start of line */
126 last_error_BOL
= e_dot(); /* Remember this position */
127 exp_p
= 1; /* Make this the new top line */
133 /* Now, visit the given file and line */
136 f_othwind(); /* To other window */
140 down_line(lineno
- 1);
141 #ifdef READJUST /* NAW */
143 exp
= cur_win
->w_ht
/ 4; /* Adjust how we look at "error" */
148 failed
: ding("No more errors!");
149 fresh_make
= 1; /* Fake-out: pretend starting over */
154 /* Do the "cmd" and put its output in the Execution buffer */
160 int status
, res
, pid
, fd
[2];
166 sel_execbuf(); /* Get our execution buffer up */
167 ed_reset(); /* Clear it out */
171 sayntoo(" ...starting up...");
173 sayntoo(" ...starting up (nasty person)...");
175 switch (pid
= fork())
178 /* Fork failed, in parent */
179 ding("Cannot fork!?!");
182 case 0: /* In child */
183 for (n
= 0; n
< 20; ++n
)
184 if (n
!= fd
[0] && n
!= fd
[1])
186 open("/dev/null", 0); /* Give ourselves empty stdin */
188 dup(fd
[1]); /* stdout, stderr out to pipe */
189 close(fd
[1]); /* Close the pipe itself */
192 { strcpy(nicecmd
, "nice -4 ");
193 strcat(nicecmd
, cmd
);
194 execl("/bin/sh", "sh", "-c", nicecmd
, 0);
197 execl("/bin/sh", "sh", "-c", cmd
, 0);
198 write(1, "Cannot execute!", 15);
204 close(fd
[1]); /* Close the output direction */
205 while ((n
= read(fd
[0], pipebuff
, sizeof(pipebuff
))) > 0)
206 { ed_nsins(pipebuff
, n
);
208 saynow("Chugging along...");
211 while ((res
= wait(&status
)) != pid
&& res
!= -1)
212 ; /* Wait for this fork to die */
213 f_bufnotmod(); /* Buffer is fresh */
217 f_othwind(); /* Back to other window */
218 chg_buf(b
); /* Back to original buffer */
221 char last_make_cmd
[256]; /* Last Unix/make command */
222 int have_last_make_cmd
= 0;
224 make_or_unix_cmd(domake
)
228 register int nicely
= exp
== 16; /* modification for apollo */
230 register int nicely
= exp
!= 16;
232 register char *reply
, *cmd
= 0;
234 if (domake
) /* If "make"-style, */
237 f_savefiles(); /* write modified files quietly */
240 if (exp_p
|| ! domake
)
241 { /* Arg given make, or Unix command */
242 reply
= ask((! domake
) ? "Unix command: " : "Command: ");
246 { if (have_last_make_cmd
)
247 cmd
= &last_make_cmd
[0];
250 ding("No previous command!");
256 if (cmd
!= &last_make_cmd
[0]) /* Update last command */
257 strcpy(last_make_cmd
, cmd
);
258 have_last_make_cmd
= 1;
261 do_exec(cmd
, nicely
);
264 else if (have_last_make_cmd
)
266 sayntoo(last_make_cmd
);
267 do_exec(last_make_cmd
, nicely
);
270 { saynow("Command: make");
271 do_exec("make", nicely
);
277 { /* Make execution buffer; don't let anyone kill it */
278 exec_buf
= make_buf("Execution");
279 exec_buf
->b_flags
|= B_PERMANENT
;
284 /* Utility: pop the given buffer to a window, getting into 2-window mode */
286 register struct buffer
*b
;
288 /* See if we already have this buffer in a visible window */
289 if (b
== cur_win
->w_buf
)
292 f_othwind(); /* Get back to our window */
295 else if (oth_win
!= 0 && b
== oth_win
->w_buf
)
297 else if (oth_win
== 0)
298 { /* One window mode */
299 f_2winds(); /* Get two, get into second */
300 sel_buf(b
); /* Select our new buffer */
303 { f_othwind(); /* Get to other window */
304 sel_buf(b
); /* and select our buffer */