1 /* $Header: /src/pub/tcsh/sh.print.c,v 3.21 2002/03/08 17:36:46 christos Exp $ */
3 * sh.print.c: Primitive Output routines.
6 * Copyright (c) 1980, 1991 The Regents of the University of California.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 RCSID("$Id: sh.print.c,v 3.21 2002/03/08 17:36:46 christos Exp $")
39 extern int Tty_eight_bit
;
40 extern int Tty_raw_mode
;
41 extern Char GettingInput
;
43 int lbuffed
= 1; /* true if line buffered */
45 static void p2dig
__P((int));
51 #if defined(BSDLIMIT) || defined(RLIMIT_CPU)
66 xprintf("%d", i
/ 60);
76 pcsecs(l
) /* PWP: print mm:ss.dd, l is in sec*100 */
89 i
= (int) (l
/ 360000);
92 i
= (int) ((l
% 360000) / 100);
97 xprintf("%d", i
/ 60);
103 p2dig((int) (l
% 100));
111 xprintf("%d%d", i
/ 10, i
% 10);
114 char linbuf
[2048]; /* was 128 */
116 bool output_raw
= 0; /* PWP */
117 bool xlate_cr
= 0; /* HE */
125 atr
|= c
& ATTRIBUTES
& TRIM
;
127 if (!output_raw
&& (c
& QUOTE
) == 0) {
130 if (c
!= '\t' && c
!= '\n' && !(adrof(STRcolorcat
) && c
=='\033') && (xlate_cr
|| c
!= '\r')) {
132 if (c
!= '\t' && c
!= '\n' && (xlate_cr
|| c
!= '\r')) {
141 if (c
== CTL_ESC('\177'))
144 c
=_toebcdic
[_toascii
[c
]|0100];
149 else if (!Isprint(c
)) {
150 xputchar('\\' | atr
);
151 xputchar((((c
>> 6) & 7) + '0') | atr
);
152 xputchar((((c
>> 3) & 7) + '0') | atr
);
155 (void) putraw(c
| atr
);
159 if (haderr
? (didfds
? is2atty
: isdiagatty
) :
160 (didfds
? is1atty
: isoutatty
))
161 SetAttributes(c
| atr
);
164 if (lbuffed
&& (c
& CHAR
) == '\n')
172 if (haderr
? (didfds
? is2atty
: isdiagatty
) :
173 (didfds
? is1atty
: isoutatty
)) {
174 if (Tty_eight_bit
== -1)
175 ed_set_tty_eight_bit();
176 if (!Tty_eight_bit
&& (c
& META
)) {
177 c
= (c
& ~META
) | STANDOUT
;
191 if (linp
>= &linbuf
[sizeof linbuf
- 10])
206 static int interrupted
= 0;
213 if (GettingInput
&& !Tty_raw_mode
&& linp
< &linbuf
[sizeof linbuf
- 10])
217 linp
= linbuf
; /* avoid resursion as stderror calls flush */
218 stderror(ERR_SILENT
);
222 unit
= didfds
? 2 : SHDIAG
;
224 unit
= didfds
? 1 : SHOUT
;
227 if (didfds
== 0 && ioctl(unit
, TIOCLGET
, (ioctl_t
) & lmode
) == 0 &&
230 (void) ioctl(unit
, TIOCLBIC
, (ioclt_t
) & lmode
);
231 (void) write(unit
, "\n", 1);
235 sz
= (size_t) (linp
- linbuf
);
236 if (write(unit
, linbuf
, sz
) == -1)
239 /* We lost our tty */
244 * Deal with Digital Unix 4.0D bogocity, returning ENXIO when
260 * Lost our file descriptor, exit (IRIS4D)
265 * Over our quota, writing the history file
270 /* Nothing to do, but die */
274 stderror(ERR_SILENT
);