Handle -h and --help according to GNU Coding Standards (#17104)

Added -h instead of -?.  And upon -h and --help, write usave to stdout
instead of stdin, and return 0 instead of 1.

-? still works like before as that's what getopt returns upon unknown
arguments.
This commit is contained in:
Behdad Esfahbod 2008-08-22 16:51:33 -04:00
parent df243f93be
commit 1439c8f21a
10 changed files with 125 additions and 107 deletions

View File

@ -72,7 +72,7 @@ const struct option longopts[] = {
{"system-only", 0, 0, 's'},
{"version", 0, 0, 'V'},
{"verbose", 0, 0, 'v'},
{"help", 0, 0, '?'},
{"help", 0, 0, 'h'},
{NULL,0,0,0},
};
#else
@ -83,34 +83,35 @@ extern int optind, opterr, optopt;
#endif
static void
usage (char *program)
usage (char *program, int error)
{
FILE *file = error ? stderr : stdout;
#if HAVE_GETOPT_LONG
fprintf (stderr, "usage: %s [-frsvV?] [--force|--really-force] [--system-only] [--verbose] [--version] [--help] [dirs]\n",
fprintf (file, "usage: %s [-frsvVh] [--force|--really-force] [--system-only] [--verbose] [--version] [--help] [dirs]\n",
program);
#else
fprintf (stderr, "usage: %s [-frsvV?] [dirs]\n",
fprintf (file, "usage: %s [-frsvVh] [dirs]\n",
program);
#endif
fprintf (stderr, "Build font information caches in [dirs]\n"
fprintf (file, "Build font information caches in [dirs]\n"
"(all directories in font configuration by default).\n");
fprintf (stderr, "\n");
fprintf (file, "\n");
#if HAVE_GETOPT_LONG
fprintf (stderr, " -f, --force scan directories with apparently valid caches\n");
fprintf (stderr, " -r, --really-force erase all existing caches, then rescan\n");
fprintf (stderr, " -s, --system-only scan system-wide directories only\n");
fprintf (stderr, " -v, --verbose display status information while busy\n");
fprintf (stderr, " -V, --version display font config version and exit\n");
fprintf (stderr, " -?, --help display this help and exit\n");
fprintf (file, " -f, --force scan directories with apparently valid caches\n");
fprintf (file, " -r, --really-force erase all existing caches, then rescan\n");
fprintf (file, " -s, --system-only scan system-wide directories only\n");
fprintf (file, " -v, --verbose display status information while busy\n");
fprintf (file, " -V, --version display font config version and exit\n");
fprintf (file, " -h, --help display this help and exit\n");
#else
fprintf (stderr, " -f (force) scan directories with apparently valid caches\n");
fprintf (stderr, " -r, (really force) erase all existing caches, then rescan\n");
fprintf (stderr, " -s (system) scan system-wide directories only\n");
fprintf (stderr, " -v (verbose) display status information while busy\n");
fprintf (stderr, " -V (version) display font config version and exit\n");
fprintf (stderr, " -? (help) display this help and exit\n");
fprintf (file, " -f (force) scan directories with apparently valid caches\n");
fprintf (file, " -r, (really force) erase all existing caches, then rescan\n");
fprintf (file, " -s (system) scan system-wide directories only\n");
fprintf (file, " -v (verbose) display status information while busy\n");
fprintf (file, " -V (version) display font config version and exit\n");
fprintf (file, " -h (help) display this help and exit\n");
#endif
exit (1);
exit (error);
}
static FcStrSet *processed_dirs;
@ -373,9 +374,9 @@ main (int argc, char **argv)
int c;
#if HAVE_GETOPT_LONG
while ((c = getopt_long (argc, argv, "frsVv?", longopts, NULL)) != -1)
while ((c = getopt_long (argc, argv, "frsVvh", longopts, NULL)) != -1)
#else
while ((c = getopt (argc, argv, "frsVv?")) != -1)
while ((c = getopt (argc, argv, "frsVvh")) != -1)
#endif
{
switch (c) {
@ -395,8 +396,10 @@ main (int argc, char **argv)
case 'v':
verbose = FcTrue;
break;
case 'h':
usage (argv[0], 0);
default:
usage (argv[0]);
usage (argv[0], 1);
}
}
i = optind;

View File

@ -63,7 +63,7 @@ manpage.1: manpage.sgml
<cmdsynopsis>
<command>&dhpackage;</command>
<arg><option>-fsvV?</option></arg>
<arg><option>-fsvVh</option></arg>
<arg><option>--force</option></arg>
<arg><option>--system-only</option></arg>
<arg><option>--verbose</option></arg>
@ -131,7 +131,7 @@ manpage.1: manpage.sgml
</listitem>
</varlistentry>
<varlistentry>
<term><option>-?</option>
<term><option>-h</option>
<option>--help</option>
</term>
<listitem>

View File

@ -56,7 +56,7 @@ const struct option longopts[] = {
{"version", 0, 0, 'V'},
{"verbose", 0, 0, 'v'},
{"recurse", 0, 0, 'r'},
{"help", 0, 0, '?'},
{"help", 0, 0, 'h'},
{NULL,0,0,0},
};
#else
@ -146,32 +146,33 @@ write_string (FILE *f, const FcChar8 *string)
}
static void
usage (char *program)
usage (char *program, int error)
{
FILE *file = error ? stderr : stdout;
#if HAVE_GETOPT_LONG
fprintf (stderr, "usage: %s [-rv] [--recurse] [--verbose] [*-%s.cache-2|directory]...\n",
fprintf (file, "usage: %s [-rv] [--recurse] [--verbose] [*-%s.cache-2|directory]...\n",
program, FC_ARCHITECTURE);
fprintf (stderr, " %s [-V?] [--version] [--help]\n", program);
fprintf (file, " %s [-Vh] [--version] [--help]\n", program);
#else
fprintf (stderr, "usage: %s [-rvV?] [*-%s.cache-2|directory]...\n",
fprintf (file, "usage: %s [-rvVh] [*-%s.cache-2|directory]...\n",
program, FC_ARCHITECTURE);
#endif
fprintf (stderr, "Reads font information cache from:\n");
fprintf (stderr, " 1) specified fontconfig cache file\n");
fprintf (stderr, " 2) related to a particular font directory\n");
fprintf (stderr, "\n");
fprintf (file, "Reads font information cache from:\n");
fprintf (file, " 1) specified fontconfig cache file\n");
fprintf (file, " 2) related to a particular font directory\n");
fprintf (file, "\n");
#if HAVE_GETOPT_LONG
fprintf (stderr, " -r, --recurse recurse into subdirectories\n");
fprintf (stderr, " -v, --verbose be verbose\n");
fprintf (stderr, " -V, --version display font config version and exit\n");
fprintf (stderr, " -?, --help display this help and exit\n");
fprintf (file, " -r, --recurse recurse into subdirectories\n");
fprintf (file, " -v, --verbose be verbose\n");
fprintf (file, " -V, --version display font config version and exit\n");
fprintf (file, " -h, --help display this help and exit\n");
#else
fprintf (stderr, " -r (recurse) recurse into subdirectories\n");
fprintf (stderr, " -v (verbose) be verbose\n");
fprintf (stderr, " -V (version) display font config version and exit\n");
fprintf (stderr, " -? (help) display this help and exit\n");
fprintf (file, " -r (recurse) recurse into subdirectories\n");
fprintf (file, " -v (verbose) be verbose\n");
fprintf (file, " -V (version) display font config version and exit\n");
fprintf (file, " -h (help) display this help and exit\n");
#endif
exit (1);
exit (error);
}
/*
@ -282,9 +283,9 @@ main (int argc, char **argv)
int c;
#if HAVE_GETOPT_LONG
while ((c = getopt_long (argc, argv, "Vvr?", longopts, NULL)) != -1)
while ((c = getopt_long (argc, argv, "Vvrh", longopts, NULL)) != -1)
#else
while ((c = getopt (argc, argv, "Vvr?")) != -1)
while ((c = getopt (argc, argv, "Vvrh")) != -1)
#endif
{
switch (c) {
@ -298,8 +299,10 @@ main (int argc, char **argv)
case 'r':
recurse++;
break;
case 'h':
usage (argv[0], 0);
default:
usage (argv[0]);
usage (argv[0], 1);
}
}
i = optind;

View File

@ -63,7 +63,7 @@ manpage.1: manpage.sgml
<cmdsynopsis>
<command>&dhpackage;</command>
<arg><option>-rvV?</option></arg>
<arg><option>-rvVh</option></arg>
<arg><option>--recurse</option></arg>
<arg><option>--verbose</option></arg>
<arg><option>--version</option></arg>
@ -109,7 +109,7 @@ manpage.1: manpage.sgml
</listitem>
</varlistentry>
<varlistentry>
<term><option>-?</option>
<term><option>-h</option>
<option>--help</option>
</term>
<listitem>

View File

@ -49,7 +49,7 @@
const struct option longopts[] = {
{"version", 0, 0, 'V'},
{"verbose", 0, 0, 'v'},
{"help", 0, 0, '?'},
{"help", 0, 0, 'h'},
{NULL,0,0,0},
};
#else
@ -59,27 +59,29 @@ extern int optind, opterr, optopt;
#endif
#endif
static void usage (char *program)
static void
usage (char *program, int error)
{
FILE *file = error ? stderr : stdout;
#if HAVE_GETOPT_LONG
fprintf (stderr, "usage: %s [-vV?] [--verbose] [--version] [--help] [pattern] {element ...} \n",
fprintf (file, "usage: %s [-vVh] [--verbose] [--version] [--help] [pattern] {element ...} \n",
program);
#else
fprintf (stderr, "usage: %s [-vV?] [pattern] {element ...} \n",
fprintf (file, "usage: %s [-vVh] [pattern] {element ...} \n",
program);
#endif
fprintf (stderr, "List fonts matching [pattern]\n");
fprintf (stderr, "\n");
fprintf (file, "List fonts matching [pattern]\n");
fprintf (file, "\n");
#if HAVE_GETOPT_LONG
fprintf (stderr, " -v, --verbose display entire font pattern\n");
fprintf (stderr, " -V, --version display font config version and exit\n");
fprintf (stderr, " -?, --help display this help and exit\n");
fprintf (file, " -v, --verbose display entire font pattern\n");
fprintf (file, " -V, --version display font config version and exit\n");
fprintf (file, " -h, --help display this help and exit\n");
#else
fprintf (stderr, " -v (verbose) display entire font pattern\n");
fprintf (stderr, " -V (version) display font config version and exit\n");
fprintf (stderr, " -? (help) display this help and exit\n");
fprintf (file, " -v (verbose) display entire font pattern\n");
fprintf (file, " -V (version) display font config version and exit\n");
fprintf (file, " -h (help) display this help and exit\n");
#endif
exit (1);
exit (error);
}
int
@ -94,9 +96,9 @@ main (int argc, char **argv)
int c;
#if HAVE_GETOPT_LONG
while ((c = getopt_long (argc, argv, "Vv?", longopts, NULL)) != -1)
while ((c = getopt_long (argc, argv, "Vvh", longopts, NULL)) != -1)
#else
while ((c = getopt (argc, argv, "Vv?")) != -1)
while ((c = getopt (argc, argv, "Vvh")) != -1)
#endif
{
switch (c) {
@ -107,8 +109,10 @@ main (int argc, char **argv)
case 'v':
verbose = 1;
break;
case 'h':
usage (argv[0], 0);
default:
usage (argv[0]);
usage (argv[0], 1);
}
}
i = optind;

View File

@ -63,7 +63,7 @@ manpage.1: manpage.sgml
<cmdsynopsis>
<command>&dhpackage;</command>
<arg><option>-vV?</option></arg>
<arg><option>-vVh</option></arg>
<arg><option>--verbose</option></arg>
<arg><option>--version</option></arg>
<arg><option>--help</option></arg>
@ -100,7 +100,7 @@ manpage.1: manpage.sgml
</listitem>
</varlistentry>
<varlistentry>
<term><option>-?</option>
<term><option>-h</option>
<option>--help</option>
</term>
<listitem>

View File

@ -53,7 +53,7 @@ static const struct option longopts[] = {
{"all", 0, 0, 'a'},
{"version", 0, 0, 'V'},
{"verbose", 0, 0, 'v'},
{"help", 0, 0, '?'},
{"help", 0, 0, 'h'},
{NULL,0,0,0},
};
#else
@ -63,31 +63,33 @@ extern int optind, opterr, optopt;
#endif
#endif
static void usage (char *program)
static void
usage (char *program, int error)
{
FILE *file = error ? stderr : stdout;
#if HAVE_GETOPT_LONG
fprintf (stderr, "usage: %s [-savV?] [--sort] [--all] [--verbose] [--version] [--help] [pattern]\n",
fprintf (file, "usage: %s [-savVh] [--sort] [--all] [--verbose] [--version] [--help] [pattern]\n",
program);
#else
fprintf (stderr, "usage: %s [-savV?] [pattern]\n",
fprintf (file, "usage: %s [-savVh] [pattern]\n",
program);
#endif
fprintf (stderr, "List fonts matching [pattern]\n");
fprintf (stderr, "\n");
fprintf (file, "List fonts matching [pattern]\n");
fprintf (file, "\n");
#if HAVE_GETOPT_LONG
fprintf (stderr, " -s, --sort display sorted list of matches\n");
fprintf (stderr, " -a, --all display unpruned sorted list of matches\n");
fprintf (stderr, " -v, --verbose display entire font pattern\n");
fprintf (stderr, " -V, --version display font config version and exit\n");
fprintf (stderr, " -?, --help display this help and exit\n");
fprintf (file, " -s, --sort display sorted list of matches\n");
fprintf (file, " -a, --all display unpruned sorted list of matches\n");
fprintf (file, " -v, --verbose display entire font pattern\n");
fprintf (file, " -V, --version display font config version and exit\n");
fprintf (file, " -h, --help display this help and exit\n");
#else
fprintf (stderr, " -s, (sort) display sorted list of matches\n");
fprintf (stderr, " -a (all) display unpruned sorted list of matches\n");
fprintf (stderr, " -v (verbose) display entire font pattern\n");
fprintf (stderr, " -V (version) display font config version and exit\n");
fprintf (stderr, " -? (help) display this help and exit\n");
fprintf (file, " -s, (sort) display sorted list of matches\n");
fprintf (file, " -a (all) display unpruned sorted list of matches\n");
fprintf (file, " -v (verbose) display entire font pattern\n");
fprintf (file, " -V (version) display font config version and exit\n");
fprintf (file, " -h (help) display this help and exit\n");
#endif
exit (1);
exit (error);
}
int
@ -103,9 +105,9 @@ main (int argc, char **argv)
int c;
#if HAVE_GETOPT_LONG
while ((c = getopt_long (argc, argv, "asVv?", longopts, NULL)) != -1)
while ((c = getopt_long (argc, argv, "asVvh", longopts, NULL)) != -1)
#else
while ((c = getopt (argc, argv, "asVv?")) != -1)
while ((c = getopt (argc, argv, "asVvh")) != -1)
#endif
{
switch (c) {
@ -122,8 +124,10 @@ main (int argc, char **argv)
case 'v':
verbose = 1;
break;
case 'h':
usage (argv[0], 0);
default:
usage (argv[0]);
usage (argv[0], 1);
}
}
i = optind;

View File

@ -63,7 +63,7 @@ manpage.1: manpage.sgml
<cmdsynopsis>
<command>&dhpackage;</command>
<arg><option>-asvV?</option></arg>
<arg><option>-asvVh</option></arg>
<arg><option>--all</option></arg>
<arg><option>--sort</option></arg>
<arg><option>--verbose</option></arg>
@ -103,7 +103,7 @@ are printed. The <option>--all</option> option works like
</listitem>
</varlistentry>
<varlistentry>
<term><option>-?</option>
<term><option>-h</option>
<option>--help</option>
</term>
<listitem>

View File

@ -54,7 +54,7 @@
static const struct option longopts[] = {
{"index", 1, 0, 'i'},
{"version", 0, 0, 'V'},
{"help", 0, 0, '?'},
{"help", 0, 0, 'h'},
{NULL,0,0,0},
};
#else
@ -64,28 +64,30 @@ extern int optind, opterr, optopt;
#endif
#endif
static void usage (char *program)
static void
usage (char *program, int error)
{
FILE *file = error ? stderr : stdout;
#if HAVE_GETOPT_LONG
fprintf (stderr, "usage: %s [-V?] [-i index] [--index index] [--version] [--help] font-file...\n",
fprintf (file, "usage: %s [-Vh] [-i index] [--index index] [--version] [--help] font-file...\n",
program);
#else
fprintf (stderr, "usage: %s [-V?] [-i index] font-file...\n",
fprintf (file, "usage: %s [-Vh] [-i index] font-file...\n",
program);
#endif
fprintf (stderr, "Query font files and print resulting pattern(s)\n");
fprintf (stderr, "\n");
fprintf (file, "Query font files and print resulting pattern(s)\n");
fprintf (file, "\n");
#if HAVE_GETOPT_LONG
fprintf (stderr, " -i, --index INDEX display the INDEX face of each font file only\n");
fprintf (stderr, " -V, --version display font config version and exit\n");
fprintf (stderr, " -?, --help display this help and exit\n");
fprintf (file, " -i, --index INDEX display the INDEX face of each font file only\n");
fprintf (file, " -V, --version display font config version and exit\n");
fprintf (file, " -h, --help display this help and exit\n");
#else
fprintf (stderr, " -i INDEX (index) display the INDEX face of each font file only\n");
fprintf (stderr, " -a (all) display unpruned sorted list of matches\n");
fprintf (stderr, " -V (version) display font config version and exit\n");
fprintf (stderr, " -? (help) display this help and exit\n");
fprintf (file, " -i INDEX (index) display the INDEX face of each font file only\n");
fprintf (file, " -a (all) display unpruned sorted list of matches\n");
fprintf (file, " -V (version) display font config version and exit\n");
fprintf (file, " -h (help) display this help and exit\n");
#endif
exit (1);
exit (error);
}
int
@ -100,9 +102,9 @@ main (int argc, char **argv)
int c;
#if HAVE_GETOPT_LONG
while ((c = getopt_long (argc, argv, "i:sVv?", longopts, NULL)) != -1)
while ((c = getopt_long (argc, argv, "i:sVvh", longopts, NULL)) != -1)
#else
while ((c = getopt (argc, argv, "i:asVv?")) != -1)
while ((c = getopt (argc, argv, "i:asVvh")) != -1)
#endif
{
switch (c) {
@ -114,8 +116,10 @@ main (int argc, char **argv)
fprintf (stderr, "fontconfig version %d.%d.%d\n",
FC_MAJOR, FC_MINOR, FC_REVISION);
exit (0);
case 'h':
usage (argv[0], 0);
default:
usage (argv[0]);
usage (argv[0], 1);
}
}
i = optind;
@ -124,7 +128,7 @@ main (int argc, char **argv)
#endif
if (i == argc)
usage (argv[0]);
usage (argv[0], 1);
if (!FcInit ())
{

View File

@ -62,7 +62,7 @@ manpage.1: manpage.sgml
<cmdsynopsis>
<command>&dhpackage;</command>
<arg><option>-V?</option></arg>
<arg><option>-Vh</option></arg>
<arg><option>--version</option></arg>
<arg><option>--help</option></arg>
<sbr>
@ -93,7 +93,7 @@ manpage.1: manpage.sgml
<variablelist>
<varlistentry>
<term><option>-?</option>
<term><option>-h</option>
<option>--help</option>
</term>
<listitem>