8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / csh / sh.print.c
blob34cd721e9304e0f67de333fdeef85eda942ef347
1 /*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
6 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
7 /* All Rights Reserved */
9 /*
10 * Copyright (c) 1980 Regents of the University of California.
11 * All rights reserved. The Berkeley Software License Agreement
12 * specifies the terms and conditions for redistribution.
15 #pragma ident "%Z%%M% %I% %E% SMI"
17 #include "sh.h"
19 void p2dig_ull(unsigned long long);
20 void p2dig_int(int);
21 void flush(void);
22 void Putchar(tchar);
26 * C Shell
29 void
30 psecs_ull(unsigned long long l)
32 unsigned long long i;
34 i = l / 3600;
35 if (i) {
36 printf("%llu:", i);
37 i = l % 3600;
38 p2dig_ull(i / 60);
39 goto minsec;
41 i = l;
42 printf("%llu", i / 60);
43 minsec:
44 i %= 60;
45 printf(":");
46 p2dig_ull(i);
49 void
50 psecs_int(int l)
52 int i;
54 i = l / 3600;
55 if (i) {
56 printf("%d:", i);
57 i = l % 3600;
58 p2dig_int(i / 60);
59 goto minsec;
61 i = l;
62 printf("%d", i / 60);
63 minsec:
64 i %= 60;
65 printf(":");
66 p2dig_int(i);
69 void
70 p2dig_ull(unsigned long long i)
72 printf("%llu%llu", i / 10, i % 10);
75 void
76 p2dig_int(int i)
78 printf("%d%d", i / 10, i % 10);
81 char linbuf[128];
82 char *linp = linbuf;
84 #ifdef MBCHAR
87 * putbyte() send a byte to SHOUT. No interpretation is done
88 * except an un-QUOTE'd control character, which is displayed
89 * as ^x.
91 void
92 putbyte(int c)
95 if ((c & QUOTE) == 0 && (c == 0177 || c < ' ' && c != '\t' &&
96 c != '\n')) {
97 putbyte('^');
98 if (c == 0177) {
99 c = '?';
100 } else {
101 c |= 'A' - 1;
104 c &= TRIM;
105 *linp++ = c;
107 if (c == '\n' || linp >= &linbuf[sizeof (linbuf) - 1 - MB_CUR_MAX]) {
108 /* 'cause the next Putchar() call may overflow the buffer. */
109 flush();
114 * Putchar(tc) does what putbyte(c) do for a byte c.
115 * Note that putbyte(c) just send the byte c (provided c is not
116 * a control character) as it is, while Putchar(tc) may expand the
117 * character tc to some byte sequnce that represents the character
118 * in EUC form.
120 void
121 Putchar(tchar tc)
123 int n;
125 if (isascii(tc&TRIM)) {
126 putbyte((int)tc);
127 return;
129 tc &= TRIM;
130 n = wctomb(linp, tc);
131 if (n == -1) {
132 return;
134 linp += n;
135 if (linp >= &linbuf[sizeof (linbuf) - 1 - MB_CUR_MAX]) {
136 flush();
140 #else /* !MBCHAR */
143 * putbyte() send a byte to SHOUT. No interpretation is done
144 * except an un-QUOTE'd control character, which is displayed
145 * as ^x.
147 void
148 putbyte(int c)
151 if ((c & QUOTE) == 0 && (c == 0177 || c < ' ' && c != '\t' &&
152 c != '\n')) {
153 putbyte('^');
154 if (c == 0177) {
155 c = '?';
156 } else {
157 c |= 'A' - 1;
160 c &= TRIM;
161 *linp++ = c;
162 if (c == '\n' || linp >= &linbuf[sizeof (linbuf) - 2]) {
163 flush();
168 * Putchar(tc) does what putbyte(c) do for a byte c.
169 * For single-byte character only environment, there is no
170 * difference between Putchar() and putbyte() though.
172 void
173 Putchar(tchar tc)
175 putbyte((int)tc);
178 #endif /* !MBCHAR */
180 void
181 draino(void)
183 linp = linbuf;
186 void
187 flush(void)
189 int unit;
190 int lmode;
192 if (linp == linbuf) {
193 return;
195 if (haderr) {
196 unit = didfds ? 2 : SHDIAG;
197 } else {
198 unit = didfds ? 1 : SHOUT;
200 #ifdef TIOCLGET
201 if (didfds == 0 && ioctl(unit, TIOCLGET, (char *)&lmode) == 0 &&
202 lmode&LFLUSHO) {
203 lmode = LFLUSHO;
204 (void) ioctl(unit, TIOCLBIC, (char *)&lmode);
205 (void) write(unit, "\n", 1);
207 #endif
208 (void) write(unit, linbuf, linp - linbuf);
209 linp = linbuf;
213 * Should not be needed.
215 void
216 write_string(char *s)
218 int unit;
220 * First let's make it sure to flush out things.
222 flush();
224 if (haderr) {
225 unit = didfds ? 2 : SHDIAG;
226 } else {
227 unit = didfds ? 1 : SHOUT;
230 (void) write(unit, s, strlen(s));