1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Gary Czvitkovicz
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
29 static const char hexdigit
[] = "0123456789ABCDEF";
32 /* call 'push()' for each output letter */
33 int (*push
)(void *userp
, unsigned char data
),
40 int ch
, width
, val
, sign
, precision
;
45 ssize_t szval
, szsign
;
48 tmpbuf
[sizeof tmpbuf
- 1] = '\0';
50 while ((ch
= *fmt
++) != '\0' && ok
)
60 while (ch
>= '0' && ch
<= '9')
62 width
= 10*width
+ ch
- '0';
70 while (ch
>= '0' && ch
<= '9')
72 precision
= 10*precision
+ ch
- '0';
79 str
= tmpbuf
+ sizeof tmpbuf
- 1;
83 *--str
= va_arg (ap
, int);
87 str
= va_arg (ap
, char*);
91 val
= sign
= va_arg (ap
, int);
96 *--str
= (val
% 10) + '0';
105 uval
= va_arg(ap
, unsigned int);
108 *--str
= (uval
% 10) + '0';
117 uval
= va_arg (ap
, int);
120 *--str
= hexdigit
[uval
& 0xf];
132 ulval
= va_arg (ap
, long);
135 *--str
= hexdigit
[ulval
& 0xf];
141 lval
= lsign
= va_arg (ap
, long);
146 *--str
= (lval
% 10) + '0';
155 ulval
= va_arg(ap
, unsigned long);
158 *--str
= (ulval
% 10) + '0';
175 szval
= szsign
= va_arg (ap
, ssize_t
);
180 *--str
= (szval
% 10) + '0';
189 uszval
= va_arg(ap
, size_t);
192 *--str
= (uszval
% 10) + '0';
212 width
-= strlen (str
);
213 while (width
-- > 0 && ok
)
216 while (*str
!= '\0' && ok
&& precision
--)
217 ok
=push(userp
, *str
++);