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 = va_arg(ap, char);
147 val = va_arg(ap, int);
155 ultoa(val, buffer, radix);
157 ltoa (val, buffer, radix);
163 radix = toupper( radix );
164 __stream_putchar(stream, (unsigned char)radix);
169 __stream_putchar(stream, (unsigned char)val);
174 __stream_putchar(stream, *ch);