Révision 134 pobysoC-4.0/src/pobyso.c

pobyso.c (revision 134)
32 32

  
33 33
/* Functions */
34 34

  
35
/* @see pobyso.h#pobyso_autprint */
35
/* @see pobyso.h#pobyso_autoprint */
36 36
void
37
pobyso_autoprint(sollya_obj_t solObj, ...)
37
pobyso_autoprint(sollya_obj_t solObj)
38 38
{
39
  va_list va;
40
  va_start(va, solObj);
41
  sollya_lib_v_autoprint(solObj, va);
42
  va_end(va);
39
  sollya_lib_autoprint(solObj, NULL);
43 40
} /* End pobyso_autoprint. */
44 41

  
42
/* @see pobyso.h#pobyso_get_verbosity */
43
int
44
pobyso_get_verbosity()
45
{
46
  sollya_obj_t verbositySo = NULL;
47
  int verbosity            = 0;
48

  
49
  verbositySo = sollya_lib_get_verbosity();
50
  sollya_lib_get_constant_as_int(&verbosity,verbositySo);
51
  sollya_lib_clear_obj(verbositySo);
52
  return verbosity;
53
} /* End pobyso_get_verbosity. */
54

  
45 55
/* @see pobyso.h#pobyso_is_constant_expression*/
46 56
int
47 57
pobyso_is_constant_expression(sollya_obj_t obj_to_test)
48 58
{
49 59
  mpfr_t dummy;
50 60
  int test;
51
  sollya_obj_t verbosity_level      = NULL;
61
  int initial_verbosity_level      = 0;
62

  
52 63
  /* Test argument. */
53 64
  if (obj_to_test == NULL)
54 65
  {
......
57 68
                        "The expression is a NULL pointer");
58 69
    return 0;
59 70
  }
60
  verbosity_level = pobyso_set_verbosity_off();
71
  initial_verbosity_level = pobyso_set_verbosity_off();
61 72

  
62 73
  if (! sollya_lib_obj_is_function(obj_to_test))
63 74
  {
64
    pobyso_set_verbosity_to(verbosity_level);
65
    sollya_lib_clear_obj(verbosity_level);
75
    pobyso_set_verbosity_to(initial_verbosity_level);
66 76
    return 0;
67 77
  }
68 78
  mpfr_init2(dummy,64);
69 79
  /* Call to previous Sollya function resets verbosity. */
70
  verbosity_level = pobyso_set_verbosity_off();
80
  pobyso_set_verbosity_off();
71 81
  test = sollya_lib_get_constant(dummy, obj_to_test);
72 82
  mpfr_clear(dummy);
73
  pobyso_set_verbosity_to(verbosity_level);
74
  sollya_lib_clear_obj(verbosity_level);
83
  pobyso_set_verbosity_to(initial_verbosity_level);
75 84
  return test;
