Used Variables instead of Options, in SConstruct
[mcc.git] / const.c
blobd8903b62120cd7c66a8305126798479378ce895f
1 #include "const.h"
2 #include "ctype.h"
3 #include "math.h"
5 void const_parse_number(struct const_value *restrict cv, const char *restrict str)
7 const char *restrict p = str;
8 long double place_value, exponent;
9 cv->type = CBT_INT;
10 cv->v.i = 0;
11 if (*p == '0'){
12 // octal or hexadecimal
13 p++;
14 if (tolower(*p) == 'x'){
15 // hexadecimal
16 p++;
17 while (isdigit(*p) || (tolower(*p) >= 'a' && tolower(*p) <= 'f')){
18 if (isdigit(*p)){
19 cv->v.i = (cv->v.i << 4) | (*p - '0');
20 } else {
21 cv->v.i = (cv->v.i << 4) | ((tolower(*p) - 'a') + 10);
23 p++;
25 } else {
26 // octal
27 p++;
28 while (*p >= '0' && *p <= '7'){
29 cv->v.i = (cv->v.i << 3) | (*p - 0);
30 p++;
33 } else if (*p >= '0' && *p <= 9){
34 // decimal
35 while (*p >= '0' && *p <= '9'){
36 cv->v.i = (cv->v.i * 10) + (*p - '0');
37 p++;
39 if (*p == '.'){
40 // decimal part
41 cv->v.ld = cv->v.i;
42 cv->type = CBT_LONGDOUBLE;
43 place_value = 0.1;
44 p++;
45 while (*p >= '0' && *p <= '9'){
46 cv->v.ld = (*p - '0') * place_value;
47 place_value /= 10.0;
48 p++;
51 if (tolower(*p) == 'e'){
52 // exponent part
53 if (cv->type != CBT_LONGDOUBLE){
54 cv->v.ld = cv->v.i;
55 cv->type = CBT_LONGDOUBLE;
57 p++;
58 exponent = 0.0;
59 while (*p >= '0' && *p <= '9'){
60 exponent = (exponent * 10.0) + (*p - '0');
61 p++;
63 cv->v.ld *= powl(10, exponent);