4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
37 #include <sys/param.h>
39 #include <wctype.h> /* iswprint() */
43 unsigned char numbuf
[21];
45 static unsigned char buffer
[BUFLEN
];
46 static unsigned char *bufp
= buffer
;
50 void prc_buff(unsigned char c
);
51 void prs_buff(unsigned char *s
);
53 void prs_cntl(unsigned char *s
);
54 void prs(unsigned char *as
);
58 * printing and io conversion
63 if ((flags
& prompt
) == 0 && cmdadr
) {
65 prs((unsigned char *)colon
);
70 prs(unsigned char *as
)
73 write(output
, as
, length(as
) - 1);
88 char mb
[MB_LEN_MAX
+ 1];
94 if ((len
= wctomb(mb
, c
)) < 0) {
95 mb
[0] = (unsigned char)c
;
98 write(output
, mb
, len
);
112 if ((hr
= t
/ 60) != 0) {
134 unsigned char buf
[21];
135 unsigned char *abuf
= &buf
[20];
138 *--abuf
= (unsigned char)'\0';
141 *--abuf
= (unsigned char)('0' + n
- 10 * (d
= n
/ 10));
142 } while ((n
= d
) != 0);
144 strncpy(numbuf
, abuf
, sizeof (numbuf
));
148 stoi(unsigned char *icp
)
150 unsigned char *cp
= icp
;
154 while ((c
= *cp
, digit(c
)) && c
&& r
>= 0) {
155 r
= r
* 10 + c
- '0';
158 if (r
< 0 || cp
== icp
) {
172 for (i
= 19; i
>= 0; i
--) {
173 numbuf
[i
] = n
% 10 + '0';
174 if ((n
/= 10) == 0) {
182 ulltos(u_longlong_t n
)
186 /* The max unsigned long long is 20 characters (+1 for '\0') */
188 for (i
= 19; i
>= 0; i
--) {
189 numbuf
[i
] = n
% 10 + '0';
190 if ((n
/= 10) == 0) {
202 write(buffd
, bufp
, length(bufp
) - 1);
208 prc_buff(unsigned char c
)
211 if (buffd
!= -1 && index
+ 1 >= BUFLEN
) {
223 prs_buff(unsigned char *s
)
225 int len
= length(s
) - 1;
227 if (buffd
!= -1 && index
+ len
>= BUFLEN
) {
231 if (buffd
!= -1 && len
>= BUFLEN
) {
232 write(buffd
, s
, len
);
234 movstr(s
, &bufp
[index
]);
239 static unsigned char *
240 octal(unsigned char c
, unsigned char *ptr
)
243 *ptr
++ = ((unsigned int)c
>> 6) + '0';
244 *ptr
++ = (((unsigned int)c
>> 3) & 07) + '0';
245 *ptr
++ = (c
& 07) + '0';
250 prs_cntl(unsigned char *s
)
254 unsigned char *olds
= s
;
255 unsigned char *ptr
= bufp
;
258 if ((n
= mbtowc(&wc
, (const char *)s
, MB_LEN_MAX
)) <= 0) {
263 ptr
= octal(*s
++, ptr
);
268 if (c
< '\040' && c
> 0) {
271 * translate a control character
272 * into a printable sequence
276 } else if (c
== 0177) {
277 /* '\0177' does not work */
282 * unprintable 8-bit byte sequence
283 * assumes all legal multibyte
287 ptr
= octal(*olds
, ptr
);
295 if (buffd
!= -1 && ptr
>= &bufp
[BUFLEN
-4]) {
301 if ((n
= mbtowc(&wc
, (const char *)s
, MB_LEN_MAX
)) <= 0) {
310 prull_buff(u_longlong_t lc
)
312 prs_buff(&numbuf
[ulltos(lc
)]);
328 if ((ofd
= buffd
) == -1) {
329 if (bufp
+index
+1 >= brkend
) {
330 growstak(bufp
+index
+1);
339 if ((buffd
= fd
) == -1) {