]> git.wh0rd.org - fontconfig.git/commitdiff
Switch fc-cat to use FcPatternFormat()
authorBehdad Esfahbod <behdad@behdad.org>
Mon, 20 Jun 2011 15:55:25 +0000 (11:55 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Mon, 20 Jun 2011 15:55:25 +0000 (11:55 -0400)
Added the a builtin "fccat" to FcPatternFormat().

doc/fcformat.fncs
fc-cat/fc-cat.c
src/fcformat.c

index 125e6b43745a34f536323205bc1b2a68ab463076..c136e8cf27c0bbcb8a6ca9e9937cc7699b5fe2c3 100644 (file)
@@ -201,6 +201,13 @@ Expands to the output of the default output format of the fc-list
 command on the pattern, without the final newline.
 </para></listitem></varlistentry>
 
 command on the pattern, without the final newline.
 </para></listitem></varlistentry>
 
+<varlistentry><term>
+fccat
+</term><listitem><para>
+Expands to the output of the default output format of the fc-cat
+command on the pattern, without the final newline.
+</para></listitem></varlistentry>
+
 <varlistentry><term>
 pkgkit
 </term><listitem><para>
 <varlistentry><term>
 pkgkit
 </term><listitem><para>
index c6c399343de4aed651f1ce4f7dca2824299b5a71..5ee947ec24938c0d1ba5326bfe5090c32dc3b2dc 100644 (file)
@@ -194,11 +194,9 @@ file_base_name (const FcChar8 *cache, const FcChar8 *file)
 static FcBool
 cache_print_set (FcFontSet *set, FcStrSet *dirs, const FcChar8 *base_name, FcBool verbose)
 {
 static FcBool
 cache_print_set (FcFontSet *set, FcStrSet *dirs, const FcChar8 *base_name, FcBool verbose)
 {
-    FcChar8        *name, *dir;
-    const FcChar8   *file, *base;
-    int                    ret;
+    FcChar8        *dir;
+    const FcChar8   *base;
     int                    n;
     int                    n;
-    int                    id;
     int                    ndir = 0;
     FcStrList      *list;
 
     int                    ndir = 0;
     FcStrList      *list;
 
@@ -227,37 +225,22 @@ cache_print_set (FcFontSet *set, FcStrSet *dirs, const FcChar8 *base_name, FcBoo
     for (n = 0; n < set->nfont; n++)
     {
        FcPattern   *font = set->fonts[n];
     for (n = 0; n < set->nfont; n++)
     {
        FcPattern   *font = set->fonts[n];
+       FcChar8 *s;
 
 
-       if (FcPatternGetString (font, FC_FILE, 0, (FcChar8 **) &file) != FcResultMatch)
-           goto bail3;
-       base = file_base_name (base_name, file);
-       if (FcPatternGetInteger (font, FC_INDEX, 0, &id) != FcResultMatch)
-           goto bail3;
-       if (!write_string (stdout, base))
-           goto bail3;
-       if (PUTC (' ', stdout) == EOF)
-           goto bail3;
-       if (!write_int (stdout, id))
-           goto bail3;
-        if (PUTC (' ', stdout) == EOF)
-           goto bail3;
-       name = FcNameUnparse (font);
-       if (!name)
-           goto bail3;
-       ret = write_string (stdout, name);
-       FcStrFree (name);
-       if (!ret)
-           goto bail3;
-       if (PUTC ('\n', stdout) == EOF)
-           goto bail3;
+       s = FcPatternFormat (font, "%{=fccat}\n");
+       if (s)
+       {
+           printf ("%s", s);
+           free (s);
+       }
     }
     if (verbose && !set->nfont && !ndir)
        printf ("<empty>\n");
     }
     if (verbose && !set->nfont && !ndir)
        printf ("<empty>\n");
-    
+
     FcStrListDone (list);
 
     return FcTrue;
     FcStrListDone (list);
 
     return FcTrue;
-    
+
 bail3:
     FcStrListDone (list);
 bail2:
 bail3:
     FcStrListDone (list);
 bail2:
index 4a850ee0944df487d95a77417b1615baba70f744..d8518f458252fba1abc6ee4b54111807c750a7c7 100644 (file)
@@ -62,6 +62,7 @@
  * unparse     FcNameUnparse
  * fcmatch     fc-match default
  * fclist      fc-list default
  * unparse     FcNameUnparse
  * fcmatch     fc-match default
  * fclist      fc-list default
+ * fccat       fc-cat default
  * pkgkit      PackageKit package tag format
  *
  *
  * pkgkit      PackageKit package tag format
  *
  *
@@ -74,6 +75,7 @@
  */
 
 
  */
 
 
+#define FCCAT_FORMAT   "\"%{file|basename|cescape}\" %{index} \"%{-file{%{=unparse|cescape}}}\""
 #define FCMATCH_FORMAT "%{file:-<unknown filename>|basename}: \"%{family[0]:-<unknown family>}\" \"%{style[0]:-<unknown style>}\""
 #define FCLIST_FORMAT  "%{?file{%{file}: }}%{-file{%{=unparse}}}"
 #define PKGKIT_FORMAT  "%{[]family{font(%{family|downcase|delete( )})\n}}%{[]lang{font(:lang=%{lang|downcase|translate(_,-)})\n}}"
 #define FCMATCH_FORMAT "%{file:-<unknown filename>|basename}: \"%{family[0]:-<unknown family>}\" \"%{style[0]:-<unknown style>}\""
 #define FCLIST_FORMAT  "%{?file{%{file}: }}%{-file{%{=unparse}}}"
 #define PKGKIT_FORMAT  "%{[]family{font(%{family|downcase|delete( )})\n}}%{[]lang{font(:lang=%{lang|downcase|translate(_,-)})\n}}"
@@ -304,6 +306,7 @@ interpret_builtin (FcFormatContext *c,
 #define BUILTIN(name, format) \
     else if (0 == strcmp ((const char *) c->word, name))\
        ret = FcPatternFormatToBuf (pat, (const FcChar8 *) format, buf)
 #define BUILTIN(name, format) \
     else if (0 == strcmp ((const char *) c->word, name))\
        ret = FcPatternFormatToBuf (pat, (const FcChar8 *) format, buf)
+    BUILTIN ("fccat",    FCCAT_FORMAT);
     BUILTIN ("fcmatch",  FCMATCH_FORMAT);
     BUILTIN ("fclist",   FCLIST_FORMAT);
     BUILTIN ("pkgkit",   PKGKIT_FORMAT);
     BUILTIN ("fcmatch",  FCMATCH_FORMAT);
     BUILTIN ("fclist",   FCLIST_FORMAT);
     BUILTIN ("pkgkit",   PKGKIT_FORMAT);