#include <limits.h>
#include "newalloc.h"
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define LONG_LONG __int64
-#else
-#define LONG_LONG long long
-#endif
-
int cNestLevel;
/*-----------------------------------------------------------------*/
short hex = 0, octal = 0;
char scanFmt[10];
int scI = 0;
- LONG_LONG sval;
+ long sval;
val = newValue (); /* alloc space for value */
SPEC_NOUN (val->type) = V_CHAR;
SPEC_USIGN (val->type) = 1;
- /* set the _long flag if 'lL' is found */
- if (strchr (s, 'l') || strchr (s, 'L'))
- SPEC_LONG (val->type) = 1;
-
hex = ((strchr (s, 'x') || strchr (s, 'X')) ? 1 : 0);
/* set the octal flag */
/* create the scan string */
scanFmt[scI++] = '%';
- scanFmt[scI++] = 'l';
scanFmt[scI++] = 'l';
if (octal)
sscanf (s, scanFmt, &sval);
+ /* Setup the flags first */
+ /* set the _long flag if 'lL' is found */
+ if (strchr (s, 'l') || strchr (s, 'L'))
+ SPEC_LONG (val->type) = 1;
+
if (sval<0) { // "-28u" will still be signed and negative
SPEC_USIGN (val->type) = 0;
if (sval<-32768) { // check if we have to promote to long
SPEC_NOUN (val->type) = V_INT;
SPEC_LONG (val->type) = 1;
- SPEC_CVAL (val->type).v_long=sval;
} else {
- SPEC_CVAL (val->type).v_int=sval;
if (sval<-128) { // check if we have to promote to int
SPEC_NOUN (val->type) = V_INT;
}
if (sval>0xffff) { // check if we have to promote to long
SPEC_NOUN (val->type) = V_INT;
SPEC_LONG (val->type) = 1;
- SPEC_CVAL (val->type).v_ulong=sval;
} else {
- SPEC_CVAL (val->type).v_uint=sval;
if (sval>0xff) { // check if we have to promote to int
SPEC_NOUN (val->type) = V_INT;
}
}
}
+ if (SPEC_LONG (val->type))
+ {
+ if (SPEC_USIGN (val->type))
+ {
+ SPEC_CVAL (val->type).v_ulong = sval;
+ }
+ else
+ {
+ SPEC_CVAL (val->type).v_long = sval;
+ }
+ }
+ else
+ {
+ if (SPEC_USIGN (val->type))
+ {
+ SPEC_CVAL (val->type).v_uint = sval;
+ }
+ else
+ {
+ SPEC_CVAL (val->type).v_int = sval;
+ }
+ }
+
return val;
}