Fix up fc-cache and fc-cat for no global cache changes.
fc-cache and fc-cat use internal (fcint.h) APIs that have changed with the elimination of the global cache.
This commit is contained in:
parent
00f059e930
commit
af180c4037
|
@ -219,7 +219,7 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
|
||||||
if (really_force)
|
if (really_force)
|
||||||
FcDirCacheUnlink (dir, config);
|
FcDirCacheUnlink (dir, config);
|
||||||
|
|
||||||
if (!FcDirScanConfig (set, subdirs, 0, FcConfigGetBlanks (config), dir, force, config))
|
if (!FcDirScanConfig (set, subdirs, FcConfigGetBlanks (config), dir, force, config))
|
||||||
{
|
{
|
||||||
fprintf (stderr, "\"%s\": error scanning\n", dir);
|
fprintf (stderr, "\"%s\": error scanning\n", dir);
|
||||||
FcFontSetDestroy (set);
|
FcFontSetDestroy (set);
|
||||||
|
|
119
fc-cat/fc-cat.c
119
fc-cat/fc-cat.c
|
@ -167,127 +167,37 @@ usage (char *program)
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FcBool
|
|
||||||
FcCacheGlobalFileReadAndPrint (FcFontSet * set, FcStrSet *dirs, char *cache_file)
|
|
||||||
{
|
|
||||||
char name_buf[8192];
|
|
||||||
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)
|
|
||||||
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);
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
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 = malloc (strlen (name_buf) + 2);
|
|
||||||
if (!dir)
|
|
||||||
goto bail1;
|
|
||||||
|
|
||||||
strcpy (dir, name_buf);
|
|
||||||
strcat (dir, "/");
|
|
||||||
|
|
||||||
FcCachePrintSet (set, dirs, dir);
|
|
||||||
free (dir);
|
|
||||||
|
|
||||||
FcFontSetDestroy (set);
|
|
||||||
set = FcFontSetCreate();
|
|
||||||
}
|
|
||||||
|
|
||||||
bail1:
|
|
||||||
close (fd);
|
|
||||||
bail:
|
|
||||||
return FcFalse;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* read serialized state from the cache file */
|
/* read serialized state from the cache file */
|
||||||
static char *
|
static char *
|
||||||
FcCacheFileRead (FcFontSet * set, FcStrSet *dirs, char *cache_file)
|
FcCacheFileRead (FcFontSet * set, FcStrSet *dirs, char *cache_file)
|
||||||
{
|
{
|
||||||
|
FILE *file;
|
||||||
int fd;
|
int fd;
|
||||||
char * current_arch_machine_name;
|
|
||||||
off_t current_arch_start = 0;
|
|
||||||
char subdirName[FC_MAX_FILE_LEN + 1 + 12 + 1];
|
char subdirName[FC_MAX_FILE_LEN + 1 + 12 + 1];
|
||||||
static char name_buf[8192], *dir;
|
static char name_buf[8192];
|
||||||
FcChar8 * ls;
|
FcChar8 * ls;
|
||||||
char * buf;
|
char * buf;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (!cache_file)
|
if (!cache_file)
|
||||||
goto bail;
|
goto bail;
|
||||||
|
|
||||||
current_arch_machine_name = FcCacheMachineSignature();
|
file = fopen(cache_file, "rb");
|
||||||
fd = open(cache_file, O_RDONLY);
|
if (file == NULL)
|
||||||
if (fd == -1)
|
|
||||||
goto bail;
|
goto bail;
|
||||||
|
|
||||||
FcCacheReadString (fd, name_buf, sizeof (name_buf));
|
if (!FcDirCacheConsume (file, set, dirs, NULL, name_buf))
|
||||||
if (!strlen (name_buf))
|
goto bail1;
|
||||||
goto bail;
|
|
||||||
if (strcmp (name_buf, FC_GLOBAL_MAGIC_COOKIE) == 0)
|
fclose (file);
|
||||||
goto bail;
|
|
||||||
printf ("fc-cat: printing directory cache for cache which would be named %s\n",
|
printf ("fc-cat: printing directory cache for cache which would be named %s\n",
|
||||||
name_buf);
|
name_buf);
|
||||||
|
|
||||||
current_arch_start = FcCacheSkipToArch(fd, current_arch_machine_name);
|
|
||||||
if (current_arch_start < 0)
|
|
||||||
goto bail1;
|
|
||||||
|
|
||||||
while ((buf = FcCacheReadString (fd, subdirName, sizeof (subdirName)))
|
|
||||||
&& *buf)
|
|
||||||
FcStrSetAdd (dirs, (FcChar8 *)subdirName);
|
|
||||||
|
|
||||||
dir = strdup(name_buf);
|
|
||||||
ls = FcStrLastSlash ((FcChar8 *)dir);
|
|
||||||
if (ls)
|
|
||||||
*ls = 0;
|
|
||||||
|
|
||||||
if (!FcDirCacheConsume (fd, dir, set, 0))
|
|
||||||
goto bail2;
|
|
||||||
free (dir);
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
return name_buf;
|
return name_buf;
|
||||||
|
|
||||||
bail2:
|
|
||||||
free (dir);
|
|
||||||
|
|
||||||
bail1:
|
bail1:
|
||||||
close (fd);
|
fclose (file);
|
||||||
bail:
|
bail:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -425,7 +335,7 @@ main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
char * dummy_name = (char *)FcStrPlus ((FcChar8 *)argv[i],
|
char * dummy_name = (char *)FcStrPlus ((FcChar8 *)argv[i],
|
||||||
(FcChar8 *)"/dummy");
|
(FcChar8 *)"/dummy");
|
||||||
if (!FcDirScanConfig (fs, dirs, 0, 0,
|
if (!FcDirScanConfig (fs, dirs, 0,
|
||||||
(const FcChar8 *)argv[i], FcFalse, config))
|
(const FcChar8 *)argv[i], FcFalse, config))
|
||||||
fprintf (stderr, "couldn't load font dir %s\n", argv[i]);
|
fprintf (stderr, "couldn't load font dir %s\n", argv[i]);
|
||||||
else
|
else
|
||||||
|
@ -439,10 +349,7 @@ main (int argc, char **argv)
|
||||||
FcCachePrintSet (fs, dirs, name_buf);
|
FcCachePrintSet (fs, dirs, name_buf);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FcStrSetDestroy (dirs);
|
printf ("nothing to do\n");
|
||||||
dirs = FcStrSetCreate ();
|
|
||||||
if (FcCacheGlobalFileReadAndPrint (fs, dirs, argv[i]))
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FcStrSetDestroy (dirs);
|
FcStrSetDestroy (dirs);
|
||||||
|
|
|
@ -132,7 +132,7 @@ FcDirCacheValid (const FcChar8 *dir, FcConfig *config)
|
||||||
|
|
||||||
file = FcDirCacheOpen (config, dir, NULL);
|
file = FcDirCacheOpen (config, dir, NULL);
|
||||||
|
|
||||||
if (file != NULL)
|
if (file == NULL)
|
||||||
return FcFalse;
|
return FcFalse;
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
|
||||||
|
@ -334,26 +334,31 @@ FcDirCacheOpen (FcConfig *config, const FcChar8 *dir, FcChar8 **cache_path)
|
||||||
|
|
||||||
/* read serialized state from the cache file */
|
/* read serialized state from the cache file */
|
||||||
FcBool
|
FcBool
|
||||||
FcDirCacheRead (FcFontSet * set, FcStrSet * dirs,
|
FcDirCacheConsume (FILE *file, FcFontSet *set, FcStrSet *dirs,
|
||||||
const FcChar8 *dir, FcConfig *config)
|
const FcChar8 *dir, char *dirname)
|
||||||
{
|
{
|
||||||
FILE *file;
|
|
||||||
FcCache metadata;
|
FcCache metadata;
|
||||||
void *current_dir_block;
|
void *current_dir_block;
|
||||||
char subdir_name[FC_MAX_FILE_LEN + 1 + 12 + 1];
|
char subdir_name[FC_MAX_FILE_LEN + 1 + 12 + 1];
|
||||||
|
int i;
|
||||||
file = FcDirCacheOpen (config, dir, NULL);
|
|
||||||
if (file == NULL)
|
|
||||||
goto bail;
|
|
||||||
|
|
||||||
if (fread(&metadata, sizeof(FcCache), 1, file) != 1)
|
if (fread(&metadata, sizeof(FcCache), 1, file) != 1)
|
||||||
goto bail1;
|
goto bail;
|
||||||
if (metadata.magic != FC_CACHE_MAGIC)
|
if (metadata.magic != FC_CACHE_MAGIC)
|
||||||
goto bail1;
|
goto bail;
|
||||||
|
|
||||||
while (FcCacheReadString (file, subdir_name, sizeof (subdir_name)) &&
|
/* skip directory name; it's just for fc-cat */
|
||||||
strlen (subdir_name) > 0)
|
if (!FcCacheReadString (file, subdir_name, sizeof (subdir_name)))
|
||||||
|
goto bail;
|
||||||
|
|
||||||
|
if (dirname)
|
||||||
|
strcpy (dirname, subdir_name);
|
||||||
|
|
||||||
|
for (i = 0; i < metadata.subdirs; i++) {
|
||||||
|
if (!FcCacheReadString (file, subdir_name, sizeof (subdir_name)))
|
||||||
|
goto bail;
|
||||||
FcStrSetAdd (dirs, (FcChar8 *)subdir_name);
|
FcStrSetAdd (dirs, (FcChar8 *)subdir_name);
|
||||||
|
}
|
||||||
|
|
||||||
if (metadata.count)
|
if (metadata.count)
|
||||||
{
|
{
|
||||||
|
@ -362,53 +367,74 @@ FcDirCacheRead (FcFontSet * set, FcStrSet * dirs,
|
||||||
current_dir_block = mmap (0, metadata.count,
|
current_dir_block = mmap (0, metadata.count,
|
||||||
PROT_READ, MAP_SHARED, fd, metadata.pos);
|
PROT_READ, MAP_SHARED, fd, metadata.pos);
|
||||||
if (current_dir_block == MAP_FAILED)
|
if (current_dir_block == MAP_FAILED)
|
||||||
goto bail1;
|
goto bail;
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
{
|
{
|
||||||
HANDLE hFileMap;
|
HANDLE hFileMap;
|
||||||
|
|
||||||
hFileMap = CreateFileMapping((HANDLE) _get_osfhandle(fd), NULL, PAGE_READONLY, 0, 0, NULL);
|
hFileMap = CreateFileMapping((HANDLE) _get_osfhandle(fd), NULL, PAGE_READONLY, 0, 0, NULL);
|
||||||
if (hFileMap == NULL)
|
if (hFileMap == NULL)
|
||||||
goto bail1;
|
goto bail;
|
||||||
|
|
||||||
current_dir_block = MapViewOfFile (hFileMap, FILE_MAP_READ, 0, metadata.pos, metadata.count);
|
current_dir_block = MapViewOfFile (hFileMap, FILE_MAP_READ, 0, metadata.pos, metadata.count);
|
||||||
if (current_dir_block == NULL)
|
if (current_dir_block == NULL)
|
||||||
{
|
{
|
||||||
CloseHandle (hFileMap);
|
CloseHandle (hFileMap);
|
||||||
goto bail1;
|
goto bail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (lseek (fd, metatdata.pos, SEEK_SET) == -1)
|
if (lseek (fd, metatdata.pos, SEEK_SET) == -1)
|
||||||
goto bail1;
|
goto bail;
|
||||||
|
|
||||||
current_dir_block = malloc (metadata.count);
|
current_dir_block = malloc (metadata.count);
|
||||||
if (!current_dir_block)
|
if (!current_dir_block)
|
||||||
goto bail1;
|
goto bail;
|
||||||
|
|
||||||
/* could also use CreateMappedViewOfFile under MinGW... */
|
/* could also use CreateMappedViewOfFile under MinGW... */
|
||||||
if (read (fd, current_dir_block, metadata.count) != metadata.count)
|
if (read (fd, current_dir_block, metadata.count) != metadata.count)
|
||||||
{
|
{
|
||||||
free (current_dir_block);
|
free (current_dir_block);
|
||||||
goto bail1;
|
goto bail;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
FcCacheAddBankDir (metadata.bank, (char *) dir);
|
FcCacheAddBankDir (metadata.bank, (char *) dir);
|
||||||
if (!FcFontSetUnserialize (&metadata, set, current_dir_block))
|
if (!FcFontSetUnserialize (&metadata, set, current_dir_block))
|
||||||
goto bail1;
|
goto bail;
|
||||||
}
|
}
|
||||||
if (config)
|
|
||||||
FcConfigAddFontDir (config, (FcChar8 *)dir);
|
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
return FcTrue;
|
return FcTrue;
|
||||||
|
|
||||||
bail1:
|
|
||||||
fclose (file);
|
|
||||||
bail:
|
bail:
|
||||||
return FcFalse;
|
return FcFalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FcBool
|
||||||
|
FcDirCacheRead (FcFontSet * set, FcStrSet * dirs,
|
||||||
|
const FcChar8 *dir, FcConfig *config)
|
||||||
|
{
|
||||||
|
FILE *file;
|
||||||
|
|
||||||
|
file = FcDirCacheOpen (config, dir, NULL);
|
||||||
|
if (file == NULL)
|
||||||
|
goto bail;
|
||||||
|
|
||||||
|
if (!FcDirCacheConsume (file, set, dirs, dir, NULL))
|
||||||
|
goto bail1;
|
||||||
|
|
||||||
|
if (config)
|
||||||
|
FcConfigAddFontDir (config, (FcChar8 *)dir);
|
||||||
|
|
||||||
|
fclose (file);
|
||||||
|
return FcTrue;
|
||||||
|
|
||||||
|
bail1:
|
||||||
|
fclose (file);
|
||||||
|
bail:
|
||||||
|
return FcFalse;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
FcDirCacheProduce (FcFontSet *set, FcCache *metadata)
|
FcDirCacheProduce (FcFontSet *set, FcCache *metadata)
|
||||||
{
|
{
|
||||||
|
@ -566,6 +592,7 @@ FcDirCacheWrite (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir, FcConfig *c
|
||||||
* Compute file header length -- the FcCache followed by the subdir names
|
* Compute file header length -- the FcCache followed by the subdir names
|
||||||
*/
|
*/
|
||||||
header_len = sizeof (FcCache);
|
header_len = sizeof (FcCache);
|
||||||
|
header_len += strlen ((char *) dir) + 1;
|
||||||
for (i = 0; i < dirs->size; i++)
|
for (i = 0; i < dirs->size; i++)
|
||||||
header_len += strlen ((char *)dirs->strs[i]) + 1;
|
header_len += strlen ((char *)dirs->strs[i]) + 1;
|
||||||
|
|
||||||
|
@ -581,6 +608,8 @@ FcDirCacheWrite (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir, FcConfig *c
|
||||||
goto bail5;
|
goto bail5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FcCacheWriteString (fd, (char *) dir);
|
||||||
|
|
||||||
for (i = 0; i < dirs->size; i++)
|
for (i = 0; i < dirs->size; i++)
|
||||||
FcCacheWriteString (fd, (char *)dirs->strs[i]);
|
FcCacheWriteString (fd, (char *)dirs->strs[i]);
|
||||||
|
|
||||||
|
|
|
@ -220,14 +220,11 @@ FcDirScanConfig (FcFontSet *set,
|
||||||
for (i = 0; i < filelist->num; i++)
|
for (i = 0; i < filelist->num; i++)
|
||||||
FcFileScanFontConfig (tmpSet, blanks, filelist->strs[i], config);
|
FcFileScanFontConfig (tmpSet, blanks, filelist->strs[i], config);
|
||||||
|
|
||||||
if (FcShouldWriteFiles ())
|
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* Now that the directory has been scanned,
|
* Now that the directory has been scanned,
|
||||||
* write out the cache file
|
* write out the cache file
|
||||||
*/
|
*/
|
||||||
FcDirCacheWrite (tmpSet, dirlist, dir, config);
|
FcDirCacheWrite (tmpSet, dirlist, dir, config);
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add the discovered fonts to our internal non-cache list
|
* Add the discovered fonts to our internal non-cache list
|
||||||
|
|
|
@ -422,6 +422,10 @@ FcCacheRead (FcConfig *config);
|
||||||
FcBool
|
FcBool
|
||||||
FcDirCacheWrite (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config);
|
FcDirCacheWrite (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config);
|
||||||
|
|
||||||
|
FcBool
|
||||||
|
FcDirCacheConsume (FILE *file, FcFontSet *set, FcStrSet *dirs,
|
||||||
|
const FcChar8 *dir, char *dirname);
|
||||||
|
|
||||||
FcBool
|
FcBool
|
||||||
FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config);
|
FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue