]> git.wh0rd.org - fontconfig.git/blobdiff - fc-match/fc-match.c
Bug 40452 - Running 'fc-match --all' core dumps when no fonts are installed
[fontconfig.git] / fc-match / fc-match.c
index 86ff25387b09e02b4a085927ee99dc8092126027..095dd4e21125aef6f373d9239d0ab1a9712c2ad4 100644 (file)
@@ -7,15 +7,15 @@
  * documentation for any purpose is hereby granted without fee, provided that
  * the above copyright notice appear in all copies and that both that
  * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Keith Packard not be used in
+ * documentation, and that the name of the author(s) not be used in
  * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission.  Keith Packard makes no
+ * specific, written prior permission.  The authors make no
  * representations about the suitability of this software for any purpose.  It
  * is provided "as is" without express or implied warranty.
  *
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
@@ -175,6 +175,11 @@ main (int argc, char **argv)
        int     j;
        font_patterns = FcFontSort (0, pat, all ? FcFalse : FcTrue, 0, &result);
 
+       if (!font_patterns || font_patterns->nfont == 0)
+       {
+           fputs("No fonts installed on the system\n", stderr);
+           return 1;
+       }
        for (j = 0; j < font_patterns->nfont; j++)
        {
            FcPattern  *font_pattern;
@@ -195,6 +200,14 @@ main (int argc, char **argv)
     }
     FcPatternDestroy (pat);
 
+    if (!format)
+    {
+       if (os)
+           format = "%{=unparse}\n";
+       else
+           format = "%{=fcmatch}\n";
+    }
+
     if (fs)
     {
        int     j;
@@ -209,7 +222,7 @@ main (int argc, char **argv)
            {
                FcPatternPrint (font);
            }
-           else if (format)
+           else
            {
                FcChar8 *s;
 
@@ -220,34 +233,6 @@ main (int argc, char **argv)
                    free (s);
                }
            }
-           else if (os)
-           {
-               FcChar8 *str;
-               str = FcNameUnparse (font);
-               printf ("%s\n", str);
-               free (str);
-           }
-           else
-           {
-               FcChar8 *family;
-               FcChar8 *style;
-               FcChar8 *file;
-
-               if (FcPatternGetString (font, FC_FILE, 0, &file) != FcResultMatch)
-                   file = (FcChar8 *) "<unknown filename>";
-               else
-               {
-                   FcChar8 *slash = (FcChar8 *) strrchr ((char *) file, '/');
-                   if (slash)
-                       file = slash+1;
-               }
-               if (FcPatternGetString (font, FC_FAMILY, 0, &family) != FcResultMatch)
-                   family = (FcChar8 *) "<unknown family>";
-               if (FcPatternGetString (font, FC_STYLE, 0, &style) != FcResultMatch)
-                   style = (FcChar8 *) "<unknown style>";
-
-               printf ("%s: \"%s\" \"%s\"\n", file, family, style);
-           }
 
            FcPatternDestroy (font);
        }