1 /* $NetBSD: output.c,v 1.7 2003/10/13 14:34:25 agc Exp $ */
4 * Copyright (c) 1988 Mark Nudelman
5 * Copyright (c) 1988, 1993
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
36 static char sccsid
[] = "@(#)output.c 8.2 (Berkeley) 4/27/95";
38 __RCSID("$NetBSD: output.c,v 1.7 2003/10/13 14:34:25 agc Exp $");
43 * High level routines dealing with the output to the screen.
54 int errmsgs
; /* Count of messages displayed by error() */
56 /* display the line which is in the line buffer. */
67 * Don't output if a signal is pending.
77 for (p
= line
; *p
!= '\0'; p
++)
83 column
+= ul_width
+1;
91 column
+= bo_width
+1;
102 } while ((column
% tabstop
) != 0);
112 * Control characters arrive here as the
113 * normal character [CARAT_CHAR(c)] with
114 * the 0200 bit set. See pappend().
126 if (column
< sc_width
|| !auto_wrap
|| ignaw
)
130 static char obuf
[1024];
131 static char *ob
= obuf
;
134 * Flush buffered output.
144 if (write(1, obuf
, n
) != n
)
150 * Purge any pending output.
160 * Output a character.
166 if (ob
>= &obuf
[sizeof(obuf
)])
184 static char return_to_continue
[] = "(press RETURN)";
187 * Output a message in the lower left corner of the screen
188 * and wait for carriage return.
199 * Nothing has been displayed yet. Output this message on
200 * error output (file descriptor 2) and don't wait for a
201 * keystroke to continue.
203 * This has the desirable effect of producing all error
204 * messages on error output if standard output is directed
205 * to a file. It also does the same if we never produce
206 * any real output; for example, if the input file(s) cannot
207 * be opened. If we do eventually produce output, code in
208 * edit() makes sure these messages can be seen before they
209 * are overwritten or scrolled away.
212 (void)write(2, s
, strlen(s
));
213 (void)write(2, "\n", 1);
225 putstr(return_to_continue
);
228 if ((ch
= getchr()) != '\n') {
235 if ((s
!= NULL
? strlen(s
) : 0) + sizeof(return_to_continue
) +
236 so_width
+ se_width
+ 1 > sc_width
)
238 * Printing the message has probably scrolled the screen.
239 * {{ Unless the terminal doesn't have auto margins,
240 * in which case we just hammered on the right margin. }}
246 static char intr_to_abort
[] = "... (interrupt to abort)";
256 putstr(intr_to_abort
);