Rev 1763 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1763 | Rev 1779 | ||
---|---|---|---|
Line 54... | Line 54... | ||
54 | * |
54 | * |
55 | * @param num Number containing digits. |
55 | * @param num Number containing digits. |
56 | * @param width Count of digits to print. |
56 | * @param width Count of digits to print. |
57 | * |
57 | * |
58 | */ |
58 | */ |
59 | static void print_fixed_hex(const __u64 num, const int width) |
59 | static void print_fixed_hex(const uint64_t num, const int width) |
60 | { |
60 | { |
61 | int i; |
61 | int i; |
62 | 62 | ||
63 | for (i = width * 8 - 4; i >= 0; i -= 4) |
63 | for (i = width * 8 - 4; i >= 0; i -= 4) |
64 | write(digits + ((num >> i) & 0xf), 1); |
64 | write(digits + ((num >> i) & 0xf), 1); |
Line 73... | Line 73... | ||
73 | * @param num Number to print. |
73 | * @param num Number to print. |
74 | * @param base Base to print the number in (should |
74 | * @param base Base to print the number in (should |
75 | * be in range 2 .. 16). |
75 | * be in range 2 .. 16). |
76 | * |
76 | * |
77 | */ |
77 | */ |
78 | static void print_number(const __native num, const unsigned int base) |
78 | static void print_number(const unative_t num, const unsigned int base) |
79 | { |
79 | { |
80 | int val = num; |
80 | int val = num; |
81 | char d[sizeof(__native) * 8 + 1]; /* this is good enough even for base == 2 */ |
81 | char d[sizeof(unative_t) * 8 + 1]; /* this is good enough even for base == 2 */ |
82 | int i = sizeof(__native) * 8 - 1; |
82 | int i = sizeof(unative_t) * 8 - 1; |
83 | 83 | ||
84 | do { |
84 | do { |
85 | d[i--] = digits[val % base]; |
85 | d[i--] = digits[val % base]; |
86 | } while (val /= base); |
86 | } while (val /= base); |
87 | 87 | ||
88 | d[sizeof(__native) * 8] = 0; |
88 | d[sizeof(unative_t) * 8] = 0; |
89 | puts(&d[i + 1]); |
89 | puts(&d[i + 1]); |
90 | } |
90 | } |
91 | 91 | ||
92 | 92 | ||
93 | /** General formatted text print |
93 | /** General formatted text print |
Line 180... | Line 180... | ||
180 | * Hexadecimal conversions with fixed width. |
180 | * Hexadecimal conversions with fixed width. |
181 | */ |
181 | */ |
182 | case 'P': |
182 | case 'P': |
183 | puts("0x"); |
183 | puts("0x"); |
184 | case 'p': |
184 | case 'p': |
185 | print_fixed_hex(va_arg(ap, __native), sizeof(__native)); |
185 | print_fixed_hex(va_arg(ap, unative_t), sizeof(unative_t)); |
186 | goto loop; |
186 | goto loop; |
187 | 187 | ||
188 | case 'Q': |
188 | case 'Q': |
189 | puts("0x"); |
189 | puts("0x"); |
190 | case 'q': |
190 | case 'q': |
191 | print_fixed_hex(va_arg(ap, __u64), INT64); |
191 | print_fixed_hex(va_arg(ap, uint64_t), INT64); |
192 | goto loop; |
192 | goto loop; |
193 | 193 | ||
194 | case 'L': |
194 | case 'L': |
195 | puts("0x"); |
195 | puts("0x"); |
196 | case 'l': |
196 | case 'l': |
197 | print_fixed_hex(va_arg(ap, __native), INT32); |
197 | print_fixed_hex(va_arg(ap, unative_t), INT32); |
198 | goto loop; |
198 | goto loop; |
199 | 199 | ||
200 | case 'W': |
200 | case 'W': |
201 | puts("0x"); |
201 | puts("0x"); |
202 | case 'w': |
202 | case 'w': |
203 | print_fixed_hex(va_arg(ap, __native), INT16); |
203 | print_fixed_hex(va_arg(ap, unative_t), INT16); |
204 | goto loop; |
204 | goto loop; |
205 | 205 | ||
206 | case 'B': |
206 | case 'B': |
207 | puts("0x"); |
207 | puts("0x"); |
208 | case 'b': |
208 | case 'b': |
209 | print_fixed_hex(va_arg(ap, __native), INT8); |
209 | print_fixed_hex(va_arg(ap, unative_t), INT8); |
210 | goto loop; |
210 | goto loop; |
211 | 211 | ||
212 | /* |
212 | /* |
213 | * Decimal and hexadecimal conversions. |
213 | * Decimal and hexadecimal conversions. |
214 | */ |
214 | */ |
215 | case 'd': |
215 | case 'd': |
216 | print_number(va_arg(ap, __native), 10); |
216 | print_number(va_arg(ap, unative_t), 10); |
217 | goto loop; |
217 | goto loop; |
218 | 218 | ||
219 | case 'X': |
219 | case 'X': |
220 | puts("0x"); |
220 | puts("0x"); |
221 | case 'x': |
221 | case 'x': |
222 | print_number(va_arg(ap, __native), 16); |
222 | print_number(va_arg(ap, unative_t), 16); |
223 | goto loop; |
223 | goto loop; |
224 | 224 | ||
225 | /* |
225 | /* |
226 | * Bad formatting. |
226 | * Bad formatting. |
227 | */ |
227 | */ |