]> git.wh0rd.org - fontconfig.git/blobdiff - fc-list/fc-list.c
Get rid of $Id$ tags
[fontconfig.git] / fc-list / fc-list.c
index 67d712020320fd5c659829a6c0f0c7c33d59a020..8384f28a1b6a0c1da4f6ab99222aba90aed6c3b7 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * $XFree86: $
+ * fontconfig/fc-list/fc-list.c
  *
- * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
+ * Copyright © 2002 Keith Packard
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
 #include <fontconfig/fontconfig.h>
 #include <stdio.h>
 #include <unistd.h>
+#include <stdlib.h>
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #else
+#ifdef linux
+#define HAVE_GETOPT_LONG 1
+#endif
 #define HAVE_GETOPT 1
 #endif
 
+#ifndef HAVE_GETOPT
+#define HAVE_GETOPT 0
+#endif
+#ifndef HAVE_GETOPT_LONG
+#define HAVE_GETOPT_LONG 0
+#endif
+
 #if HAVE_GETOPT_LONG
+#undef  _GNU_SOURCE
 #define _GNU_SOURCE
 #include <getopt.h>
 const struct option longopts[] = {
@@ -47,27 +59,35 @@ extern int optind, opterr, optopt;
 #endif
 #endif
 
-void usage (char *program)
+static void usage (char *program)
 {
-    fprintf (stderr, "usage: %s [-vV?] [--verbose] [--version] [--help] [dirs]\n",
+#if HAVE_GETOPT_LONG
+    fprintf (stderr, "usage: %s [-vV?] [--verbose] [--version] [--help] [pattern] {element ...} \n",
+            program);
+#else
+    fprintf (stderr, "usage: %s [-vV?] [pattern] {element ...} \n",
             program);
-    fprintf (stderr, "Build font information caches in [dirs]\n"
-            "(all directories in font configuration by default).\n");
+#endif
+    fprintf (stderr, "List fonts matching [pattern]\n");
     fprintf (stderr, "\n");
-    fprintf (stderr, "  -v, --verbose        display status information while busy\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");
+#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");
+#endif
     exit (1);
 }
 
 int
 main (int argc, char **argv)
 {
-    int                ret = 0;
-    FcFontSet  *set;
     int                verbose = 0;
     int                i;
-    FcObjectSet *os = FcObjectSetBuild (FC_FAMILY, FC_LANG, 0);
+    FcObjectSet *os = 0;
     FcFontSet  *fs;
     FcPattern   *pat;
 #if HAVE_GETOPT_LONG || HAVE_GETOPT
@@ -102,11 +122,24 @@ main (int argc, char **argv)
        return 1;
     }
     if (argv[i])
-       pat = FcNameParse (argv[i]);
+    {
+       pat = FcNameParse ((FcChar8 *) argv[i]);
+       if (!verbose)
+           while (argv[++i])
+           {
+               if (!os)
+                   os = FcObjectSetCreate ();
+               FcObjectSetAdd (os, argv[i]);
+           }
+    }
     else
        pat = FcPatternCreate ();
     
+    if (!verbose && !os)
+       os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, (char *) 0);
     fs = FcFontList (0, pat, os);
+    if (os)
+       FcObjectSetDestroy (os);
     if (pat)
        FcPatternDestroy (pat);
 
@@ -117,12 +150,23 @@ main (int argc, char **argv)
        for (j = 0; j < fs->nfont; j++)
        {
            FcChar8 *font;
+           FcChar8 *file;
 
-           font = FcNameUnparse (fs->fonts[j]);
-           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);
     }
+
+    FcFini ();
+
     return 0;
 }