Rev 430 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 430 | Rev 452 | ||
---|---|---|---|
Line 39... | Line 39... | ||
39 | static spinlock_t printflock; /**< printf spinlock */ |
39 | static spinlock_t printflock; /**< printf spinlock */ |
40 | 40 | ||
41 | #define DEFAULT_DOUBLE_PRECISION 16 |
41 | #define DEFAULT_DOUBLE_PRECISION 16 |
42 | #define DEFAULT_DOUBLE_BUFFER_SIZE 128 |
42 | #define DEFAULT_DOUBLE_BUFFER_SIZE 128 |
43 | 43 | ||
- | 44 | ||
- | 45 | /** Print NULL terminated string |
|
- | 46 | * |
|
- | 47 | * Print characters from str using putchar() until |
|
- | 48 | * \\0 character is reached. |
|
- | 49 | * |
|
- | 50 | * @param str Characters to print. |
|
- | 51 | * |
|
- | 52 | */ |
|
- | 53 | static void print_str(const char *str) |
|
- | 54 | { |
|
- | 55 | int i = 0; |
|
- | 56 | char c; |
|
- | 57 | ||
- | 58 | while (c = str[i++]) |
|
- | 59 | putchar(c); |
|
- | 60 | } |
|
- | 61 | ||
- | 62 | ||
- | 63 | /** Print hexadecimal digits |
|
- | 64 | * |
|
- | 65 | * Print fixed count of hexadecimal digits from |
|
- | 66 | * the number num. The digits are printed in |
|
- | 67 | * natural left-to-right order starting with |
|
- | 68 | * the width-th digit. |
|
- | 69 | * |
|
- | 70 | * @param num Number containing digits. |
|
- | 71 | * @param width Count of digits to print. |
|
- | 72 | * |
|
- | 73 | */ |
|
- | 74 | static void print_fixed_hex(const __u64 num, const int width) |
|
- | 75 | { |
|
- | 76 | int i; |
|
- | 77 | ||
- | 78 | for (i = width*8 - 4; i >= 0; i -= 4) |
|
- | 79 | putchar(digits[(num>>i) & 0xf]); |
|
- | 80 | } |
|
- | 81 | ||
- | 82 | ||
- | 83 | /** Print number in given base |
|
- | 84 | * |
|
- | 85 | * Print significant digits of a number in given |
|
- | 86 | * base. |
|
- | 87 | * |
|
- | 88 | * @param num Number to print. |
|
- | 89 | * @param base Base to print the number in (should |
|
- | 90 | * be in range 2 .. 16). |
|
- | 91 | * |
|
- | 92 | */ |
|
- | 93 | static void print_number(const __native num, const unsigned int base) |
|
- | 94 | { |
|
- | 95 | int val = num; |
|
- | 96 | char d[sizeof(__native)*8+1]; /* this is good enough even for base == 2 */ |
|
- | 97 | int i = sizeof(__native)*8-1; |
|
- | 98 | ||
- | 99 | do { |
|
- | 100 | d[i--] = digits[val % base]; |
|
- | 101 | } while (val /= base); |
|
- | 102 | ||
- | 103 | d[sizeof(__native)*8] = 0; |
|
- | 104 | print_str(&d[i + 1]); |
|
- | 105 | } |
|
- | 106 | ||
- | 107 | ||
44 | void print_double(double num, __u8 modifier, __u16 precision) |
108 | static void print_double(double num, __u8 modifier, __u16 precision) |
45 | { |
109 | { |
46 | double intval,intval2; |
110 | double intval,intval2; |
47 | int counter; |
111 | int counter; |
48 | int exponent,exponenttmp; |
112 | int exponent,exponenttmp; |
49 | unsigned char buf[DEFAULT_DOUBLE_BUFFER_SIZE]; |
113 | unsigned char buf[DEFAULT_DOUBLE_BUFFER_SIZE]; |
Line 140... | Line 204... | ||
140 | putchar(buf[--counter]); |
204 | putchar(buf[--counter]); |
141 | } |
205 | } |
142 | return; |
206 | return; |
143 | } |
207 | } |
144 | 208 | ||
145 | /** Print NULL terminated string |
- | |
146 | * |
- | |
147 | * Print characters from str using putchar() until |
- | |
148 | * \\0 character is reached. |
- | |
149 | * |
- | |
150 | * @param str Characters to print. |
- | |
151 | * |
- | |
152 | */ |
- | |
153 | void print_str(const char *str) |
- | |
154 | { |
- | |
155 | int i = 0; |
- | |
156 | char c; |
- | |
157 | - | ||
158 | while (c = str[i++]) |
- | |
159 | putchar(c); |
- | |
160 | } |
- | |
161 | - | ||
162 | - | ||
163 | /** Print hexadecimal digits |
- | |
164 | * |
- | |
165 | * Print fixed count of hexadecimal digits from |
- | |
166 | * the number num. The digits are printed in |
- | |
167 | * natural left-to-right order starting with |
- | |
168 | * the width-th digit. |
- | |
169 | * |
- | |
170 | * @param num Number containing digits. |
- | |
171 | * @param width Count of digits to print. |
- | |
172 | * |
- | |
173 | */ |
- | |
174 | void print_fixed_hex(const __u64 num, const int width) |
- | |
175 | { |
- | |
176 | int i; |
- | |
177 | - | ||
178 | for (i = width*8 - 4; i >= 0; i -= 4) |
- | |
179 | putchar(digits[(num>>i) & 0xf]); |
- | |
180 | } |
- | |
181 | - | ||
182 | - | ||
183 | /** Print number in given base |
- | |
184 | * |
- | |
185 | * Print significant digits of a number in given |
- | |
186 | * base. |
- | |
187 | * |
- | |
188 | * @param num Number to print. |
- | |
189 | * @param base Base to print the number in (should |
- | |
190 | * be in range 2 .. 16). |
- | |
191 | * |
- | |
192 | */ |
- | |
193 | void print_number(const __native num, const unsigned int base) |
- | |
194 | { |
- | |
195 | int val = num; |
- | |
196 | char d[sizeof(__native)*8+1]; /* this is good enough even for base == 2 */ |
- | |
197 | int i = sizeof(__native)*8-1; |
- | |
198 | - | ||
199 | do { |
- | |
200 | d[i--] = digits[val % base]; |
- | |
201 | } while (val /= base); |
- | |
202 | - | ||
203 | d[sizeof(__native)*8] = 0; |
- | |
204 | print_str(&d[i + 1]); |
- | |
205 | } |
- | |
206 | - | ||
207 | 209 | ||
208 | /** General formatted text print |
210 | /** General formatted text print |
209 | * |
211 | * |
210 | * Print text formatted according the fmt parameter |
212 | * Print text formatted according the fmt parameter |
211 | * and variant arguments. Each formatting directive |
213 | * and variant arguments. Each formatting directive |