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!
26 As a special exception, if you link this library with other files,
27 some of which are compiled with SDCC, to produce an executable,
28 this library does not by itself cause the resulting executable
29 to be covered by the GNU General Public License.
30 This exception does not however invalidate any other reasons why
31 the executable file might be covered by the GNU General Public License.
32 -------------------------------------------------------------------------*/
34 /* This function uses function putchar() to dump a character
35 * to standard output. putchar() is defined in libc18f.lib
36 * as dummy function, which will be linked if no putchar()
37 * function is provided by the user.
38 * The user can write his own putchar() function and link it
39 * with the source *BEFORE* the libc18f.lib library. This way
40 * the linker will link the first function (i.e. the user's function) */
42 /* following formats are supported :-
43 format output type argument-type
57 %s character generic pointer
61 * This macro enables the use of the 'b' binary specifier and
62 * the use of "%b", "%hb" and "%lb"
64 /* #define BINARY_SPECIFIER */
72 #define DPUT(c) putchar(c)
77 #define ISLONG (flong)
79 #define ISCHAR (fchar)
80 #define HAVESIGN (nosign)
82 #ifdef BINARY_SPECIFIER
83 /* "%lb" = "0" - "11111111111111111111111111111111" */
86 /* "%lo" = "0" - "37777777777" or "-21777777777" - "17777777777" */
91 printf_tiny (const char *fmt, ...)
101 char buffer[BUF_SIZE];
107 while (*ch) //for (; *fmt ; fmt++ )
154 #ifdef BINARX_SPECIFIER
161 str = va_arg (ap, char *);
171 val = va_arg (ap, long);
174 val = (unsigned char) va_arg (ap, int); // FIXME: SDCC casts char arguments into ints
176 val = (char) val; // FIXME cont'd: sign-extend if required
179 val = va_arg (ap, int);
184 ultoa (val, buffer, radix);
186 ltoa (val, buffer, radix);
193 radix = toupper (radix);
199 putchar ((char) val);