xref: /csrg-svn/usr.bin/window/error.c (revision 33514)
118737Sedward /*
2*33514Sbostic  * Copyright (c) 1983 Regents of the University of California.
3*33514Sbostic  * All rights reserved.
4*33514Sbostic  *
5*33514Sbostic  * Redistribution and use in source and binary forms are permitted
6*33514Sbostic  * provided that this notice is preserved and that due credit is given
7*33514Sbostic  * to the University of California at Berkeley. The name of the University
8*33514Sbostic  * may not be used to endorse or promote products derived from this
9*33514Sbostic  * software without specific prior written permission. This software
10*33514Sbostic  * is provided ``as is'' without express or implied warranty.
1118737Sedward  */
1218737Sedward 
13*33514Sbostic #ifndef lint
14*33514Sbostic static char sccsid[] = "@(#)error.c	3.13 (Berkeley) 02/21/88";
15*33514Sbostic #endif /* not lint */
16*33514Sbostic 
1714194Sedward #include "defs.h"
1815580Sedward #include "value.h"
1915580Sedward #include "context.h"
2016309Sedward #include "char.h"
2114194Sedward 
2214418Sedward #define ERRLINES 10			/* number of lines for errwin */
2314194Sedward 
2414194Sedward /*VARARGS1*/
2514194Sedward error(fmt, a, b, c, d, e, f, g, h)
2614194Sedward char *fmt;
2714194Sedward {
2816445Sedward 	register struct context *x;
2915681Sedward 	register struct ww *w;
3015681Sedward 
3116445Sedward 	for (x = &cx; x != 0 && x->x_type != X_FILE; x = x->x_link)
3216445Sedward 		;
3316445Sedward 	if (x == 0) {
3414194Sedward 		if (terse)
3516313Sedward 			wwbell();
3614194Sedward 		else {
3716121Sedward 			wwprintf(cmdwin, fmt, a, b, c, d, e, f, g, h);
3816121Sedward 			wwputs("  ", cmdwin);
3914194Sedward 		}
4014194Sedward 		return;
4114194Sedward 	}
4216445Sedward 	if (x->x_noerr)
4314194Sedward 		return;
4416445Sedward 	if ((w = x->x_errwin) == 0) {
4514194Sedward 		char buf[512];
4614194Sedward 
4716445Sedward 		(void) sprintf(buf, "Errors from %s", x->x_filename);
4816445Sedward 		if ((w = x->x_errwin = openiwin(ERRLINES, buf)) == 0) {
4916121Sedward 			wwputs("Can't open error window.  ", cmdwin);
5016445Sedward 			x->x_noerr = 1;
5114194Sedward 			return;
5214194Sedward 		}
5314194Sedward 	}
5415857Sedward 	if (more(w, 0) == 2) {
5516445Sedward 		x->x_noerr = 1;
5615857Sedward 		return;
5715857Sedward 	}
5816445Sedward 	wwprintf(w, "line %d: ", x->x_lineno);
5916121Sedward 	wwprintf(w, fmt, a, b, c, d, e, f, g, h);
6016121Sedward 	wwputc('\n', w);
6114194Sedward }
6214194Sedward 
6315580Sedward err_end()
6414194Sedward {
6516445Sedward 	if (cx.x_type == X_FILE && cx.x_errwin != 0) {
6615857Sedward 		if (!cx.x_noerr)
6715857Sedward 			waitnl(cx.x_errwin);
6815580Sedward 		closeiwin(cx.x_errwin);
6915580Sedward 		cx.x_errwin = 0;
7014194Sedward 	}
7114194Sedward }
72