From: vrokas Date: Sat, 22 Jan 2005 19:24:50 +0000 (+0000) Subject: * printf_tiny.c: NEW, X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=f854ba28b6bc695c57cb3977ab869bc1bc67adb9;p=fw%2Fsdcc * printf_tiny.c: NEW, * device/lib/pic16/libc/*/Makefile: added --stack-auto to correctly compile printf_*.c, ltoa.c, etc... git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3649 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/device/include/pic16/stdio.h b/device/include/pic16/stdio.h index daf5d204..22cecd56 100644 --- a/device/include/pic16/stdio.h +++ b/device/include/pic16/stdio.h @@ -53,8 +53,12 @@ /*-----------------------------------------------------------------------*/ +/* printf_small() supports float print */ extern void printf_small(char *, ...); +/* printf_tiny() does not support float print */ +extern void printf_tiny(char *, ...); + extern int printf (char *,...); extern int vprintf (char *, va_list); diff --git a/device/lib/pic16/libc/Makefile.rules b/device/lib/pic16/libc/Makefile.rules index 582d5bd9..83975781 100644 --- a/device/lib/pic16/libc/Makefile.rules +++ b/device/lib/pic16/libc/Makefile.rules @@ -20,7 +20,8 @@ LIBC_INC_DIR = $(PRJDIR)/device/include/pic16 #OPT_FLAGS += --pstack-model=large -COMPILE_FLAGS += $(MODELFLAGS) $(OPT_FLAGS) +COMPILE_FLAGS += $(MODELFLAGS) +COMPILE_FLAGS += $(OPT_FLAGS) CFLAGS = -I$(LIBC_INC_DIR) diff --git a/device/lib/pic16/libc/stdio/Makefile b/device/lib/pic16/libc/stdio/Makefile index 3797e4e0..40080668 100644 --- a/device/lib/pic16/libc/stdio/Makefile +++ b/device/lib/pic16/libc/stdio/Makefile @@ -21,7 +21,7 @@ CFILES = $(patsubst %,%.c,$(SRCS)) OFILES = $(patsubst %.c,%.o,$(CFILES)) -DEBUG= +DEBUG= --stack-auto #COMPILE_FLAGS += --pomit-config-words --pomit-ivt --no-peep COMPILE_FLAGS += $(DEBUG) diff --git a/device/lib/pic16/libc/stdio/printf_small.c b/device/lib/pic16/libc/stdio/printf_small.c index 31ef4202..2fc589af 100644 --- a/device/lib/pic16/libc/stdio/printf_small.c +++ b/device/lib/pic16/libc/stdio/printf_small.c @@ -67,8 +67,10 @@ void printf_small(char *fmt, ...) float flt; char *str; data char *str1; +//#define str1 str long val; - static char buffer[16]; +// static + char buffer[35]; va_list ap ; ch = fmt; @@ -76,7 +78,8 @@ void printf_small(char *fmt, ...) while( *ch ) { //for (; *fmt ; fmt++ ) if (*ch == '%') { - flong = fstr = fchar = ffloat = 0; + flong = 0; fstr = 0; fchar = 0; + ffloat = 0; radix = 0; ch++; diff --git a/device/lib/pic16/libc/stdio/printf_tiny.c b/device/lib/pic16/libc/stdio/printf_tiny.c new file mode 100644 index 00000000..d700b3f0 --- /dev/null +++ b/device/lib/pic16/libc/stdio/printf_tiny.c @@ -0,0 +1,122 @@ +/*----------------------------------------------------------------- + printf_tiny.c - source file for reduced version of printf + + Modified for pic16 port, by Vangelis Rokas, 2004 (vrokas@otenet.gr) + + Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! +-------------------------------------------------------------------------*/ + +/* +** $Id$ +*/ + +/* This function uses function putchar() to dump a character + * to standard output. putchar() is defined in libc18f.lib + * as dummy function, which will be linked if no putchar() + * function is provided by the user. + * The user can write his own putchar() function and link it + * with the source *BEFORE* the libc18f.lib library. This way + * the linker will link the first function (i.e. the user's function) */ + +/* following formats are supported :- + format output type argument-type + %d decimal int + %ld decimal long + %hd decimal char + %x hexadecimal int + %lx hexadecimal long + %hx hexadecimal char + %o octal int + %lo octal long + %ho octal char + %c character char + %s character generic pointer +*/ + +#include +#include +#include + +void printf_tiny(char *fmt, ...) +{ + char *ch; + char radix; + char flong; + char fstr; + char fchar; + char *str; + data char *str1; + long val; +// static + char buffer[35]; + va_list ap ; + + ch = fmt; + va_start(ap,fmt); + + while( *ch ) { //for (; *fmt ; fmt++ ) + if (*ch == '%') { + flong = fstr = fchar = 0; + radix = 0; + ch++; + + if(*ch == 'l') { + flong = 1; + ch++; + } else + if(*ch == 'h') { + fchar = 1; + ch++; + } + + if(*ch == 's')fstr = 1; + else if(*ch == 'd')radix = 10; + else if(*ch == 'x')radix = 16; + else if(*ch == 'c')radix = 0; + else if(*ch == 'o')radix = 8; + + if(fstr) { + str = va_arg(ap, char *); + while (*str) putchar(*str++); + } else { + if(flong)val = va_arg(ap, long); + else + if(fchar)val = va_arg(ap, char); + else { + val = va_arg(ap, int); + } + + if(radix) { + ltoa (val, buffer, radix); + + str1 = buffer; + while ( *str1 ) { + putchar ( *str1++ ); + } + } else + putchar((char)val); + } + } else + putchar(*ch); + + ch++; + } +} diff --git a/device/lib/pic16/libc/stdlib/Makefile b/device/lib/pic16/libc/stdlib/Makefile index b166c469..00cf59f4 100644 --- a/device/lib/pic16/libc/stdlib/Makefile +++ b/device/lib/pic16/libc/stdlib/Makefile @@ -29,7 +29,7 @@ CFILES = $(patsubst %,%.c,$(SRCS)) OFILES = $(patsubst %.c,%.o,$(CFILES)) -DEBUG= +DEBUG= --stack-auto #COMPILE_FLAGS += --pomit-config-words --pomit-ivt --denable-peeps --optimize-goto --obanksel=2 COMPILE_FLAGS += $(DEBUG) diff --git a/device/lib/pic16/libc/stdlib/ltoa.c b/device/lib/pic16/libc/stdlib/ltoa.c index 84203e8b..875972bf 100644 --- a/device/lib/pic16/libc/stdlib/ltoa.c +++ b/device/lib/pic16/libc/stdlib/ltoa.c @@ -15,7 +15,7 @@ #define NUMBER_OF_DIGITS 32 -void ultoa(unsigned long value, data char* string, unsigned char radix) +void ultoa(unsigned long value, data char *string, unsigned char radix) { unsigned char index; char buffer[NUMBER_OF_DIGITS]; /* space for NUMBER_OF_DIGITS + '\0' */ @@ -35,7 +35,7 @@ char buffer[NUMBER_OF_DIGITS]; /* space for NUMBER_OF_DIGITS + '\0' */ *string = 0; /* string terminator */ } -void ltoa(long value, data char* string, unsigned char radix) +void ltoa(long value, data char *string, unsigned char radix) { if (value < 0 && radix == 10) { *string++ = '-';