root / pobysoC-4.0 / src / test-pobyso-is-int.c @ 137
Historique | Voir | Annoter | Télécharger (2,16 ko)
1 |
/** @file test-pobyso-is-int.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 = strtol(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 |
} /* End read_unsigned_long_decimal. */
|
77 |
|
78 |
int
|
79 |
main(int argc, char** argv) |
80 |
{ |
81 |
pobyso_func_exp_t expressionSo = NULL;
|
82 |
|
83 |
if (argc < 2) |
84 |
{ |
85 |
fprintf(stderr, |
86 |
"Usage: %s quotedExpression \n",
|
87 |
argv[0]);
|
88 |
return 1; |
89 |
} |
90 |
|
91 |
pobyso_set_canonical_on(); |
92 |
expressionSo = pobyso_parse_string(argv[1]);
|
93 |
if (expressionSo != NULL) |
94 |
{ |
95 |
fprintf(stdout, "Sollya expression: ");
|
96 |
pobyso_autoprint(expressionSo); |
97 |
} |
98 |
else
|
99 |
{ |
100 |
fprintf(stdout, "NULL expression");
|
101 |
} |
102 |
if (pobyso_is_int(expressionSo))
|
103 |
{ |
104 |
return 0; |
105 |
} |
106 |
else
|
107 |
{ |
108 |
return 1; |
109 |
} |
110 |
} /* End main */
|