1 /* $Header: /src/pub/tcsh/sh.print.c,v 3.28 2005/03/03 17:19:35 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. 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.28 2005/03/03 17:19:35 kim Exp $")
39 extern int Tty_eight_bit;
41 int lbuffed = 1; /* true if line buffered */
43 static void p2dig __P((unsigned int));
49 #if defined(BSDLIMIT) || defined(RLIMIT_CPU)
64 xprintf("%d", i / 60);
74 pcsecs(l) /* PWP: print mm:ss.dd, l is in sec*100 */
87 i = (int) (l / 360000);
90 i = (int) ((l % 360000) / 100);
95 xprintf("%d", i / 60);
101 p2dig((int) (l % 100));
109 xprintf("%u%u", i / 10, i % 10);
112 char linbuf[2048]; /* was 128 */
114 int output_raw = 0; /* PWP */
115 int xlate_cr = 0; /* HE */
121 char buf[MB_LEN_MAX];
124 len = one_wctomb(buf, c & CHAR);
125 for (i = 0; i < len; i++)
126 putraw((unsigned char)buf[i] | (c & ~CHAR));
132 char buf[MB_LEN_MAX];
135 len = one_wctomb(buf, c & CHAR);
136 for (i = 0; i < len; i++)
137 xputchar((unsigned char)buf[i] | (c & ~CHAR));
147 atr |= c & ATTRIBUTES & TRIM;
149 if (!output_raw && (c & QUOTE) == 0) {
150 if (iscntrl(c) && (c < 0x80 || MB_CUR_MAX == 1)) {
152 if (c != '\t' && c != '\n' && !(adrof(STRcolorcat) && c=='\033') && (xlate_cr || c != '\r'))
154 if (c != '\t' && c != '\n' && (xlate_cr || c != '\r'))
164 if (c == CTL_ESC('\177'))
167 c =_toebcdic[_toascii[c]|0100];
172 else if (!isprint(c) && (c < 0x80 || MB_CUR_MAX == 1)) {
173 xputchar('\\' | atr);
174 xputchar((((c >> 6) & 7) + '0') | atr);
175 xputchar((((c >> 3) & 7) + '0') | atr);
178 (void) putraw(c | atr);
182 if (haderr ? (didfds ? is2atty : isdiagatty) :
183 (didfds ? is1atty : isoutatty))
184 SetAttributes(c | atr);
187 if (lbuffed && (c & CHAR) == '\n')
195 if (haderr ? (didfds ? is2atty : isdiagatty) :
196 (didfds ? is1atty : isoutatty)) {
197 if (Tty_eight_bit == -1)
198 ed_set_tty_eight_bit();
199 if (!Tty_eight_bit && (c & META)) {
200 c = (c & ~META) | STANDOUT;
214 if (linp >= &linbuf[sizeof linbuf - 10])
229 static int interrupted = 0;
236 if (GettingInput && !Tty_raw_mode && linp < &linbuf[sizeof linbuf - 10])
240 linp = linbuf; /* avoid resursion as stderror calls flush */
241 stderror(ERR_SILENT);
245 unit = didfds ? 2 : SHDIAG;
247 unit = didfds ? 1 : SHOUT;
250 if (didfds == 0 && ioctl(unit, TIOCLGET, (ioctl_t) & lmode) == 0 &&
253 (void) ioctl(unit, TIOCLBIC, (ioclt_t) & lmode);
254 (void) write(unit, "\n", 1);
258 sz = (size_t) (linp - linbuf);
259 if (write(unit, linbuf, sz) == -1)
262 /* We lost our tty */
267 * Deal with Digital Unix 4.0D bogocity, returning ENXIO when
283 * Lost our file descriptor, exit (IRIS4D)
288 * Over our quota, writing the history file
293 /* Nothing to do, but die */
297 stderror(ERR_SILENT);