if (really_force)
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);
FcFontSetDestroy (set);
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 */
static char *
FcCacheFileRead (FcFontSet * set, FcStrSet *dirs, char *cache_file)
{
+ FILE *file;
int fd;
- char * current_arch_machine_name;
- off_t current_arch_start = 0;
char subdirName[FC_MAX_FILE_LEN + 1 + 12 + 1];
- static char name_buf[8192], *dir;
+ static char name_buf[8192];
FcChar8 * ls;
char * buf;
+ int i;
if (!cache_file)
goto bail;
- current_arch_machine_name = FcCacheMachineSignature();
- fd = open(cache_file, O_RDONLY);
- if (fd == -1)
+ file = fopen(cache_file, "rb");
+ if (file == NULL)
goto bail;
- FcCacheReadString (fd, name_buf, sizeof (name_buf));
- if (!strlen (name_buf))
- goto bail;
- if (strcmp (name_buf, FC_GLOBAL_MAGIC_COOKIE) == 0)
- goto bail;
+ if (!FcDirCacheConsume (file, set, dirs, NULL, name_buf))
+ goto bail1;
+
+ fclose (file);
+
printf ("fc-cat: printing directory cache for cache which would be named %s\n",
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;
- bail2:
- free (dir);
-
bail1:
- close (fd);
+ fclose (file);
bail:
return 0;
}
{
char * dummy_name = (char *)FcStrPlus ((FcChar8 *)argv[i],
(FcChar8 *)"/dummy");
- if (!FcDirScanConfig (fs, dirs, 0, 0,
+ if (!FcDirScanConfig (fs, dirs, 0,
(const FcChar8 *)argv[i], FcFalse, config))
fprintf (stderr, "couldn't load font dir %s\n", argv[i]);
else
FcCachePrintSet (fs, dirs, name_buf);
else
{
- FcStrSetDestroy (dirs);
- dirs = FcStrSetCreate ();
- if (FcCacheGlobalFileReadAndPrint (fs, dirs, argv[i]))
- ;
+ printf ("nothing to do\n");
}
FcStrSetDestroy (dirs);
file = FcDirCacheOpen (config, dir, NULL);
- if (file != NULL)
+ if (file == NULL)
return FcFalse;
fclose (file);
/* read serialized state from the cache file */
FcBool
-FcDirCacheRead (FcFontSet * set, FcStrSet * dirs,
- const FcChar8 *dir, FcConfig *config)
+FcDirCacheConsume (FILE *file, FcFontSet *set, FcStrSet *dirs,
+ const FcChar8 *dir, char *dirname)
{
- FILE *file;
FcCache metadata;
void *current_dir_block;
char subdir_name[FC_MAX_FILE_LEN + 1 + 12 + 1];
-
- file = FcDirCacheOpen (config, dir, NULL);
- if (file == NULL)
- goto bail;
+ int i;
if (fread(&metadata, sizeof(FcCache), 1, file) != 1)
- goto bail1;
+ goto bail;
if (metadata.magic != FC_CACHE_MAGIC)
- goto bail1;
+ goto bail;
- while (FcCacheReadString (file, subdir_name, sizeof (subdir_name)) &&
- strlen (subdir_name) > 0)
- FcStrSetAdd (dirs, (FcChar8 *)subdir_name);
+ /* skip directory name; it's just for fc-cat */
+ 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);
+ }
if (metadata.count)
{
current_dir_block = mmap (0, metadata.count,
PROT_READ, MAP_SHARED, fd, metadata.pos);
if (current_dir_block == MAP_FAILED)
- goto bail1;
+ goto bail;
#elif defined(_WIN32)
{
HANDLE hFileMap;
hFileMap = CreateFileMapping((HANDLE) _get_osfhandle(fd), NULL, PAGE_READONLY, 0, 0, NULL);
if (hFileMap == NULL)
- goto bail1;
+ goto bail;
current_dir_block = MapViewOfFile (hFileMap, FILE_MAP_READ, 0, metadata.pos, metadata.count);
if (current_dir_block == NULL)
{
CloseHandle (hFileMap);
- goto bail1;
+ goto bail;
}
}
#else
if (lseek (fd, metatdata.pos, SEEK_SET) == -1)
- goto bail1;
+ goto bail;
current_dir_block = malloc (metadata.count);
if (!current_dir_block)
- goto bail1;
+ goto bail;
/* could also use CreateMappedViewOfFile under MinGW... */
if (read (fd, current_dir_block, metadata.count) != metadata.count)
{
free (current_dir_block);
- goto bail1;
+ goto bail;
}
#endif
FcCacheAddBankDir (metadata.bank, (char *) dir);
if (!FcFontSetUnserialize (&metadata, set, current_dir_block))
- goto bail1;
+ goto bail;
}
+
+ return FcTrue;
+
+ bail:
+ 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);
+
+ fclose (file);
return FcTrue;
- bail1:
+bail1:
fclose (file);
- bail:
+bail:
return FcFalse;
}
+
static void *
FcDirCacheProduce (FcFontSet *set, FcCache *metadata)
* Compute file header length -- the FcCache followed by the subdir names
*/
header_len = sizeof (FcCache);
+ header_len += strlen ((char *) dir) + 1;
for (i = 0; i < dirs->size; i++)
header_len += strlen ((char *)dirs->strs[i]) + 1;
goto bail5;
}
+ FcCacheWriteString (fd, (char *) dir);
+
for (i = 0; i < dirs->size; i++)
FcCacheWriteString (fd, (char *)dirs->strs[i]);
for (i = 0; i < filelist->num; i++)
FcFileScanFontConfig (tmpSet, blanks, filelist->strs[i], config);
- if (FcShouldWriteFiles ())
- {
- /*
- * Now that the directory has been scanned,
- * write out the cache file
- */
- FcDirCacheWrite (tmpSet, dirlist, dir, config);
- }
+ /*
+ * Now that the directory has been scanned,
+ * write out the cache file
+ */
+ FcDirCacheWrite (tmpSet, dirlist, dir, config);
/*
* Add the discovered fonts to our internal non-cache list
FcBool
FcDirCacheWrite (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config);
+FcBool
+FcDirCacheConsume (FILE *file, FcFontSet *set, FcStrSet *dirs,
+ const FcChar8 *dir, char *dirname);
+
FcBool
FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config);