|
MentOS
0.8.0
The Mentoring Operating System
|
Print formatting routines. More...
Macros | |
| #define | __DEBUG_HEADER__ "[PRINTF]" |
| Change header. | |
| #define | __DEBUG_LEVEL__ LOGLEVEL_NOTICE |
| Set log level. | |
| #define | CVTBUFSIZE 500 |
| Size of the buffer used to call cvt functions. | |
| #define | FLAGS_ZEROPAD (1U << 0U) |
| Fill zeros before the number. | |
| #define | FLAGS_LEFT (1U << 1U) |
| Left align the value. | |
| #define | FLAGS_PLUS (1U << 2U) |
| Print the plus sign. | |
| #define | FLAGS_SPACE (1U << 3U) |
| If positive add a space instead of the plus sign. | |
| #define | FLAGS_HASH (1U << 4U) |
| Preceed with 0x or 0X, x or X respectively. | |
| #define | FLAGS_UPPERCASE (1U << 5U) |
| Print uppercase. | |
| #define | FLAGS_SIGN (1U << 6U) |
| Print the sign. | |
Functions | |
| static int | skip_atoi (const char **s) |
| Returns the integer value parsed from the beginning of the string until a non-integer character is found. More... | |
| static char * | number (char *str, long num, int base, int size, int32_t precision, unsigned flags) |
| Transforms the number into a string. More... | |
| static char * | eaddr (char *str, unsigned char *addr, int size, int precision, unsigned flags) |
| Converts a MAC address into a human-readable string format. More... | |
| static char * | iaddr (char *str, unsigned char *addr, int size, int precision, unsigned flags) |
| Converts an IPv4 address into a human-readable string format. More... | |
| static void | cfltcvt (double value, char *buffer, char fmt, int precision) |
| Converts a floating-point number to a string with a specified format. More... | |
| static void | forcdecpt (char *buffer) |
| Ensures that a decimal point is present in the given number string. More... | |
| static void | cropzeros (char *buffer) |
| Removes trailing zeros after the decimal point in a number string. More... | |
| static char * | flt (char *str, double num, int size, int precision, char fmt, unsigned flags) |
| Formats a floating-point number into a string with specified options. More... | |
| int | vsprintf (char *str, const char *fmt, va_list args) |
| Write formatted data from variable argument list to string. More... | |
| int | printf (const char *fmt,...) |
| Write formatted output to stdout. More... | |
| int | sprintf (char *str, const char *fmt,...) |
Write formatted output to str. More... | |
| int | vfprintf (int fd, const char *fmt, va_list args) |
| Write formatted data from variable argument list to a file. More... | |
| int | fprintf (int fd, const char *fmt,...) |
| Write formatted output to a file. More... | |
Variables | |
| static char * | _digits = "0123456789abcdefghijklmnopqrstuvwxyz" |
| The list of digits. | |
| static char * | _upper_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| The list of uppercase digits. | |
Print formatting routines.
|
static |
Converts a floating-point number to a string with a specified format.
| value | The floating-point value to be converted. |
| buffer | The output buffer to store the resulting string. |
| fmt | The format specifier ('e', 'f', or 'g'). |
| precision | The number of digits to be displayed after the decimal point. |
|
static |
Removes trailing zeros after the decimal point in a number string.
| buffer | The string representation of a number. |
|
static |
Converts a MAC address into a human-readable string format.
| str | The output string where the MAC address will be written. |
| addr | The 6-byte MAC address to be formatted. |
| size | The minimum field width for the output (pads with spaces if necessary). |
| precision | Unused in this function (for compatibility with similar functions). |
| flags | Control flags that affect the format (e.g., uppercase and left alignment). |
|
static |
Formats a floating-point number into a string with specified options.
This function converts a floating-point number into a string representation based on the specified format, precision, and flags. It handles alignment, padding, and sign appropriately.
| str | Pointer to the output string where the formatted number will be stored. |
| num | The floating-point number to format. |
| size | The total size of the output string, including padding. |
| precision | The number of digits to display after the decimal point. |
| fmt | The format specifier for the output ('f', 'g', 'e', etc.). |
| flags | Control flags that modify the output format (e.g., left alignment, zero padding). |
If the FLAGS_LEFT is set, clear the FLAGS_ZEROPAD flag. Left alignment implies no zero padding.
Determine the padding character (c) and the sign of the number. If FLAGS_ZEROPAD is set, the padding will be '0', otherwise it will be a space (' ').
Check the FLAGS_SIGN flag to determine if the sign should be added.
If the number is negative, set sign to '-' and make the number positive.
If FLAGS_PLUS is set, prepend a '+' to positive numbers.
If FLAGS_SPACE is set, prepend a space to positive numbers.
Set the default precision if no precision is provided.
Convert the floating-point number num into a string workbuf using the given format fmt.
If the FLAGS_HASH is set and precision is 0, force a decimal point in the output.
For format 'g', remove trailing zeros unless FLAGS_HASH is set.
Calculate the length of the resulting string workbuf.
Adjust size to account for the length of the output string.
Add padding spaces before the number if neither FLAGS_ZEROPAD nor FLAGS_LEFT are set.
Add the sign character (if any) before the number.
Add padding characters (either '0' or spaces) before the number if FLAGS_ZEROPAD is set.
Copy the formatted number string to the output str.
Add padding spaces after the number if FLAGS_LEFT is set (left-aligned output).
Return the resulting string after formatting the number.
|
static |
Ensures that a decimal point is present in the given number string.
| buffer | The string representation of a number. |
| int fprintf | ( | int | fd, |
| const char * | fmt, | ||
| ... | |||
| ) |
Write formatted output to a file.
| fd | The file descriptor associated with the file. |
| fmt | Format string, following the same specifications as printf. |
| ... | The list of arguments. |
|
static |
Converts an IPv4 address into a human-readable string format.
| str | The output string where the IPv4 address will be written. |
| addr | The 4-byte IPv4 address to be formatted. |
| size | The minimum field width for the output (pads with spaces if necessary). |
| precision | Unused in this function (for compatibility with similar functions). |
| flags | Control flags that affect the format (e.g., left alignment). |
|
static |
Transforms the number into a string.
| str | the output string. |
| num | the number to transform to string. |
| base | the base to use for number transformation (e.g., 10 for decimal, 16 for hex). |
| size | the minimum size of the output string (pads with '0' or spaces if necessary). |
| precision | the precision for number conversion (affects floating point numbers and zero padding). |
| flags | control flags (e.g., for padding, sign, and case sensitivity). |
| int printf | ( | const char * | fmt, |
| ... | |||
| ) |
Write formatted output to stdout.
| fmt | The format string. |
| ... | The list of arguments. |
|
inlinestatic |
Returns the integer value parsed from the beginning of the string until a non-integer character is found.
| s | the string we need to analyze. |
s points to a valid string and will stop parsing at the first non-integer character. | int sprintf | ( | char * | str, |
| const char * | fmt, | ||
| ... | |||
| ) |
Write formatted output to str.
| str | The buffer where the formatted string will be placed. |
| fmt | Format string, following the same specifications as printf. |
| ... | The list of arguments. |
| int vfprintf | ( | int | fd, |
| const char * | fmt, | ||
| va_list | args | ||
| ) |
Write formatted data from variable argument list to a file.
| fd | The file descriptor associated with the file. |
| fmt | Format string, following the same specifications as printf. |
| args | A variable arguments list. |
| int vsprintf | ( | char * | str, |
| const char * | fmt, | ||
| va_list | args | ||
| ) |
Write formatted data from variable argument list to string.
| str | Pointer to a buffer where the resulting C-string is stored. |
| fmt | Format string, following the same specifications as printf. |
| args | A variable arguments list. |