+2006-06-25 Borut Razem <borut.razem AT siol.net>
+
+ * device/lib/pic16/libc/stdio/sprintf.c: return the number of
+ characters printed (not including the trailing '\0' used to end
+ output to strings). Problem detected in regression test bug-927659.c.
+ NOTE: printf() family functions should return int instead
+ unsigned int!
+ * device/lib/pic16/libc/stdio/vfprintf.c: "%%" prints "%", unknown
+ specifier are printed as themselves
+ * sdcc/support/regression/tests/bug1057979.c: pic16 printf doesn't
+ support flags, width and precision specifiers
+
2006-06-24 Borut Razem <borut.razem AT siol.net>
* sdcc/support/regression/tests/bitvars.c: added gbz80, pic16 and pic16
/* following formats are supported :-
format output type argument-type
+ %% - -
%u* unsigned *
- %b binary
+ %b binary int
+ %lb binary long
+ %hb binary char
%d decimal int
%ld decimal long
%hd decimal char
- %x hexadecimal int
- %lxX hexadecimal long
- %hxX hexadecimal char
+ %[xX] hexadecimal int
+ %l[xX] hexadecimal long
+ %h[xX] hexadecimal char
%o octal int
%lo octal long
%ho octal char
#if _DEBUG
- io_str( "vfprintf: " );
- io_long( (unsigned long)stream );
- io_long( (unsigned long)fmt );
+ io_str( "vfprintf: " );
+ io_long( (unsigned long)stream );
+ io_long( (unsigned long)fmt );
#endif
// va_start(ap,fmt);
- ch = fmt;
+ ch = fmt;
- while( *ch ) { //for (; *fmt ; fmt++ )
- if (*ch == '%') {
- flong = 0;
- fstr = 0;
- fchar = 0;
- nosign = 0;
- radix = 0;
- upcase = 0;
- ch++;
-
- if(*ch == 'u') {
- nosign = 1;
- 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; upcase = 0; }
- else if(*ch == 'X'){ radix = 16; upcase = 1; }
- else if(*ch == 'c')radix = 0;
- else if(*ch == 'o')radix = 8;
- else if(*ch == 'b')radix = 2;
-
- if(fstr) {
- str = va_arg(ap, char *);
- while(*str) { __stream_putchar(stream, *str); str++; count++; }
- } else {
- val = 0;
- if(flong) {
- val = va_arg(ap, long);
+ while( *ch ) { //for (; *fmt ; fmt++ )
+ if (*ch == '%') {
+ flong = 0;
+ fstr = 0;
+ fchar = 0;
+ nosign = 0;
+ radix = 0;
+ upcase = 0;
+ ch++;
+
+ if(*ch == '%') {
+ __stream_putchar(stream, *ch);
+ ++count;
+ ++ch;
+ continue;
+ }
+
+ if(*ch == 'u') {
+ nosign = 1;
+ 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; upcase = 0; }
+ else if(*ch == 'X'){ radix = 16; upcase = 1; }
+ else if(*ch == 'c')radix = 0;
+ else if(*ch == 'o')radix = 8;
+ else if(*ch == 'b')radix = 2;
+ else {
+ __stream_putchar(stream, *ch);
+ ++count;
+ ++ch;
+ continue;
+ }
+
+ if(fstr) {
+ str = va_arg(ap, char *);
+ while(*str) { __stream_putchar(stream, *str); str++; count++; }
+ } else {
+ val = 0;
+ if(flong) {
+ val = va_arg(ap, long);
#if _DEBUG
- io_long(val);
+ io_long(val);
#endif
- }
- else
- if(fchar) {
- val = va_arg(ap, char);
+ }
+ else if(fchar) {
+ val = va_arg(ap, char);
#if _DEBUG
- io_long(val);
+ io_long(val);
#endif
- }
- else {
- val = va_arg(ap, int);
+ }
+ else {
+ val = va_arg(ap, int);
#if _DEBUG
- io_long(val);
+ io_long(val);
#endif
- }
-
- if(radix) {
- if(nosign)
- ultoa(val, buffer, radix);
- else
- ltoa (val, buffer, radix);
-
- str1 = buffer;
- while( (*str1) ) {
- radix = *str1;
- if(upcase)
- radix = toupper( radix );
- __stream_putchar(stream, (unsigned char)radix);
- count++;
- str1++;
- }
- } else {
- __stream_putchar(stream, (unsigned char)val);
- count++;
- }
- }
- } else {
- __stream_putchar(stream, *ch);
+ }
+
+ if(radix) {
+ if(nosign)
+ ultoa(val, buffer, radix);
+ else
+ ltoa (val, buffer, radix);
+
+ str1 = buffer;
+ while( (*str1) ) {
+ radix = *str1;
+ if(upcase)
+ radix = toupper( radix );
+ __stream_putchar(stream, (unsigned char)radix);
count++;
+ str1++;
}
-
- ch++;
+ } else {
+ __stream_putchar(stream, (unsigned char)val);
+ count++;
+ }
+ }
+ } else {
+ __stream_putchar(stream, *ch);
+ count++;
}
-
+
+ ch++;
+ }
+
return (count);
}
ASSERT( 0 == strcmp( s, "2147483647" ) );
//and from bug 1073386
+#ifdef SDCC_pic16
+ //pic16 printf doesn't support flags, width and precision specifiers
+ sprintf( s, "%04X", 0x8765u );
+ ASSERT( 0 == strcmp( s, "04X" ) );
+
+ //and from bug 1193299
+ sprintf( s, "%3.3s", "abcd" );
+ ASSERT( 0 == strcmp( s, "3.3s" ) );
+ sprintf( s, "%-3.3s", "abcd" );
+ ASSERT( 0 == strcmp( s, "-3.3s" ) );
+ sprintf( s, "%3.3s", "ab" );
+ ASSERT( 0 == strcmp( s, "3.3s" ) );
+ sprintf( s, "%-3.3s", "ab" );
+ ASSERT( 0 == strcmp( s, "-3.3s" ) );
+#else
sprintf( s, "%04X", 0x8765u );
ASSERT( 0 == strcmp( s, "8765" ) );
//and from bug 1193299
sprintf( s, "%3.3s", "abcd" );
- LOG((s));
ASSERT( 0 == strcmp( s, "abc" ) );
sprintf( s, "%-3.3s", "abcd" );
ASSERT( 0 == strcmp( s, "abc" ) );
ASSERT( 0 == strcmp( s, " ab" ) );
sprintf( s, "%-3.3s", "ab" );
ASSERT( 0 == strcmp( s, "ab " ) );
+#endif
#if defined(SDCC__ds390) || defined(PORT_HOST)
//and from bug 1358192