1 /*-----------------------------------------------------------------
2 vfprintf.c - source file for reduced version of printf
4 Modified for pic16 port, by Vangelis Rokas, 2005 (vrokas@otenet.gr)
6 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
8 This library is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Library General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 In other words, you are welcome to use, share and improve this program.
23 You are forbidden to forbid anyone else to use, share and improve
24 what you give them. Help stamp out software-hoarding!
25 -------------------------------------------------------------------------*/
31 /* following formats are supported :-
32 format output type argument-type
42 %l[xX] hexadecimal long
43 %h[xX] hexadecimal char
48 %s character generic pointer
57 extern void io_long(unsigned long);
58 extern void io_str(char *);
59 extern void io_int(unsigned int);
62 unsigned int vfprintf(FILE *stream, char *fmt, va_list ap)
65 unsigned char flong, fstr;
66 unsigned char fchar, nosign;
69 unsigned char *str, *ch;
72 // static char buffer[16];
77 io_str( "vfprintf: " );
78 io_long( (unsigned long)stream );
79 io_long( (unsigned long)fmt );
85 while( *ch ) { //for (; *fmt ; fmt++ )
96 __stream_putchar(stream, *ch);
110 } else if(*ch == 'h') {
115 if(*ch == 's')fstr = 1;
116 else if(*ch == 'd')radix = 10;
117 else if(*ch == 'x'){ radix = 16; upcase = 0; }
118 else if(*ch == 'X'){ radix = 16; upcase = 1; }
119 else if(*ch == 'c')radix = 0;
120 else if(*ch == 'o')radix = 8;
121 else if(*ch == 'b')radix = 2;
123 __stream_putchar(stream, *ch);
130 str = va_arg(ap, char *);
131 while(*str) { __stream_putchar(stream, *str); str++; count++; }
135 val = va_arg(ap, long);
141 val = (unsigned char)va_arg(ap, int); // FIXME: SDCC passes 1-byte char varargs as 2-byte ints...
142 if (!nosign) val = (char) val; // (FIXME cont'd) sign extend if required
148 val = va_arg(ap, int);
156 ultoa(val, buffer, radix);
158 ltoa (val, buffer, radix);
164 radix = toupper( radix );
165 __stream_putchar(stream, (unsigned char)radix);
170 __stream_putchar(stream, (unsigned char)val);
175 __stream_putchar(stream, *ch);