Home | History | Annotate | Line # | Download | only in tests
      1 /* tpl_mpfr.c --  Helper functions for data with native types.
      2 
      3 Copyright (C) 2012, 2013 INRIA
      4 
      5 This file is part of GNU MPC.
      6 
      7 GNU MPC is free software; you can redistribute it and/or modify it under
      8 the terms of the GNU Lesser General Public License as published by the
      9 Free Software Foundation; either version 3 of the License, or (at your
     10 option) any later version.
     11 
     12 GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
     13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     14 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
     15 more details.
     16 
     17 You should have received a copy of the GNU Lesser General Public License
     18 along with this program. If not, see http://www.gnu.org/licenses/ .
     19 */
     20 
     21 #include "mpc-tests.h"
     22 
     23 
     24 /* int */
     25 
     26 void
     27 tpl_read_int (mpc_datafile_context_t* datafile_context, int *nread, const char *name)
     28 {
     29   int n = 0;
     30 
     31   if (datafile_context->nextchar == EOF)
     32     {
     33       printf ("Error: Unexpected EOF when reading int "
     34               "in file '%s' line %lu\n",
     35               datafile_context->pathname, datafile_context->line_number);
     36       exit (1);
     37     }
     38   ungetc (datafile_context->nextchar, datafile_context->fd);
     39   n = fscanf (datafile_context->fd, "%i", nread);
     40   if (ferror (datafile_context->fd) || n == 0 || n == EOF)
     41     {
     42       printf ("Error: Cannot read %s in file '%s' line %lu\n",
     43               name, datafile_context->pathname, datafile_context->line_number);
     44       exit (1);
     45     }
     46   datafile_context->nextchar = getc (datafile_context->fd);
     47   tpl_skip_whitespace_comments (datafile_context);
     48 }
     49 
     50 void
     51 tpl_copy_int (int *dest, const int * const src)
     52 {
     53   *dest = *src;
     54 }
     55 
     56 /* unsigned long int */
     57 
     58 void
     59 tpl_read_ui (mpc_datafile_context_t* datafile_context, unsigned long int *ui)
     60 {
     61   int n = 0;
     62 
     63   if (datafile_context->nextchar == EOF)
     64     {
     65       printf ("Error: Unexpected EOF when reading uint "
     66               "in file '%s' line %lu\n",
     67               datafile_context->pathname, datafile_context->line_number);
     68       exit (1);
     69     }
     70   ungetc (datafile_context->nextchar, datafile_context->fd);
     71   n = fscanf (datafile_context->fd, "%lu", ui);
     72   if (ferror (datafile_context->fd) || n == 0 || n == EOF)
     73     {
     74       printf ("Error: Cannot read uint in file '%s' line %lu\n",
     75               datafile_context->pathname, datafile_context->line_number);
     76       exit (1);
     77     }
     78   datafile_context->nextchar = getc (datafile_context->fd);
     79   tpl_skip_whitespace_comments (datafile_context);
     80 }
     81 
     82 void
     83 tpl_copy_ui (unsigned long int *dest, const unsigned long int * const src)
     84 {
     85   *dest = *src;
     86 }
     87 
     88 
     89 /* long int */
     90 
     91 void
     92 tpl_read_si (mpc_datafile_context_t* datafile_context, long int *si)
     93 {
     94   int n = 0;
     95 
     96   if (datafile_context->nextchar == EOF)
     97     {
     98       printf ("Error: Unexpected EOF when reading sint "
     99               "in file '%s' line %lu\n",
    100               datafile_context->pathname, datafile_context->line_number);
    101       exit (1);
    102     }
    103   ungetc (datafile_context->nextchar, datafile_context->fd);
    104   n = fscanf (datafile_context->fd, "%li", si);
    105   if (ferror (datafile_context->fd) || n == 0 || n == EOF)
    106     {
    107       printf ("Error: Cannot read sint in file '%s' line %lu\n",
    108               datafile_context->pathname, datafile_context->line_number);
    109       exit (1);
    110     }
    111   datafile_context->nextchar = getc (datafile_context->fd);
    112   tpl_skip_whitespace_comments (datafile_context);
    113 }
    114 
    115 void
    116 tpl_copy_si (long int *dest, const long int * const src)
    117 {
    118   *dest = *src;
    119 }
    120 
    121 /* double */
    122 
    123 void
    124 tpl_copy_d (double *dest, const double * const src)
    125 {
    126   *dest = *src;
    127 }
    128