Next: Defining the Output Handler, Previous: Registering New Conversions, Up: Customizing printf
[Contents][Index]
If you define a meaning for ‘%A’, what if the template contains ‘%+23A’ or ‘%-#A’? To implement a sensible meaning for these, the handler when called needs to be able to get the options specified in the template.
Both the handler-function and arginfo-function accept an
argument that points to a struct printf_info
, which contains
information about the options appearing in an instance of the conversion
specifier. This data type is declared in the header file
printf.h.
This structure is used to pass information about the options appearing
in an instance of a conversion specifier in a printf
template
string to the handler and arginfo functions for that specifier. It
contains the following members:
int prec
This is the precision specified. The value is -1
if no precision
was specified. If the precision was given as ‘*’, the
printf_info
structure passed to the handler function contains the
actual value retrieved from the argument list. But the structure passed
to the arginfo function contains a value of INT_MIN
, since the
actual value is not known.
int width
This is the minimum field width specified. The value is 0
if no
width was specified. If the field width was given as ‘*’, the
printf_info
structure passed to the handler function contains the
actual value retrieved from the argument list. But the structure passed
to the arginfo function contains a value of INT_MIN
, since the
actual value is not known.
wchar_t spec
This is the conversion specifier character specified. It’s stored in the structure so that you can register the same handler function for multiple characters, but still have a way to tell them apart when the handler function is called.
unsigned int is_long_double
This is a boolean that is true if the ‘L’, ‘ll’, or ‘q’
type modifier was specified. For integer conversions, this indicates
long long int
, as opposed to long double
for floating
point conversions.
unsigned int is_char
This is a boolean that is true if the ‘hh’ type modifier was specified.
unsigned int is_short
This is a boolean that is true if the ‘h’ type modifier was specified.
unsigned int is_long
This is a boolean that is true if the ‘l’ type modifier was specified.
unsigned int alt
This is a boolean that is true if the ‘#’ flag was specified.
unsigned int space
This is a boolean that is true if the ‘ ’ flag was specified.
unsigned int left
This is a boolean that is true if the ‘-’ flag was specified.
unsigned int showsign
This is a boolean that is true if the ‘+’ flag was specified.
unsigned int group
This is a boolean that is true if the ‘'’ flag was specified.
unsigned int extra
This flag has a special meaning depending on the context. It could
be used freely by the user-defined handlers but when called from
the printf
function this variable always contains the value
0
.
unsigned int wide
This flag is set if the stream is wide oriented.
wchar_t pad
This is the character to use for padding the output to the minimum field
width. The value is '0'
if the ‘0’ flag was specified, and
' '
otherwise.
Next: Defining the Output Handler, Previous: Registering New Conversions, Up: Customizing printf
[Contents][Index]