diff options
Diffstat (limited to 'libc/stdio/printf.c')
-rw-r--r-- | libc/stdio/printf.c | 73 |
1 files changed, 71 insertions, 2 deletions
diff --git a/libc/stdio/printf.c b/libc/stdio/printf.c index 6e7b3e1..b7b0b81 100644 --- a/libc/stdio/printf.c +++ b/libc/stdio/printf.c @@ -129,7 +129,7 @@ static FILE string[1] = #ifdef L_vfprintf -#ifdef FLOATS +#ifndef __HAS_NO_FLOATS__ int (*__fp_print)() = 0; #endif @@ -344,7 +344,7 @@ register va_list ap; sign, pad, width, preci, buffer_mode); break; -#if FLOATS +#ifndef __HAS_NO_FLOATS__ case 'e': /* float */ case 'f': case 'g': @@ -378,3 +378,72 @@ register va_list ap; return (cnt); } #endif + +#ifdef L_fp_print +#ifndef __HAS_NO_FLOATS__ + +#ifdef __AS386_16__ +#asm + loc 1 ! Make sure the pointer is in the correct segment +auto_func: ! Label for bcc -M to work. + .word ___xfpcvt ! Pointer to the autorun function + .text ! So the function after is also in the correct seg. +#endasm +#endif + +#ifdef __AS386_32__ +#asm + loc 1 ! Make sure the pointer is in the correct segment +auto_func: ! Label for bcc -M to work. + .long ___xfpcvt ! Pointer to the autorun function + .text ! So the function after is also in the correct seg. +#endasm +#endif + +void +__fp_print_func(pval, style, preci, ptmp) + double * pval; + int style; + int preci; + char * ptmp; +{ + int decpt, negative; + char * cvt; + double val = *pval; + + if (preci < 0) preci = 6; + + cvt = fcvt(val, preci, &decpt, &negative); + if(negative) + *ptmp++ = '-'; + + if (decpt<0) { + *ptmp++ = '0'; + *ptmp++ = '.'; + while(decpt<0) { + *ptmp++ = '0'; decpt++; + } + } + + while(*cvt) { + *ptmp++ = *cvt++; + if (decpt == 1) + *ptmp++ = '.'; + decpt--; + } + + while(decpt > 0) { + *ptmp++ = '0'; + decpt--; + } +} + +void +__xfpcvt() +{ + extern int (*__fp_print)(); + __fp_print = __fp_print_func; +} + +#endif +#endif |