13 print_widget (FILE *stream
, const struct printf_info
*info
, va_list *app
)
19 /* Format the output into a string. */
20 w
= va_arg (*app
, Widget
*);
21 len
= asprintf (&buffer
, "<Widget %p: %s>", w
, w
->name
);
25 /* Pad to the minimum field width and print to the stream. */
26 len
= fprintf (stream
, "%*s",
27 (info
->left
? - info
->width
: info
->width
),
30 /* Clean up and return. */
39 /* Make a widget to print. */
41 mywidget
.name
= "mywidget";
43 /* Register the print function for widgets. */
44 register_printf_function ('W', print_widget
, NULL
); /* No arginfo. */
46 /* Now print the widget. */
47 printf ("|%W|\n", &mywidget
);
48 printf ("|%35W|\n", &mywidget
);
49 printf ("|%-35W|\n", &mywidget
);