| 20 | #define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ |
| 21 | |
| 22 | static int number(void (*tx_byte)(unsigned char byte, void *data), unsigned long long inum, |
| 23 | int base, int size, int precision, int type, void *data) |
| 24 | { |
| 25 | char c, sign, tmp[66]; |
| 26 | const char *digits = "0123456789abcdef"; |
| 27 | int i; |
| 28 | int count = 0; |
| 29 | unsigned long long num = inum; |
| 30 | long long snum = num; |
| 31 | |
| 32 | if (type & LARGE) |
| 33 | digits = "0123456789ABCDEF"; |
| 34 | if (type & LEFT) |
| 35 | type &= ~ZEROPAD; |
| 36 | c = (type & ZEROPAD) ? '0' : ' '; |
| 37 | sign = 0; |
| 38 | if (type & SIGN) { |
| 39 | if (snum < 0) { |
| 40 | sign = '-'; |
| 41 | num = -snum; |
| 42 | size--; |
| 43 | } else if (type & PLUS) { |
| 44 | sign = '+'; |
| 45 | size--; |
| 46 | } else if (type & SPACE) { |
| 47 | sign = ' '; |
| 48 | size--; |
| 49 | } |
| 50 | } |
| 51 | if (type & SPECIAL) { |
| 52 | if (base == 16) |
| 53 | size -= 2; |
| 54 | else if (base == 8) |
| 55 | size--; |
| 56 | } |
| 57 | i = 0; |
| 58 | if (num == 0) { |
| 59 | tmp[i++] = '0'; |
| 60 | } else { |
| 61 | while (num != 0) { |
| 62 | tmp[i++] = digits[num % base]; |
| 63 | num /= base; |
| 64 | } |
| 65 | } |
| 66 | if (i > precision) { |
| 67 | precision = i; |
| 68 | } |
| 69 | size -= precision; |
| 70 | if (!(type & (ZEROPAD | LEFT))) { |
| 71 | while (size-- > 0) |
| 72 | call_tx(' '), count++; |
| 73 | } |
| 74 | if (sign) { |
| 75 | call_tx(sign), count++; |
| 76 | } |
| 77 | if (type & SPECIAL) { |
| 78 | if (base == 8) |
| 79 | call_tx('0'), count++; |
no outgoing calls
no test coverage detected