Annotation of OpenXM/src/kan96xx/gmp-2.0.2/mpbsd/min.c, Revision 1.1.1.1
1.1 maekawa 1: /* min(MINT) -- Do decimal input from standard input and store result in
2: MINT.
3:
4: Copyright (C) 1991, 1994 Free Software Foundation, Inc.
5:
6: This file is part of the GNU MP Library.
7:
8: The GNU MP Library is free software; you can redistribute it and/or modify
9: it under the terms of the GNU Library General Public License as published by
10: the Free Software Foundation; either version 2 of the License, or (at your
11: option) any later version.
12:
13: The GNU MP Library is distributed in the hope that it will be useful, but
14: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
16: License for more details.
17:
18: You should have received a copy of the GNU Library General Public License
19: along with the GNU MP Library; see the file COPYING.LIB. If not, write to
20: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21: MA 02111-1307, USA. */
22:
23: #include <stdio.h>
24: #include <ctype.h>
25: #include "mp.h"
26: #include "gmp.h"
27: #include "gmp-impl.h"
28:
29: void
30: #if __STDC__
31: min (MINT *dest)
32: #else
33: min (dest)
34: MINT *dest;
35: #endif
36: {
37: char *str;
38: size_t alloc_size, str_size;
39: int c;
40: int negative;
41: mp_size_t dest_size;
42:
43: alloc_size = 100;
44: str = (char *) (*_mp_allocate_func) (alloc_size);
45: str_size = 0;
46:
47: /* Skip whitespace. */
48: do
49: c = getc (stdin);
50: while (isspace (c));
51:
52: negative = 0;
53: if (c == '-')
54: {
55: negative = 1;
56: c = getc (stdin);
57: }
58:
59: if (digit_value_in_base (c, 10) < 0)
60: return; /* error if no digits */
61:
62: for (;;)
63: {
64: int dig;
65: if (str_size >= alloc_size)
66: {
67: size_t old_alloc_size = alloc_size;
68: alloc_size = alloc_size * 3 / 2;
69: str = (char *) (*_mp_reallocate_func) (str, old_alloc_size, alloc_size);
70: }
71: dig = digit_value_in_base (c, 10);
72: if (dig < 0)
73: break;
74: str[str_size++] = dig;
75: c = getc (stdin);
76: }
77:
78: ungetc (c, stdin);
79:
80: dest_size = str_size / __mp_bases[10].chars_per_limb + 1;
81: if (dest->_mp_alloc < dest_size)
82: _mp_realloc (dest, dest_size);
83:
84: dest_size = mpn_set_str (dest->_mp_d, (unsigned char *) str, str_size, 10);
85: dest->_mp_size = negative ? -dest_size : dest_size;
86:
87: (*_mp_free_func) (str, alloc_size);
88: return;
89: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>