Changeset 0bc36ba in mainline


Ignore:
Timestamp:
2006-05-02T11:52:52Z (19 years ago)
Author:
Josef Cejka <malyzelenyhnus@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
432c648
Parents:
6180b57
Message:

Comments update.

Location:
libc/generic/io
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libc/generic/io/printf_core.c

    r6180b57 r0bc36ba  
    2828 */
    2929
     30/**
     31 * @file        print.c
     32 * @brief       Printing functions.
     33 */
     34
    3035#include <unistd.h>
    3136#include <stdio.h>
     
    3439#include <string.h>
    3540
    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 number
     41#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
    4651                                                         * printed in base 2, sign, prefix and
    4752                                                         * 0 to terminate string.. (last one is only for better testing
    4853                                                         * end of buffer by zero-filling subroutine)
    4954                                                         */
     55/** Enumeration of possible arguments types.
     56 */
    5057typedef enum {
    5158        PrintfQualifierByte = 0,
     
    5865} qualifier_t;
    5966
    60 static char digits_small[] = "0123456789abcdef";        /* Small hexadecimal characters */
    61 static char digits_big[] = "0123456789ABCDEF";  /* Big hexadecimal characters */
     67static char digits_small[] = "0123456789abcdef";        /**< Small hexadecimal characters */
     68static char digits_big[] = "0123456789ABCDEF";          /**< Big hexadecimal characters */
    6269
    6370/** Print count chars from buffer without adding newline
     
    350357
    351358
    352 /** General formatted text print
    353  *
    354  * Print string formatted according the fmt parameter
    355  * and variant arguments. Each formatting directive
     359/** Print formatted string.
     360 *
     361 * Print string formatted according to the fmt parameter
     362 * and variadic arguments. Each formatting directive
    356363 * 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.
    374391 * Smaller numbers are printed with leading zeroes. Bigger numbers are not affected.
    375  * Strings with more than precision characters are cutted of.
    376  * Just as width 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 char
    382  * h    signed or usigned short
    383  *      signed or usigned int (default value)
    384  * l    signed or usigned long int
    385  * ll   signed or usigned long long int
    386  * z    size_t type
    387  *
    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 prefix
    398  * ( 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.
    409426 *
    410427 * All other characters from fmt except the formatting directives
     
    412429 *
    413430 * @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.
    415432 */
    416433int printf_core(const char *fmt, struct printf_spec *ps, va_list ap)
    417434{
    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 */
    419436        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 */
    422439        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 */
    427444        int width, precision;
    428445        uint64_t flags;
  • libc/generic/io/vsnprintf.c

    r6180b57 r0bc36ba  
    8383int vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
    8484{
    85         size_t retval;
    8685        struct vsnprintf_data data = {size, 0, str};
    8786        struct printf_spec ps = {(int(*)(void *, size_t, void *))vsnprintf_write, &data};
Note: See TracChangeset for help on using the changeset viewer.