Rev 1196 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1196 | Rev 1198 | ||
---|---|---|---|
Line 206... | Line 206... | ||
206 | * @param width |
206 | * @param width |
207 | * @param precision |
207 | * @param precision |
208 | * @param base Base to print the number in (should |
208 | * @param base Base to print the number in (should |
209 | * be in range 2 .. 16). |
209 | * be in range 2 .. 16). |
210 | * @param flags output modifiers |
210 | * @param flags output modifiers |
211 | * @return number of written characters or EOF |
211 | * @return number of written characters or negative value on fail. |
212 | * |
- | |
213 | */ |
212 | */ |
214 | static int print_number(__u64 num, int width, int precision, int base , __u64 flags) |
213 | static int print_number(__u64 num, int width, int precision, int base , __u64 flags) |
215 | { |
214 | { |
216 | char *digits = digits_small; |
215 | char *digits = digits_small; |
217 | char d[PRINT_NUMBER_BUFFER_SIZE]; /* this is good enough even for base == 2, prefix and sign */ |
216 | char d[PRINT_NUMBER_BUFFER_SIZE]; /* this is good enough even for base == 2, prefix and sign */ |
Line 343... | Line 342... | ||
343 | } |
342 | } |
344 | 343 | ||
345 | return written; |
344 | return written; |
346 | } |
345 | } |
347 | 346 | ||
348 | - | ||
349 | - | ||
350 | /** General formatted text print |
347 | /** General formatted text print |
351 | * |
348 | * |
352 | * Print text formatted according the fmt parameter |
349 | * Print string formatted according the fmt parameter |
353 | * and variant arguments. Each formatting directive |
350 | * and variant arguments. Each formatting directive |
354 | * begins with \% (percentage) character and one of the |
- | |
355 | * following character: |
351 | * must have the following form: |
356 | * |
- | |
357 | * \% Prints the percentage character. |
352 | * % [ flags ] [ width ] [ .precision ] [ type ] conversion |
358 | * |
353 | * |
- | 354 | * FLAGS: |
|
- | 355 | * # Force to print prefix. For conversion %o is prefix 0, for %x and %X are prefixes 0x and 0X and for conversion %b is prefix 0b. |
|
- | 356 | * - Align to left. |
|
359 | * s The next variant argument is treated as char* |
357 | * + Print positive sign just as negative. |
360 | * and printed as a NULL terminated string. |
358 | * (space) If printed number is positive and '+' flag is not set, print space in place of sign. |
- | 359 | * 0 Print 0 as padding instead of spaces. Zeroes are placed between sign and the rest of number. This flag is ignored if '-' flag is specified. |
|
361 | * |
360 | * |
- | 361 | * WIDTH: |
|
362 | * c The next variant argument is treated as a single char. |
362 | * Specify minimal width of printed argument. If it is bigger, width is ignored. |
- | 363 | * If width is specified with a '*' character instead of number, width is taken from parameter list. |
|
- | 364 | * Int parameter expected before parameter for processed conversion specification. |
|
- | 365 | * If this value is negative it is taken its absolute value and the '-' flag is set. |
|
363 | * |
366 | * |
- | 367 | * PRECISION: |
|
364 | * p The next variant argument is treated as a maximum |
368 | * Value precision. For numbers it specifies minimum valid numbers. |
- | 369 | * Smaller numbers are printed with leading zeroes. Bigger numbers are not affected. |
|
365 | * bit-width integer with respect to architecture |
370 | * Strings with more than precision characters are cutted of. |
366 | * and printed in full hexadecimal width. |
371 | * Just as width could be '*' used instead a number. |
- | 372 | * A int value is then expected in parameters. When both width and precision are specified using '*', |
|
- | 373 | * first parameter is used for width and second one for precision. |
|
367 | * |
374 | * |
- | 375 | * TYPE: |
|
- | 376 | * hh signed or unsigned char |
|
- | 377 | * h signed or usigned short |
|
368 | * P As with 'p', but '0x' is prefixed. |
378 | * signed or usigned int (default value) |
- | 379 | * l signed or usigned long int |
|
- | 380 | * ll signed or usigned long long int |
|
- | 381 | * z __native (non-standard extension) |
|
369 | * |
382 | * |
370 | * q The next variant argument is treated as a 64b integer |
- | |
371 | * and printed in full hexadecimal width. |
- | |
372 | * |
383 | * |
373 | * Q As with 'q', but '0x' is prefixed. |
384 | * CONVERSIONS: |
374 | * |
385 | * |
375 | * l The next variant argument is treated as a 32b integer |
- | |
376 | * and printed in full hexadecimal width. |
386 | * % Print percentage character. |
377 | * |
387 | * |
378 | * L As with 'l', but '0x' is prefixed. |
388 | * c Print single character. |
379 | * |
389 | * |
380 | * w The next variant argument is treated as a 16b integer |
390 | * s Print zero terminated string. If a NULL value is passed as value, "(NULL)" is printed instead. |
381 | * and printed in full hexadecimal width. |
- | |
382 | * |
391 | * |
- | 392 | * P, p Print value of a pointer. Void * value is expected and it is printed in hexadecimal notation with prefix |
|
383 | * W As with 'w', but '0x' is prefixed. |
393 | * ( as with %#X or %#x for 32bit or %#X / %#x for 64bit long pointers). |
384 | * |
394 | * |
385 | * b The next variant argument is treated as a 8b integer |
395 | * b Print value as unsigned binary number. Prefix is not printed by default. (Nonstandard extension.) |
386 | * and printed in full hexadecimal width. |
- | |
387 | * |
396 | * |
388 | * B As with 'b', but '0x' is prefixed. |
397 | * o Print value as unsigned octal number. Prefix is not printed by default. |
389 | * |
398 | * |
390 | * d The next variant argument is treated as integer |
399 | * d,i Print signed decimal number. There is no difference between d and i conversion. |
391 | * and printed in standard decimal format (only significant |
- | |
392 | * digits). |
- | |
393 | * |
400 | * |
394 | * x The next variant argument is treated as integer |
401 | * u Print unsigned decimal number. |
395 | * and printed in standard hexadecimal format (only significant |
- | |
396 | * digits). |
- | |
397 | * |
402 | * |
398 | * X As with 'x', but '0x' is prefixed. |
403 | * X, x Print hexadecimal number with upper- or lower-case. Prefix is not printed by default. |
399 | * |
404 | * |
400 | * All other characters from fmt except the formatting directives |
405 | * All other characters from fmt except the formatting directives |
401 | * are printed in verbatim. |
406 | * are printed in verbatim. |
402 | * |
407 | * |
403 | * @param fmt Formatting NULL terminated string. |
408 | * @param fmt Formatting NULL terminated string. |
- | 409 | * @return count of printed characters or negative value on fail. |
|
404 | */ |
410 | */ |
405 | int printf(const char *fmt, ...) |
411 | int printf(const char *fmt, ...) |
406 | { |
412 | { |
407 | int irqpri; |
413 | int irqpri; |
408 | int i = 0, j = 0; /* i is index of currently processed char from fmt, j is index to the first not printed nonformating character */ |
414 | int i = 0, j = 0; /* i is index of currently processed char from fmt, j is index to the first not printed nonformating character */ |