]> git.wh0rd.org - fontconfig.git/blobdiff - fc-cat/fc-cat.c
Eliminate NormalizeDir. Eliminate gratuitous stat/access calls per dir.
[fontconfig.git] / fc-cat / fc-cat.c
index 3b24302dee0805d61dd079c21030fdfaf71f2bdb..cf3632325f4fd7a1e924e429cf2db1d566ed0d9a 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include <fontconfig/fontconfig.h>
-#include <../src/fccache.c>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <libgen.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #else
 #define HAVE_GETOPT 1
 #endif
 
+#include <fontconfig/fontconfig.h>
+#include <../src/fccache.c>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+
 #ifndef HAVE_GETOPT
 #define HAVE_GETOPT 0
 #endif
@@ -174,6 +174,7 @@ FcCacheGlobalFileReadAndPrint (FcFontSet * set, FcStrSet *dirs, char *cache_file
     int fd;
     char * current_arch_machine_name;
     char candidate_arch_machine_name[9+MACHINE_SIGNATURE_SIZE];
+    char               subdirName[FC_MAX_FILE_LEN + 1 + 12 + 1];
     off_t current_arch_start = 0;
 
     if (!cache_file)
@@ -195,13 +196,22 @@ FcCacheGlobalFileReadAndPrint (FcFontSet * set, FcStrSet *dirs, char *cache_file
 
     while (1) 
     {
-       char * dir, * ls;
+       char * dir;
        FcCacheReadString (fd, name_buf, sizeof (name_buf));
        if (!strlen(name_buf))
            break;
        printf ("fc-cat: printing global cache contents for dir %s\n", 
                name_buf);
 
+       do
+       {
+           if (!FcCacheReadString (fd, subdirName, 
+                                   sizeof (subdirName)) ||
+               !strlen (subdirName))
+               break;
+           /* then don't do anything with subdirName. */
+       } while (1);
+
        if (!FcDirCacheConsume (fd, name_buf, set, 0))
            goto bail1;
 
@@ -231,11 +241,11 @@ FcCacheFileRead (FcFontSet * set, FcStrSet *dirs, char *cache_file)
 {
     int fd;
     char * current_arch_machine_name;
-    char candidate_arch_machine_name[9+MACHINE_SIGNATURE_SIZE];
     off_t current_arch_start = 0;
     char subdirName[FC_MAX_FILE_LEN + 1 + 12 + 1];
     static char name_buf[8192], *dir;
     FcChar8 * ls;
+    char * buf;
 
     if (!cache_file)
         goto bail;
@@ -257,7 +267,8 @@ FcCacheFileRead (FcFontSet * set, FcStrSet *dirs, char *cache_file)
     if (current_arch_start < 0)
         goto bail1;
 
-    while (strlen(FcCacheReadString (fd, subdirName, sizeof (subdirName))) > 0)
+    while ((buf = FcCacheReadString (fd, subdirName, sizeof (subdirName))) 
+          && *buf)
         FcStrSetAdd (dirs, (FcChar8 *)subdirName);
 
     dir = strdup(name_buf);
@@ -377,6 +388,7 @@ main (int argc, char **argv)
     FcFontSet  *fs = FcFontSetCreate();
     FcStrSet    *dirs = FcStrSetCreate();
     char       *name_buf;
+    FcConfig   *config;
 
 #if HAVE_GETOPT_LONG
     while ((c = getopt_long (argc, argv, "fsVv?", longopts, NULL)) != -1)
@@ -398,10 +410,32 @@ main (int argc, char **argv)
     i = 1;
 #endif
 
+    config = FcInitLoadConfig ();
+    if (!config)
+    {
+       fprintf (stderr, "%s: Can't init font config library\n", argv[0]);
+       return 1;
+    }
+    FcConfigSetCurrent (config);
+    
     if (i >= argc)
         usage (argv[0]);
 
-    if (name_buf = FcCacheFileRead (fs, dirs, argv[i]))
+    if (FcFileIsDir ((const FcChar8 *)argv[i]))
+    {
+        char * dummy_name = (char *)FcStrPlus ((FcChar8 *)argv[i], 
+                                               (FcChar8 *)"/dummy");
+        if (!FcDirScanConfig (fs, dirs, 0, 0, 
+                              (const FcChar8 *)argv[i], FcFalse, config))
+            fprintf (stderr, "couldn't load font dir %s\n", argv[i]);
+        else
+        {
+            /* sorry, we can't tell you where the cache file is. */
+            FcCachePrintSet (fs, dirs, dummy_name);
+            FcStrFree ((FcChar8 *)dummy_name);
+        }
+    }
+    else if ((name_buf = FcCacheFileRead (fs, dirs, argv[i])) != 0)
        FcCachePrintSet (fs, dirs, name_buf);
     else
     {