Statistiques
| Révision :

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

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

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