Statistiques
| Révision :

root / pobysoC-4.0 / src / test-pobyso-is-monomial.c @ 138

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

1 138 storres
/** @file test-pobyso-monomial-int.c
2 138 storres
 * Name & purpose
3 138 storres
 *
4 138 storres
 * @author S.T.
5 138 storres
 * @date 2014-11-14
6 138 storres
 *
7 138 storres
 */
8 138 storres
/******************************************************************************/
9 138 storres
/* Headers, applying the "particular to general" convention.*/
10 138 storres
11 138 storres
#include "pobyso.h"
12 138 storres
13 138 storres
/* includes of local headers */
14 138 storres
15 138 storres
/* includes of project headers */
16 138 storres
17 138 storres
/* includes of system headers */
18 138 storres
#include <stdlib.h>
19 138 storres
/* Other declarations */
20 138 storres
21 138 storres
/* Internal prototypes */
22 138 storres
int
23 138 storres
read_long_decimal(long int* value, char* string);
24 138 storres
int
25 138 storres
read_unsigned_long_decimal(long unsigned int* value, char* string);
26 138 storres
27 138 storres
/* Types, constants and macros definitions */
28 138 storres
29 138 storres
/* Global variables */
30 138 storres
31 138 storres
/* Functions */
32 138 storres
int
33 138 storres
read_long_decimal(long int* returnValue, char* string)
34 138 storres
{
35 138 storres
  char* endptr[1];
36 138 storres
  long int convertedValue = 0;
37 138 storres
38 138 storres
  convertedValue = strtol(string, endptr, 10);
39 138 storres
  /* For a completely safe conversion *endptr must point to 0 value char. */
40 138 storres
  if (**endptr != '\0')
41 138 storres
  {
42 138 storres
    return 1;
43 138 storres
  }
44 138 storres
  else
45 138 storres
  {
46 138 storres
    *returnValue = convertedValue;
47 138 storres
    return 0;
48 138 storres
  }
49 138 storres
} /* End read_long_decimal. */
50 138 storres
51 138 storres
int
52 138 storres
read_unsigned_long_decimal(long unsigned int* returnValue, char* string)
53 138 storres
{
54 138 storres
  char* endptr[1];
55 138 storres
  long int convertedValue = 0;
56 138 storres
57 138 storres
  /* Negative sign -> failure. */
58 138 storres
  if (*string == '-')
59 138 storres
  {
60 138 storres
    return 1;
61 138 storres
  }
62 138 storres
  convertedValue = strtoul(string, endptr, 10);
63 138 storres
  /* For a completely safe conversion *endptr must point to 0 value char. */
64 138 storres
  if (**endptr != '\0')
65 138 storres
  {
66 138 storres
    return 1;
67 138 storres
  }
68 138 storres
  else
69 138 storres
  {
70 138 storres
    *returnValue = convertedValue;
71 138 storres
    return 0;
72 138 storres
  }
73 138 storres
} /* End read_unsigned_long_decimal. */
74 138 storres
75 138 storres
int
76 138 storres
main(int argc, char** argv)
77 138 storres
{
78 138 storres
  pobyso_func_exp_t expressionSo = NULL;
79 138 storres
  int outcome = 1;
80 138 storres
81 138 storres
  sollya_lib_init();
82 138 storres
  /* No command line argument test the function with the NULL argument. */
83 138 storres
  if (argc == 1)
84 138 storres
  {
85 138 storres
    outcome = pobyso_is_monomial(expressionSo);
86 138 storres
    sollya_lib_close();
87 138 storres
    return ! outcome;
88 138 storres
  }
89 138 storres
90 138 storres
  pobyso_set_canonical_on();
91 138 storres
  expressionSo = pobyso_parse_string(argv[1]);
92 138 storres
  if (expressionSo != NULL)
93 138 storres
  {
94 138 storres
    fprintf(stdout, "Sollya expression: ");
95 138 storres
    pobyso_autoprint(expressionSo);
96 138 storres
  }
97 138 storres
  else
98 138 storres
  {
99 138 storres
    fprintf(stdout, "NULL expression");
100 138 storres
  }
101 138 storres
  if (pobyso_is_monomial(expressionSo))
102 138 storres
  {
103 138 storres
    sollya_lib_close();
104 138 storres
    return 0;
105 138 storres
  }
106 138 storres
  else
107 138 storres
  {
108 138 storres
    sollya_lib_close();
109 138 storres
    return 1;
110 138 storres
  }
111 138 storres
} /* End main */