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