OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [common/] [cprintf.c] - Diff between revs 355 and 406

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 355 Rev 406
Line 180... Line 180...
//#include "floatio.h"
//#include "floatio.h"
 
 
#define BUF             (MAXEXP+MAXFRACT+1)     /* + decimal point */
#define BUF             (MAXEXP+MAXFRACT+1)     /* + decimal point */
#define DEFPREC         6
#define DEFPREC         6
 
 
static char *cvt _PARAMS((struct _reent *, double, int, int, char *, int *, int, int *));
static char *cvt
 
_PARAMS((struct _reent *, double, int, int, char *, int *, int, int *));
static int exponent _PARAMS((char *, int, int));
static int exponent _PARAMS((char *, int, int));
 
 
#else /* no FLOATING_POINT */
#else /* no FLOATING_POINT */
 
 
#define BUF             40
#define BUF             40
Line 216... Line 217...
         * fields occur frequently, increase PADSIZE and make the initialisers
         * fields occur frequently, increase PADSIZE and make the initialisers
         * below longer.
         * below longer.
         */
         */
#define PADSIZE 16              /* pad chunk size */
#define PADSIZE 16              /* pad chunk size */
        static _CONST char blanks[PADSIZE] =
        static _CONST char blanks[PADSIZE] =
         {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
    { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
 
' ' };
        static _CONST char zeroes[PADSIZE] =
        static _CONST char zeroes[PADSIZE] =
         {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
    { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
 
'0' };
 
 
inline void pc (_CONST char c) {
inline void pc(_CONST char c)
 
{
#ifdef OR1K
#ifdef OR1K
  putc (c);
  putc (c);
#else
#else
  printf ("%c", c);
  printf ("%c", c);
#endif
#endif
}
}
 
 
        /*
        /*
         * BEWARE, these `goto error' on error, and PAD uses `n'.
         * BEWARE, these `goto error' on error, and PAD uses `n'.
         */
         */
inline void     PRINT(_CONST char *ptr, int len) {
inline void PRINT(_CONST char *ptr, int len)
 
{
  int i;
  int i;
  for (i = 0; i < len; i++)
  for (i = 0; i < len; i++)
          pc(*(ptr++));
          pc(*(ptr++));
}
}
 
 
inline void PAD(int howmany, _CONST char *with) {
inline void PAD(int howmany, _CONST char *with)
 
{
  int n;
  int n;
        if ((n = howmany) > 0) {
        if ((n = howmany) > 0) {
                while (n > PADSIZE) {
                while (n > PADSIZE) {
                        PRINT(with, PADSIZE);
                        PRINT(with, PADSIZE);
                        n -= PADSIZE;
                        n -= PADSIZE;
Line 275... Line 282...
         */
         */
#if 0
#if 0
        double _double;         /* double precision arguments %[eEfgG] */
        double _double;         /* double precision arguments %[eEfgG] */
#else
#else
                                /* double precision arguments %[eEfgG] */
                                /* double precision arguments %[eEfgG] */
        union { int i; double d; } _double_ = {0};
        union {
 
                int i;
 
                double d;
 
        } _double_ = {
 
        0};
#define _double (_double_.d)
#define _double (_double_.d)
#endif
#endif
        int expt;               /* integer value of exponent */
        int expt;               /* integer value of exponent */
        int expsize;            /* character count for expstr */
        int expsize;            /* character count for expstr */
        int ndig;               /* actual number of digits returned by cvt */
        int ndig;               /* actual number of digits returned by cvt */
Line 408... Line 419...
                         * beginning of a field width.''
                         * beginning of a field width.''
                         *      -- ANSI X3J11
                         *      -- ANSI X3J11
                         */
                         */
                        flags |= ZEROPAD;
                        flags |= ZEROPAD;
                        goto rflag;
                        goto rflag;
                case '1': case '2': case '3': case '4':
                case '1':
                case '5': case '6': case '7': case '8': case '9':
                case '2':
 
                case '3':
 
                case '4':
 
                case '5':
 
                case '6':
 
                case '7':
 
                case '8':
 
                case '9':
                        n = 0;
                        n = 0;
                        do {
                        do {
                                n = 10 * n + to_digit(ch);
                                n = 10 * n + to_digit(ch);
                                ch = *fmt++;
                                ch = *fmt++;
                        } while (is_digit(ch));
                        } while (is_digit(ch));
Line 443... Line 461...
                        size = 1;
                        size = 1;
                        sign = '\0';
                        sign = '\0';
                        break;
                        break;
                case 'D':
                case 'D':
                        flags |= LONGINT;
                        flags |= LONGINT;
                        /*FALLTHROUGH*/
                 /*FALLTHROUGH*/ case 'd':
                case 'd':
 
                case 'i':
                case 'i':
                        _uquad = SARG();
                        _uquad = SARG();
#ifndef _NO_LONGLONG
#ifndef _NO_LONGLONG
                        if ((quad_t)_uquad < 0)
                        if ((quad_t)_uquad < 0)
#else
#else
Line 518... Line 535...
                        } else if (expt >= ndig) {      /* fixed g fmt */
                        } else if (expt >= ndig) {      /* fixed g fmt */
                                size = expt;
                                size = expt;
                                if (flags & ALT)
                                if (flags & ALT)
                                        ++size;
                                        ++size;
                        } else
                        } else
                                size = ndig + (expt > 0 ?
                                size = ndig + (expt > 0 ? 1 : 2 - expt);
                                        1 : 2 - expt);
 
 
 
                        if (softsign)
                        if (softsign)
                                sign = '-';
                                sign = '-';
                        break;
                        break;
#endif /* FLOATING_POINT */
#endif /* FLOATING_POINT */
Line 540... Line 556...
                        else
                        else
                                *va_arg(ap, int *) = ret;
                                *va_arg(ap, int *) = ret;
                        continue;       /* no output */
                        continue;       /* no output */
                case 'O':
                case 'O':
                        flags |= LONGINT;
                        flags |= LONGINT;
                        /*FALLTHROUGH*/
                 /*FALLTHROUGH*/ case 'o':
                case 'o':
 
                        _uquad = UARG();
                        _uquad = UARG();
                        base = OCT;
                        base = OCT;
                        goto nosign;
                        goto nosign;
                case 'p':
                case 'p':
                        /*
                        /*
Line 554... Line 569...
                         * of printable characters, in an implementation-
                         * of printable characters, in an implementation-
                         * defined manner.''
                         * defined manner.''
                         *      -- ANSI X3J11
                         *      -- ANSI X3J11
                         */
                         */
                        /* NOSTRICT */
                        /* NOSTRICT */
                        _uquad = (u_long)(unsigned _POINTER_INT)va_arg(ap, void *);
                        _uquad =
 
                            (u_long) (unsigned _POINTER_INT)va_arg(ap, void *);
                        base = HEX;
                        base = HEX;
                        xdigs = "0123456789abcdef";
                        xdigs = "0123456789abcdef";
                        flags |= HEXPREFIX;
                        flags |= HEXPREFIX;
                        ch = 'x';
                        ch = 'x';
                        goto nosign;
                        goto nosign;
Line 583... Line 599...
                                size = strlen(cp);
                                size = strlen(cp);
                        sign = '\0';
                        sign = '\0';
                        break;
                        break;
                case 'U':
                case 'U':
                        flags |= LONGINT;
                        flags |= LONGINT;
                        /*FALLTHROUGH*/
                 /*FALLTHROUGH*/ case 'u':
                case 'u':
 
                        _uquad = UARG();
                        _uquad = UARG();
                        base = DEC;
                        base = DEC;
                        goto nosign;
                        goto nosign;
                case 'X':
                case 'X':
                        xdigs = "0123456789ABCDEF";
                        xdigs = "0123456789ABCDEF";
Line 776... Line 791...
#ifdef FLOATING_POINT
#ifdef FLOATING_POINT
 
 
extern char *_dtoa_r _PARAMS((struct _reent *, double, int,
extern char *_dtoa_r _PARAMS((struct _reent *, double, int,
                              int, int *, int *, char **));
                              int, int *, int *, char **));
 
 
static char *
static char *cvt(data, value, ndigits, flags, sign, decpt, ch, length)
cvt(data, value, ndigits, flags, sign, decpt, ch, length)
 
        struct _reent *data;
        struct _reent *data;
        double value;
        double value;
        int ndigits, flags, *decpt, ch, *length;
        int ndigits, flags, *decpt, ch, *length;
        char *sign;
        char *sign;
{
{
Line 823... Line 837...
        }
        }
        *length = rve - digits;
        *length = rve - digits;
        return (digits);
        return (digits);
}
}
 
 
static int
static int exponent(p0, exp, fmtch)
exponent(p0, exp, fmtch)
 
        char *p0;
        char *p0;
        int exp, fmtch;
        int exp, fmtch;
{
{
        register char *p, *t;
        register char *p, *t;
        char expbuf[MAXEXP];
        char expbuf[MAXEXP];
Line 836... Line 849...
        p = p0;
        p = p0;
        *p++ = fmtch;
        *p++ = fmtch;
        if (exp < 0) {
        if (exp < 0) {
                exp = -exp;
                exp = -exp;
                *p++ = '-';
                *p++ = '-';
        }
        } else
        else
 
                *p++ = '+';
                *p++ = '+';
        t = expbuf + MAXEXP;
        t = expbuf + MAXEXP;
        if (exp > 9) {
        if (exp > 9) {
                do {
                do {
                        *--t = to_char(exp % 10);
                        *--t = to_char(exp % 10);
                } while ((exp /= 10) > 9);
                } while ((exp /= 10) > 9);
                *--t = to_char(exp);
                *--t = to_char(exp);
                for (; t < expbuf + MAXEXP; *p++ = *t++);
                for (; t < expbuf + MAXEXP; *p++ = *t++);
        }
        } else {
        else {
 
                *p++ = '0';
                *p++ = '0';
                *p++ = to_char(exp);
                *p++ = to_char(exp);
        }
        }
        return (p - p0);
        return (p - p0);
}
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.