13 print_widget (FILE *stream
,
14 const struct printf_info
*info
,
21 /* Format the output into a string. */
22 w
= va_arg (*app
, Widget
*);
23 len
= asprintf (&buffer
, "<Widget %p: %s>", w
, w
->name
);
27 /* Pad to the minimum field width and print to the stream. */
28 len
= fprintf (stream
, "%*s",
29 (info
->left
? - info
->width
: info
->width
),
32 /* Clean up and return. */
39 print_widget_arginfo (const struct printf_info
*info
, size_t n
,
42 /* We always take exactly one argument and this is a pointer to the
45 argtypes
[0] = PA_POINTER
;
53 /* Make a widget to print. */
55 mywidget
.name
= "mywidget";
57 /* Register the print function for widgets. */
58 register_printf_function ('W', print_widget
, print_widget_arginfo
);
60 /* Now print the widget. */
61 printf ("|%W|\n", &mywidget
);
62 printf ("|%35W|\n", &mywidget
);
63 printf ("|%-35W|\n", &mywidget
);