1 /* $Header: /src/pub/tcsh/sh.print.c,v 3.20 2000/06/11 02:14:15 kim 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. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 RCSID("$Id: sh.print.c,v 3.20 2000/06/11 02:14:15 kim Exp $")
43 extern int Tty_eight_bit;
44 extern int Tty_raw_mode;
45 extern Char GettingInput;
47 int lbuffed = 1; /* true if line buffered */
49 static void p2dig __P((int));
55 #if defined(BSDLIMIT) || defined(RLIMIT_CPU)
70 xprintf("%d", i / 60);
80 pcsecs(l) /* PWP: print mm:ss.dd, l is in sec*100 */
93 i = (int) (l / 360000);
96 i = (int) ((l % 360000) / 100);
101 xprintf("%d", i / 60);
107 p2dig((int) (l % 100));
115 xprintf("%d%d", i / 10, i % 10);
118 char linbuf[2048]; /* was 128 */
120 bool output_raw = 0; /* PWP */
121 bool xlate_cr = 0; /* HE */
129 atr |= c & ATTRIBUTES & TRIM;
131 if (!output_raw && (c & QUOTE) == 0) {
134 if (c != '\t' && c != '\n' && !(adrof(STRcolorcat) && c=='\033') && (xlate_cr || c != '\r')) {
136 if (c != '\t' && c != '\n' && (xlate_cr || c != '\r')) {
145 if (c == CTL_ESC('\177'))
148 c =_toebcdic[_toascii[c]|0100];
153 else if (!Isprint(c)) {
154 xputchar('\\' | atr);
155 xputchar((((c >> 6) & 7) + '0') | atr);
156 xputchar((((c >> 3) & 7) + '0') | atr);
159 (void) putraw(c | atr);
163 if (haderr ? (didfds ? is2atty : isdiagatty) :
164 (didfds ? is1atty : isoutatty))
165 SetAttributes(c | atr);
168 if (lbuffed && (c & CHAR) == '\n')
176 if (haderr ? (didfds ? is2atty : isdiagatty) :
177 (didfds ? is1atty : isoutatty)) {
178 if (Tty_eight_bit == -1)
179 ed_set_tty_eight_bit();
180 if (!Tty_eight_bit && (c & META)) {
181 c = (c & ~META) | STANDOUT;
195 if (linp >= &linbuf[sizeof linbuf - 10])
210 static int interrupted = 0;
217 if (GettingInput && !Tty_raw_mode && linp < &linbuf[sizeof linbuf - 10])
221 linp = linbuf; /* avoid resursion as stderror calls flush */
222 stderror(ERR_SILENT);
226 unit = didfds ? 2 : SHDIAG;
228 unit = didfds ? 1 : SHOUT;
231 if (didfds == 0 && ioctl(unit, TIOCLGET, (ioctl_t) & lmode) == 0 &&
234 (void) ioctl(unit, TIOCLBIC, (ioclt_t) & lmode);
235 (void) write(unit, "\n", 1);
239 sz = (size_t) (linp - linbuf);
240 if (write(unit, linbuf, sz) == -1)
243 /* We lost our tty */
248 * Deal with Digital Unix 4.0D bogocity, returning ENXIO when
264 * Lost our file descriptor, exit (IRIS4D)
269 * Over our quota, writing the history file
274 /* Nothing to do, but die */
278 stderror(ERR_SILENT);