2007-09-25 21:08:21 +05:30
|
|
|
/*!
|
2007-04-17 18:14:32 +05:30
|
|
|
* @file _usage.c
|
|
|
|
* @brief standardize help/usage output across all our programs
|
|
|
|
* @internal
|
|
|
|
*
|
|
|
|
* Copyright 2007 Gentoo Foundation
|
|
|
|
* Released under the GPLv2
|
|
|
|
*/
|
|
|
|
|
2007-09-26 14:37:31 +05:30
|
|
|
__attribute__ ((__noreturn__))
|
2007-04-17 18:14:32 +05:30
|
|
|
static void usage (int exit_status)
|
|
|
|
{
|
2007-09-26 04:27:32 +05:30
|
|
|
const char * const has_arg[] = { "", "<arg>", "[arg]" };
|
2007-04-17 18:14:32 +05:30
|
|
|
int i;
|
2007-09-21 17:22:37 +05:30
|
|
|
printf ("Usage: " APPLET " [options] ");
|
|
|
|
#ifdef extraopts
|
|
|
|
printf (extraopts);
|
|
|
|
#endif
|
|
|
|
printf ("\n\nOptions: [" getoptstring "]\n");
|
2007-09-26 04:27:32 +05:30
|
|
|
for (i = 0; longopts[i].name; ++i) {
|
|
|
|
int len = printf (" -%c, --%s %s", longopts[i].val, longopts[i].name,
|
|
|
|
has_arg[longopts[i].has_arg]);
|
2007-10-29 21:32:18 +05:30
|
|
|
|
|
|
|
char *lo = xstrdup (longopts_help[i]);
|
|
|
|
char *p = lo;
|
|
|
|
char *token;
|
|
|
|
|
|
|
|
while ((token = strsep (&p, "\n"))) {
|
|
|
|
while (++len < 37)
|
|
|
|
printf (" ");
|
|
|
|
puts (token);
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
free (lo);
|
2007-09-26 04:27:32 +05:30
|
|
|
}
|
2007-04-17 18:14:32 +05:30
|
|
|
exit (exit_status);
|
|
|
|
}
|
|
|
|
|