Statistiques
| Révision :

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

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

1 136 storres
/** @file test-pobyso-subpoly.c
2 133 storres
 * Name & purpose
3 133 storres
 *
4 133 storres
 * @author
5 133 storres
 * @date
6 133 storres
 *
7 133 storres
 * @details Verbosity manipulation are performed  to make sur  that verbosity
8 133 storres
 *  suppression is correctly managed in pobyso_is_constant_expression()
9 133 storres
 *  function.
10 133 storres
 */
11 133 storres
/******************************************************************************/
12 133 storres
/* Headers, applying the "particular to general" convention.*/
13 133 storres
14 133 storres
#include "pobyso.h"
15 133 storres
16 133 storres
/* includes of local headers */
17 133 storres
18 133 storres
/* includes of project headers */
19 133 storres
20 133 storres
/* includes of system headers */
21 136 storres
#include <stdlib.h>
22 133 storres
/* Other declarations */
23 133 storres
24 133 storres
/* Internal prototypes */
25 136 storres
long int
26 136 storres
read_long_decimal(long int* value, char* string);
27 136 storres
long int
28 136 storres
read_unsigned_long_decimal(long int* value, char* string);
29 133 storres
30 133 storres
/* Types, constants and macros definitions */
31 133 storres
32 133 storres
/* Global variables */
33 133 storres
34 133 storres
/* Functions */
35 136 storres
long int
36 136 storres
read_long_decimal(long int* returnValue, char* string)
37 133 storres
{
38 136 storres
  char* endptr[1];
39 136 storres
  long int convertedValue = 0;
40 133 storres
41 136 storres
  convertedValue = strtoul(string, endptr, 10);
42 136 storres
  /* For a completely safe conversion *endptr must point to 0 value char. */
43 136 storres
  if (**endptr != '\0')
44 133 storres
  {
45 136 storres
    return 1;
46 133 storres
  }
47 133 storres
  else
48 133 storres
  {
49 136 storres
    *returnValue = convertedValue;
50 136 storres
    return 0;
51 133 storres
  }
52 136 storres
  return 0;
53 136 storres
} /* End read_long_decimal. */
54 133 storres
55 136 storres
long int
56 136 storres
read_unsigned_long_decimal(long int* returnValue, char* string)
57 136 storres
{
58 136 storres
  char* endptr[1];
59 136 storres
  long int convertedValue = 0;
60 136 storres
61 136 storres
  /* Negative sign -> failure. */
62 136 storres
  if (*string == '-')
63 133 storres
  {
64 136 storres
    return 1;
65 133 storres
  }
66 136 storres
  convertedValue = strtoul(string, endptr, 10);
67 136 storres
  /* For a completely safe conversion *endptr must point to 0 value char. */
68 136 storres
  if (**endptr != '\0')
69 133 storres
  {
70 133 storres
    return 1;
71 133 storres
  }
72 133 storres
  else
73 133 storres
  {
74 136 storres
    *returnValue = convertedValue;
75 136 storres
    return 0;
76 133 storres
  }
77 136 storres
  return 0;
78 136 storres
} /* End read_unsigned_long_decimal. */
79 133 storres
80 136 storres
int
81 136 storres
main(int argc, char** argv)
82 136 storres
{
83 136 storres
  long int* expsArray   = NULL;
84 136 storres
  int i;
85 136 storres
  pobyso_func_exp_t polynomial;
86 136 storres
  pobyso_func_exp_t subpoly;
87 136 storres
88 136 storres
  if (argc < 3)
89 133 storres
  {
90 136 storres
    fprintf(stderr,
91 136 storres
            "Usage: %s polynomialAsString power1 [power2 [...[powern]..]\n",
92 136 storres
            argv[0]);
93 133 storres
    return 1;
94 133 storres
  }
95 133 storres
96 136 storres
  pobyso_set_canonical_on();
97 136 storres
  polynomial = pobyso_parse_string(argv[1]);
98 136 storres
  if (polynomial == NULL)
99 133 storres
  {
100 136 storres
    fprintf(stderr,
101 136 storres
            "%s: can't create the polynomial.\n",
102 136 storres
            argv[0]);
103 136 storres
    return 1;
104 133 storres
  }
105 136 storres
  pobyso_autoprint(polynomial);
106 136 storres
  expsArray = (long int*) malloc((argc - 2) * sizeof(long int));
107 136 storres
  if (expsArray == NULL)
108 133 storres
  {
109 136 storres
    fprintf(stderr,
110 136 storres
            "%s: can't create the exponents array.\n",
111 136 storres
            argv[0]);
112 133 storres
    return 1;
113 133 storres
  }
114 136 storres
  for (i = 2 ; i < argc ; i++)
115 133 storres
  {
116 136 storres
    if (read_long_decimal(&(expsArray[i - 2]), argv[i]))
117 136 storres
    {
118 136 storres
      fprintf(stderr,
119 136 storres
              "%s: can't read exponent \"%s\".\n",
120 136 storres
              argv[0],
121 136 storres
              argv[i]);
122 136 storres
      return 1;
123 136 storres
    }
124 133 storres
  }
125 136 storres
  subpoly = pobyso_subpoly(polynomial, argc - 2, expsArray);
126 136 storres
  if (subpoly == NULL)
127 133 storres
  {
128 133 storres
    return 1;
129 133 storres
  }
130 133 storres
  else
131 133 storres
  {
132 136 storres
    pobyso_autoprint(subpoly);
133 136 storres
    return 0;
134 133 storres
  }
135 133 storres
} /* End main */