Subject: Re: small hack
To: Christos Zoulas <christos@zoulas.com>
From: Perry E. Metzger <perry@piermont.com>
List: tech-userlevel
Date: 09/23/1998 11:27:02
Christos Zoulas writes:
> On Sep 22,  6:24pm, perry@piermont.com ("Perry E. Metzger") wrote:
> -- Subject: small hack
> 
> I would like to see some more functionality of this:
> 	- if no arguments are given, it reads lines from stdin
> 	  and prints the lines in random order.

Already done.

> 	- if the -p <n> is given, <n> random items are printed.
> 	  p stands for pick

Easy to do -- I will add it!

> 	- don't use errx in usage it would print the program name in usage
> 	  twice; use fprintf("Usage: %s ...\n", __progname); I think at
> 	  this point we should add a usage() function in libc that is
> 	  printf like, since so many programs do this:

I like the idea a lot, but could we call it something other than
"usage" since the name "usage" is the one commonly used in existing
programs and it would cause confusion? maybe "print_usage()" or
something. We should also make sure gcc is taught how to find bugs in 
its use (and in that of the warn* and err* functions if that isn't
already done.)

> #include <stdio.h>
> #ifdef __STDC__
> #include <stdarg.h>
> #else
> #include <varargs.h>
> #endif
> #include <stdlib.h>
> #include <util.h>
> 
> void
> #ifdef __STDC__
> usage(int eval, const char *fmt, ...)
> #else
> usage(va_alist)
> 	va_dcl
> #endif
> {
> 	va_list ap;
> #ifndef __STDC__
> 	int eval;
> 	const char *fmt;
> 
> 	va_start(ap);
> 	eval = va_arg(ap, int);
> 	fmt = va_arg(ap, const char *);
> #else
> 	va_start(ap, fmt);
> #endif
> 	(void)fprintf(stderr, "Usage: %s ", __progname);
> 	(void)vfprintf(strderr, fmt, ap);
> 	va_end(ap);
> 	exit(eval);
> }
>