From 1439c8f21af1533a920b54333f79459f456a402e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 22 Aug 2008 16:51:33 -0400 Subject: [PATCH] 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. --- fc-cache/fc-cache.c | 47 ++++++++++++++++++++++-------------------- fc-cache/fc-cache.sgml | 4 ++-- fc-cat/fc-cat.c | 45 +++++++++++++++++++++------------------- fc-cat/fc-cat.sgml | 4 ++-- fc-list/fc-list.c | 36 ++++++++++++++++++-------------- fc-list/fc-list.sgml | 4 ++-- fc-match/fc-match.c | 44 +++++++++++++++++++++------------------ fc-match/fc-match.sgml | 4 ++-- fc-query/fc-query.c | 40 +++++++++++++++++++---------------- fc-query/fc-query.sgml | 4 ++-- 10 files changed, 125 insertions(+), 107 deletions(-) diff --git a/fc-cache/fc-cache.c b/fc-cache/fc-cache.c index c11bb3d..225c085 100644 --- a/fc-cache/fc-cache.c +++ b/fc-cache/fc-cache.c @@ -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; diff --git a/fc-cache/fc-cache.sgml b/fc-cache/fc-cache.sgml index 62c0ddf..20a7e85 100644 --- a/fc-cache/fc-cache.sgml +++ b/fc-cache/fc-cache.sgml @@ -63,7 +63,7 @@ manpage.1: manpage.sgml &dhpackage; - + @@ -131,7 +131,7 @@ manpage.1: manpage.sgml - + diff --git a/fc-cat/fc-cat.c b/fc-cat/fc-cat.c index 86a1c2f..ec2b032 100644 --- a/fc-cat/fc-cat.c +++ b/fc-cat/fc-cat.c @@ -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; diff --git a/fc-cat/fc-cat.sgml b/fc-cat/fc-cat.sgml index 94c74b2..69482b5 100644 --- a/fc-cat/fc-cat.sgml +++ b/fc-cat/fc-cat.sgml @@ -63,7 +63,7 @@ manpage.1: manpage.sgml &dhpackage; - + @@ -109,7 +109,7 @@ manpage.1: manpage.sgml - + diff --git a/fc-list/fc-list.c b/fc-list/fc-list.c index 8384f28..97baea4 100644 --- a/fc-list/fc-list.c +++ b/fc-list/fc-list.c @@ -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; diff --git a/fc-list/fc-list.sgml b/fc-list/fc-list.sgml index f4a3147..35bf899 100644 --- a/fc-list/fc-list.sgml +++ b/fc-list/fc-list.sgml @@ -63,7 +63,7 @@ manpage.1: manpage.sgml &dhpackage; - + @@ -100,7 +100,7 @@ manpage.1: manpage.sgml - + diff --git a/fc-match/fc-match.c b/fc-match/fc-match.c index 05bf774..5ed8def 100644 --- a/fc-match/fc-match.c +++ b/fc-match/fc-match.c @@ -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; diff --git a/fc-match/fc-match.sgml b/fc-match/fc-match.sgml index c2f699d..b5ca675 100644 --- a/fc-match/fc-match.sgml +++ b/fc-match/fc-match.sgml @@ -63,7 +63,7 @@ manpage.1: manpage.sgml &dhpackage; - + @@ -103,7 +103,7 @@ are printed. The option works like - + diff --git a/fc-query/fc-query.c b/fc-query/fc-query.c index 2a36bf0..6ea45ea 100644 --- a/fc-query/fc-query.c +++ b/fc-query/fc-query.c @@ -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 ()) { diff --git a/fc-query/fc-query.sgml b/fc-query/fc-query.sgml index 4a1a5e6..2c73129 100644 --- a/fc-query/fc-query.sgml +++ b/fc-query/fc-query.sgml @@ -62,7 +62,7 @@ manpage.1: manpage.sgml &dhpackage; - + @@ -93,7 +93,7 @@ manpage.1: manpage.sgml - + -- 2.39.2