With no args, fc-cat now dumps all directories.
Automatically list all font directories when no arguments are given to fc-cat. Also add -r option to recurse from specified cache directories. fc-cat also now prints the cache filename in verbose mode, along with the related directory name.
This commit is contained in:
parent
d8ab9e6c42
commit
0a87ce715e
121
fc-cat/fc-cat.c
121
fc-cat/fc-cat.c
|
@ -32,6 +32,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../src/fccache.c"
|
#include "../src/fccache.c"
|
||||||
|
#include "../fc-arch/fcarch.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -53,6 +54,7 @@
|
||||||
const struct option longopts[] = {
|
const struct option longopts[] = {
|
||||||
{"version", 0, 0, 'V'},
|
{"version", 0, 0, 'V'},
|
||||||
{"verbose", 0, 0, 'v'},
|
{"verbose", 0, 0, 'v'},
|
||||||
|
{"recurse", 0, 0, 'r'},
|
||||||
{"help", 0, 0, '?'},
|
{"help", 0, 0, '?'},
|
||||||
{NULL,0,0,0},
|
{NULL,0,0,0},
|
||||||
};
|
};
|
||||||
|
@ -78,9 +80,6 @@ extern int optind, opterr, optopt;
|
||||||
#define PUTC(c,f) putc(c,f)
|
#define PUTC(c,f) putc(c,f)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FcBool
|
|
||||||
FcCachePrintSet (FcFontSet *set, FcStrSet *dirs, char *base_name);
|
|
||||||
|
|
||||||
static FcBool
|
static FcBool
|
||||||
FcCacheWriteChars (FILE *f, const FcChar8 *chars)
|
FcCacheWriteChars (FILE *f, const FcChar8 *chars)
|
||||||
{
|
{
|
||||||
|
@ -149,13 +148,15 @@ static void
|
||||||
usage (char *program)
|
usage (char *program)
|
||||||
{
|
{
|
||||||
#if HAVE_GETOPT_LONG
|
#if HAVE_GETOPT_LONG
|
||||||
fprintf (stderr, "usage: %s [-V?] [--version] [--help] <fonts.cache-2>\n",
|
fprintf (stderr, "usage: %s [-V?] [--version] [--help] {*-%s.cache-2|directory}...\n",
|
||||||
program);
|
program, FC_ARCHITECTURE);
|
||||||
#else
|
#else
|
||||||
fprintf (stderr, "usage: %s [-fsvV?] <fonts.cache-2>\n",
|
fprintf (stderr, "usage: %s [-fsvV?] {*-%s.cache-2|directory}...\n",
|
||||||
program);
|
program, FC_ARCHITECTURE);
|
||||||
#endif
|
#endif
|
||||||
fprintf (stderr, "Reads font information caches in <fonts.cache-2>\n");
|
fprintf (stderr, "Reads font information cache from:\n");
|
||||||
|
fprintf (stderr, " 1) specified fontconfig cache file\n");
|
||||||
|
fprintf (stderr, " 2) related to a particular font directory\n");
|
||||||
fprintf (stderr, "\n");
|
fprintf (stderr, "\n");
|
||||||
#if HAVE_GETOPT_LONG
|
#if HAVE_GETOPT_LONG
|
||||||
fprintf (stderr, " -V, --version display font config version and exit\n");
|
fprintf (stderr, " -V, --version display font config version and exit\n");
|
||||||
|
@ -201,7 +202,7 @@ FcFileBaseName (const char *cache, const FcChar8 *file)
|
||||||
}
|
}
|
||||||
|
|
||||||
FcBool
|
FcBool
|
||||||
FcCachePrintSet (FcFontSet *set, FcStrSet *dirs, char *base_name)
|
FcCachePrintSet (FcFontSet *set, FcStrSet *dirs, char *base_name, FcBool verbose)
|
||||||
{
|
{
|
||||||
FcPattern *font;
|
FcPattern *font;
|
||||||
FcChar8 *name, *dir;
|
FcChar8 *name, *dir;
|
||||||
|
@ -209,6 +210,7 @@ FcCachePrintSet (FcFontSet *set, FcStrSet *dirs, char *base_name)
|
||||||
int ret;
|
int ret;
|
||||||
int n;
|
int n;
|
||||||
int id;
|
int id;
|
||||||
|
int ndir = 0;
|
||||||
FcStrList *list;
|
FcStrList *list;
|
||||||
|
|
||||||
list = FcStrListCreate (dirs);
|
list = FcStrListCreate (dirs);
|
||||||
|
@ -230,6 +232,7 @@ FcCachePrintSet (FcFontSet *set, FcStrSet *dirs, char *base_name)
|
||||||
goto bail3;
|
goto bail3;
|
||||||
if (PUTC ('\n', stdout) == EOF)
|
if (PUTC ('\n', stdout) == EOF)
|
||||||
goto bail3;
|
goto bail3;
|
||||||
|
ndir++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (n = 0; n < set->nfont; n++)
|
for (n = 0; n < set->nfont; n++)
|
||||||
|
@ -261,6 +264,8 @@ FcCachePrintSet (FcFontSet *set, FcStrSet *dirs, char *base_name)
|
||||||
if (PUTC ('\n', stdout) == EOF)
|
if (PUTC ('\n', stdout) == EOF)
|
||||||
goto bail3;
|
goto bail3;
|
||||||
}
|
}
|
||||||
|
if (verbose && !set->nfont && !ndir)
|
||||||
|
printf ("<empty>\n");
|
||||||
|
|
||||||
FcStrListDone (list);
|
FcStrListDone (list);
|
||||||
|
|
||||||
|
@ -286,12 +291,12 @@ FcCacheFileMap (const FcChar8 *file)
|
||||||
close (fd);
|
close (fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (FcCacheLoad (fd, file_stat.st_size, &cache)) {
|
if (!FcDirCacheLoad (fd, file_stat.st_size, &cache)) {
|
||||||
close (fd);
|
close (fd);
|
||||||
return cache;
|
return NULL;
|
||||||
}
|
}
|
||||||
close (fd);
|
close (fd);
|
||||||
return NULL;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -301,16 +306,21 @@ main (int argc, char **argv)
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
FcFontSet *fs;
|
FcFontSet *fs;
|
||||||
FcStrSet *dirs;
|
FcStrSet *dirs;
|
||||||
|
FcStrSet *args = NULL;
|
||||||
|
FcStrList *arglist;
|
||||||
FcCache *cache;
|
FcCache *cache;
|
||||||
FcConfig *config;
|
FcConfig *config;
|
||||||
|
FcChar8 *arg;
|
||||||
int verbose = 0;
|
int verbose = 0;
|
||||||
|
int recurse = 0;
|
||||||
|
FcBool first = FcTrue;
|
||||||
#if HAVE_GETOPT_LONG || HAVE_GETOPT
|
#if HAVE_GETOPT_LONG || HAVE_GETOPT
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
#if HAVE_GETOPT_LONG
|
#if HAVE_GETOPT_LONG
|
||||||
while ((c = getopt_long (argc, argv, "Vv?", longopts, NULL)) != -1)
|
while ((c = getopt_long (argc, argv, "Vvr?", longopts, NULL)) != -1)
|
||||||
#else
|
#else
|
||||||
while ((c = getopt (argc, argv, "Vv?")) != -1)
|
while ((c = getopt (argc, argv, "Vvr?")) != -1)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
@ -321,6 +331,9 @@ main (int argc, char **argv)
|
||||||
case 'v':
|
case 'v':
|
||||||
verbose++;
|
verbose++;
|
||||||
break;
|
break;
|
||||||
|
case 'r':
|
||||||
|
recurse++;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage (argv[0]);
|
usage (argv[0]);
|
||||||
}
|
}
|
||||||
|
@ -338,22 +351,62 @@ main (int argc, char **argv)
|
||||||
}
|
}
|
||||||
FcConfigSetCurrent (config);
|
FcConfigSetCurrent (config);
|
||||||
|
|
||||||
if (i >= argc)
|
args = FcStrSetCreate ();
|
||||||
usage (argv[0]);
|
if (!args)
|
||||||
|
|
||||||
for (; i < argc; i++)
|
|
||||||
{
|
{
|
||||||
int j;
|
fprintf (stderr, "%s: malloc failure\n", argv[0]);
|
||||||
off_t size;
|
return 1;
|
||||||
intptr_t *cache_dirs;
|
}
|
||||||
|
if (i < argc)
|
||||||
|
{
|
||||||
|
for (; i < argc; i++)
|
||||||
|
{
|
||||||
|
if (!FcStrSetAdd (args, argv[i]))
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: malloc failure\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
arglist = FcStrListCreate (args);
|
||||||
|
if (!arglist)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: malloc failure\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
recurse++;
|
||||||
|
arglist = FcConfigGetFontDirs (config);
|
||||||
|
while ((arg = FcStrListNext (arglist)))
|
||||||
|
if (!FcStrSetAdd (args, arg))
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: malloc failure\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
FcStrListDone (arglist);
|
||||||
|
}
|
||||||
|
arglist = FcStrListCreate (args);
|
||||||
|
if (!arglist)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: malloc failure\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((arg = FcStrListNext (arglist)))
|
||||||
|
{
|
||||||
|
int j;
|
||||||
|
off_t size;
|
||||||
|
intptr_t *cache_dirs;
|
||||||
|
FcChar8 *cache_file = NULL;
|
||||||
|
|
||||||
if (FcFileIsDir ((const FcChar8 *)argv[i]))
|
if (FcFileIsDir (arg))
|
||||||
cache = FcDirCacheMap ((const FcChar8 *) argv[i], config);
|
cache = FcDirCacheMap (arg, config, &cache_file);
|
||||||
else
|
else
|
||||||
cache = FcCacheFileMap (argv[i]);
|
cache = FcCacheFileMap (arg);
|
||||||
if (!cache)
|
if (!cache)
|
||||||
{
|
{
|
||||||
perror (argv[i]);
|
perror ((char *) arg);
|
||||||
ret++;
|
ret++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -362,17 +415,31 @@ main (int argc, char **argv)
|
||||||
fs = FcCacheSet (cache);
|
fs = FcCacheSet (cache);
|
||||||
cache_dirs = FcCacheDirs (cache);
|
cache_dirs = FcCacheDirs (cache);
|
||||||
for (j = 0; j < cache->dirs_count; j++)
|
for (j = 0; j < cache->dirs_count; j++)
|
||||||
|
{
|
||||||
FcStrSetAdd (dirs, FcOffsetToPtr (cache_dirs,
|
FcStrSetAdd (dirs, FcOffsetToPtr (cache_dirs,
|
||||||
cache_dirs[j],
|
cache_dirs[j],
|
||||||
FcChar8));
|
FcChar8));
|
||||||
|
if (recurse)
|
||||||
|
FcStrSetAdd (args, FcOffsetToPtr (cache_dirs,
|
||||||
|
cache_dirs[j],
|
||||||
|
FcChar8));
|
||||||
|
}
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf ("Name: %s\nDirectory: %s\n", argv[i], FcCacheDir(cache));
|
{
|
||||||
FcCachePrintSet (fs, dirs, FcCacheDir (cache));
|
if (!first)
|
||||||
|
printf ("\n");
|
||||||
|
printf ("Directory: %s\nCache: %s\n--------\n",
|
||||||
|
FcCacheDir(cache), cache_file ? cache_file : arg);
|
||||||
|
first = FcFalse;
|
||||||
|
}
|
||||||
|
FcCachePrintSet (fs, dirs, FcCacheDir (cache), verbose);
|
||||||
|
|
||||||
FcStrSetDestroy (dirs);
|
FcStrSetDestroy (dirs);
|
||||||
|
|
||||||
FcDirCacheUnmap (cache);
|
FcDirCacheUnmap (cache);
|
||||||
|
if (cache_file)
|
||||||
|
FcStrFree (cache_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -197,7 +197,7 @@ FcCacheRead (FcConfig *config)
|
||||||
static FcBool
|
static FcBool
|
||||||
FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
|
FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
|
||||||
FcBool (*callback) (int fd, off_t size, void *closure),
|
FcBool (*callback) (int fd, off_t size, void *closure),
|
||||||
void *closure)
|
void *closure, FcChar8 **cache_file_ret)
|
||||||
{
|
{
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
FcChar8 cache_base[CACHEBASE_LEN];
|
FcChar8 cache_base[CACHEBASE_LEN];
|
||||||
|
@ -221,7 +221,6 @@ FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
|
||||||
if (!cache_hashed)
|
if (!cache_hashed)
|
||||||
break;
|
break;
|
||||||
fd = open((char *) cache_hashed, O_RDONLY | O_BINARY);
|
fd = open((char *) cache_hashed, O_RDONLY | O_BINARY);
|
||||||
FcStrFree (cache_hashed);
|
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
if (fstat (fd, &file_stat) >= 0 &&
|
if (fstat (fd, &file_stat) >= 0 &&
|
||||||
dir_stat.st_mtime <= file_stat.st_mtime)
|
dir_stat.st_mtime <= file_stat.st_mtime)
|
||||||
|
@ -229,12 +228,17 @@ FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
|
||||||
ret = (*callback) (fd, file_stat.st_size, closure);
|
ret = (*callback) (fd, file_stat.st_size, closure);
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
|
if (cache_file_ret)
|
||||||
|
*cache_file_ret = cache_hashed;
|
||||||
|
else
|
||||||
|
FcStrFree (cache_hashed);
|
||||||
close (fd);
|
close (fd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close (fd);
|
close (fd);
|
||||||
}
|
}
|
||||||
|
FcStrFree (cache_hashed);
|
||||||
}
|
}
|
||||||
FcStrListDone (list);
|
FcStrListDone (list);
|
||||||
|
|
||||||
|
@ -303,13 +307,13 @@ FcDirCacheLoad (int fd, off_t size, void *closure)
|
||||||
}
|
}
|
||||||
|
|
||||||
FcCache *
|
FcCache *
|
||||||
FcDirCacheMap (const FcChar8 *dir, FcConfig *config)
|
FcDirCacheMap (const FcChar8 *dir, FcConfig *config, FcChar8 **cache_file)
|
||||||
{
|
{
|
||||||
FcCache *cache = NULL;
|
FcCache *cache = NULL;
|
||||||
|
|
||||||
if (!FcDirCacheProcess (config, dir,
|
if (!FcDirCacheProcess (config, dir,
|
||||||
FcDirCacheLoad,
|
FcDirCacheLoad,
|
||||||
&cache))
|
&cache, cache_file))
|
||||||
return NULL;
|
return NULL;
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
@ -324,7 +328,7 @@ FcDirCacheRead (FcFontSet * set, FcStrSet * dirs,
|
||||||
intptr_t *cache_dirs;
|
intptr_t *cache_dirs;
|
||||||
FcPattern **cache_fonts;
|
FcPattern **cache_fonts;
|
||||||
|
|
||||||
cache = FcDirCacheMap (dir, config);
|
cache = FcDirCacheMap (dir, config, NULL);
|
||||||
if (!cache)
|
if (!cache)
|
||||||
return FcFalse;
|
return FcFalse;
|
||||||
|
|
||||||
|
@ -378,7 +382,7 @@ FcDirCacheValidate (int fd, off_t size, void *closure)
|
||||||
FcBool
|
FcBool
|
||||||
FcDirCacheValid (const FcChar8 *dir, FcConfig *config)
|
FcDirCacheValid (const FcChar8 *dir, FcConfig *config)
|
||||||
{
|
{
|
||||||
return FcDirCacheProcess (config, dir, FcDirCacheValidate, NULL);
|
return FcDirCacheProcess (config, dir, FcDirCacheValidate, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -507,7 +507,7 @@ FcBool
|
||||||
FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config);
|
FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config);
|
||||||
|
|
||||||
FcCache *
|
FcCache *
|
||||||
FcDirCacheMap (const FcChar8 *dir, FcConfig *config);
|
FcDirCacheMap (const FcChar8 *dir, FcConfig *config, FcChar8 **cache_file);
|
||||||
|
|
||||||
FcBool
|
FcBool
|
||||||
FcDirCacheLoad (int fd, off_t size, void *closure);
|
FcDirCacheLoad (int fd, off_t size, void *closure);
|
||||||
|
|
Loading…
Reference in New Issue