diff options
author | Roland McGrath <roland@gnu.org> | 1992-10-19 20:28:19 +0000 |
---|---|---|
committer | Roland McGrath <roland@gnu.org> | 1992-10-19 20:28:19 +0000 |
commit | 1600c1c5ccb5c4dc4df840d9a772d3ac541d8881 (patch) | |
tree | d7fb85c9c20cf95e4612a74b28602e6576c9d71d /manual/examples | |
parent | be67a1f3902e89d79fef8ff8a2ce7469597fcc71 (diff) |
misc cleanups.
Diffstat (limited to 'manual/examples')
-rw-r--r-- | manual/examples/rprintf.c | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/manual/examples/rprintf.c b/manual/examples/rprintf.c index c62ff4956e..eff1d8e7cf 100644 --- a/manual/examples/rprintf.c +++ b/manual/examples/rprintf.c @@ -2,55 +2,51 @@ #include <printf.h> #include <stdarg.h> -typedef struct widget +/*@group*/ +typedef struct { char *name; } Widget; +/*@end group*/ int print_widget (FILE *stream, const struct printf_info *info, va_list *app) { Widget *w; char *buffer; - int len, fill, i; + int len; /* Format the output into a string. */ w = va_arg (*app, Widget *); len = asprintf (&buffer, "<Widget %p: %s>", w, w->name); if (len == -1) return -1; - fill = info->width - len; - if (fill < 0) - fill = 0; /* Pad to the minimum field width and print to the stream. */ - if (!info->left) - for (i = 0; i < fill; i++) - putc (' ', stream); - fputs (buffer, stream); - if (info->left) - for (i = 0; i < fill; i++) - putc (' ', stream); + len = fprintf (stream, "%*s", + (info->left ? - info->width : info->width), + buffer); /* Clean up and return. */ free (buffer); - return (len + fill); + return len; } -void +int main (void) { - /* Make a widget to print. */ Widget mywidget; mywidget.name = "mywidget"; /* Register the print function for widgets. */ - register_printf_function ('W', print_widget); + register_printf_function ('W', print_widget, NULL); /* No arginfo. */ /* Now print the widget. */ printf ("|%W|\n", &mywidget); printf ("|%35W|\n", &mywidget); printf ("|%-35W|\n", &mywidget); + + return 0; } |