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