]> git.wh0rd.org - fontconfig.git/blobdiff - fc-list/fc-list.c
Handle -h and --help according to GNU Coding Standards (#17104)
[fontconfig.git] / fc-list / fc-list.c
index 04026cfa3552f682e393122c105225d2fdcc428f..97baea4ca1a10ebb734ccbd2c515db1a6bdb8469 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $RCSId: xc/lib/fontconfig/fc-list/fc-list.c,v 1.5 2002/06/30 23:45:40 keithp Exp $
+ * fontconfig/fc-list/fc-list.c
  *
  * Copyright © 2002 Keith Packard
  *
@@ -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 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, "  -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 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, "  -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;
@@ -124,20 +128,22 @@ main (int argc, char **argv)
     if (argv[i])
     {
        pat = FcNameParse ((FcChar8 *) argv[i]);
-       while (argv[++i])
-       {
-           if (!os)
-               os = FcObjectSetCreate ();
-           FcObjectSetAdd (os, argv[i]);
-       }
+       if (!verbose)
+           while (argv[++i])
+           {
+               if (!os)
+                   os = FcObjectSetCreate ();
+               FcObjectSetAdd (os, argv[i]);
+           }
     }
     else
        pat = FcPatternCreate ();
     
-    if (!os)
+    if (!verbose && !os)
        os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, (char *) 0);
     fs = FcFontList (0, pat, os);
-    FcObjectSetDestroy (os);
+    if (os)
+       FcObjectSetDestroy (os);
     if (pat)
        FcPatternDestroy (pat);
 
@@ -150,11 +156,16 @@ main (int argc, char **argv)
            FcChar8 *font;
            FcChar8 *file;
 
-           font = FcNameUnparse (fs->fonts[j]);
-           if (FcPatternGetString (fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch)
-               printf ("%s: ", file);
-           printf ("%s\n", font);
-           free (font);
+           if (verbose)
+               FcPatternPrint (fs->fonts[j]);
+           else
+           {
+               font = FcNameUnparse (fs->fonts[j]);
+               if (FcPatternGetString (fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch)
+                   printf ("%s: ", file);
+               printf ("%s\n", font);
+               free (font);
+           }
        }
        FcFontSetDestroy (fs);
     }