]> git.wh0rd.org - fontconfig.git/blobdiff - fc-cat/fc-cat.c
Enable fc-cat to print out old-style cache info when given a directory
[fontconfig.git] / fc-cat / fc-cat.c
index 419d29ffeabaa6b83cd2060fda1a51d49b6a45c6..f466e3ecbc62f3af09f1dd8feef1b698d5e44391 100644 (file)
@@ -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,17 +196,30 @@ 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;
 
-       dir = strdup(name_buf);
+       dir = malloc (strlen (name_buf) + 2);
+       if (!dir)
+           goto bail1;
+
+       strcpy (dir, name_buf);
        strcat (dir, "/");
 
        FcCachePrintSet (set, dirs, dir);
@@ -227,7 +241,6 @@ 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;
@@ -364,6 +377,16 @@ bail2:
     return FcFalse;
 }
 
+FcBool
+FcFileIsDir (const FcChar8 *file)
+{
+    struct stat            statb;
+
+    if (stat ((const char *) file, &statb) != 0)
+       return FcFalse;
+    return S_ISDIR(statb.st_mode);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -397,7 +420,21 @@ main (int argc, char **argv)
     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, 0))
+            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
     {