1 /* mpz_inp_str(dest_integer, stream, base) -- Input a number in base
2 BASE from stdio stream STREAM and store the result in DEST_INTEGER.
4 Copyright (C) 1991, 1993 Free Software Foundation, Inc.
6 This file is part of the GNU MP Library.
8 The GNU MP Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 The GNU MP Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with the GNU MP Library; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
28 char_ok_for_base (c, base)
33 return (unsigned) c - '0' < base;
35 return (unsigned) c - 'a' + 10 < base;
37 return (unsigned) c - 'A' + 10 < base;
44 mpz_inp_str (MP_INT *dest, FILE *stream, int base)
46 mpz_inp_str (dest, stream, base)
59 str = (char *) (*_mp_allocate_func) (str_size);
68 /* If BASE is 0, try to find out the base by looking at the initial
77 if (c == 'x' || c == 'X')
85 for (i = 0; char_ok_for_base (c, base); i++)
89 size_t old_str_size = str_size;
90 str_size = str_size * 3 / 2;
91 str = (char *) (*_mp_reallocate_func) (str, old_str_size, str_size);
100 _mpz_set_str (dest, str, base);
102 dest->size = -dest->size;
104 (*_mp_free_func) (str, str_size);