]> git.wh0rd.org - fontconfig.git/blobdiff - fc-cat/fc-cat.c
Migrate cache files from fonts directories to /var/cache/fontconfig. This
[fontconfig.git] / fc-cat / fc-cat.c
index 4436512ae93bddbd357ecff106c9900e91c0f3d6..f088e4585a9220ff2003f190f02014b0b8e4fe11 100644 (file)
@@ -78,6 +78,9 @@ extern int optind, opterr, optopt;
 #define PUTC(c,f) putc(c,f)
 #endif
 
+FcBool
+FcCachePrintSet (FcFontSet *set, FcStrSet *dirs, char *cache_file);
+
 static FcBool
 FcCacheWriteChars (FILE *f, const FcChar8 *chars)
 {
@@ -164,6 +167,56 @@ usage (char *program)
     exit (1);
 }
 
+static FcBool 
+FcCacheGlobalFileReadAndPrint (FcFontSet * set, FcStrSet *dirs, char * dir, char *cache_file)
+{
+    char               name_buf[8192];
+    int fd;
+    char * current_arch_machine_name;
+    char candidate_arch_machine_name[9+MACHINE_SIGNATURE_SIZE];
+    off_t current_arch_start = 0;
+
+    if (!cache_file)
+       goto bail;
+
+    current_arch_machine_name = FcCacheMachineSignature();
+    fd = open(cache_file, O_RDONLY);
+    if (fd == -1)
+       goto bail;
+
+    current_arch_start = FcCacheSkipToArch(fd, current_arch_machine_name,
+                                          FcTrue);
+    if (current_arch_start < 0)
+       goto bail1;
+
+    lseek (fd, current_arch_start, SEEK_SET);
+    if (FcCacheReadString (fd, candidate_arch_machine_name, 
+                          sizeof (candidate_arch_machine_name)) == 0)
+       goto bail1;
+
+    while (1) 
+    {
+       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);
+
+       if (!FcDirCacheConsume (fd, dir, set))
+           goto bail1;
+
+       FcCachePrintSet (set, dirs, name_buf);
+
+       FcFontSetDestroy (set);
+       set = FcFontSetCreate();
+    }
+
+ bail1:
+    close (fd);
+ bail:
+    return FcFalse;
+}
+
 /* read serialized state from the cache file */
 static FcBool
 FcCacheFileRead (FcFontSet * set, FcStrSet *dirs, char * dir, char *cache_file)
@@ -173,6 +226,7 @@ FcCacheFileRead (FcFontSet * set, FcStrSet *dirs, char * dir, char *cache_file)
     char candidate_arch_machine_name[9+MACHINE_SIGNATURE_SIZE];
     off_t current_arch_start = 0;
     char subdirName[FC_MAX_FILE_LEN + 1 + 12 + 1];
+    char name_buf[8192];
 
     if (!cache_file)
         goto bail;
@@ -182,7 +236,14 @@ FcCacheFileRead (FcFontSet * set, FcStrSet *dirs, char * dir, char *cache_file)
     if (fd == -1)
         goto bail;
 
-    current_arch_start = FcCacheSkipToArch(fd, current_arch_machine_name);
+    FcCacheReadString (fd, name_buf, sizeof (name_buf));
+    if (!strlen (name_buf))
+       goto bail;
+    printf ("fc-cat: printing directory cache contents for dir %s\n", 
+           name_buf);
+
+    current_arch_start = FcCacheSkipToArch(fd, current_arch_machine_name,
+                                          FcFalse);
     if (current_arch_start < 0)
         goto bail1;
 
@@ -228,9 +289,9 @@ FcCachePrintSet (FcFontSet *set, FcStrSet *dirs, char *cache_file)
     FcPattern      *font;
     FcChar8        *name, *dir;
     const FcChar8   *file, *base;
+    int                    ret;
     int                    n;
     int                    id;
-    FcBool         ret;
     FcStrList      *list;
 
     list = FcStrListCreate (dirs);
@@ -290,8 +351,6 @@ FcCachePrintSet (FcFontSet *set, FcStrSet *dirs, char *cache_file)
 bail3:
     FcStrListDone (list);
 bail2:
-bail1:
-bail0:
     return FcFalse;
 }
 
@@ -299,7 +358,6 @@ int
 main (int argc, char **argv)
 {
     int                i;
-    int                ret;
 #if HAVE_GETOPT_LONG || HAVE_GETOPT
     int                c;
     FcFontSet  *fs = FcFontSetCreate();
@@ -330,6 +388,14 @@ main (int argc, char **argv)
 
     if (FcCacheFileRead (fs, dirs, dirname (strdup(argv[i])), argv[i]))
        FcCachePrintSet (fs, dirs, argv[i]);
+    else
+    {
+        FcStrSetDestroy (dirs);
+        dirs = FcStrSetCreate ();
+        if (FcCacheGlobalFileReadAndPrint (fs, dirs, dirname (strdup (argv[i])),
+                                           argv[i]))
+            ;
+    }
 
     FcStrSetDestroy (dirs);
     FcFontSetDestroy (fs);