PIPS
pnome-error.c
Go to the documentation of this file.
1 /*
2 
3  $Id: pnome-error.c 1641 2016-03-02 08:20:19Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of Linear/C3 Library.
8 
9  Linear/C3 Library is free software: you can redistribute it and/or modify it
10  under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  Linear/C3 Library is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with Linear/C3 Library. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 
25 /***************************************************************** pnome-error.c
26  *
27  * "POLYNOME-ERROR" FUNCTION, MONOMIAL AND POLYNOMIAL CHECK
28  *
29  */
30 
31 /*LINTLIBRARY*/
32 
33 #ifdef HAVE_CONFIG_H
34  #include "config.h"
35 #endif
36 #include <stdio.h>
37 #include <stdarg.h>
38 #include <stdlib.h>
39 
40 #include "boolean.h"
41 #include "arithmetique.h"
42 #include "vecteur.h"
43 #include "polynome.h"
44 
45 /* void polynome_error(va_dcl va_list):
46  * should be called to terminate execution and to core dump
47  * when data structures are corrupted or when an undefined operation is
48  * requested (zero divide for instance).
49  * polynome_error should be called as:
50  *
51  * polynome_error(function_name, format, expression-list)
52  *
53  * where function_name is a string containing the name of the function
54  * calling POLYNOME_ERROR, and where format and expression-list are passed
55  * as arguments to vprintf.
56  * POLYNOME_ERROR terminates execution with abort.
57  * Ex: polynome_error("polynome_power_n", "negative power: %d\n", p);
58  *
59  */
60 
61 /*VARARGS0*/
62 void polynome_error(const char * name, char * fmt, ...)
63 {
64  va_list args;
65 
66  va_start(args, fmt);
67 
68  /* print name of function causing error */
69  (void) fprintf(stderr, "\npolynome error in %s: ", name);
70 
71  /* print out remainder of message */
72  (void) vfprintf(stderr, fmt, args);
73  va_end(args);
74 
75  /* create a core file for debug */
76  (void) abort();
77 }
78 
79 
80 /* void good_polynome_assert(va_alist)
81  * Check if the second argument is a valid polynomial.
82  * If not, print first argument ((char *) function name) and abort.
83  */
84 void good_polynome_assert(char * function, ...)
85 {
86  va_list args;
87  Ppolynome pp;
88 
89  va_start(args, function);
90  pp = va_arg(args, Ppolynome);
91 
92  if (polynome_check(pp)) return;
93 
94  fprintf(stderr, "Bad internal polynomial representation in %s\n", function);
95  va_end(args);
96  abort();
97 }
98 
99 
100 /* bool monome_check(Pmonome pm)
101  * Return true if all's right.
102  * Looks if pm is MONOME_UNDEFINED; if not:
103  * make sure that the coeff is non nul, that the term is non nul,
104  * and checks the (Pvecteur) term.
105  * All this also checks that pm is pointing to a valid address.
106  *
107  * Modification:
108  * - MONOME_NUL means 0 monome, and it's a good monome. LZ 10/10/91
109  */
110 bool monome_check(pm)
111 Pmonome pm;
112 {
113  if ( MONOME_UNDEFINED_P(pm) )
114  return (false);
115  else if (MONOME_NUL_P(pm) )
116  return (true);
117  else
118  return ((monome_coeff(pm) != 0) &&
119  !VECTEUR_NUL_P(monome_term(pm)) &&
120  vect_check(monome_term(pm)));
121 }
122 
123 /* bool polynome_check(Ppolynome pp)
124  * Return true if all's right.
125  * Check each monomial, make sure there's no nul or undefined monomial,
126  * then check unicity of each monomial.
127  *
128  * Modification:
129  * - POLYNOME_NUL means 0 polynome, and it's a good one. LZ 10/10/91
130  */
132 Ppolynome pp;
133 {
134  if ( POLYNOME_UNDEFINED_P(pp) )
135  return (false);
136  if ( POLYNOME_NUL_P(pp) )
137  return (true);
138  else {
139  Ppolynome curpp, curpp2;
140 
141  for (curpp = pp; curpp != POLYNOME_NUL; curpp = polynome_succ(curpp)) {
142  if ( !monome_check(polynome_monome(curpp)) ) {
143  return (false);
144  }
145  for (curpp2 = polynome_succ(curpp); curpp2 != POLYNOME_NUL;
146  curpp2 = polynome_succ(curpp2))
147  if (monome_colin(polynome_monome(curpp),polynome_monome(curpp2)))
148  return (false);
149  }
150  return (true);
151  }
152 }
153 
154 /* bool is_polynome_a_monome(Ppolynome pp)
155  * Return true if the pp is just a monome.
156  * that means the polynom has only one term
157  * Check each monomial, make sure there's no nul or undefined monomial,
158  * then check unicity of each monomial.
159  *
160  * LZ 06 Nov. 92
161  */
163 Ppolynome pp;
164 {
165  if ( ! polynome_check(pp) )
166  return (false);
167  else if ( pp != POLYNOME_NUL && polynome_succ(pp) == POLYNOME_NUL )
168  return (true);
169  else
170  return (false);
171 }
bool vect_check(Pvecteur cv)
bool vect_check(Pvecteur v): renvoie true si le vecteur v est coherent avec les specifications du pac...
Definition: reductions.c:529
#define abort()
Definition: misc-local.h:53
void good_polynome_assert(char *function,...)
void good_polynome_assert(va_alist) Check if the second argument is a valid polynomial.
Definition: pnome-error.c:84
void polynome_error(const char *name, char *fmt,...)
INTLIBRARY.
Definition: pnome-error.c:62
bool monome_check(Pmonome pm)
bool monome_check(Pmonome pm) Return true if all's right.
Definition: pnome-error.c:110
bool is_polynome_a_monome(Ppolynome pp)
bool is_polynome_a_monome(Ppolynome pp) Return true if the pp is just a monome.
Definition: pnome-error.c:162
bool polynome_check(Ppolynome pp)
bool polynome_check(Ppolynome pp) Return true if all's right.
Definition: pnome-error.c:131
bool monome_colin(Pmonome pm1, Pmonome pm2)
bool monome_colin(Pmonome pm1, Pmonome pm2) PRIVATE returns true if the two monomials are "colinear":...
Definition: pnome-private.c:77
#define POLYNOME_NUL
#define POLYNOME_UNDEFINED_P(pp)
#define monome_term(pm)
#define MONOME_UNDEFINED_P(pm)
#define polynome_monome(pp)
#define monome_coeff(pm)
Macros definitions.
#define POLYNOME_NUL_P(pp)
#define MONOME_NUL_P(pm)
#define polynome_succ(pp)
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
#define VECTEUR_NUL_P(v)