1 /*-----------------------------------------------------------------
2 printf_tiny.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
54 %s character generic pointer
63 #define DPUT(c) putchar( c )
68 #define ISLONG (flong)
70 #define ISCHAR (fchar)
71 #define HAVESIGN (nosign)
75 extern void io_long(long);
76 extern void io_int(long);
77 extern void io_char(char);
80 void printf_tiny(char *fmt, ...)
90 // static char buffer[16];
97 while( *ch ) { //for (; *fmt ; fmt++ )
121 if(*ch == 's')ISSTR = 1;
122 else if(*ch == 'd')radix = 10;
123 else if(*ch == 'x'){ radix = 16; upcase = 0; }
124 else if(*ch == 'X'){ radix = 16; upcase = 1; }
125 else if(*ch == 'c')radix = 0;
126 else if(*ch == 'o')radix = 8;
127 else if(*ch == 'b')radix = 2;
130 str = va_arg(ap, char *);
131 while(*str) { putchar(*str);str++;}
133 if(ISLONG)val = va_arg(ap, long);
135 if(ISCHAR)val = va_arg(ap, char);
137 val = va_arg(ap, int);
142 ultoa(val, buffer, radix);
144 ltoa (val, buffer, radix);
150 radix = toupper( radix );