summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@neko.keithp.com>2006-08-27 22:24:39 -0700
committerKeith Packard <keithp@neko.keithp.com>2006-08-27 22:24:39 -0700
commitaf180c40376690b7ced5262156fbe13c9ebba1e2 (patch)
tree2097e05497a48f45b916c94e4e5a4858a68f2935
parent00f059e930f12ca7c66cf2ffbc6c4ae789912af7 (diff)
downloadfontconfig-af180c40376690b7ced5262156fbe13c9ebba1e2.tar.gz
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.
-rw-r--r--fc-cache/fc-cache.c2
-rw-r--r--fc-cat/fc-cat.c119
-rw-r--r--src/fccache.c77
-rw-r--r--src/fcdir.c13
-rw-r--r--src/fcint.h4
5 files changed, 76 insertions, 139 deletions
diff --git a/fc-cache/fc-cache.c b/fc-cache/fc-cache.c
index 281f835..134d33d 100644
--- a/fc-cache/fc-cache.c
+++ b/fc-cache/fc-cache.c
@@ -219,7 +219,7 @@ scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool
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);
diff --git a/fc-cat/fc-cat.c b/fc-cat/fc-cat.c
index cf36323..36f8bd9 100644
--- a/fc-cat/fc-cat.c
+++ b/fc-cat/fc-cat.c
@@ -167,127 +167,37 @@ usage (char *program)
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;
}
@@ -425,7 +335,7 @@ main (int argc, char **argv)
{
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
@@ -439,10 +349,7 @@ main (int argc, char **argv)
FcCachePrintSet (fs, dirs, name_buf);
else
{
- FcStrSetDestroy (dirs);
- dirs = FcStrSetCreate ();
- if (FcCacheGlobalFileReadAndPrint (fs, dirs, argv[i]))
- ;
+ printf ("nothing to do\n");
}
FcStrSetDestroy (dirs);
diff --git a/src/fccache.c b/src/fccache.c
index 295ee77..a677253 100644
--- a/src/fccache.c
+++ b/src/fccache.c
@@ -132,7 +132,7 @@ FcDirCacheValid (const FcChar8 *dir, FcConfig *config)
file = FcDirCacheOpen (config, dir, NULL);
- if (file != NULL)
+ if (file == NULL)
return FcFalse;
fclose (file);
@@ -334,26 +334,31 @@ FcDirCacheOpen (FcConfig *config, const FcChar8 *dir, FcChar8 **cache_path)
/* 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)
{
@@ -362,52 +367,73 @@ FcDirCacheRead (FcFontSet * set, FcStrSet * dirs,
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)
@@ -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
*/
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;
@@ -581,6 +608,8 @@ FcDirCacheWrite (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir, FcConfig *c
goto bail5;
}
+ FcCacheWriteString (fd, (char *) dir);
+
for (i = 0; i < dirs->size; i++)
FcCacheWriteString (fd, (char *)dirs->strs[i]);
diff --git a/src/fcdir.c b/src/fcdir.c
index 62314a3..c15b727 100644
--- a/src/fcdir.c
+++ b/src/fcdir.c
@@ -220,14 +220,11 @@ FcDirScanConfig (FcFontSet *set,
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
diff --git a/src/fcint.h b/src/fcint.h
index 494552e..cb137d3 100644
--- a/src/fcint.h
+++ b/src/fcint.h
@@ -423,6 +423,10 @@ 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);
extern int *_fcBankId, *_fcBankIdx;