76 85
} /* End pobyso_is_constant_expression. */
77 86

  
78 87
/** @see pobyso.h#pobyso_new_monomial. */
79 88
pobyso_func_exp_t
80
pobyso_new_monomial(pobyso_func_exp_t coefficientSa, long degree)
89
pobyso_new_monomial(pobyso_func_exp_t coefficientSo, long degree)
81 90
{
82
  sollya_obj_t degreeSa   = NULL;
83
  sollya_obj_t varToPowSa = NULL;
84
  sollya_obj_t monomialSa = NULL;
85
  if (coefficientSa == NULL)
91
  sollya_obj_t degreeSo   = NULL;
92
  sollya_obj_t varToPowSo = NULL;
93
  sollya_obj_t monomialSo = NULL;
94
  int initial_verbosity_level = 0;
95

  
96
  /* Arguments check. */
97
  if (coefficientSo == NULL)
86 98
  {
87 99
    pobyso_error_message("pobyso_parse_string",
88 100
                        "NULL_POINTER_ARGUMENT",
89 101
                        "The expression is a NULL pointer");
90
    return sollya_lib_error();
102
    return NULL;
91 103
  }
92
  if (! pobyso_is_constant_expression(coefficientSa))
104
  if (! pobyso_is_constant_expression(coefficientSo))
93 105
  {
94
    return sollya_lib_error();
106
    return NULL;
95 107
  }
96 108
  if (degree < 0)
97 109
  {
98
    return sollya_lib_error();
110
    pobyso_error_message("pobyso_new_monomial",
111
                        "NEGATIVE_DEGREE_ARGUMENT",
112
                        "The degree is a negative integer");
113
    return NULL;
99 114
  }
100
  degreeSa    = sollya_lib_constant_from_int64(degree);
101
  varToPowSa  = sollya_lib_build_function_pow(sollya_lib_free_variable(),
102
                                              degreeSa);
103
  monomialSa = sollya_lib_mul(coefficientSa,varToPowSa);
104
  sollya_lib_clear_obj(varToPowSa);
105
  return monomialSa;
115
  /* If degree == 0, just return a copy of the coefficient. Do not
116
   * return the coefficient itself to avoid "double clear" issues. */
117
  if (degree == 0)
118
  {
119
    initial_verbosity_level = pobyso_set_verbosity_off();
120
    monomialSo = sollya_lib_copy_obj(coefficientSo);
121
    pobyso_set_verbosity_to(initial_verbosity_level);
122
  }
123
  degreeSo    = sollya_lib_constant_from_int64(degree);
124
  varToPowSo  = sollya_lib_build_function_pow(sollya_lib_free_variable(),
125
                                              degreeSo);
126
  /* Do not use the "build" version to avoid "eating up" the coefficient. */
127
  monomialSo = sollya_lib_mul(coefficientSo,varToPowSo);
128
  sollya_lib_clear_obj(varToPowSo);
129
  /* Do not clear degreeSa: it was "eaten" by sollya-lib_build_function. */
130
  return monomialSo;
106 131
} /* End pobyso_new_monomial. */
107 132

  
108 133
/* @see pobyso.h#pobyso_parse_string*/
......
119 144
    pobyso_error_message("pobyso_parse_string",
120 145
                        "NULL_POINTER_ARGUMENT",
121 146
                        "The expression is a NULL pointer");
122
    return(sollya_lib_error());
147
    return  NULL;
123 148
  }
124 149
  expressionLength = strlen(expression);
125 150
  if (expressionLength == 0)
......
127 152
    pobyso_error_message("pobyso_parse_string",
128 153
                        "EMPTY_STRING_ARGUMENT",
129 154
                        "The expression is an empty string");
130
    return sollya_lib_error();
155
    return NULL;
131 156
  }
132 157
  /* Search from the last char of the expression until, whichever happens
133 158
   * first:
......
161 186
          pobyso_error_message("pobyso_parse_string",
162 187
                                "MEMORY_ALLOCATION_ERROR",
163 188
                                "Could not allocate the expression string");
164
          return sollya_lib_error();
189
          return NULL;
165 190
        }
166 191
        strncpy(expressionWithSemiCo, expression, i+1);
167 192
        expressionWithSemiCo[i + 1] = ';';
......
180 205
  pobyso_error_message("pobyso_parse_string",
181 206
                       "ONLY_BLANK_ARGUMENT",
182 207
                        "The expression is only made of blanks");
183
  return(sollya_lib_error());
208
  return NULL;
184 209

  
185 210
} /* pobyso_parse_string */
186 211

  
......
192 217
                                      double quality,
193 218
                                      pobyso_range_t bounds)
