version 1.1.1.2, 2000/09/09 14:13:11 |
version 1.1.1.3, 2003/08/25 16:06:35 |
|
|
/* mpf_inp_str(dest_float, stream, base) -- Input a number in base |
/* mpf_inp_str(dest_float, stream, base) -- Input a number in base |
BASE from stdio stream STREAM and store the result in DEST_FLOAT. |
BASE from stdio stream STREAM and store the result in DEST_FLOAT. |
|
|
Copyright (C) 1996 Free Software Foundation, Inc. |
Copyright 1996, 2000, 2001, 2002 Free Software Foundation, Inc. |
|
|
This file is part of the GNU MP Library. |
This file is part of the GNU MP Library. |
|
|
Line 26 MA 02111-1307, USA. */ |
|
Line 26 MA 02111-1307, USA. */ |
|
#include "gmp-impl.h" |
#include "gmp-impl.h" |
|
|
size_t |
size_t |
#if __STDC__ |
|
mpf_inp_str (mpf_ptr rop, FILE *stream, int base) |
mpf_inp_str (mpf_ptr rop, FILE *stream, int base) |
#else |
|
mpf_inp_str (rop, stream, base) |
|
mpf_ptr rop; |
|
FILE *stream; |
|
int base; |
|
#endif |
|
{ |
{ |
char *str; |
char *str; |
size_t alloc_size, str_size; |
size_t alloc_size, str_size; |
Line 45 mpf_inp_str (rop, stream, base) |
|
Line 38 mpf_inp_str (rop, stream, base) |
|
stream = stdin; |
stream = stdin; |
|
|
alloc_size = 100; |
alloc_size = 100; |
str = (char *) (*_mp_allocate_func) (alloc_size); |
str = (char *) (*__gmp_allocate_func) (alloc_size); |
str_size = 0; |
str_size = 0; |
nread = 0; |
nread = 0; |
|
|
Line 63 mpf_inp_str (rop, stream, base) |
|
Line 56 mpf_inp_str (rop, stream, base) |
|
{ |
{ |
size_t old_alloc_size = alloc_size; |
size_t old_alloc_size = alloc_size; |
alloc_size = alloc_size * 3 / 2; |
alloc_size = alloc_size * 3 / 2; |
str = (char *) (*_mp_reallocate_func) (str, old_alloc_size, alloc_size); |
str = (char *) (*__gmp_reallocate_func) (str, old_alloc_size, alloc_size); |
} |
} |
if (c == EOF || isspace (c)) |
if (c == EOF || isspace (c)) |
break; |
break; |
Line 71 mpf_inp_str (rop, stream, base) |
|
Line 64 mpf_inp_str (rop, stream, base) |
|
c = getc (stream); |
c = getc (stream); |
} |
} |
ungetc (c, stream); |
ungetc (c, stream); |
|
nread--; |
|
|
if (str_size >= alloc_size) |
if (str_size >= alloc_size) |
{ |
{ |
size_t old_alloc_size = alloc_size; |
size_t old_alloc_size = alloc_size; |
alloc_size = alloc_size * 3 / 2; |
alloc_size = alloc_size * 3 / 2; |
str = (char *) (*_mp_reallocate_func) (str, old_alloc_size, alloc_size); |
str = (char *) (*__gmp_reallocate_func) (str, old_alloc_size, alloc_size); |
} |
} |
str[str_size] = 0; |
str[str_size] = 0; |
|
|
retval = mpf_set_str (rop, str, base); |
retval = mpf_set_str (rop, str, base); |
|
(*__gmp_free_func) (str, alloc_size); |
|
|
if (retval == -1) |
if (retval == -1) |
return 0; /* error */ |
return 0; /* error */ |
|
|
(*_mp_free_func) (str, alloc_size); |
|
return str_size + nread; |
return str_size + nread; |
} |
} |