misc bugs, malloc & free
[unix-history] / usr / src / usr.bin / window / error.c
CommitLineData
46285cba 1#ifndef lint
7f49d932 2static char *sccsid = "@(#)error.c 3.2 83/08/16";
46285cba
EW
3#endif
4
5#include "defs.h"
6
46285cba
EW
7static char *filename; /* source file name */
8static struct ww *errwin; /* window for error reporting */
9static int errlineno; /* lineno in errwin */
10static char baderror; /* can't open the error window */
11
bb94cfe3 12#define ERRLINES 10 /* number of lines for errwin */
46285cba
EW
13
14/*VARARGS1*/
15error(fmt, a, b, c, d, e, f, g, h)
16char *fmt;
17{
18 if (filename == 0) {
19 if (terse)
bb94cfe3 20 wwbell();
46285cba 21 else {
bb94cfe3
EW
22 (void) wwprintf(cmdwin, fmt, a, b, c, d, e, f, g, h);
23 (void) wwputs(" ", cmdwin);
46285cba
EW
24 }
25 return;
26 }
27 if (baderror)
28 return;
29 if (errwin == 0) {
30 char buf[512];
31
32 (void) sprintf(buf, "Errors from %s", filename);
bb94cfe3
EW
33 if ((errwin = openiwin(ERRLINES, buf)) == 0) {
34 (void) wwprintf(cmdwin, "Can't open error window. ");
46285cba
EW
35 baderror++;
36 return;
37 }
38 errlineno = 0;
39 }
40 if (errlineno++ > ERRLINES - 4) {
41 waitnl(errwin);
42 errlineno = 0;
43 }
44 if (lineno != 0)
bb94cfe3
EW
45 (void) wwprintf(errwin, "line %d: ", lineno);
46 (void) wwprintf(errwin, fmt, a, b, c, d, e, f, g, h);
7f49d932 47 (void) wwprintf(errwin, "\n");
46285cba
EW
48}
49
50beginerror(fn)
51char *fn;
52{
bb94cfe3
EW
53 filename = malloc((unsigned) strlen(fn) + 1);
54 (void) strcpy(filename, fn);
46285cba
EW
55}
56
57enderror()
58{
59 if (errwin != 0) {
60 waitnl(errwin);
bb94cfe3 61 closeiwin(errwin);
46285cba
EW
62 errwin = 0;
63 }
64 baderror = 0;
fd3dcb0b 65 free(filename);
46285cba
EW
66 filename = 0;
67}