194 219
{
195
  sollya_obj_t  degreeSa = NULL;
196
  sollya_obj_t qualitySa = NULL;
220
  sollya_obj_t  degreeSo = NULL;
221
  sollya_obj_t qualitySo = NULL;
197 222

  
198
  degreeSa = sollya_lib_constant_from_int(degree);
199
  qualitySa = sollya_lib_constant_from_double(quality);
223
  degreeSo = sollya_lib_constant_from_int(degree);
224
  qualitySo = sollya_lib_constant_from_double(quality);
200 225

  
226
  sollya_lib_clear_obj(degreeSo);
227
  sollya_lib_clear_obj(qualitySo);
201 228
  return NULL;
202 229
} /* End pobyso_remez_canonical_monomials_base. */
203 230

  
......
205 232
pobyso_set_canonical_on()
206 233
{
207 234
  pobyso_on_off_t currentCanonicalModeSo;
208
  int currentCanonicalMode;
209 235
  pobyso_on_off_t on;
210 236

  
211
  on = sollya_lib_on();
212 237
  currentCanonicalModeSo = sollya_lib_get_canonical();
213 238
  if (sollya_lib_is_on(currentCanonicalModeSo))
214 239
  {
215
    currentCanonicalMode = POBYSO_ON;
240
    sollya_lib_clear_obj(currentCanonicalModeSo);
241
    return POBYSO_ON;
216 242
  }
217 243
  else
218 244
  {
219
    currentCanonicalMode = POBYSO_OFF;
245
    on = sollya_lib_on();
246
    sollya_lib_set_canonical(on);
247
    sollya_lib_clear_obj(on);
248
    sollya_lib_clear_obj(currentCanonicalModeSo);
249
    return POBYSO_OFF;
220 250
  }
221
  sollya_lib_set_canonical(on);
222
  sollya_lib_clear_obj(on);
223
  sollya_lib_clear_obj(currentCanonicalModeSo);
224
  return currentCanonicalMode;
225 251
} /* End pobyso_set_canonical_on. */
226 252

  
227
pobyso_sollya_verbosity_t
253
int
228 254
pobyso_set_verbosity_off()
229 255
{
230
  sollya_obj_t verbosityLevelZero;
231
  sollya_obj_t currentVerbosityLevel = NULL;
256
  sollya_obj_t verbosityLevelZeroSo;
257
  sollya_obj_t currentVerbosityLevelSo = NULL;
258
  int currentVerbosityLevel = 0;
232 259

  
233
  currentVerbosityLevel = sollya_lib_get_verbosity();
234
  verbosityLevelZero = sollya_lib_constant_from_int(0);
235
  sollya_lib_set_verbosity(verbosityLevelZero);
236
  sollya_lib_clear_obj(verbosityLevelZero);
237
  return(currentVerbosityLevel);
260
  currentVerbosityLevelSo = sollya_lib_get_verbosity();
261
  sollya_lib_get_constant_as_int(&currentVerbosityLevel,
262
                                 currentVerbosityLevelSo);
263
  verbosityLevelZeroSo = sollya_lib_constant_from_int(0);
264
  sollya_lib_set_verbosity(verbosityLevelZeroSo);
265
  sollya_lib_clear_obj(verbosityLevelZeroSo);
266
  sollya_lib_clear_obj(currentVerbosityLevelSo);
267
  return currentVerbosityLevel;
238 268
} /* End of pobyso_set_verbosity_off. */
239 269

  
240
pobyso_sollya_verbosity_t
241
pobyso_set_verbosity_to(pobyso_sollya_verbosity_t newVerbosityLevel)
270
int
271
pobyso_set_verbosity_to(int newVerbosityLevel)
242 272
{
243
  sollya_obj_t currentVerbosityLevel = NULL;
244
  if (newVerbosityLevel == NULL)
273
  int initialVerbosityLevel = 0;
274
  sollya_obj_t initialVerbosityLevelSo = NULL;
275
  sollya_obj_t newVerbosityLevelSo = NULL;
276

  
277
  initialVerbosityLevelSo = sollya_lib_get_verbosity();
278
  sollya_lib_get_constant_as_int(&initialVerbosityLevel,
279
                                 initialVerbosityLevelSo);
280
  sollya_lib_clear_obj(initialVerbosityLevelSo);
281
  if (newVerbosityLevel < 0)
245 282
  {
246 283
    pobyso_error_message("pobyso_set_verbosity_to",
247
                        "NULL_POINTER_ARGUMENT",
248
                        "The new verbosity level is a null pointer");
249
    return(sollya_lib_error());
284
                        "INVALID_VALUE",
285
                        "The new verbosity level is a negative number");
286
    return initialVerbosityLevel;
250 287
  }
