Statistiques
| Révision :

root / pobysoC-4.0 / src / test-pobyso-is-int.c

Historique | Voir | Annoter | Télécharger (2,31 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
  int outcome = 1;
83

    
84
  sollya_lib_init();
85

    
86
  /* No command line argument test the function with the NULL argument. */
87
  if (argc == 1)
88
  {
89
    outcome = pobyso_is_int(expressionSo);
90
    sollya_lib_close();
91
    return outcome;
92
  }
93

    
94
  pobyso_set_canonical_on();
95
  expressionSo = pobyso_parse_string(argv[1]);
96
  if (expressionSo != NULL)
97
  {
98
    fprintf(stdout, "Sollya expression: ");
99
    pobyso_autoprint(expressionSo);
100
  }
101
  else
102
  {
103
    fprintf(stdout, "NULL expression");
104
  }
105
  if (pobyso_is_int(expressionSo))
106
  {
107
    sollya_lib_close();
108
    return 0;
109
  }
110
  else
111
  {
112
    sollya_lib_close();
113
    return 1;
114
  }
115
} /* End main */