Statistiques
| Révision :

root / pobysoC-4.0 / src / test-pobyso-subpoly.c @ 287

Historique | Voir | Annoter | Télécharger (2,78 ko)

1
/** @file test-pobyso-subpoly.c
2
 * Name & purpose
3
 *
4
 * @author
5
 * @date
6
 *
7
 * @details Verbosity manipulation are performed  to make sur  that verbosity
8
 *  suppression is correctly managed in pobyso_is_constant_expression()
9
 *  function.
10
 */
11
/******************************************************************************/
12
/* Headers, applying the "particular to general" convention.*/
13

    
14
#include "pobyso.h"
15

    
16
/* includes of local headers */
17

    
18
/* includes of project headers */
19

    
20
/* includes of system headers */
21
#include <stdlib.h>
22
/* Other declarations */
23

    
24
/* Internal prototypes */
25
int
26
read_long_decimal(long int* value, char* string);
27
int
28
read_unsigned_long_decimal(long unsigned int* value, char* string);
29

    
30
/* Types, constants and macros definitions */
31

    
32
/* Global variables */
33

    
34
/* Functions */
35
int
36
read_long_decimal(long int* returnValue, char* string)
37
{
38
  char* endptr[1];
39
  long int convertedValue = 0;
40

    
41
  convertedValue = strtoul(string, endptr, 10);
42
  /* For a completely safe conversion *endptr must point to 0 value char. */
43
  if (**endptr != '\0')
44
  {
45
    return 1;
46
  }
47
  else
48
  {
49
    *returnValue = convertedValue;
50
    return 0;
51
  }
52
} /* End read_long_decimal. */
53

    
54
int
55
read_unsigned_long_decimal(long unsigned int* returnValue, char* string)
56
{
57
  char* endptr[1];
58
  long int convertedValue = 0;
59

    
60
  /* Negative sign -> failure. */
61
  if (*string == '-')
62
  {
63
    return 1;
64
  }
65
  convertedValue = strtoul(string, endptr, 10);
66
  /* For a completely safe conversion *endptr must point to 0 value char. */
67
  if (**endptr != '\0')
68
  {
69
    return 1;
70
  }
71
  else
72
  {
73
    *returnValue = convertedValue;
74
    return 0;
75
  }
76
  return 0;
77
} /* End read_unsigned_long_decimal. */
78

    
79
int
80
main(int argc, char** argv)
81
{
82
  long int* expsArray   = NULL;
83
  int i;
84
  pobyso_func_exp_t polynomial;
85
  pobyso_func_exp_t subpoly;
86

    
87
  if (argc < 3)
88
  {
89
    fprintf(stderr,
90
            "Usage: %s polynomialAsString power1 [power2 [...[powern]..]\n",
91
            argv[0]);
92
    return 1;
93
  }
94

    
95
  pobyso_set_canonical_on();
96
  polynomial = pobyso_parse_string(argv[1]);
97
  if (polynomial == NULL)
98
  {
99
    fprintf(stderr,
100
            "%s: can't create the polynomial.\n",
101
            argv[0]);
102
    return 1;
103
  }
104
  pobyso_autoprint(polynomial);
105
  expsArray = (long int*) malloc((argc - 2) * sizeof(long int));
106
  if (expsArray == NULL)
107
  {
108
    fprintf(stderr,
109
            "%s: can't create the exponents array.\n",
110
            argv[0]);
111
    return 1;
112
  }
113
  for (i = 2 ; i < argc ; i++)
114
  {
115
    if (read_long_decimal(&(expsArray[i - 2]), argv[i]))
116
    {
117
      fprintf(stderr,
118
              "%s: can't read exponent \"%s\".\n",
119
              argv[0],
120
              argv[i]);
121
      return 1;
122
    }
123
  }
124
  subpoly = pobyso_subpoly(polynomial, argc - 2, expsArray);
125
  if (subpoly == NULL)
126
  {
127
    return 1;
128
  }
129
  else
130
  {
131
    pobyso_autoprint(subpoly);
132
    return 0;
133
  }
134
} /* End main */