Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 602 lines (532 sloc) 16.166 kb
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
1 /* exmake.c */
2 /* Copyright 1995 by Steve Kirkendall */
3
4
5 #include "elvis.h"
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
6 #ifdef FEATURE_RCSID
7 char id_make[] = "$Id: exmake.c,v 2.43 2003/10/18 04:47:18 steve Exp $";
8 #endif
9
10 #ifdef FEATURE_MAKE
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
11
12 #if USE_PROTOTYPES
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
13 static ELVBOOL parse_errmsg(void);
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
14 static RESULT gotoerr(EXINFO *xinf);
15 static void errprep(void);
16 #endif
17
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
18 ELVBOOL makeflag;
3a9bb556 »
2011-12-10 Import Elvis 2.1_3 (written by Steve Kirkendall)
19
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
20 static char *maybedir; /* directory name extracted from errlist */
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
21 static CHAR *errfile; /* name of file where error was detected */
22 static long errline; /* the line number for an error */
23 static CHAR *errdesc; /* description of the error */
24 static MARK errnext; /* used for stepping through the error list */
25
26
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
27 /* This function tries to parse an error message from the (Elvis error list)
28 * buffer; the errnext variable points to the next line in the buffer.
29 *
30 * Each error message is assumed to fit on a single line. Within the line,
31 * this parser attempts to locate three fields: the source file name, the line
32 * number, and the description of the error.
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
33 *
34 * The line is scanned for words. "Words", for this purpose, are considered
35 * to be contiguous strings of non-whitespace characters other than ':'
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
36 * (unless followed by a backslash) or any of ( ) , " '
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
37 *
38 * If a word happens to be the name of an existing file which is writable
39 * by the user, then it is taken to be the filename. Otherwise, if it contains
40 * only digits then it is taken as the line number.
41 *
42 * After both the filename and line number have been found, the remainder of
43 * the line is taken to be the description... except that any garbage between
44 * the filename/line# and the interesting part of the description will be
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
45 * discarded. Usually, this discarded text consists simply of a colon and some
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
46 * whitespace.
47 *
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
48 * Returns ElvTrue normally, or ElvFalse at the end of the list. If it returns ElvTrue,
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
49 * then the errfile, errline, and errdesc variables will have been set to
50 * reflect anything that was found in the line; if all three are non-NULL
51 * then the line contained an error message.
52 */
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
53 static ELVBOOL parse_errmsg()
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
54 {
55 BUFFER errlist; /* buffer containing err list */
56 CHAR *word; /* dynamically allocated string */
57 CHAR *cp; /* used for scanning line */
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
58 CHAR prevch; /* previous char while scanning */
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
59 DIRPERM perms; /* permissions of a file */
60 long top; /* start of line */
61 WINDOW errwin; /* window which displays errors */
62
63 /* if we aren't already reading the errlist, then start at beginning */
64 if (!errnext)
65 {
66 errlist = buffind(toCHAR(ERRLIST_BUF));
67 if (!errlist)
68 goto NoMoreErrors;
69 errnext = markalloc(errlist, 0);
70 }
71
72 /* if we reached the end of the errlist, then say so */
73 if (markoffset(errnext) >= o_bufchars(markbuffer(errnext)))
74 goto NoMoreErrors;
75
76 /* prepare to start scanning */
77 top = markoffset(errnext);
78 if (errfile)
79 safefree(errfile);
80 if (errdesc)
81 safefree(errdesc);
82 errfile = NULL;
83 errline = 0;
84 errdesc = NULL;
85 word = NULL;
86
87 /* scan the line */
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
88 for (scanalloc(&cp, errnext), prevch = 0;
89 cp && *cp != '\n';
90 prevch = *cp, cp && scannext(&cp))
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
91 {
92 /* is the character legal in a word? */
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
93 if (!elvspace(*cp) && CHARchr("():\"'`,", *cp) == NULL)
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
94 {
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
95 /* work around a quirk of Microsoft's compilers:
96 * if the sequence "/\" is seen, convert it to "/".
97 */
98 if (*cp == '\\' && prevch == '/')
99 continue;
100
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
101 /* character in word */
102 buildCHAR(&word, *cp);
103 continue;
104 }
105 else if (*cp == ':' && word)
106 {
107 /* followed by a backslash? */
108 if (scannext(&cp) && *cp == '\\')
109 {
110 /* both characters are in the word */
111 buildCHAR(&word, (_CHAR_)':');
112 buildCHAR(&word, *cp);
113 continue;
114 }
115
116 /* The ':' isn't in the word, and we shouldn't have
117 * used up the following character yet. Go back if
118 * possible.
119 */
120 if (cp)
121 scanprev(&cp);
122 }
123 else if (errfile && errline && (*cp == '"' && *cp == '\'' && *cp != '`'))
124 {
125 /* quotes are allowed at the start of a description */
126 buildCHAR(&word, *cp);
127 continue;
128 }
129
130 /* if we get here, then we aren't in a word. If no word was
131 * in progress before this character, then we can ignore this
132 * character.
133 */
134 if (!word)
135 continue;
136
137 /* So we must have a word that we need to process. Is it the
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
138 * name of an existing, writable text file?
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
139 */
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
140 if (!errfile
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
141 && (elvalnum(*word) || *word == '/' || *word == '\\')
97d89980 »
2011-12-10 Import Elvis 2.1_4 (written by Steve Kirkendall)
142 && ((perms = dirperm(tochar8(word))) == DIR_READWRITE
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
143 || (o_anyerror && perms == DIR_READONLY))
144 && *ioeol(tochar8(word)) != 'b')
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
145 {
146 /* this is the name of the source file */
147 errfile = word;
148 }
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
149 else if (dirperm(tochar8(word)) == DIR_DIRECTORY)
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
150 {
151 /* this may be the name of a directory where
152 * source files reside */
153 if (maybedir)
154 safefree(maybedir);
155 maybedir = tochar8(word);
156 }
157 else if (!errfile
158 && maybedir
159 && ((perms = dirperm(dirpath(maybedir, tochar8(word))) ) == DIR_READWRITE
160 || (o_anyerror && perms == DIR_READONLY))
161 && *ioeol(dirpath(maybedir, tochar8(word))) != 'b')
162 {
163 errfile = CHARdup(toCHAR(dirpath(maybedir, tochar8(word))));
164 safefree(word);
165 }
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
166 else if (!errline && calcnumber(word))
167 {
168 /* this is the line number */
169 errline = atol(tochar8(word));
170 safefree(word);
171 }
172 else if (errfile && errline &&
173 (!CHARcmp(word + 1, toCHAR("arning"))
174 || !CHARcmp(word + 1, toCHAR("rror"))))
175 {
176 /* skip over error number and other garbage */
177 safefree(word);
178 word = NULL;
179 while (cp && *cp != '\n' &&
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
180 (elvspace(*cp) || elvdigit(*cp) || *cp == ':' || *cp == '-'))
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
181 {
182 scannext(&cp);
183 }
184
185 /* if we hit the end of the line, then we have no
186 * description.
187 */
188 if (!cp || *cp == '\n')
189 {
190 errdesc = CHARdup(toCHAR("unknown error"));
191 }
192
193 /* back up one character, if possible */
194 if (cp)
195 {
196 scanprev(&cp);
197 }
198 }
199 else if (errfile && errline)
200 {
201 /* This word marks the start of the description.
202 * Collect the rest of it.
203 */
204 while (cp && *cp != '\n')
205 {
206 buildCHAR(&word, *cp);
207 scannext(&cp);
208 }
209 break;
210 }
211 else
212 {
213 /* just some word mixed in with filename & line# */
214 safefree(word);
215 }
216
217 /* prepare for next word */
218 word = NULL;
219 }
220
221 /* if we're in a word here, it must be the description */
222 if (word)
223 {
224 assert(!errdesc);
225 errdesc = word;
226 }
227
228 /* if scanning ended at '\n', then move past the '\n' */
229 if (cp && *cp == '\n')
230 {
231 scannext(&cp);
232 }
233
234 /* remember where next line starts */
235 if (cp)
236 {
237 marksetoffset(errnext, markoffset(scanmark(&cp)));
238 }
239 else
240 {
241 marksetoffset(errnext, o_bufchars(markbuffer(errnext)));
242 }
243
244 /* If a window is showing the error list, then highlight the current
245 * line, and leave the cursor at its end.
246 */
247 errwin = winofbuf(NULL, markbuffer(errnext));
248 if (errwin && !errwin->state->acton)
249 {
250 /* move the cursor to the end of the line */
251 marksetoffset(errwin->cursor, markoffset(errnext) - 2);
252 marksetoffset(errwin->state->top, markoffset(errwin->cursor));
253 marksetoffset(errwin->state->bottom, markoffset(errwin->cursor));
254
255 /* select the line, so it appears highlighted */
256 if (!errwin->seltop) errwin->seltop = markdup(errwin->cursor);
257 if (!errwin->selbottom) errwin->selbottom = markdup(errwin->cursor);
258 marksetoffset(errwin->seltop, top);
259 marksetoffset(errwin->selbottom, markoffset(errnext) - 1);
260 errwin->selleft = 0;
261 errwin->selright = INFINITY;
262 errwin->seltype = 'l';
263 }
264
265 /* Set the changepos to end of the message. This is so that if, after
266 * finding one or more messages, the user creates a new window for
267 * viewing the error list, the new window's cursor will start at the
268 * end of the current message instead of at the top of the buffer.
269 */
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
270 markaddoffset(errnext, -1L);
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
271 bufwilldo(errnext, ElvFalse);
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
272 markaddoffset(errnext, 1L);
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
273
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
274 /* return ElvTrue since there was a line for us to parse */
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
275 scanfree(&cp);
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
276 return ElvTrue;
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
277
278 NoMoreErrors:
279 /* if a window is showing the error list, then unhighlight the old
280 * line (if any was highlighted)
281 */
282 errlist = buffind(toCHAR(ERRLIST_BUF));
283 errwin = errlist ? winofbuf(NULL, errlist) : NULL;
284 if (errwin && !errwin->state->acton)
285 {
286 /* leave the cursor after the last error message */
287 if (o_bufchars(errlist) > 2)
288 marksetoffset(errwin->cursor, o_bufchars(errlist) - 2);
289 else
290 marksetoffset(errwin->cursor, 0L);
291 marksetoffset(errwin->state->top, markoffset(errwin->cursor));
292 marksetoffset(errwin->state->bottom, markoffset(errwin->cursor));
293
294 /* unselect the line, so nothing appears highlighted */
295 if (errwin->seltop)
296 {
297 assert(errwin->selbottom);
298 markfree(errwin->seltop);
299 markfree(errwin->selbottom);
300 errwin->seltop = errwin->selbottom = NULL;
301 }
302
303 /* make sure the window will be redrawn */
304 errwin->di->logic = DRAW_CHANGED;
305 }
306
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
307 return ElvFalse;
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
308 }
309
310
311 /* This function moves the cursor to the next error that was detected, and
312 * outputs an informational line describing the error. This function is
313 * called by both ex_errlist() and ex_make().
314 */
315 static RESULT gotoerr(xinf)
316 EXINFO *xinf;
317 {
318 BUFFER blamebuf;
319 long blameline;
320 WINDOW errwin;
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
321 WINDOW blamewin;
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
322
323 /* if there is a window showing the error buffer, then search forward
324 * from its cursor. (Else search forward from end of previous error.)
325 */
326 errwin = (errnext ? winofbuf(NULL, markbuffer(errnext)) : NULL);
327 if (errwin)
328 marksetoffset(errnext, markoffset(errwin->cursor));
329
330 /* parse lines from the errlist buffer until we find an error message */
331 do
332 {
333 if (!parse_errmsg())
334 {
335 msg(MSG_ERROR, "no more errors");
336 return RESULT_ERROR;
337 }
338 } while (!errfile || !errline || !errdesc);
339
340 /* load (if necessary) the file where error was detected. */
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
341 blamebuf = bufload(NULL, tochar8(errfile), ElvFalse);
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
342 assert(blamebuf != NULL);
343
344 /* figure out which line the cursor should be left on, taking into
345 * account the fact that lines may have been inserted/deleted since
346 * the errlist was created.
347 */
348 blameline = errline + o_buflines(blamebuf) - o_errlines(blamebuf);
349 if (blameline < 1)
350 blameline = 1;
351 else if (blameline > o_buflines(blamebuf))
352 blameline = o_buflines(blamebuf);
353
354 /* move the cursor to the erroneous line of the new buffer */
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
355 blamewin = winofbuf(NULL, blamebuf);
356 if (blamewin && markbuffer(xinf->window->cursor) != blamebuf)
357 {
358 /* another window is already showing this buffer -- switch
359 * to that window, leaving this window unchanged.
360 */
361 if (gui->focusgw)
362 {
363 (*gui->focusgw)(blamewin->gw);
364 }
365 else
366 {
367 eventfocus(blamewin->gw, ElvTrue);
368 }
369 marksetoffset(blamewin->cursor,
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
370 lowline(bufbufinfo(blamebuf), blameline));
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
371 }
372 else
373 {
374 xinf->newcurs = markalloc(blamebuf,
375 lowline(bufbufinfo(blamebuf), blameline));
376 }
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
377
378 /* describe the error */
379 if (o_buflines(blamebuf) == o_errlines(blamebuf))
380 {
381 msg(MSG_INFO, "[dS]line $1: $2", errline, errdesc);
382 }
383 else if (o_buflines(blamebuf) < o_errlines(blamebuf))
384 {
385 msg(MSG_INFO, "[ddS]line $1-$2: $3", errline,
386 o_errlines(blamebuf) - o_buflines(blamebuf), errdesc);
387 }
388 else
389 {
390 msg(MSG_INFO, "[ddS]line $1+$2: $3", errline,
391 o_buflines(blamebuf) - o_errlines(blamebuf), errdesc);
392 }
393
394 return RESULT_COMPLETE;
395 }
396
397
398 /* This function does some preparatory steps towards creating a new errlist */
399 static void errprep()
400 {
401 BUFFER buf;
402 MARKBUF top;
403 MARKBUF end;
404
405 /* find the "Elvis error list" buffer */
406 buf = buffind(toCHAR(ERRLIST_BUF));
407 assert(buf != NULL);
408
409 /* if it has old text in it, discard that text */
410 if (o_bufchars(buf) > 0)
411 {
412 bufreplace(marktmp(top, buf, 0),
413 marktmp(end, buf, o_bufchars(buf)),
414 NULL, 0);
415 }
416
417 /* reset the "errnext" mark so we start at the top of the buffer */
418 if (errnext)
419 {
420 markfree(errnext);
421 errnext = NULL;
422 }
423
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
424 /* clobber the maybedir */
425 if (maybedir)
426 {
427 safefree(maybedir);
428 maybedir = NULL;
429 }
430
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
431 /* remember how many lines each buffer has now */
432 for (buf = NULL; (buf = buflist(buf)) != NULL; )
433 {
434 o_errlines(buf) = o_buflines(buf);
435 }
436 }
437
438
439 RESULT ex_errlist(xinf)
440 EXINFO *xinf;
441 {
442 BUFFER errbuf;
443 WINDOW errwin;
444 MARKBUF from;
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
445 ELVBOOL retval;
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
446
447 assert(xinf->command == EX_ERRLIST);
448
449 /* was a filename given? */
450 if (xinf->nfiles > 0 || xinf->rhs)
451 {
452 /* prepare to create a new error list */
453 errprep();
454
455 /* load the buffer from the named file */
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
456 errbuf = bufalloc(toCHAR(ERRLIST_BUF), 0, ElvTrue);
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
457 retval = bufread(marktmp(from, errbuf, 0), xinf->rhs ? tochar8(xinf->rhs) : xinf->file[0]);
458
459 /* turn off the "modified" flag on the (Elvis error list) buf */
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
460 o_modified(errbuf) = ElvFalse;
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
461
462 /* if there are any windows showing this buffer, move its cursor
463 * to offset 0
464 */
465 for (errwin = NULL; (errwin = winofbuf(errwin, errbuf)) != NULL; )
466 {
467 marksetoffset(errwin->cursor, 0L);
468 }
469
470 /* if failed to read errors, then return RESULT_ERROR */
471 if (!retval)
472 return RESULT_ERROR;
473 }
474
475 /* move the cursor to the next error */
476 return gotoerr(xinf);
477 }
478
479
480 RESULT ex_make(xinf)
481 EXINFO *xinf;
482 {
483 CHAR *args[3];/* arguments to calculate() expression */
484 CHAR *str; /* shell command string */
485 CHAR *io; /* buffer for reading chars from program */
486 int nio; /* number of characters read */
487 MARKBUF start, end;/* ends of errlist buffer, used for appending */
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
488 ELVBOOL origrefresh;
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
489 long origpollfreq;
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
490 BUFFER buf;
491 WINDOW errwin; /* window which is displaying errors */
492
493 assert(xinf->command == EX_MAKE || xinf->command == EX_CC);
494
495 /* if any user buffer was modified & not saved, then complain unless
496 * '!' given.
497 */
498 if (!xinf->bang)
499 {
500 for (buf = NULL; (buf = buflist(buf)) != NULL; )
501 {
502 if (!o_internal(buf) && o_modified(buf))
503 {
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
504 if (!o_autowrite)
505 {
506 msg(MSG_ERROR, "[S]$1 modified, not saved", o_filename(buf) ? o_filename(buf) : o_bufname(buf));
507 return RESULT_ERROR;
508 }
509
510 /* write the buffer */
511 if (!bufsave(buf, ElvFalse, ElvFalse))
512 /* error message already given */
513 return RESULT_ERROR;
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
514 }
515 }
516 }
517
518 /* create the shell command line that we'll be running */
519 buf = markbuffer(&xinf->defaddr);
520 args[0] = (xinf->rhs ? xinf->rhs : toCHAR(""));
521 args[1] = (o_filename(buf) ? o_filename(buf) : toCHAR(""));
522 args[2] = NULL;
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
523 str = calculate(xinf->command==EX_CC ? o_cc(buf) : o_make(buf), args, CALC_MSG);
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
524 if (!str)
525 {
526 /* error message already given */
527 return RESULT_ERROR;
528 }
529
530 /* output the command name, so the user knows what's happening */
531 origrefresh = o_exrefresh;
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
532 o_exrefresh = ElvTrue;
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
533 origpollfreq = o_pollfrequency;
534 o_pollfrequency = 1;
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
535 (void)guipoll(ElvTrue);
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
536 drawextext(xinf->window, str, (int)CHARlen(str));
537 drawextext(xinf->window, toCHAR("\n"), 1);
538
539 /* prepare to create the new errlist */
540 errprep();
541
542 /* run the program, and read its stdout/stderr. Write this to the
543 * window as ex output text, and also store it in the errlist buffer.
544 */
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
545 if (!prgopen(tochar8(str), ElvFalse, ElvTrue) || !prggo())
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
546 {
547 /* failed -- error message already given */
548 o_exrefresh = origrefresh;
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
549 o_pollfrequency = origpollfreq;
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
550 return RESULT_ERROR;
551 }
552 buf = buffind(toCHAR(ERRLIST_BUF));
553 assert(buf != NULL);
554 if (o_bufchars(buf) > 0)
555 {
556 bufreplace(marktmp(start, buf, 0), marktmp(end, buf, o_bufchars(buf)), NULL, 0);
557 }
558 io = (CHAR *)safealloc(1024, sizeof(CHAR));
559 (void)marktmp(end, buf, 0);
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
560 while (!guipoll(ElvFalse) && (nio = prgread(io, 1024)) > 0)
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
561 {
562 /* show it on the screen */
563 drawextext(xinf->window, io, nio);
564
565 /* append it to the buffer */
566 bufreplace(&end, &end, io, nio);
567 markaddoffset(&end, nio);
568 }
569 (void)prgclose();
570 safefree(io);
571 o_exrefresh = origrefresh;
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
572 o_pollfrequency = origpollfreq;
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
573
574 /* turn off the "modified" flag on the (Elvis error list) buf */
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
575 o_modified(buf) = ElvFalse;
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
576
577 /* if there is a window showing this buffer, move its cursor
578 * to offset 0
579 */
580 for (errwin = NULL; (errwin = winofbuf(errwin, buf)) != NULL; )
581 {
582 marksetoffset(errwin->cursor, 0L);
583 }
584
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
585 #if 0
3a9bb556 »
2011-12-10 Import Elvis 2.1_3 (written by Steve Kirkendall)
586 /* delay the first error message until after <Enter> */
587 if (eventcounter > 5)
588 {
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
589 makeflag = ElvTrue;
590 morehit = ElvFalse;
3a9bb556 »
2011-12-10 Import Elvis 2.1_3 (written by Steve Kirkendall)
591 }
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
592 #else
593 /* don't wait for the user to hit <Enter> after this */
594 xinf->window->di->logic = DRAW_SCRATCH;
595 xinf->window->di->drawstate = DRAW_VISUAL;
596 #endif
3a9bb556 »
2011-12-10 Import Elvis 2.1_3 (written by Steve Kirkendall)
597
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
598 /* move the cursor to the first error */
599 return gotoerr(xinf);
600 }
9f1c6f0f »
2011-12-10 Import Elvis 2.2_0 (written by Steve Kirkendall)
601 #endif /* FEATURE_MAKE */
Something went wrong with that request. Please try again.