]> git.saurik.com Git - apple/shell_cmds.git/blob - window/error.c
6c82e23d62a847f5f21ab9c299169cbcaacb3ef2
[apple/shell_cmds.git] / window / error.c
1 /* $NetBSD: error.c,v 1.4 1997/11/21 08:36:00 lukem Exp $ */
2
3 /*
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Edward Wang at The University of California, Berkeley.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 #ifndef lint
41 #if 0
42 static char sccsid[] = "@(#)error.c 8.1 (Berkeley) 6/6/93";
43 #else
44 __RCSID("$NetBSD: error.c,v 1.4 1997/11/21 08:36:00 lukem Exp $");
45 #endif
46 #endif /* not lint */
47
48 #include "defs.h"
49 #include "context.h"
50 #include "char.h"
51
52 #define ERRLINES 10 /* number of lines for errwin */
53
54 void
55 #if __STDC__
56 error(const char *fmt, ...)
57 #else
58 error(fmt, va_alist)
59 char *fmt;
60 va_dcl
61 #endif
62 {
63 va_list ap;
64 #if __STDC__
65 va_start(ap, fmt);
66 #else
67 va_start(ap);
68 #endif
69 verror(fmt, ap);
70 va_end(ap);
71 }
72
73 void
74 verror(fmt, ap)
75 const char *fmt;
76 va_list ap;
77 {
78 struct context *x;
79 struct ww *w;
80
81 for (x = &cx; x != 0 && x->x_type != X_FILE; x = x->x_link)
82 ;
83 if (x == 0) {
84 if (terse)
85 wwbell();
86 else {
87 wwvprintf(cmdwin, fmt, ap);
88 wwputs(" ", cmdwin);
89 }
90 return;
91 }
92 if (x->x_noerr)
93 return;
94 if ((w = x->x_errwin) == 0) {
95 char buf[512];
96
97 (void) snprintf(buf, sizeof(buf), "Errors from %s",
98 x->x_filename);
99 if ((w = x->x_errwin = openiwin(ERRLINES, buf)) == 0) {
100 wwputs("Can't open error window. ", cmdwin);
101 x->x_noerr = 1;
102 return;
103 }
104 }
105 if (more(w, 0) == 2) {
106 x->x_noerr = 1;
107 return;
108 }
109 wwprintf(w, "line %d: ", x->x_lineno);
110 wwvprintf(w, fmt, ap);
111 wwputc('\n', w);
112 }
113
114 void
115 err_end()
116 {
117 if (cx.x_type == X_FILE && cx.x_errwin != 0) {
118 if (!cx.x_noerr)
119 waitnl(cx.x_errwin);
120 closeiwin(cx.x_errwin);
121 cx.x_errwin = 0;
122 }
123 }