251
  currentVerbosityLevel = sollya_lib_get_verbosity();
252
  sollya_lib_set_verbosity(newVerbosityLevel);
253
  return(currentVerbosityLevel);
288
  newVerbosityLevelSo = sollya_lib_constant_from_int(newVerbosityLevel);
289
  sollya_lib_set_verbosity(newVerbosityLevelSo);
290
  sollya_lib_clear_obj(newVerbosityLevelSo);
291
  return initialVerbosityLevel;
254 292
} /* End of pobyso_set_verbosity_to. */
255 293

  
256
pobyso_sollya_verbosity_t
257
pobyso_set_verbosity_to_int(int intVerbosityLevel)
294
/**
295
 * @see pobyso.h#pobyso_subpoly
296
 */
297
pobyso_func_exp_t
298
pobyso_subpoly(pobyso_func_exp_t polynomialSo, long expsNum,...)
258 299
{
259
  sollya_obj_t currentVerbosityLevel = NULL;
260
  sollya_obj_t newVerbosityLevel     = NULL;
261
  if (intVerbosityLevel < 0)
300
  sollya_obj_t expsListSo = NULL;
301
  sollya_obj_t* expsList  = NULL;
302
  sollya_obj_t subpoly    = NULL;
303

  
304
  va_list vaExpsList;
305
  int currentExp;
306
  int i;
307

  
308
  /* Arguments check. */
309
  if (polynomialSo == NULL) return NULL;
310
  if (expsNum < 0) return NULL;
311
  if (expsNum == 0) return sollya_lib_copy_obj(polynomialSo);
312

  
313
  va_start(vaExpsList, expsNum);
314
  expsList = (sollya_obj_t*) malloc(expsNum * sizeof(sollya_obj_t));
315
  if (expsList == NULL)
262 316
  {
263
    pobyso_error_message("pobyso_set_verbosity_to",
264
                        "INVALID_VALUE",
265
                        "The new verbosity level is a negative number");
266
    return(sollya_lib_error());
317
    pobyso_error_message("pobyso_subpoly",
318
                          "MEMORY_ALLOCATION_ERROR",
319
                          "Could not allocate the expression string");
320
    return NULL;
267 321
  }
268
  newVerbosityLevel = sollya_lib_constant_from_int(intVerbosityLevel);
269
  currentVerbosityLevel = sollya_lib_get_verbosity();
270
  sollya_lib_set_verbosity(newVerbosityLevel);
271
  return(currentVerbosityLevel);
272
} /* End of pobyso_set_verbosity_to_int. */
322
  for (i = 0 ; i < expsNum ; i++)
323
  {
324
    currentExp = va_arg(vaExpsList, long);
325
    expsList[i] = sollya_lib_constant_from_int64(currentExp);
326
  } /* End for */
327
  va_end(vaExpsList);
328
  expsListSo = sollya_lib_list(expsList, expsNum);
329
  if (expsList == NULL)
330
  {
331
    pobyso_error_message("pobyso_subpoly",
332
                          "LIST_CREATIONERROR",
333
                          "Could not create the exponents list");
334
    for (i = 0 ; i < expsNum ; i++)
335
    {
336
      sollya_lib_clear_obj(expsList[i]);
337
    }
338
    free(expsList);
339
    return NULL;
340
  }
341
  subpoly = sollya_lib_subpoly(polynomialSo, expsListSo);
342
  sollya_lib_clear_obj(expsListSo);
343
  for (i = 0 ; i < expsNum ; i++)
344
  {
345
    sollya_lib_clear_obj(expsList[i]);
346
  }
347
  free(expsList);
348
  return subpoly;
349
} /* pobyso_subpoly. */
273 350

  
274 351
/* Attic from the sollya_lib < 4. */
275 352
#if 0

Formats disponibles : Unified diff