1 /* $Header: /p/tcsh/cvsroot/tcsh/sh.print.c,v 3.36 2011/05/25 20:17:20 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("$tcsh: sh.print.c,v 3.36 2011/05/25 20:17:20 christos Exp $")
39 extern int Tty_eight_bit;
41 int lbuffed = 1; /* true if line buffered */
43 static void p2dig (unsigned int);
49 #if defined(BSDLIMIT) || defined(RLIMIT_CPU)
51 psecs(unsigned long l)
63 xprintf("%d", i / 60);
72 void /* PWP: print mm:ss.dd, l is in sec*100 */
74 pcsecs(unsigned long l)
85 i = (int) (l / 360000);
88 i = (int) ((l % 360000) / 100);
93 xprintf("%d", i / 60);
99 p2dig((int) (l % 100));
106 xprintf("%u%u", i / 10, i % 10);
109 char linbuf[2048]; /* was 128 */
111 int output_raw = 0; /* PWP */
112 int xlate_cr = 0; /* HE */
114 /* For cleanup_push() */
116 output_raw_restore(void *xorig)
128 char buf[MB_LEN_MAX];
131 len = one_wctomb(buf, c & CHAR);
132 for (i = 0; i < len; i++)
133 putraw((unsigned char)buf[i] | (c & ~CHAR));
139 char buf[MB_LEN_MAX];
142 len = one_wctomb(buf, c & CHAR);
143 for (i = 0; i < len; i++)
144 xputchar((unsigned char)buf[i] | (c & ~CHAR));
153 atr = c & ATTRIBUTES & TRIM;
155 if (!output_raw && (c & QUOTE) == 0) {
156 if (iscntrl(c) && (ASC(c) < 0x80 || MB_CUR_MAX == 1)) {
157 if (c != '\t' && c != '\n'
159 && !(adrof(STRcolorcat) && c == CTL_ESC('\033'))
161 && (xlate_cr || c != '\r'))
164 if (c == CTL_ESC('\177'))
167 /* Note: for IS_ASCII, this compiles to: c = c | 0100 */
168 c = CTL_ESC(ASC(c)|0100);
171 else if (!isprint(c) && (ASC(c) < 0x80 || MB_CUR_MAX == 1)) {
172 xputchar('\\' | atr);
173 xputchar((((c >> 6) & 7) + '0') | atr);
174 xputchar((((c >> 3) & 7) + '0') | atr);
177 (void) putraw(c | atr);
181 if (haderr ? (didfds ? is2atty : isdiagatty) :
182 (didfds ? is1atty : isoutatty))
183 SetAttributes(c | atr);
186 if (lbuffed && (c & CHAR) == '\n')
193 if (haderr ? (didfds ? is2atty : isdiagatty) :
194 (didfds ? is1atty : isoutatty)) {
195 if (Tty_eight_bit == -1)
196 ed_set_tty_eight_bit();
197 if (!Tty_eight_bit && (c & META)) {
198 c = (c & ~META) | STANDOUT;
211 if (linp >= &linbuf[sizeof linbuf - 10])
225 int unit, oldexitset = exitset;
226 static int interrupted = 0;
232 if (GettingInput && !Tty_raw_mode && linp < &linbuf[sizeof linbuf - 10])
239 linp = linbuf; /* avoid recursion as stderror calls flush */
243 stderror(ERR_SILENT);
247 unit = didfds ? 2 : SHDIAG;
249 unit = didfds ? 1 : SHOUT;
252 if (didfds == 0 && ioctl(unit, TIOCLGET, (ioctl_t) & lmode) == 0 &&
255 (void) ioctl(unit, TIOCLBIC, (ioclt_t) & lmode);
256 (void) xwrite(unit, "\n", 1);
260 if (xwrite(unit, linbuf, linp - linbuf) == -1)
263 /* We lost our tty */
268 * Deal with Digital Unix 4.0D bogocity, returning ENXIO when
284 * Lost our file descriptor, exit (IRIS4D)
290 * Deal with SoFS bogocity: returns ENOENT instead of ESTALE.
295 * Over our quota, writing the history file
300 /* Nothing to do, but die */
301 if (handle_intr == 0)
308 stderror(ERR_SILENT);
312 exitset = oldexitset;