14 print_widget (FILE *stream
,
15 const struct printf_info
*info
,
16 const void *const *args
)
22 /* Format the output into a string. */
23 w
= *((const Widget
**) (args
[0]));
24 len
= asprintf (&buffer
, "<Widget %p: %s>", w
, w
->name
);
28 /* Pad to the minimum field width and print to the stream. */
29 len
= fprintf (stream
, "%*s",
30 (info
->left
? -info
->width
: info
->width
),
33 /* Clean up and return. */
40 print_widget_arginfo (const struct printf_info
*info
, size_t n
,
43 /* We always take exactly one argument and this is a pointer to the
46 argtypes
[0] = PA_POINTER
;
54 /* Make a widget to print. */
56 mywidget
.name
= "mywidget";
58 /* Register the print function for widgets. */
59 register_printf_function ('W', print_widget
, print_widget_arginfo
);
61 /* Now print the widget. */
62 printf ("|%W|\n", &mywidget
);
63 printf ("|%35W|\n", &mywidget
);
64 printf ("|%-35W|\n", &mywidget
);