Changeset 0bc36ba in mainline
- Timestamp:
- 2006-05-02T11:52:52Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 432c648
- Parents:
- 6180b57
- Location:
- libc/generic/io
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libc/generic/io/printf_core.c
r6180b57 r0bc36ba 28 28 */ 29 29 30 /** 31 * @file print.c 32 * @brief Printing functions. 33 */ 34 30 35 #include <unistd.h> 31 36 #include <stdio.h> … … 34 39 #include <string.h> 35 40 36 #define __PRINTF_FLAG_PREFIX 0x00000001 /* show prefixes 0x or 0*/37 #define __PRINTF_FLAG_SIGNED 0x00000002 /* signed / unsigned number */38 #define __PRINTF_FLAG_ZEROPADDED 0x00000004 /* print leading zeroes */39 #define __PRINTF_FLAG_LEFTALIGNED 0x00000010 /* align to left */40 #define __PRINTF_FLAG_SHOWPLUS 0x00000020 /* always show + sign */41 #define __PRINTF_FLAG_SPACESIGN 0x00000040 /* print space instead of plus */42 #define __PRINTF_FLAG_BIGCHARS 0x00000080 /* show big characters */43 #define __PRINTF_FLAG_NEGATIVE 0x00000100 /* number has - sign */44 45 #define PRINT_NUMBER_BUFFER_SIZE (64+5) /* Buffer big enought for 64 bit number41 #define __PRINTF_FLAG_PREFIX 0x00000001 /**< show prefixes 0x or 0*/ 42 #define __PRINTF_FLAG_SIGNED 0x00000002 /**< signed / unsigned number */ 43 #define __PRINTF_FLAG_ZEROPADDED 0x00000004 /**< print leading zeroes */ 44 #define __PRINTF_FLAG_LEFTALIGNED 0x00000010 /**< align to left */ 45 #define __PRINTF_FLAG_SHOWPLUS 0x00000020 /**< always show + sign */ 46 #define __PRINTF_FLAG_SPACESIGN 0x00000040 /**< print space instead of plus */ 47 #define __PRINTF_FLAG_BIGCHARS 0x00000080 /**< show big characters */ 48 #define __PRINTF_FLAG_NEGATIVE 0x00000100 /**< number has - sign */ 49 50 #define PRINT_NUMBER_BUFFER_SIZE (64+5) /**< Buffer big enought for 64 bit number 46 51 * printed in base 2, sign, prefix and 47 52 * 0 to terminate string.. (last one is only for better testing 48 53 * end of buffer by zero-filling subroutine) 49 54 */ 55 /** Enumeration of possible arguments types. 56 */ 50 57 typedef enum { 51 58 PrintfQualifierByte = 0, … … 58 65 } qualifier_t; 59 66 60 static char digits_small[] = "0123456789abcdef"; /*Small hexadecimal characters */61 static char digits_big[] = "0123456789ABCDEF"; /*Big hexadecimal characters */67 static char digits_small[] = "0123456789abcdef"; /**< Small hexadecimal characters */ 68 static char digits_big[] = "0123456789ABCDEF"; /**< Big hexadecimal characters */ 62 69 63 70 /** Print count chars from buffer without adding newline … … 350 357 351 358 352 /** General formatted text print353 * 354 * Print string formatted according t he fmt parameter355 * and varia ntarguments. Each formatting directive359 /** Print formatted string. 360 * 361 * Print string formatted according to the fmt parameter 362 * and variadic arguments. Each formatting directive 356 363 * must have the following form: 357 * % [ flags ] [ width ] [ .precision ] [ type ] conversion 358 * 359 * FLAGS: 360 * # 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. 361 * - Align to left. 362 * + Print positive sign just as negative. 363 * (space) If printed number is positive and '+' flag is not set, print space in place of sign. 364 * 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. 365 * 366 * WIDTH: 367 * Specify minimal width of printed argument. If it is bigger, width is ignored. 368 * If width is specified with a '*' character instead of number, width is taken from parameter list. 369 * Int parameter expected before parameter for processed conversion specification. 370 * If this value is negative it is taken its absolute value and the '-' flag is set. 371 * 372 * PRECISION: 373 * Value precision. For numbers it specifies minimum valid numbers. 364 * 365 * \% [ FLAGS ] [ WIDTH ] [ .PRECISION ] [ TYPE ] CONVERSION 366 * 367 * FLAGS:@n 368 * - "#" Force to print prefix. 369 * For conversion \%o the prefix is 0, for %x and \%X prefixes are 0x and 0X 370 * and for conversion \%b the prefix is 0b. 371 * 372 * - "-" Align to left. 373 * 374 * - "+" Print positive sign just as negative. 375 * 376 * - " " If the printed number is positive and "+" flag is not set, print space in 377 * place of sign. 378 * 379 * - "0" Print 0 as padding instead of spaces. Zeroes are placed between sign and the 380 * rest of the number. This flag is ignored if "-" flag is specified. 381 * 382 * WIDTH:@n 383 * - Specify minimal width of printed argument. If it is bigger, width is ignored. 384 * If width is specified with a "*" character instead of number, width is taken from 385 * parameter list. And integer parameter is expected before parameter for processed 386 * conversion specification. If this value is negative its absolute value is taken 387 * and the "-" flag is set. 388 * 389 * PRECISION:@n 390 * - Value precision. For numbers it specifies minimum valid numbers. 374 391 * Smaller numbers are printed with leading zeroes. Bigger numbers are not affected. 375 * Strings with more than precision characters are cut ted of.376 * Just as wi dth could be '*' used instead a number.377 * A int value is then expected in parameters. When both width and precision are specified using '*',378 * first parameter is used for width and second one for precision.379 * 380 * TYPE:381 * hh signed or unsigned char382 * h signed or usigned short383 * signed or usigned int (default value)384 * l signed or usigned long int385 * ll signed or usigned long long int386 * z size_t type387 * 388 * 389 * CONVERSIONS:390 * 391 * % Print percentage character.392 * 393 * c Print single character.394 * 395 * s Print zero terminated string. If a NULL value is passed as value, "(NULL)" is printed instead.396 * 397 * P, p Print value of a pointer. Void * value is expected and it is printed in hexadecimal notation with prefix398 * ( as with %#X or %#x for 32bit or %#X / %#x for 64bit long pointers)399 * 400 * b Print value as unsigned binary number.Prefix is not printed by default. (Nonstandard extension.)401 * 402 * o Print value as unsigned octal number. Prefix is not printed by default.403 * 404 * d,i Print signed decimal number. There is no difference between d and i conversion.405 * 406 * u Print unsigned decimal number.407 * 408 * X, x Print hexadecimal number with upper- or lower-case. Prefix is not printed by default.392 * Strings with more than precision characters are cut off. 393 * Just as with width, an "*" can be used used instead of a number. 394 * An integer value is then expected in parameters. When both width and precision 395 * are specified using "*", the first parameter is used for width and the second one 396 * for precision. 397 * 398 * TYPE:@n 399 * - "hh" Signed or unsigned char.@n 400 * - "h" Signed or usigned short.@n 401 * - "" Signed or usigned int (default value).@n 402 * - "l" Signed or usigned long int.@n 403 * - "ll" Signed or usigned long long int.@n 404 * - "z" Type size_t.@n 405 * 406 * 407 * CONVERSION:@n 408 * - % Print percentile character itself. 409 * 410 * - c Print single character. 411 * 412 * - s Print zero terminated string. If a NULL value is passed as value, "(NULL)" is printed instead. 413 * 414 * - P, p Print value of a pointer. Void * value is expected and it is printed in hexadecimal notation with prefix 415 * (as with \%#X or \%#x for 32bit or \%#X / \%#x for 64bit long pointers). 416 * 417 * - b Print value as unsigned binary number. Prefix is not printed by default. (Nonstandard extension.) 418 * 419 * - o Print value as unsigned octal number. Prefix is not printed by default. 420 * 421 * - d,i Print signed decimal number. There is no difference between d and i conversion. 422 * 423 * - u Print unsigned decimal number. 424 * 425 * - X, x Print hexadecimal number with upper- or lower-case. Prefix is not printed by default. 409 426 * 410 427 * All other characters from fmt except the formatting directives … … 412 429 * 413 430 * @param fmt Formatting NULL terminated string. 414 * @return count of printed characters or negative value on fail.431 * @return Number of printed characters or negative value on failure. 415 432 */ 416 433 int printf_core(const char *fmt, struct printf_spec *ps, va_list ap) 417 434 { 418 int i = 0, j = 0; /* i is index of currently processed char from fmt, j is index to the first not printed nonformating character */435 int i = 0, j = 0; /**< i is index of currently processed char from fmt, j is index to the first not printed nonformating character */ 419 436 int end; 420 int counter; /* counter of printed characters */421 int retval; /* used to store return values from called functions */437 int counter; /**< counter of printed characters */ 438 int retval; /**< used to store return values from called functions */ 422 439 char c; 423 qualifier_t qualifier; /* type of argument */424 int base; /* base in which will be parameter (numbers only) printed */425 uint64_t number; /* argument value */426 size_t size; /* byte size of integer parameter */440 qualifier_t qualifier; /**< type of argument */ 441 int base; /**< base in which will be parameter (numbers only) printed */ 442 uint64_t number; /**< argument value */ 443 size_t size; /**< byte size of integer parameter */ 427 444 int width, precision; 428 445 uint64_t flags; -
libc/generic/io/vsnprintf.c
r6180b57 r0bc36ba 83 83 int vsnprintf(char *str, size_t size, const char *fmt, va_list ap) 84 84 { 85 size_t retval;86 85 struct vsnprintf_data data = {size, 0, str}; 87 86 struct printf_spec ps = {(int(*)(void *, size_t, void *))vsnprintf_write, &data};
Note:
See TracChangeset
for help on using the changeset viewer.