Home | History | Annotate | Line # | Download | only in mpq
      1      1.1  mrg /* mpq_inp_str -- read an mpq from a FILE.
      2      1.1  mrg 
      3  1.1.1.4  mrg Copyright 2001, 2018 Free Software Foundation, Inc.
      4      1.1  mrg 
      5      1.1  mrg This file is part of the GNU MP Library.
      6      1.1  mrg 
      7      1.1  mrg The GNU MP Library is free software; you can redistribute it and/or modify
      8  1.1.1.3  mrg it under the terms of either:
      9  1.1.1.3  mrg 
     10  1.1.1.3  mrg   * the GNU Lesser General Public License as published by the Free
     11  1.1.1.3  mrg     Software Foundation; either version 3 of the License, or (at your
     12  1.1.1.3  mrg     option) any later version.
     13  1.1.1.3  mrg 
     14  1.1.1.3  mrg or
     15  1.1.1.3  mrg 
     16  1.1.1.3  mrg   * the GNU General Public License as published by the Free Software
     17  1.1.1.3  mrg     Foundation; either version 2 of the License, or (at your option) any
     18  1.1.1.3  mrg     later version.
     19  1.1.1.3  mrg 
     20  1.1.1.3  mrg or both in parallel, as here.
     21      1.1  mrg 
     22      1.1  mrg The GNU MP Library is distributed in the hope that it will be useful, but
     23      1.1  mrg WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     24  1.1.1.3  mrg or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     25  1.1.1.3  mrg for more details.
     26      1.1  mrg 
     27  1.1.1.3  mrg You should have received copies of the GNU General Public License and the
     28  1.1.1.3  mrg GNU Lesser General Public License along with the GNU MP Library.  If not,
     29  1.1.1.3  mrg see https://www.gnu.org/licenses/.  */
     30      1.1  mrg 
     31      1.1  mrg #include <stdio.h>
     32      1.1  mrg #include <ctype.h>
     33      1.1  mrg #include "gmp-impl.h"
     34      1.1  mrg 
     35      1.1  mrg 
     36      1.1  mrg size_t
     37      1.1  mrg mpq_inp_str (mpq_ptr q, FILE *fp, int base)
     38      1.1  mrg {
     39      1.1  mrg   size_t  nread;
     40      1.1  mrg   int     c;
     41      1.1  mrg 
     42      1.1  mrg   if (fp == NULL)
     43      1.1  mrg     fp = stdin;
     44      1.1  mrg 
     45  1.1.1.2  mrg   SIZ(DEN(q)) = 1;
     46  1.1.1.4  mrg   MPZ_NEWALLOC (DEN(q), 1)[0] = 1;
     47      1.1  mrg 
     48      1.1  mrg   nread = mpz_inp_str (mpq_numref(q), fp, base);
     49      1.1  mrg   if (nread == 0)
     50      1.1  mrg     return 0;
     51      1.1  mrg 
     52      1.1  mrg   c = getc (fp);
     53      1.1  mrg   nread++;
     54      1.1  mrg 
     55      1.1  mrg   if (c == '/')
     56      1.1  mrg     {
     57      1.1  mrg       c = getc (fp);
     58      1.1  mrg       nread++;
     59      1.1  mrg 
     60      1.1  mrg       nread = mpz_inp_str_nowhite (mpq_denref(q), fp, base, c, nread);
     61      1.1  mrg       if (nread == 0)
     62  1.1.1.2  mrg 	{
     63  1.1.1.2  mrg 	  SIZ(NUM(q)) = 0;
     64  1.1.1.2  mrg 	  SIZ(DEN(q)) = 1;
     65  1.1.1.2  mrg 	  PTR(DEN(q))[0] = 1;
     66  1.1.1.2  mrg 	}
     67      1.1  mrg     }
     68      1.1  mrg   else
     69      1.1  mrg     {
     70      1.1  mrg       ungetc (c, fp);
     71      1.1  mrg       nread--;
     72      1.1  mrg     }
     73      1.1  mrg 
     74      1.1  mrg   return nread;
     75      1.1  mrg }
     76