pci: don't do sanity check for missing pci bus, the check can misfire.
[minix.git] / commands / elle / eemake.c
blobc3420bfde655c6ccd3ad77ca49214f77f38f9138
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.
5 */
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
10 * configuration.
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.
25 #include "elle.h"
27 #if !(IMAGEN) /* Only with IMAGEN config for now */
28 f_xucmd() {}
29 f_make() {}
30 f_nxterr() {}
31 #else
33 #include <stdio.h>
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" */
43 f_xucmd()
45 make_or_unix_cmd(0);
48 /* EFUN: "Execute Make" */
49 f_make()
51 make_or_unix_cmd(1);
54 /* EFUN: "Find Next Error" */
55 f_nxterr()
57 register struct sbstr *sb;
58 register char *cp;
59 register int c;
60 char file[64], line[32];
61 #ifdef ONEWINDOW
62 char msg[512];
63 #endif
64 chroff linedot;
65 int lineno;
66 register int len;
68 sel_execbuf();
69 if (! fresh_make)
70 { e_go(last_error_BOL);
71 e_gonl();
73 else
74 { fresh_make = 0;
75 e_gobob();
76 last_error_BOL = e_dot();
79 /* Looking for `"file", line n: msg' */
80 if (! e_search("\", line ", 8, 0))
81 goto failed;
82 linedot = e_dot();
83 e_gobol(); /* Found something, get to BOL */
84 if (e_getc() != '"')
85 goto failed; /* Insist on beginning "file" */
86 cp = file; /* Pick up filename */
87 while ((c = e_getc()) != '"')
88 *cp++ = c;
89 *cp = 0;
90 e_go(linedot); /* Back to after "line " */
91 cp = line;
92 while ((c = e_getc()) >= '0' && c <= '9')
93 *cp++ = c;
94 *cp = 0;
95 lineno = atoi(line); /* Pick up line number */
96 #ifdef ONEWINDOW
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)
101 { if (c == '\t')
102 len = (len + 8) & ~07;
103 else if (c < ' ' || c > 0176)
104 len += 2;
105 else
106 ++len;
107 *cp++ = c;
109 *cp = 0;
110 if (len > MSGLENGTH)
111 strcat(msg, "...");
112 #ifdef DEBUG
113 say("file ");
114 saytoo(file);
115 saytoo(", line ");
116 saytoo(line);
117 saytoo(", msg: ");
118 sayntoo(msg);
119 #else
120 say(line);
121 saytoo(": ");
122 sayntoo(msg);
123 #endif /*DEBUG*/
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 */
128 exp = 0;
129 f_newwin();
130 upd_wind(0);
131 #endif /*ONEWINDOW*/
133 /* Now, visit the given file and line */
134 #ifdef ONEWINDOW
135 #else
136 f_othwind(); /* To other window */
137 #endif
138 find_file(file);
139 f_gobeg();
140 down_line(lineno - 1);
141 #ifdef READJUST /* NAW */
142 exp_p = 1;
143 exp = cur_win->w_ht / 4; /* Adjust how we look at "error" */
144 f_newwin();
145 #endif /*READJUST*/
146 return;
148 failed: ding("No more errors!");
149 fresh_make = 1; /* Fake-out: pretend starting over */
150 return;
154 /* Do the "cmd" and put its output in the Execution buffer */
155 do_exec(cmd, nicely)
156 char *cmd;
157 int nicely;
159 register int n;
160 int status, res, pid, fd[2];
161 char nicecmd[256];
162 char pipebuff[512];
163 struct buffer *b;
165 b = cur_buf;
166 sel_execbuf(); /* Get our execution buffer up */
167 ed_reset(); /* Clear it out */
168 fresh_make = 1;
169 upd_wind(0);
170 if (nicely)
171 sayntoo(" ...starting up...");
172 else
173 sayntoo(" ...starting up (nasty person)...");
174 pipe(fd);
175 switch (pid = fork())
177 case -1:
178 /* Fork failed, in parent */
179 ding("Cannot fork!?!");
180 break;
182 case 0: /* In child */
183 for (n = 0; n < 20; ++n)
184 if (n != fd[0] && n != fd[1])
185 close(n);
186 open("/dev/null", 0); /* Give ourselves empty stdin */
187 dup(fd[1]);
188 dup(fd[1]); /* stdout, stderr out to pipe */
189 close(fd[1]); /* Close the pipe itself */
190 close(fd[0]);
191 if (nicely)
192 { strcpy(nicecmd, "nice -4 ");
193 strcat(nicecmd, cmd);
194 execl("/bin/sh", "sh", "-c", nicecmd, 0);
196 else
197 execl("/bin/sh", "sh", "-c", cmd, 0);
198 write(1, "Cannot execute!", 15);
199 _exit(-1);
200 break;
202 default:
203 /* Parent */
204 close(fd[1]); /* Close the output direction */
205 while ((n = read(fd[0], pipebuff, sizeof(pipebuff))) > 0)
206 { ed_nsins(pipebuff, n);
207 upd_wind(0);
208 saynow("Chugging along...");
210 close(fd[0]);
211 while ((res = wait(&status)) != pid && res != -1)
212 ; /* Wait for this fork to die */
213 f_bufnotmod(); /* Buffer is fresh */
214 saynow("Done!");
215 break;
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)
225 int domake;
227 #if APOLLO
228 register int nicely = exp == 16; /* modification for apollo */
229 #else
230 register int nicely = exp != 16;
231 #endif /*-APOLLO*/
232 register char *reply, *cmd = 0;
234 if (domake) /* If "make"-style, */
235 { int savp = exp_p;
236 exp_p = 1;
237 f_savefiles(); /* write modified files quietly */
238 exp_p = savp;
240 if (exp_p || ! domake)
241 { /* Arg given make, or Unix command */
242 reply = ask((! domake) ? "Unix command: " : "Command: ");
243 if (! reply)
244 return;
245 if (*reply == 0)
246 { if (have_last_make_cmd)
247 cmd = &last_make_cmd[0];
248 else
249 { chkfree(reply);
250 ding("No previous command!");
251 return;
254 else
255 cmd = reply;
256 if (cmd != &last_make_cmd[0]) /* Update last command */
257 strcpy(last_make_cmd, cmd);
258 have_last_make_cmd = 1;
259 say("Command: ");
260 sayntoo(cmd);
261 do_exec(cmd, nicely);
262 chkfree(reply);
264 else if (have_last_make_cmd)
265 { say("Command: ");
266 sayntoo(last_make_cmd);
267 do_exec(last_make_cmd, nicely);
269 else
270 { saynow("Command: make");
271 do_exec("make", nicely);
275 sel_execbuf()
276 { if(!exec_buf)
277 { /* Make execution buffer; don't let anyone kill it */
278 exec_buf = make_buf("Execution");
279 exec_buf->b_flags |= B_PERMANENT;
281 popto_buf(exec_buf);
284 /* Utility: pop the given buffer to a window, getting into 2-window mode */
285 popto_buf(b)
286 register struct buffer *b;
288 /* See if we already have this buffer in a visible window */
289 if (b == cur_win->w_buf)
290 { if (oth_win == 0)
291 { f_2winds();
292 f_othwind(); /* Get back to our window */
295 else if (oth_win != 0 && b == oth_win->w_buf)
296 f_othwind();
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 */
302 else
303 { f_othwind(); /* Get to other window */
304 sel_buf(b); /* and select our buffer */
308 #endif /*IMAGEN*/