[BACK]Return to mout.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / mpbsd

Annotation of OpenXM_contrib/gmp/mpbsd/mout.c, Revision 1.1.1.3

1.1       maekawa     1: /* mout(MINT) -- Do decimal output of MINT to standard output.
                      2:
1.1.1.3 ! ohara       3: Copyright 1991, 1994, 1996, 2000, 2001, 2002 Free Software Foundation, Inc.
1.1       maekawa     4:
                      5: This file is part of the GNU MP Library.
                      6:
                      7: The GNU MP Library is free software; you can redistribute it and/or modify
1.1.1.2   maekawa     8: it under the terms of the GNU Lesser General Public License as published by
                      9: the Free Software Foundation; either version 2.1 of the License, or (at your
1.1       maekawa    10: option) any later version.
                     11:
                     12: The GNU MP Library is distributed in the hope that it will be useful, but
                     13: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1.1.1.2   maekawa    14: or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
1.1       maekawa    15: License for more details.
                     16:
1.1.1.2   maekawa    17: You should have received a copy of the GNU Lesser General Public License
1.1       maekawa    18: along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
                     19: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
                     20: MA 02111-1307, USA. */
                     21:
                     22: #include <stdio.h>
1.1.1.2   maekawa    23: #include <string.h>
1.1       maekawa    24: #include "mp.h"
                     25: #include "gmp.h"
                     26: #include "gmp-impl.h"
1.1.1.3 ! ohara      27: #include "longlong.h"
1.1       maekawa    28:
                     29: void
                     30: mout (const MINT *x)
                     31: {
                     32:   mp_ptr xp;
1.1.1.3 ! ohara      33:   mp_srcptr x_ptr;
        !            34:   mp_size_t x_size;
1.1       maekawa    35:   unsigned char *str;
                     36:   size_t str_size;
                     37:   int i;
                     38:   TMP_DECL (marker);
                     39:
1.1.1.3 ! ohara      40:   x_size = x->_mp_size;
1.1       maekawa    41:   if (x_size == 0)
                     42:     {
                     43:       fputc ('0', stdout);
1.1.1.3 ! ohara      44:       fputc ('\n', stdout);
1.1       maekawa    45:       return;
                     46:     }
                     47:   if (x_size < 0)
                     48:     {
                     49:       fputc ('-', stdout);
                     50:       x_size = -x_size;
                     51:     }
                     52:
                     53:   TMP_MARK (marker);
1.1.1.3 ! ohara      54:   x_ptr = x->_mp_d;
        !            55:   MPN_SIZEINBASE (str_size, x_ptr, x_size, 10);
        !            56:   str_size += 2;
1.1       maekawa    57:   str = (unsigned char *) TMP_ALLOC (str_size);
                     58:
1.1.1.3 ! ohara      59:   /* mpn_get_str clobbers its argument */
        !            60:   xp = TMP_ALLOC_LIMBS (x_size);
        !            61:   MPN_COPY (xp, x_ptr, x_size);
1.1       maekawa    62:
                     63:   str_size = mpn_get_str (str, 10, xp, x_size);
                     64:
1.1.1.3 ! ohara      65:   /* mpn_get_str might make a leading zero, skip it.  */
        !            66:   str_size -= (*str == 0);
        !            67:   str += (*str == 0);
        !            68:   ASSERT (*str != 0);
1.1       maekawa    69:
                     70:   /* Translate to printable chars.  */
                     71:   for (i = 0; i < str_size; i++)
                     72:     str[i] = "0123456789"[str[i]];
                     73:   str[str_size] = 0;
                     74:
1.1.1.2   maekawa    75:   str_size = strlen ((char *) str);
1.1       maekawa    76:   if (str_size % 10 != 0)
                     77:     {
                     78:       fwrite (str, 1, str_size % 10, stdout);
                     79:       str += str_size % 10;
                     80:       str_size -= str_size % 10;
                     81:       if (str_size != 0)
                     82:        fputc (' ', stdout);
                     83:     }
                     84:   for (i = 0; i < str_size; i += 10)
                     85:     {
                     86:       fwrite (str, 1, 10, stdout);
                     87:       str += 10;
                     88:       if (i + 10 < str_size)
                     89:        fputc (' ', stdout);
                     90:     }
                     91:   fputc ('\n', stdout);
                     92:   TMP_FREE (marker);
                     93: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>