Statistiques
| Révision :

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

Historique | Voir | Annoter | Télécharger (2,8 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
long int
26
read_long_decimal(long int* value, char* string);
27
long int
28
read_unsigned_long_decimal(long int* value, char* string);
29

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

    
32
/* Global variables */
33

    
34
/* Functions */
35
long 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
  return 0;
53
} /* End read_long_decimal. */
54

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

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

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

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

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