/*
- * $RCSId: xc/lib/fontconfig/fc-cache/fc-cache.c,v 1.8tsi Exp $
+ * fontconfig/fc-cat/fc-cat.c
*
* Copyright © 2002 Keith Packard
*
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
#define HAVE_GETOPT 1
#endif
-#include "../src/fccache.c"
+#include <fontconfig/fontconfig.h>
#include "../fc-arch/fcarch.h"
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
{"version", 0, 0, 'V'},
{"verbose", 0, 0, 'v'},
{"recurse", 0, 0, 'r'},
- {"help", 0, 0, '?'},
+ {"help", 0, 0, 'h'},
{NULL,0,0,0},
};
#else
}
static void
-usage (char *program)
+usage (char *program, int error)
{
+ FILE *file = error ? stderr : stdout;
#if HAVE_GETOPT_LONG
- fprintf (stderr, "usage: %s [-V?] [--version] [--help] {*-%s.cache-2|directory}...\n",
+ fprintf (file, "usage: %s [-rv] [--recurse] [--verbose] [*-%s.cache-2|directory]...\n",
program, FC_ARCHITECTURE);
+ fprintf (file, " %s [-Vh] [--version] [--help]\n", program);
#else
- fprintf (stderr, "usage: %s [-fsvV?] {*-%s.cache-2|directory}...\n",
+ fprintf (file, "usage: %s [-rvVh] [*-%s.cache-2|directory]...\n",
program, FC_ARCHITECTURE);
#endif
- 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 (file, "Reads font information cache from:\n");
+ fprintf (file, " 1) specified fontconfig cache file\n");
+ fprintf (file, " 2) related to a particular font directory\n");
+ fprintf (file, "\n");
#if HAVE_GETOPT_LONG
- fprintf (stderr, " -V, --version display font config version and exit\n");
- fprintf (stderr, " -?, --help display this help and exit\n");
+ fprintf (file, " -r, --recurse recurse into subdirectories\n");
+ fprintf (file, " -v, --verbose be verbose\n");
+ fprintf (file, " -V, --version display font config version and exit\n");
+ fprintf (file, " -h, --help display this help and exit\n");
#else
- fprintf (stderr, " -V (version) display font config version and exit\n");
- fprintf (stderr, " -? (help) display this help and exit\n");
+ fprintf (file, " -r (recurse) recurse into subdirectories\n");
+ fprintf (file, " -v (verbose) be verbose\n");
+ fprintf (file, " -V (version) display font config version and exit\n");
+ fprintf (file, " -h (help) display this help and exit\n");
#endif
- exit (1);
+ exit (error);
}
/*
*/
static const FcChar8 *
-file_base_name (const char *cache, const FcChar8 *file)
+file_base_name (const FcChar8 *cache, const FcChar8 *file)
{
- const FcChar8 *cache_slash;
- int cache_len = strlen (cache);
+ int cache_len = strlen ((char *) cache);
- if (!strncmp (cache, file, cache_len) && file[cache_len] == '/')
+ if (!strncmp ((char *) cache, (char *) file, cache_len) && file[cache_len] == '/')
return file + cache_len + 1;
return file;
}
+#define FC_FONT_FILE_DIR ((FcChar8 *) ".dir")
+
static FcBool
-cache_print_set (FcFontSet *set, FcStrSet *dirs, char *base_name, FcBool verbose)
+cache_print_set (FcFontSet *set, FcStrSet *dirs, const FcChar8 *base_name, FcBool verbose)
{
- FcPattern *font;
FcChar8 *name, *dir;
const FcChar8 *file, *base;
int ret;
for (n = 0; n < set->nfont; n++)
{
- FcPattern **fonts = FcFontSetFonts (set);
- FcPattern *encoded_font = fonts[n];
- FcPattern *font = FcEncodedOffsetToPtr (set, encoded_font, FcPattern);
+ FcPattern *font = set->fonts[n];
if (FcPatternGetString (font, FC_FILE, 0, (FcChar8 **) &file) != FcResultMatch)
goto bail3;
int c;
#if HAVE_GETOPT_LONG
- while ((c = getopt_long (argc, argv, "Vvr?", longopts, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, "Vvrh", longopts, NULL)) != -1)
#else
- while ((c = getopt (argc, argv, "Vvr?")) != -1)
+ while ((c = getopt (argc, argv, "Vvrh")) != -1)
#endif
{
switch (c) {
case 'r':
recurse++;
break;
+ case 'h':
+ usage (argv[0], 0);
default:
- usage (argv[0]);
+ usage (argv[0], 1);
}
}
i = optind;
{
for (; i < argc; i++)
{
- if (!FcStrSetAddFilename (args, argv[i]))
+ if (!FcStrSetAddFilename (args, (const FcChar8 *) argv[i]))
{
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;
struct stat file_stat;
}
dirs = FcStrSetCreate ();
- fs = FcCacheSet (cache);
- cache_dirs = FcCacheDirs (cache);
- for (j = 0; j < cache->dirs_count; j++)
+ fs = FcCacheCopySet (cache);
+ for (j = 0; j < FcCacheNumSubdir (cache); j++)
{
- FcStrSetAdd (dirs, FcOffsetToPtr (cache_dirs,
- cache_dirs[j],
- FcChar8));
+ FcStrSetAdd (dirs, FcCacheSubdir (cache, j));
if (recurse)
- FcStrSetAdd (args, FcOffsetToPtr (cache_dirs,
- cache_dirs[j],
- FcChar8));
+ FcStrSetAdd (args, FcCacheSubdir (cache, j));
}
if (verbose)
FcStrSetDestroy (dirs);
+ FcFontSetDestroy (fs);
FcDirCacheUnload (cache);
if (cache_file)
FcStrFree (cache_file);