diff options
author | Siteshwar Vashisht <siteshwar@gmail.com> | 2013-03-17 00:04:11 +0530 |
---|---|---|
committer | Siteshwar Vashisht <siteshwar@gmail.com> | 2013-03-17 00:04:11 +0530 |
commit | 490ead52eb8fa246f882c8993344184904fe1eb0 (patch) | |
tree | 1fc5749833ce981256dc983b3a67448f84f946d8 /builtin_printf.cpp | |
parent | a5a7a324479203b18c20b984cc7740e07bec7e11 (diff) |
Changed octtobin, hextobin and isodigit macros into functions
Diffstat (limited to 'builtin_printf.cpp')
-rw-r--r-- | builtin_printf.cpp | 76 |
1 files changed, 71 insertions, 5 deletions
diff --git a/builtin_printf.cpp b/builtin_printf.cpp index c63231ae..b190b316 100644 --- a/builtin_printf.cpp +++ b/builtin_printf.cpp @@ -59,12 +59,78 @@ #define AUTHORS "David MacKenzie" -#define isodigit(c) ((c) >= L'0' && (c) <= L'7') -#define hextobin(c) ((c) >= L'a' && (c) <= L'f' ? (c) - L'a' + 10 : \ - (c) >= L'A' && (c) <= L'F' ? (c) - L'A' + 10 : (c) - L'0') -#define octtobin(c) ((c) - L'0') +bool isodigit(const wchar_t &c) +{ + return wcschr(L"01234567", c) != NULL; +} + +int hextobin(const wchar_t &c) +{ + switch (c) + { + case L'0': + return 0; + case L'1': + return 1; + case L'2': + return 2; + case L'3': + return 3; + case L'4': + return 4; + case L'5': + return 5; + case L'6': + return 6; + case L'7': + return 7; + case L'8': + return 8; + case L'9': + return 9; + case L'a': + return 10; + case L'b': + return 11; + case L'c': + return 12; + case 'd': + return 13; + case 'e': + return 14; + case 'f': + return 15; + default: + append_format(stderr_buffer, L"Invalid hex number : %lc", c); + return -1; + } +} -# define ISDIGIT(c) ((unsigned int) (c) - L'0' <= 9) +int octtobin(const wchar_t &c) +{ + switch (c) + { + case L'0': + return 0; + case L'1': + return 1; + case L'2': + return 2; + case L'3': + return 3; + case L'4': + return 4; + case L'5': + return 5; + case L'6': + return 6; + case L'7': + return 7; + default: + append_format(stderr_buffer, L"Invalid octal number : %lc", c); + return -1; + } +} static int exit_code; |