]> git.wh0rd.org - fontconfig.git/commitdiff
Handle -h and --help according to GNU Coding Standards (#17104)
authorBehdad Esfahbod <behdad@behdad.org>
Fri, 22 Aug 2008 20:51:33 +0000 (16:51 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Sat, 14 Feb 2009 00:53:59 +0000 (16:53 -0800)
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
fc-cache/fc-cache.sgml
fc-cat/fc-cat.c
fc-cat/fc-cat.sgml
fc-list/fc-list.c
fc-list/fc-list.sgml
fc-match/fc-match.c
fc-match/fc-match.sgml
fc-query/fc-query.c
fc-query/fc-query.sgml

index c11bb3d668e8c9f9f2bf880979782d496a67471e..225c0854befb6ad019d1eed1a80f49901224246a 100644 (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;
index 62c0ddf4810c249106033ac1cf8c80c8386d0c18..20a7e85cc51ccea08e2f58681bf50ffc109f36a2 100644 (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>
index 86a1c2f3bb3227b6f4286374d52a7bb98340be37..ec2b032a9c3db6393d5407ba063b1c0b13ff19cf 100644 (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;
index 94c74b259a21d5b430bd69ceef740c0f33a0c46e..69482b57c74cda52a3826109b1769345ad2102c3 100644 (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>
index 8384f28a1b6a0c1da4f6ab99222aba90aed6c3b7..97baea4ca1a10ebb734ccbd2c515db1a6bdb8469 100644 (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;
index f4a314774aaaa628110a28f172c162d45cb74532..35bf899db7c7a1ed0724bf8098b0f86f7c5c3f1c 100644 (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>
index 05bf7746a01da4db213690be17e1cca4db9d3b5f..5ed8deff676b7e26e86829af3a796270478d5e37 100644 (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;
index c2f699d512fb5c4ce99ff87c6b805afabc9485a7..b5ca67562b64089af2152b98abcc9f6354c9cbeb 100644 (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>
index 2a36bf0447f49cabbdd86a1eb6853ce3406c0f79..6ea45ea517f8020607a50d38a8bee022e8db8e88 100644 (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 ())
     {
index 4a1a5e6ac1d78c5f06aa66526be52714f7bf20ce..2c7312912f64c4ba6cfb7d7804ee63223c4d22b0 100644 (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>