diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2008-08-22 16:51:33 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2009-02-13 16:53:59 -0800 |
commit | 1439c8f21af1533a920b54333f79459f456a402e (patch) | |
tree | a7898c1fe4dbd026f85a2308a2672c49192dce8a /fc-cat | |
parent | df243f93be4306e788aebf6b2ac4a7c1b97550ae (diff) |
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.
Diffstat (limited to 'fc-cat')
-rw-r--r-- | fc-cat/fc-cat.c | 45 | ||||
-rw-r--r-- | fc-cat/fc-cat.sgml | 4 |
2 files changed, 26 insertions, 23 deletions
diff --git a/fc-cat/fc-cat.c b/fc-cat/fc-cat.c index 86a1c2f3..ec2b032a 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 94c74b25..69482b57 100644 --- a/fc-cat/fc-cat.sgml +++ b/fc-cat/fc-cat.sgml @@ -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> |