1 /*-----------------------------------------------------------------
2 printf_small.c - source file for reduced version of printf
4 Modified for pic16 port, by Vangelis Rokas, 2004 (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 /* This function uses function putchar() to dump a character
32 * to standard output. putchar() is defined in libc18f.lib
33 * as dummy function, which will be linked if no putchar()
34 * function is provided by the user.
35 * The user can write his own putchar() function and link it
36 * with the source *BEFORE* the libc18f.lib library. This way
37 * the linker will link the first function (i.e. the user's function) */
39 /* following formats are supported :-
40 format output type argument-type
51 %s character generic pointer
59 void printf_small(char *fmt, ...) __reentrant
71 static char buffer[16];
77 while( *ch ) { //for (; *fmt ; fmt++ )
79 flong = fstr = fchar = ffloat = 0;
92 if(*ch == 's')fstr = 1;
93 else if(*ch == 'f')ffloat = 1;
94 else if(*ch == 'd')radix = 10;
95 else if(*ch == 'x')radix = 16;
96 else if(*ch == 'c')radix = 0;
97 else if(*ch == 'o')radix = 8;
100 str = va_arg(ap, char *);
101 while (*str) putchar(*str++);
104 flt = va_arg(ap, float);
105 x_ftoa(flt, buffer, 32, 6);
107 while( *str1 )str1++; str1--;
108 while( *str1 == '0' )str1--; str1++;
109 *str1 = 0; str1 = buffer;
110 while( *str1 )putchar(*str1++);
112 if(flong)val = va_arg(ap, long);
114 if(fchar)val = va_arg(ap, char);
116 val = va_arg(ap, int);
120 ltoa (val, buffer, radix);