Commit ccb3e93b authored by Keith Packard's avatar Keith Packard

fontconfig library: build fixes and compiler warning fixes

parent 3be03bed
INCLUDES=$(FREETYPE2INCLUDES) $(LIBXML2INCLUDES) -I..
LOCAL_LIBRARIES=FontconfigClientLibs
DEPLIBS=FontconfigDepLibs
DEPLIBS=FontconfigClientDepLibs
SRCS=fc-cache.c
OBJS=fc-cache.o
......
INCLUDES=$(FREETYPE2INCLUDES) $(LIBXML2INCLUDES) -I..
LOCAL_LIBRARIES=FontconfigClientLibs
DEPLIBS=FontconfigDepLibs
DEPLIBS=FontconfigClientDepLibs
SRCS=fc-list.c
OBJS=fc-list.o
......
......@@ -25,6 +25,7 @@
#include <fontconfig/fontconfig.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#else
......@@ -47,7 +48,7 @@ extern int optind, opterr, optopt;
#endif
#endif
void usage (char *program)
static void usage (char *program)
{
fprintf (stderr, "usage: %s [-vV?] [--verbose] [--version] [--help] [dirs]\n",
program);
......@@ -63,8 +64,6 @@ void usage (char *program)
int
main (int argc, char **argv)
{
int ret = 0;
FcFontSet *set;
int verbose = 0;
int i;
FcObjectSet *os = FcObjectSetBuild (FC_FAMILY, FC_LANG, 0);
......
......@@ -24,6 +24,7 @@
#ifndef _FCFREETYPE_H_
#define _FCFREETYPE_H_
#include <freetype/freetype.h>
FT_UInt
FcFreeTypeCharIndex (FT_Face face, FcChar32 ucs4);
......
......@@ -59,7 +59,7 @@
__v__.u.d = va_arg (va, double); \
break; \
case FcTypeString: \
__v__.u.s = va_arg (va, char *); \
__v__.u.s = va_arg (va, FcChar8 *); \
break; \
case FcTypeBool: \
__v__.u.b = va_arg (va, FcBool); \
......
......@@ -28,7 +28,7 @@
#include <libxml/parser.h>
xmlDocPtr
FcConfigLoad (const char *file);
FcConfigLoad (const FcChar8 *file);
FcBool
FcConfigParse (FcConfig *config,
......
......@@ -168,7 +168,7 @@ typedef struct _FcObjectType {
} FcObjectType;
typedef struct _FcConstant {
const char *name;
const FcChar8 *name;
const char *object;
int value;
} FcConstant;
......@@ -242,8 +242,8 @@ FcBool
FcBlanksIsMember (FcBlanks *b, FcChar32 ucs4);
/* fccfg.c */
char *
FcConfigFilename (const char *url);
FcChar8 *
FcConfigFilename (const FcChar8 *url);
FcConfig *
FcConfigCreate (void);
......@@ -260,13 +260,13 @@ FcConfigGetCurrent (void);
FcBool
FcConfigBuildFonts (FcConfig *config);
char **
FcChar8 **
FcConfigGetDirs (FcConfig *config);
char **
FcChar8 **
FcConfigGetConfigFiles (FcConfig *config);
char *
FcChar8 *
FcConfigGetCache (FcConfig *config);
FcBlanks *
......@@ -278,11 +278,11 @@ FcConfigGetFonts (FcConfig *config,
FcBool
FcConfigAppFontAddFile (FcConfig *config,
const char *file);
const FcChar8 *file);
FcBool
FcConfigAppFontAddDir (FcConfig *config,
const char *dir);
const FcChar8 *dir);
void
FcConfigAppFontClear (FcConfig *config);
......@@ -329,12 +329,6 @@ FcCharSetIntersectCount (const FcCharSet *a, const FcCharSet *b);
FcChar32
FcCharSetSubtractCount (const FcCharSet *a, const FcCharSet *b);
#ifndef FONTCONFIG_NO_FREETYPE
#include <freetype/freetype.h>
FT_UInt
FcFreeTypeCharIndex (FT_Face face, FcChar32 ucs4);
#endif
/* fcdbg.c */
void
FcPatternPrint (FcPattern *p);
......@@ -345,18 +339,25 @@ FcDefaultSubstitute (FcPattern *pattern);
/* fcdir.c */
FcBool
FcDirScan (FcFontSet *set,
FcFileCache *cache,
FcBlanks *blanks,
const char *dir,
FcBool force);
FcFileScan (FcFontSet *set,
FcFileCache *cache,
FcBlanks *blanks,
const FcChar8 *file,
FcBool force);
FcBool
FcDirSave (FcFontSet *set, const char *dir);
FcDirScan (FcFontSet *set,
FcFileCache *cache,
FcBlanks *blanks,
const FcChar8 *dir,
FcBool force);
FcBool
FcDirSave (FcFontSet *set, const FcChar8 *dir);
/* fcfreetype.c */
FcPattern *
FcFreeTypeQuery (const char *file, int id, FcBlanks *blanks, int *count);
FcFreeTypeQuery (const FcChar8 *file, int id, FcBlanks *blanks, int *count);
/* fcfs.c */
......@@ -443,13 +444,13 @@ FcBool
FcNameUnregisterConstants (const FcConstant *consts, int nconsts);
const FcConstant *
FcNameGetConstant (char *string);
FcNameGetConstant (FcChar8 *string);
FcBool
FcNameConstant (char *string, int *result);
FcNameConstant (FcChar8 *string, int *result);
FcPattern *
FcNameParse (const char *name);
FcNameParse (const FcChar8 *name);
FcChar8 *
FcNameUnparse (FcPattern *pat);
......@@ -486,7 +487,7 @@ FcBool
FcPatternAddDouble (FcPattern *p, const char *object, double d);
FcBool
FcPatternAddString (FcPattern *p, const char *object, const char *s);
FcPatternAddString (FcPattern *p, const char *object, const FcChar8 *s);
FcBool
FcPatternAddMatrix (FcPattern *p, const char *object, const FcMatrix *s);
......@@ -504,7 +505,7 @@ FcResult
FcPatternGetDouble (FcPattern *p, const char *object, int n, double *d);
FcResult
FcPatternGetString (FcPattern *p, const char *object, int n, char **const s);
FcPatternGetString (FcPattern *p, const char *object, int n, FcChar8 const** s);
FcResult
FcPatternGetMatrix (FcPattern *p, const char *object, int n, FcMatrix **s);
......@@ -523,13 +524,13 @@ FcPatternBuild (FcPattern *orig, ...);
/* fcstr.c */
char *
FcStrCopy (const char *s);
FcChar8 *
FcStrCopy (const FcChar8 *s);
#define FcToLower(c) (('A' <= (c) && (c) <= 'Z') ? (c) - 'A' + 'a' : (c))
int
FcStrCmpIgnoreCase (const char *s1, const char *s2);
FcStrCmpIgnoreCase (const FcChar8 *s1, const FcChar8 *s2);
int
FcUtf8ToUcs4 (FcChar8 *src_orig,
......@@ -544,7 +545,7 @@ FcUtf8Len (FcChar8 *string,
/* fcxml.c */
FcBool
FcConfigParseAndLoad (FcConfig *config, const char *file, FcBool complain);
FcConfigParseAndLoad (FcConfig *config, const FcChar8 *file, FcBool complain);
_FCFUNCPROTOEND
......
......@@ -25,25 +25,25 @@
#include "fcint.h"
static unsigned int
FcFileCacheHash (const char *string)
FcFileCacheHash (const FcChar8 *string)
{
unsigned int h = 0;
char c;
FcChar8 c;
while ((c = *string++))
h = (h << 1) ^ c;
return h;
}
char *
FcChar8 *
FcFileCacheFind (FcFileCache *cache,
const char *file,
const FcChar8 *file,
int id,
int *count)
{
unsigned int hash;
const char *match;
FcFileCacheEnt *c, *name;
const FcChar8 *match;
FcFileCacheEnt *c, *name;
int maxid;
struct stat statb;
......@@ -60,7 +60,7 @@ FcFileCacheFind (FcFileCache *cache,
maxid = c->id;
if (c->id == id)
{
if (stat (file, &statb) < 0)
if (stat ((char *) file, &statb) < 0)
{
if (FcDebug () & FC_DBG_CACHE)
printf (" file missing\n");
......@@ -94,11 +94,14 @@ FcFileCacheFind (FcFileCache *cache,
* "file_name" id time "font_name" \n
*/
static FcBool
FcFileCacheReadString (FILE *f, char *dest, int len)
static FcChar8 *
FcFileCacheReadString (FILE *f, FcChar8 *dest, int len)
{
int c;
FcBool escape;
int c;
FcBool escape;
FcChar8 *d;
int size;
int i;
while ((c = getc (f)) != EOF)
if (c == '"')
......@@ -108,6 +111,9 @@ FcFileCacheReadString (FILE *f, char *dest, int len)
if (len == 0)
return FcFalse;
size = len;
i = 0;
d = dest;
escape = FcFalse;
while ((c = getc (f)) != EOF)
{
......@@ -115,19 +121,32 @@ FcFileCacheReadString (FILE *f, char *dest, int len)
{
switch (c) {
case '"':
*dest++ = '\0';
return FcTrue;
c = '\0';
break;
case '\\':
escape = FcTrue;
continue;
}
}
if (--len <= 1)
return FcFalse;
*dest++ = c;
if (i == size)
{
FcChar8 *new = malloc (size * 2);
if (!new)
break;
memcpy (new, d, size);
size *= 2;
if (d != dest)
free (d);
d = new;
}
d[i++] = c;
if (c == '\0')
return d;
escape = FcFalse;
}
return FcFalse;
if (d != dest)
free (d);
return 0;
}
static FcBool
......@@ -183,10 +202,10 @@ FcFileCacheReadTime (FILE *f, time_t *dest)
static FcBool
FcFileCacheAdd (FcFileCache *cache,
const char *file,
const FcChar8 *file,
int id,
time_t time,
const char *name,
const FcChar8 *name,
FcBool replace)
{
FcFileCacheEnt *c;
......@@ -220,16 +239,16 @@ FcFileCacheAdd (FcFileCache *cache,
}
c = malloc (sizeof (FcFileCacheEnt) +
strlen (file) + 1 +
strlen (name) + 1);
strlen ((char *) file) + 1 +
strlen ((char *) name) + 1);
if (!c)
return FcFalse;
c->next = *prev;
*prev = c;
c->hash = hash;
c->file = (char *) (c + 1);
c->file = (FcChar8 *) (c + 1);
c->id = id;
c->name = c->file + strlen (file) + 1;
c->name = c->file + strlen ((char *) file) + 1;
strcpy (c->file, file);
c->time = time;
c->referenced = replace;
......@@ -274,42 +293,54 @@ FcFileCacheDestroy (FcFileCache *cache)
void
FcFileCacheLoad (FcFileCache *cache,
const char *cache_file)
const FcChar8 *cache_file)
{
FILE *f;
char file[8192];
FcChar8 file_buf[8192], *file;
int id;
time_t time;
char name[8192];
FcChar8 name_buf[8192], *name;
f = fopen (cache_file, "r");
f = fopen ((char *) cache_file, "r");
if (!f)
return;
cache->updated = FcFalse;
while (FcFileCacheReadString (f, file, sizeof (file)) &&
file = 0;
name = 0;
while ((file = FcFileCacheReadString (f, file_buf, sizeof (file_buf))) &&
FcFileCacheReadInt (f, &id) &&
FcFileCacheReadTime (f, &time) &&
FcFileCacheReadString (f, name, sizeof (name)))
(name = FcFileCacheReadString (f, name_buf, sizeof (name_buf))))
{
(void) FcFileCacheAdd (cache, file, id, time, name, FcFalse);
if (file != file_buf)
free (file);
if (name != name_buf)
free (name);
file = 0;
name = 0;
}
if (file && file != file_buf)
free (file);
if (name && name != name_buf)
free (name);
fclose (f);
}
FcBool
FcFileCacheUpdate (FcFileCache *cache,
const char *file,
int id,
const char *name)
FcFileCacheUpdate (FcFileCache *cache,
const FcChar8 *file,
int id,
const FcChar8 *name)
{
const char *match;
const FcChar8 *match;
struct stat statb;
FcBool ret;
match = file;
if (stat (file, &statb) < 0)
if (stat ((char *) file, &statb) < 0)
return FcFalse;
ret = FcFileCacheAdd (cache, match, id,
statb.st_mtime, name, FcTrue);
......@@ -319,7 +350,7 @@ FcFileCacheUpdate (FcFileCache *cache,
}
static FcBool
FcFileCacheWriteString (FILE *f, char *string)
FcFileCacheWriteString (FILE *f, const FcChar8 *string)
{
char c;
......@@ -382,10 +413,10 @@ FcFileCacheWriteTime (FILE *f, time_t t)
FcBool
FcFileCacheSave (FcFileCache *cache,
const char *cache_file)
const FcChar8 *cache_file)
{
char *lck;
char *tmp;
FcChar8 *lck;
FcChar8 *tmp;
FILE *f;
int h;
FcFileCacheEnt *c;
......@@ -393,19 +424,19 @@ FcFileCacheSave (FcFileCache *cache,
if (!cache->updated && cache->referenced == cache->entries)
return FcTrue;
lck = malloc (strlen (cache_file)*2 + 4);
lck = malloc (strlen ((char *) cache_file)*2 + 4);
if (!lck)
goto bail0;
tmp = lck + strlen (cache_file) + 2;
strcpy (lck, cache_file);
strcat (lck, "L");
strcpy (tmp, cache_file);
strcat (tmp, "T");
if (link (lck, cache_file) < 0 && errno != ENOENT)
tmp = lck + strlen ((char *) cache_file) + 2;
strcpy ((char *) lck, (char *) cache_file);
strcat ((char *) lck, "L");
strcpy ((char *) tmp, (char *) cache_file);
strcat ((char *) tmp, "T");
if (link ((char *) lck, (char *) cache_file) < 0 && errno != ENOENT)
goto bail1;
if (access (tmp, F_OK) == 0)
if (access ((char *) tmp, F_OK) == 0)
goto bail2;
f = fopen (tmp, "w");
f = fopen ((char *) tmp, "w");
if (!f)
goto bail2;
......@@ -437,19 +468,19 @@ FcFileCacheSave (FcFileCache *cache,
if (fclose (f) == EOF)
goto bail3;
if (rename (tmp, cache_file) < 0)
if (rename ((char *) tmp, (char *) cache_file) < 0)
goto bail3;
unlink (lck);
unlink ((char *) lck);
cache->updated = FcFalse;
return FcTrue;
bail4:
fclose (f);
bail3:
unlink (tmp);
unlink ((char *) tmp);
bail2:
unlink (lck);
unlink ((char *) lck);
bail1:
free (lck);
bail0:
......@@ -457,15 +488,15 @@ bail0:
}
FcBool
FcFileCacheReadDir (FcFontSet *set, const char *cache_file)
FcFileCacheReadDir (FcFontSet *set, const FcChar8 *cache_file)
{
FcPattern *font;
FILE *f;
char *path;
char *base;
char file[8192];
FcChar8 *path;
FcChar8 *base;
FcChar8 file_buf[8192], *file;
int id;
char name[8192];
FcChar8 name_buf[8192], *name;
FcBool ret = FcFalse;
if (FcDebug () & FC_DBG_CACHE)
......@@ -473,7 +504,7 @@ FcFileCacheReadDir (FcFontSet *set, const char *cache_file)
printf ("FcFileCacheReadDir cache_file \"%s\"\n", cache_file);
}
f = fopen (cache_file, "r");
f = fopen ((char *) cache_file, "r");
if (!f)
{
if (FcDebug () & FC_DBG_CACHE)
......@@ -483,7 +514,7 @@ FcFileCacheReadDir (FcFontSet *set, const char *cache_file)
goto bail0;
}
base = strrchr (cache_file, '/');
base = (FcChar8 *) strrchr ((char *) cache_file, '/');
if (!base)
goto bail1;
base++;
......@@ -493,9 +524,11 @@ FcFileCacheReadDir (FcFontSet *set, const char *cache_file)
memcpy (path, cache_file, base - cache_file);
base = path + (base - cache_file);
while (FcFileCacheReadString (f, file, sizeof (file)) &&
file = 0;
name = 0;
while ((file = FcFileCacheReadString (f, file_buf, sizeof (file_buf))) &&
FcFileCacheReadInt (f, &id) &&
FcFileCacheReadString (f, name, sizeof (name)))
(name = FcFileCacheReadString (f, name_buf, sizeof (name_buf))))
{
font = FcNameParse (name);
if (font)
......@@ -509,6 +542,11 @@ FcFileCacheReadDir (FcFontSet *set, const char *cache_file)
if (!FcFontSetAdd (set, font))
goto bail2;
}
if (file != file_buf)
free (file);
if (name != name_buf)
free (name);
file = name = 0;
}
if (FcDebug () & FC_DBG_CACHE)
{
......@@ -518,6 +556,10 @@ FcFileCacheReadDir (FcFontSet *set, const char *cache_file)
ret = FcTrue;
bail2:
free (path);
if (file && file != file_buf)
free (file);
if (name && name != name_buf)
free (name);
bail1:
fclose (f);
bail0:
......@@ -525,12 +567,12 @@ bail0:
}
FcBool
FcFileCacheWriteDir (FcFontSet *set, const char *cache_file)
FcFileCacheWriteDir (FcFontSet *set, const FcChar8 *cache_file)
{
FcPattern *font;
FILE *f;
char *name;
char *file, *base;
FcChar8 *name;
const FcChar8 *file, *base;
int n;
int id;
FcBool ret;
......@@ -538,7 +580,7 @@ FcFileCacheWriteDir (FcFontSet *set, const char *cache_file)
if (FcDebug () & FC_DBG_CACHE)
printf ("FcFileCacheWriteDir cache_file \"%s\"\n", cache_file);
f = fopen (cache_file, "w");
f = fopen ((char *) cache_file, "w");
if (!f)
{
if (FcDebug () & FC_DBG_CACHE)
......@@ -550,7 +592,7 @@ FcFileCacheWriteDir (FcFontSet *set, const char *cache_file)
font = set->fonts[n];
if (FcPatternGetString (font, FC_FILE, 0, &file) != FcResultMatch)
goto bail1;
base = strrchr (file, '/');
base = (FcChar8 *) strrchr ((char *) file, '/');
if (base)
base = base + 1;
else
......@@ -587,6 +629,6 @@ FcFileCacheWriteDir (FcFontSet *set, const char *cache_file)
bail1:
fclose (f);
bail0:
unlink (cache_file);
unlink ((char *) cache_file);
return FcFalse;
}
......@@ -50,7 +50,7 @@ FcConfigCreate (void)
config->configFiles[0] = 0;
config->cache = 0;
if (!FcConfigSetCache (config, "~/" FC_USER_CACHE_FILE))
if (!FcConfigSetCache (config, (FcChar8 *) ("~/" FC_USER_CACHE_FILE)))
goto bail3;
config->blanks = 0;
......@@ -88,9 +88,9 @@ FcSubstDestroy (FcSubst *s)
}
static void
FcConfigDestroyStrings (char **strings)
FcConfigDestroyStrings (FcChar8 **strings)
{
char **s;
FcChar8 **s;
for (s = strings; s && *s; s++)
free (*s);
......@@ -99,20 +99,20 @@ FcConfigDestroyStrings (char **strings)
}
static FcBool
FcConfigAddString (char ***strings, char *string)
FcConfigAddString (FcChar8 ***strings, FcChar8 *string)
{
int n;
char **s;
FcChar8 **s;
n = 0;
for (s = *strings; s && *s; s++)
n++;
s = malloc ((n + 2) * sizeof (char *));
s = malloc ((n + 2) * sizeof (FcChar8 *));
if (!s)
return FcFalse;
s[n] = string;
s[n+1] = 0;
memcpy (s, *strings, n * sizeof (char *));
memcpy (s, *strings, n * sizeof (FcChar8 *));
free (*strings);
*strings = s;
return FcTrue;
......@@ -145,7 +145,7 @@ FcConfigBuildFonts (FcConfig *config)
{
FcFontSet *fonts;
FcFileCache *cache;
char **d;
FcChar8 **d;
fonts = FcFontSetCreate ();
if (!fonts)
......@@ -200,25 +200,25 @@ FcConfigGetCurrent (void)
FcBool
FcConfigAddDir (FcConfig *config,
const char *d)
const FcChar8 *d)
{
char *dir;
char *h;
FcChar8 *dir;
FcChar8 *h;
if (*d == '~')
{
h = getenv ("HOME");
h = (FcChar8 *) getenv ("HOME");
if (!h)
return FcFalse;
dir = (char *) malloc (strlen (h) + strlen (d));
dir = (FcChar8 *) malloc (strlen ((char *) h) + strlen ((char *) d));
if (!dir)
return FcFalse;
strcpy (dir, h);
strcat (dir, d+1);
strcpy ((char *) dir, (char *) h);
strcat ((char *) dir, (char *) d+1);
}
else
{
dir = (char *) malloc (strlen (d) + 1);
dir = (FcChar8 *) malloc (strlen ((char *) d) + 1);
if (!dir)
return FcFalse;
strcpy (dir, d);
......@@ -231,7 +231,7 @@ FcConfigAddDir (FcConfig *config,
return FcTrue;
}
char **
FcChar8 **
FcConfigGetDirs (FcConfig *config)
{
if (!config)
......@@ -245,9 +245,9 @@ FcConfigGetDirs (FcConfig *config)
FcBool
FcConfigAddConfigFile (FcConfig *config,
const char *f)
const FcChar8 *f)
{
char *file;
FcChar8 *file;
file = FcConfigFilename (f);
if (!file)
return FcFalse;
......@@ -259,7 +259,7 @@ FcConfigAddConfigFile (FcConfig *config,
return FcTrue;
}
char **
FcChar8 **
FcConfigGetConfigFiles (FcConfig *config)
{
if (!config)
......@@ -273,21 +273,21 @@ FcConfigGetConfigFiles (FcConfig *config)
FcBool
FcConfigSetCache (FcConfig *config,
const char *c)
const FcChar8 *c)
{
char *new;