diff options
author | H. Peter Anvin <hpa@zytor.com> | 2007-10-22 16:53:48 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2007-10-22 16:53:48 -0700 |
commit | bea0bbb62c9947421bc0fddcd2b58a40435e2181 (patch) | |
tree | 21623213cc08b04a9eb771b2a46bb1e057a1948c /nasmlib.c | |
parent | 3b2ad1bc370653e90d6b2fa9cfc587a7aea405f3 (diff) | |
download | nasm-bea0bbb62c9947421bc0fddcd2b58a40435e2181.tar.gz |
More consistent handling of radix letters
Allow any radix letter from the set [bydtoqhx] to be used either
"Intel-style" (0...x) or "C-style" (0x...). In Intel style, the
leading 0 remains optional as long as the first digit is in the range
0-9.
As a consequence, allow the prefix "0h" for hexadecimal floating
point.
Diffstat (limited to 'nasmlib.c')
-rw-r--r-- | nasmlib.c | 46 |
1 files changed, 31 insertions, 15 deletions
@@ -196,6 +196,26 @@ char *nasm_strsep(char **stringp, const char *delim) #define lib_isnumchar(c) (isalnum(c) || (c) == '$' || (c) == '_') #define numvalue(c) ((c)>='a' ? (c)-'a'+10 : (c)>='A' ? (c)-'A'+10 : (c)-'0') +static int radix_letter(char c) +{ + switch (c) { + case 'b': case 'B': + case 'y': case 'Y': + return 2; /* Binary */ + case 'o': case 'O': + case 'q': case 'Q': + return 8; /* Octal */ + case 'h': case 'H': + case 'x': case 'X': + return 16; /* Hexadecimal */ + case 'd': case 'D': + case 't': case 'T': + return 10; /* Decimal */ + default: + return 0; /* Not a known radix letter */ + } +} + int64_t readnum(char *str, bool *error) { char *r = str, *q; @@ -225,24 +245,20 @@ int64_t readnum(char *str, bool *error) q++; /* find end of number */ /* - * If it begins 0x, 0X or $, or ends in H, it's in hex. if it - * ends in Q, it's octal. if it ends in B, it's binary. - * Otherwise, it's ordinary decimal. + * Handle radix formats: + * + * 0<radix-letter><string> + * $<string> (hexadecimal) + * <string><radix-letter> */ - if (*r == '0' && (r[1] == 'x' || r[1] == 'X')) - radix = 16, r += 2; + if (*r == '0' && (radix = radix_letter(r[1]))) + r += 2; else if (*r == '$') - radix = 16, r++; - else if (q[-1] == 'H' || q[-1] == 'h') - radix = 16, q--; - else if (q[-1] == 'Q' || q[-1] == 'q' || q[-1] == 'O' || q[-1] == 'o') - radix = 8, q--; - else if (q[-1] == 'B' || q[-1] == 'b' || q[-1] == 'Y' || q[-1] == 'y') - radix = 2, q--; - else if (q[-1] == 'D' || q[-1] == 'd' || q[-1] == 'T' || q[-1] == 't') - radix = 10, q--; + radix = 16, r++; + else if ((radix = radix_letter(q[-1])) != 0) + q--; else - radix = 10; + radix = 10; /* * If this number has been found for us by something other than |