[Fontconfig] fontconfig cleanup patch
Behdad Esfahbod
behdad at cs.toronto.edu
Mon Sep 19 11:51:55 EST 2005
[sent this patch to Keith a while back. resending here.]
Attaching the patch.
The theme is:
- Cast sizeof to int, to shut up signedness warnings in comparison.
- Add consts were appropriate.
- Use char arrays instead of char pointers in static const
structures. Optimizes per-process memory and relocation time.
It's a bit controversial, since hardcodes upper limit on the size
of the strings, but gcc would nag if you break that limit. I
find it safe enough, YMMV :)
Cheers,
--behdad
http://behdad.org/
-------------- next part --------------
Index: doc/edit-sgml.c
===================================================================
RCS file: /cvs/fontconfig/fontconfig/doc/edit-sgml.c,v
retrieving revision 1.6
diff -u -p -r1.6 edit-sgml.c
--- doc/edit-sgml.c 7 Dec 2004 01:14:45 -0000 1.6
+++ doc/edit-sgml.c 27 Aug 2005 15:59:55 -0000
@@ -77,7 +77,7 @@ static void
ReplaceDispose (Replace *r);
static void
-Bail (char *format, char *arg);
+Bail (const char *format, const char *arg);
static Replace *
ReplaceRead (FILE *f);
@@ -249,7 +249,7 @@ ReplaceDispose (Replace *r)
}
static void
-Bail (char *format, char *arg)
+Bail (const char *format, const char *arg)
{
fprintf (stderr, "fatal: ");
fprintf (stderr, format, arg);
Index: fc-case/fc-case.c
===================================================================
RCS file: /cvs/fontconfig/fontconfig/fc-case/fc-case.c,v
retrieving revision 1.1
diff -u -p -r1.1 fc-case.c
--- fc-case/fc-case.c 29 Dec 2004 09:15:17 -0000 1.1
+++ fc-case/fc-case.c 27 Aug 2005 15:59:55 -0000
@@ -31,11 +31,11 @@
typedef enum _caseFoldClass { CaseFoldCommon, CaseFoldFull, CaseFoldSimple, CaseFoldTurkic } CaseFoldClass;
typedef struct _caseFoldClassMap {
- char *name;
+ const char *name;
CaseFoldClass class;
} CaseFoldClassMap;
-static CaseFoldClassMap caseFoldClassMap[] = {
+static const CaseFoldClassMap caseFoldClassMap[] = {
{ "C", CaseFoldCommon },
{ "F", CaseFoldFull },
{ "S", CaseFoldSimple },
@@ -51,7 +51,7 @@ typedef struct _caseFoldRaw {
} CaseFoldRaw;
static void
-panic (char *reason)
+panic (const char *reason)
{
fprintf (stderr, "fc-case: panic %s\n", reason);
exit (1);
@@ -148,7 +148,7 @@ foldExtends (FcCaseFold *fold, CaseFoldR
return 0;
}
-static char *
+static const char *
case_fold_method_name (FcChar16 method)
{
switch (method) {
Index: fc-glyphname/fc-glyphname.c
===================================================================
RCS file: /cvs/fontconfig/fontconfig/fc-glyphname/fc-glyphname.c,v
retrieving revision 1.5
diff -u -p -r1.5 fc-glyphname.c
--- fc-glyphname/fc-glyphname.c 25 Jul 2005 20:39:19 -0000 1.5
+++ fc-glyphname/fc-glyphname.c 27 Aug 2005 15:59:55 -0000
@@ -25,7 +25,7 @@
#include "fcint.h"
static int
-rawindex (FcGlyphName *gn);
+rawindex (const FcGlyphName *gn);
static void
scan (FILE *f, char *filename);
@@ -43,7 +43,7 @@ static void
insert (FcGlyphName *gn, FcGlyphName **table, FcChar32 h);
static void
-dump (FcGlyphName **table, char *name);
+dump (FcGlyphName * const *table, const char *name);
static FcGlyphName *
FcAllocGlyphName (FcChar32 ucs, FcChar8 *name)
@@ -59,9 +59,13 @@ FcAllocGlyphName (FcChar32 ucs, FcChar8
}
static void
-fatal (char *file, int lineno, char *msg)
+fatal (const char *file, int lineno, const char *msg)
{
- fprintf (stderr, "%s:%d: %s\n", file, lineno, msg);
+ if (lineno)
+ fprintf (stderr, "%s:%d: %s\n", file, lineno, msg);
+ else
+ fprintf (stderr, "%s: %s\n", file, msg);
+
exit (1);
}
@@ -77,7 +81,7 @@ FcGlyphName *ucs_to_name[MAX_GLYPHNAME*2
int hash, rehash;
static int
-rawindex (FcGlyphName *gn)
+rawindex (const FcGlyphName *gn)
{
int i;
@@ -211,7 +215,7 @@ insert (FcGlyphName *gn, FcGlyphName **t
}
static void
-dump (FcGlyphName **table, char *name)
+dump (FcGlyphName * const *table, const char *name)
{
int i;
@@ -235,11 +239,12 @@ main (int argc, char **argv)
int i;
i = 0;
- while (*++argv)
+ while (argv[i+1])
{
if (i == MAX_GLYPHFILE)
fatal (*argv, 0, "Too many glyphname files");
- files[i++] = *argv;
+ files[i] = argv[i+1];
+ i++;
}
files[i] = 0;
qsort (files, i, sizeof (char *), compare_string);
Index: fc-lang/fc-lang.c
===================================================================
RCS file: /cvs/fontconfig/fontconfig/fc-lang/fc-lang.c,v
retrieving revision 1.12
diff -u -p -r1.12 fc-lang.c
--- fc-lang/fc-lang.c 25 Jul 2005 20:39:19 -0000 1.12
+++ fc-lang/fc-lang.c 27 Aug 2005 15:59:55 -0000
@@ -54,9 +54,12 @@ FcConfigHome (void)
}
static void
-fatal (char *file, int lineno, char *msg)
+fatal (const char *file, int lineno, const char *msg)
{
- fprintf (stderr, "%s:%d: %s\n", file, lineno, msg);
+ if (lineno)
+ fprintf (stderr, "%s:%d: %s\n", file, lineno, msg);
+ else
+ fprintf (stderr, "%s:%d: %s\n", file, lineno, msg);
exit (1);
}
@@ -220,6 +223,7 @@ main (int argc, char **argv)
FILE *f;
int ncountry = 0;
int i = 0;
+ int argi;
FcCharLeaf **leaves, **sleaves;
int total_leaves = 0;
int l, sl, tl;
@@ -231,16 +235,18 @@ main (int argc, char **argv)
int setRangeEnd[26];
FcChar8 setRangeChar;
- while (*++argv)
+ argi = 1;
+ while (argv[argi])
{
- if (!strcmp (*argv, "-d"))
+ if (!strcmp (argv[argi], "-d"))
{
- dir = *++argv;
+ argi++;
+ dir = argv[argi++];
continue;
}
if (i == MAX_LANG)
- fatal (*argv, 0, "Too many languages");
- files[i++] = *argv;
+ fatal (argv[0], 0, "Too many languages");
+ files[i++] = argv[argi++];
}
files[i] = 0;
qsort (files, i, sizeof (char *), compare);
Index: src/fccache.c
===================================================================
RCS file: /cvs/fontconfig/fontconfig/src/fccache.c,v
retrieving revision 1.23
diff -u -p -r1.23 fccache.c
--- src/fccache.c 4 Jan 2005 21:54:50 -0000 1.23
+++ src/fccache.c 27 Aug 2005 15:59:55 -0000
@@ -254,11 +254,11 @@ FcCacheFontSetAdd (FcFontSet *set,
const FcChar8 *name,
FcConfig *config)
{
- FcChar8 path_buf[8192], *path;
- int len;
- FcBool ret = FcFalse;
- FcPattern *font;
- FcPattern *frozen;
+ FcChar8 path_buf[8192], *path;
+ unsigned int len;
+ FcBool ret = FcFalse;
+ FcPattern *font;
+ FcPattern *frozen;
path = path_buf;
len = (dir_len + 1 + strlen ((const char *) file) + 1);
@@ -453,7 +453,6 @@ static FcGlobalCacheInfo *
FcGlobalCacheDirAdd (FcGlobalCache *cache,
const FcChar8 *dir,
time_t time,
- FcBool replace,
FcBool create_missing)
{
FcGlobalCacheDir *d;
@@ -533,7 +532,7 @@ FcGlobalCacheReferenceSubdir (FcGlobalCa
const FcChar8 *dir)
{
FcGlobalCacheInfo *info;
- info = FcGlobalCacheDirAdd (cache, dir, 0, FcFalse, FcFalse);
+ info = FcGlobalCacheDirAdd (cache, dir, 0, FcFalse);
if (info && !info->referenced)
{
info->referenced = FcTrue;
@@ -797,7 +796,7 @@ FcGlobalCacheLoad (FcGlobalCache *cac
if (FcDebug () & FC_DBG_CACHEV)
printf ("FcGlobalCacheLoad \"%s\" \"%20.20s\"\n", file, name);
if (!FcStrCmp (name, FC_FONT_FILE_DIR))
- info = FcGlobalCacheDirAdd (cache, file, time, FcFalse, FcTrue);
+ info = FcGlobalCacheDirAdd (cache, file, time, FcTrue);
else
info = FcGlobalCacheFileAdd (cache, file, id, time, name, FcFalse);
if (!info)
@@ -836,8 +835,7 @@ FcGlobalCacheUpdate (FcGlobalCache *cac
if (stat ((char *) file, &statb) < 0)
return FcFalse;
if (S_ISDIR (statb.st_mode))
- info = FcGlobalCacheDirAdd (cache, file, statb.st_mtime,
- FcTrue, FcTrue);
+ info = FcGlobalCacheDirAdd (cache, file, statb.st_mtime, FcTrue);
else
info = FcGlobalCacheFileAdd (cache, file, id, statb.st_mtime,
name, FcTrue);
Index: src/fccharset.c
===================================================================
RCS file: /cvs/fontconfig/fontconfig/src/fccharset.c,v
retrieving revision 1.25
diff -u -p -r1.25 fccharset.c
--- src/fccharset.c 7 Dec 2004 01:14:46 -0000 1.25
+++ src/fccharset.c 27 Aug 2005 15:59:55 -0000
@@ -307,6 +307,7 @@ FcCharSetIterStart (const FcCharSet *fcs
FcCharSetDump (fcs);
#endif
iter->ucs4 = 0;
+ iter->pos = 0;
FcCharSetIterSet (fcs, iter);
}
@@ -954,7 +955,7 @@ FcCharSetHash (FcCharSet *fcs)
/* hash in leaves */
p = (FcChar32 *) fcs->leaves;
- for (i = 0; i < fcs->num * sizeof (FcCharLeaf *) / sizeof (FcChar32); i++)
+ for (i = 0; i < fcs->num * (int) (sizeof (FcCharLeaf *) / sizeof (FcChar32)); i++)
hash = ((hash << 1) | (hash >> 31)) ^ *p++;
/* hash in numbers */
for (i = 0; i < fcs->num; i++)
Index: src/fcdefault.c
===================================================================
RCS file: /cvs/fontconfig/fontconfig/src/fcdefault.c,v
retrieving revision 1.7
diff -u -p -r1.7 fcdefault.c
--- src/fcdefault.c 7 Dec 2004 01:14:46 -0000 1.7
+++ src/fcdefault.c 27 Aug 2005 15:59:55 -0000
@@ -26,7 +26,7 @@
#include <locale.h>
static struct {
- char *field;
+ const char *field;
FcBool value;
} FcBoolDefaults[] = {
{ FC_HINTING, FcTrue }, /* !FT_LOAD_NO_HINTING */
@@ -35,7 +35,7 @@ static struct {
{ FC_GLOBAL_ADVANCE, FcTrue }, /* !FC_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH */
};
-#define NUM_FC_BOOL_DEFAULTS (sizeof FcBoolDefaults / sizeof FcBoolDefaults[0])
+#define NUM_FC_BOOL_DEFAULTS (int) (sizeof FcBoolDefaults / sizeof FcBoolDefaults[0])
void
FcDefaultSubstitute (FcPattern *pattern)
@@ -127,7 +127,7 @@ FcDefaultSubstitute (FcPattern *pattern)
after = territory + strlen (territory);
}
territory_len = after - territory;
- if (lang_len + 1 + territory_len + 1 <= sizeof (lang_local))
+ if (lang_len + 1 + territory_len + 1 <= (int) sizeof (lang_local))
{
strncpy (lang_local, lang, lang_len);
lang_local[lang_len] = '-';
Index: src/fcfreetype.c
===================================================================
RCS file: /cvs/fontconfig/fontconfig/src/fcfreetype.c,v
retrieving revision 1.61
diff -u -p -r1.61 fcfreetype.c
--- src/fcfreetype.c 25 Jul 2005 20:39:19 -0000 1.61
+++ src/fcfreetype.c 27 Aug 2005 15:59:55 -0000
@@ -95,7 +95,7 @@ static const struct {
{ 20, (const FcChar8 *) "zh-tw" },
};
-#define NUM_CODE_PAGE_RANGE (sizeof FcCodePageRange / sizeof FcCodePageRange[0])
+#define NUM_CODE_PAGE_RANGE (int) (sizeof FcCodePageRange / sizeof FcCodePageRange[0])
FcBool
FcFreeTypeIsExclusiveLang (const FcChar8 *lang)
@@ -113,7 +113,7 @@ FcFreeTypeIsExclusiveLang (const FcChar8
typedef struct {
FT_UShort platform_id;
FT_UShort encoding_id;
- char *fromcode;
+ const char fromcode[12];
} FcFtEncoding;
#define TT_ENCODING_DONT_CARE 0xffff
@@ -135,18 +135,18 @@ static const FcFtEncoding fcFtEncoding
{ TT_PLATFORM_ISO, TT_ISO_ID_8859_1, "ISO-8859-1" },
};
-#define NUM_FC_FT_ENCODING (sizeof (fcFtEncoding) / sizeof (fcFtEncoding[0]))
+#define NUM_FC_FT_ENCODING (int) (sizeof (fcFtEncoding) / sizeof (fcFtEncoding[0]))
typedef struct {
FT_UShort platform_id;
FT_UShort language_id;
- char *lang;
+ const char lang[8];
} FcFtLanguage;
#define TT_LANGUAGE_DONT_CARE 0xffff
static const FcFtLanguage fcFtLanguage[] = {
- { TT_PLATFORM_APPLE_UNICODE, TT_LANGUAGE_DONT_CARE, 0 },
+ { TT_PLATFORM_APPLE_UNICODE, TT_LANGUAGE_DONT_CARE, "" },
{ TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_ENGLISH, "en" },
{ TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_FRENCH, "fr" },
{ TT_PLATFORM_MACINTOSH, TT_MAC_LANGID_GERMAN, "de" },
@@ -545,11 +545,11 @@ static const FcFtLanguage fcFtLanguage
{ TT_PLATFORM_MICROSOFT, TT_MS_LANGID_PAPIAMENTU_NETHERLANDS_ANTILLES,"pap" },
};
-#define NUM_FC_FT_LANGUAGE (sizeof (fcFtLanguage) / sizeof (fcFtLanguage[0]))
+#define NUM_FC_FT_LANGUAGE (int) (sizeof (fcFtLanguage) / sizeof (fcFtLanguage[0]))
typedef struct {
FT_UShort language_id;
- char *fromcode;
+ char fromcode[12];
} FcMacRomanFake;
static const FcMacRomanFake fcMacRomanFake[] = {
@@ -560,7 +560,7 @@ static const FcMacRomanFake fcMacRomanFa
static FcChar8 *
FcFontCapabilities(FT_Face face);
-#define NUM_FC_MAC_ROMAN_FAKE (sizeof (fcMacRomanFake) / sizeof (fcMacRomanFake[0]))
+#define NUM_FC_MAC_ROMAN_FAKE (int) (sizeof (fcMacRomanFake) / sizeof (fcMacRomanFake[0]))
#if HAVE_ICONV && HAVE_ICONV_H
#define USE_ICONV 1
@@ -570,8 +570,8 @@ FcFontCapabilities(FT_Face face);
static FcChar8 *
FcSfntNameTranscode (FT_SfntName *sname)
{
- int i;
- char *fromcode;
+ int i;
+ const char *fromcode;
#if USE_ICONV
iconv_t cd;
#endif
@@ -596,7 +596,7 @@ FcSfntNameTranscode (FT_SfntName *sname)
{
int f;
- fromcode = 0;
+ fromcode = NULL;
for (f = 0; f < NUM_FC_MAC_ROMAN_FAKE; f++)
if (fcMacRomanFake[f].language_id == sname->language_id)
{
@@ -749,7 +749,12 @@ FcSfntNameLanguage (FT_SfntName *sname)
if (fcFtLanguage[i].platform_id == sname->platform_id &&
(fcFtLanguage[i].language_id == TT_LANGUAGE_DONT_CARE ||
fcFtLanguage[i].language_id == sname->language_id))
- return (FcChar8 *) fcFtLanguage[i].lang;
+ {
+ if (fcFtLanguage[i].lang[0] == '\0')
+ return NULL;
+ else
+ return (FcChar8 *) fcFtLanguage[i].lang;
+ }
return 0;
}
@@ -781,7 +786,7 @@ static const struct {
(const FcChar8 *) "hanyang" }
};
-#define NUM_NOTICE_FOUNDRIES (sizeof (FcNoticeFoundries) / sizeof (FcNoticeFoundries[0]))
+#define NUM_NOTICE_FOUNDRIES (int) (sizeof (FcNoticeFoundries) / sizeof (FcNoticeFoundries[0]))
static const FcChar8 *
FcNoticeFoundry(const FT_String *notice)
@@ -850,7 +855,7 @@ static const struct {
{ (const FT_Char *) "Y&Y", (const FcChar8 *) "y&y"}
};
-#define NUM_VENDOR_FOUNDRIES (sizeof (FcVendorFoundries) / sizeof (FcVendorFoundries[0]))
+#define NUM_VENDOR_FOUNDRIES (int) (sizeof (FcVendorFoundries) / sizeof (FcVendorFoundries[0]))
static const FcChar8 *
FcVendorFoundry(const FT_Char vendor[4])
@@ -916,7 +921,7 @@ static const FcStringConst weightConsts
{ (FC8) "heavy", FC_WEIGHT_HEAVY },
};
-#define NUM_WEIGHT_CONSTS (sizeof (weightConsts) / sizeof (weightConsts[0]))
+#define NUM_WEIGHT_CONSTS (int) (sizeof (weightConsts) / sizeof (weightConsts[0]))
#define FcIsWeight(s) FcStringIsConst(s,weightConsts,NUM_WEIGHT_CONSTS)
#define FcContainsWeight(s) FcStringContainsConst (s,weightConsts,NUM_WEIGHT_CONSTS)
@@ -933,7 +938,7 @@ static const FcStringConst widthConsts[
{ (FC8) "expanded", FC_WIDTH_EXPANDED }, /* must be after *expanded */
};
-#define NUM_WIDTH_CONSTS (sizeof (widthConsts) / sizeof (widthConsts[0]))
+#define NUM_WIDTH_CONSTS (int) (sizeof (widthConsts) / sizeof (widthConsts[0]))
#define FcIsWidth(s) FcStringIsConst(s,widthConsts,NUM_WIDTH_CONSTS)
#define FcContainsWidth(s) FcStringContainsConst (s,widthConsts,NUM_WIDTH_CONSTS)
@@ -943,7 +948,7 @@ static const FcStringConst slantConsts[
{ (FC8) "oblique", FC_SLANT_OBLIQUE },
};
-#define NUM_SLANT_CONSTS (sizeof (slantConsts) / sizeof (slantConsts[0]))
+#define NUM_SLANT_CONSTS (int) (sizeof (slantConsts) / sizeof (slantConsts[0]))
#define FcIsSlant(s) FcStringIsConst(s,slantConsts,NUM_SLANT_CONSTS)
#define FcContainsSlant(s) FcStringContainsConst (s,slantConsts,NUM_SLANT_CONSTS)
@@ -970,7 +975,7 @@ FcGetPixelSize (FT_Face face, int i)
}
static FcBool
-FcStringInPatternElement (FcPattern *pat, char *elt, FcChar8 *string)
+FcStringInPatternElement (FcPattern *pat, const char *elt, FcChar8 *string)
{
int e;
FcChar8 *old;
@@ -1075,7 +1080,7 @@ FcFreeTypeQuery (const FcChar8 *file,
{
FcChar8 *utf8;
FcChar8 *lang;
- char *elt = 0, *eltlang = 0;
+ const char *elt = 0, *eltlang = 0;
int *np = 0, *nlangp = 0;
if (FT_Get_Sfnt_Name (face, snamei, &sname) != 0)
@@ -2125,13 +2130,13 @@ static const FcFontDecode fcFontDecoders
{ ft_encoding_apple_roman, &AppleRoman, (1 << 16) - 1 },
};
-#define NUM_DECODE (sizeof (fcFontDecoders) / sizeof (fcFontDecoders[0]))
+#define NUM_DECODE (int) (sizeof (fcFontDecoders) / sizeof (fcFontDecoders[0]))
static const FcChar32 prefer_unicode[] = {
0x20ac, /* EURO SIGN */
};
-#define NUM_PREFER_UNICODE (sizeof (prefer_unicode) / sizeof (prefer_unicode[0]))
+#define NUM_PREFER_UNICODE (int) (sizeof (prefer_unicode) / sizeof (prefer_unicode[0]))
FcChar32
FcFreeTypeUcs4ToPrivate (FcChar32 ucs4, const FcCharMap *map)
@@ -2272,7 +2277,7 @@ FcFreeTypeGlyphNameIndex (FT_Face face,
FT_UInt gindex;
FcChar8 name_buf[FC_GLYPHNAME_MAXLEN + 2];
- for (gindex = 0; gindex < face->num_glyphs; gindex++)
+ for (gindex = 0; gindex < (FT_UInt) face->num_glyphs; gindex++)
{
if (FT_Get_Glyph_Name (face, gindex, name_buf, FC_GLYPHNAME_MAXLEN+1) == 0)
if (!strcmp ((char *) name, (char *) name_buf))
@@ -2326,7 +2331,7 @@ FcFreeTypeCharIndex (FT_Face face, FcCha
if (fcFontDecoders[decode].map)
{
charcode = FcFreeTypeUcs4ToPrivate (ucs4, fcFontDecoders[decode].map);
- if (charcode == ~0)
+ if (charcode == ~0U)
continue;
}
else
@@ -2586,7 +2591,7 @@ FcFreeTypeCharSetAndSpacing (FT_Face fac
{
FcChar8 name_buf[FC_GLYPHNAME_MAXLEN + 2];
- for (glyph = 0; glyph < face->num_glyphs; glyph++)
+ for (glyph = 0; glyph < (FT_UInt) face->num_glyphs; glyph++)
{
if (FT_Get_Glyph_Name (face, glyph, name_buf, FC_GLYPHNAME_MAXLEN+1) == 0)
{
Index: src/fcinit.c
===================================================================
RCS file: /cvs/fontconfig/fontconfig/src/fcinit.c,v
retrieving revision 1.13
diff -u -p -r1.13 fcinit.c
--- src/fcinit.c 15 Jul 2005 17:43:44 -0000 1.13
+++ src/fcinit.c 27 Aug 2005 15:59:55 -0000
@@ -161,7 +161,7 @@ FcInitBringUptoDate (void)
}
static struct {
- char *name;
+ char name[16];
int alloc_count;
int alloc_mem;
int free_count;
Index: src/fcmatch.c
===================================================================
RCS file: /cvs/fontconfig/fontconfig/src/fcmatch.c,v
retrieving revision 1.28
diff -u -p -r1.28 fcmatch.c
--- src/fcmatch.c 31 Mar 2005 19:16:49 -0000 1.28
+++ src/fcmatch.c 27 Aug 2005 15:59:55 -0000
@@ -28,7 +28,7 @@
#include <stdio.h>
static double
-FcCompareNumber (char *object, FcValue value1, FcValue value2)
+FcCompareNumber (const char *object, FcValue value1, FcValue value2)
{
double v1, v2, v;
@@ -59,23 +59,23 @@ FcCompareNumber (char *object, FcValue v
}
static double
-FcCompareString (char *object, FcValue value1, FcValue value2)
+FcCompareString (const char *object, FcValue value1, FcValue value2)
{
if (value2.type != FcTypeString || value1.type != FcTypeString)
return -1.0;
- return (double) FcStrCmpIgnoreCase (value1.u.s, value2.u.s) != 0;
+ return (double) (FcStrCmpIgnoreCase (value1.u.s, value2.u.s) != 0);
}
static double
-FcCompareFamily (char *object, FcValue value1, FcValue value2)
+FcCompareFamily (const char *object, FcValue value1, FcValue value2)
{
if (value2.type != FcTypeString || value1.type != FcTypeString)
return -1.0;
- return (double) FcStrCmpIgnoreBlanksAndCase (value1.u.s, value2.u.s) != 0;
+ return (double) (FcStrCmpIgnoreBlanksAndCase (value1.u.s, value2.u.s) != 0);
}
static double
-FcCompareLang (char *object, FcValue value1, FcValue value2)
+FcCompareLang (const char *object, FcValue value1, FcValue value2)
{
FcLangResult result;
@@ -119,7 +119,7 @@ FcCompareLang (char *object, FcValue val
}
static double
-FcCompareBool (char *object, FcValue value1, FcValue value2)
+FcCompareBool (const char *object, FcValue value1, FcValue value2)
{
if (value2.type != FcTypeBool || value1.type != FcTypeBool)
return -1.0;
@@ -127,15 +127,15 @@ FcCompareBool (char *object, FcValue val
}
static double
-FcCompareCharSet (char *object, FcValue value1, FcValue value2)
+FcCompareCharSet (const char *object, FcValue value1, FcValue value2)
{
if (value2.type != FcTypeCharSet || value1.type != FcTypeCharSet)
return -1.0;
- return (double) FcCharSetSubtractCount (value1.u.c, value2.u.c);
+ return (double) (int) FcCharSetSubtractCount (value1.u.c, value2.u.c);
}
static double
-FcCompareSize (char *object, FcValue value1, FcValue value2)
+FcCompareSize (const char *object, FcValue value1, FcValue value2)
{
double v1, v2, v;
@@ -168,8 +168,8 @@ FcCompareSize (char *object, FcValue val
}
typedef struct _FcMatcher {
- char *object;
- double (*compare) (char *object, FcValue value1, FcValue value2);
+ const char *object;
+ double (*compare) (const char *object, FcValue value1, FcValue value2);
int strong, weak;
} FcMatcher;
Index: src/fcpat.c
===================================================================
RCS file: /cvs/fontconfig/fontconfig/src/fcpat.c,v
retrieving revision 1.29
diff -u -p -r1.29 fcpat.c
--- src/fcpat.c 25 Jul 2005 20:39:19 -0000 1.29
+++ src/fcpat.c 27 Aug 2005 15:59:55 -0000
@@ -287,7 +287,7 @@ typedef union _FcValueListAlign {
static int FcValueListFrozenCount[FcTypeLangSet + 1];
static int FcValueListFrozenBytes[FcTypeLangSet + 1];
-static char *FcValueListFrozenName[] = {
+static char FcValueListFrozenName[][8] = {
"Void",
"Integer",
"Double",
Index: src/fcxml.c
===================================================================
RCS file: /cvs/fontconfig/fontconfig/src/fcxml.c,v
retrieving revision 1.39
diff -u -p -r1.39 fcxml.c
--- src/fcxml.c 25 Jul 2005 20:39:19 -0000 1.39
+++ src/fcxml.c 27 Aug 2005 15:59:55 -0000
@@ -323,72 +323,72 @@ typedef enum _FcElement {
FcElementUnknown
} FcElement;
+static struct {
+ const char name[16];
+ FcElement element;
+} fcElementMap[] = {
+ { "fontconfig", FcElementFontconfig },
+ { "dir", FcElementDir },
+ { "cache", FcElementCache },
+ { "include", FcElementInclude },
+ { "config", FcElementConfig },
+ { "match", FcElementMatch },
+ { "alias", FcElementAlias },
+
+ { "blank", FcElementBlank },
+ { "rescan", FcElementRescan },
+
+ { "prefer", FcElementPrefer },
+ { "accept", FcElementAccept },
+ { "default", FcElementDefault },
+ { "family", FcElementFamily },
+
+ { "selectfont", FcElementSelectfont },
+ { "acceptfont", FcElementAcceptfont },
+ { "rejectfont", FcElementRejectfont },
+ { "glob", FcElementGlob },
+ { "pattern", FcElementPattern },
+ { "patelt", FcElementPatelt },
+
+ { "test", FcElementTest },
+ { "edit", FcElementEdit },
+ { "int", FcElementInt },
+ { "double", FcElementDouble },
+ { "string", FcElementString },
+ { "matrix", FcElementMatrix },
+ { "bool", FcElementBool },
+ { "charset", FcElementCharset },
+ { "name", FcElementName },
+ { "const", FcElementConst },
+ { "or", FcElementOr },
+ { "and", FcElementAnd },
+ { "eq", FcElementEq },
+ { "not_eq", FcElementNotEq },
+ { "less", FcElementLess },
+ { "less_eq", FcElementLessEq },
+ { "more", FcElementMore },
+ { "more_eq", FcElementMoreEq },
+ { "contains", FcElementContains },
+ { "not_contains", FcElementNotContains },
+ { "plus", FcElementPlus },
+ { "minus", FcElementMinus },
+ { "times", FcElementTimes },
+ { "divide", FcElementDivide },
+ { "not", FcElementNot },
+ { "if", FcElementIf },
+ { "floor", FcElementFloor },
+ { "ceil", FcElementCeil },
+ { "round", FcElementRound },
+ { "trunc", FcElementTrunc },
+};
+#define NUM_ELEMENT_MAPS (int) (sizeof fcElementMap / sizeof fcElementMap[0])
+
static FcElement
FcElementMap (const XML_Char *name)
{
- static struct {
- char *name;
- FcElement element;
- } fcElementMap[] = {
- { "fontconfig", FcElementFontconfig },
- { "dir", FcElementDir },
- { "cache", FcElementCache },
- { "include", FcElementInclude },
- { "config", FcElementConfig },
- { "match", FcElementMatch },
- { "alias", FcElementAlias },
-
- { "blank", FcElementBlank },
- { "rescan", FcElementRescan },
-
- { "prefer", FcElementPrefer },
- { "accept", FcElementAccept },
- { "default", FcElementDefault },
- { "family", FcElementFamily },
-
- { "selectfont", FcElementSelectfont },
- { "acceptfont", FcElementAcceptfont },
- { "rejectfont", FcElementRejectfont },
- { "glob", FcElementGlob },
- { "pattern", FcElementPattern },
- { "patelt", FcElementPatelt },
-
- { "test", FcElementTest },
- { "edit", FcElementEdit },
- { "int", FcElementInt },
- { "double", FcElementDouble },
- { "string", FcElementString },
- { "matrix", FcElementMatrix },
- { "bool", FcElementBool },
- { "charset", FcElementCharset },
- { "name", FcElementName },
- { "const", FcElementConst },
- { "or", FcElementOr },
- { "and", FcElementAnd },
- { "eq", FcElementEq },
- { "not_eq", FcElementNotEq },
- { "less", FcElementLess },
- { "less_eq", FcElementLessEq },
- { "more", FcElementMore },
- { "more_eq", FcElementMoreEq },
- { "contains", FcElementContains },
- { "not_contains",FcElementNotContains },
- { "plus", FcElementPlus },
- { "minus", FcElementMinus },
- { "times", FcElementTimes },
- { "divide", FcElementDivide },
- { "not", FcElementNot },
- { "if", FcElementIf },
- { "floor", FcElementFloor },
- { "ceil", FcElementCeil },
- { "round", FcElementRound },
- { "trunc", FcElementTrunc },
-
- { 0, 0 }
- };
int i;
- for (i = 0; fcElementMap[i].name; i++)
+ for (i = 0; i < NUM_ELEMENT_MAPS; i++)
if (!strcmp ((char *) name, fcElementMap[i].name))
return fcElementMap[i].element;
return FcElementUnknown;
@@ -461,9 +461,9 @@ typedef enum _FcConfigSeverity {
} FcConfigSeverity;
static void
-FcConfigMessage (FcConfigParse *parse, FcConfigSeverity severe, char *fmt, ...)
+FcConfigMessage (FcConfigParse *parse, FcConfigSeverity severe, const char *fmt, ...)
{
- char *s = "unknown";
+ const char *s = "unknown";
va_list args;
va_start (args, fmt);
@@ -492,7 +492,7 @@ FcConfigMessage (FcConfigParse *parse, F
}
-static char *
+static const char *
FcTypeName (FcType type)
{
switch (type) {
@@ -998,7 +998,7 @@ FcConfigCleanup (FcConfigParse *parse)
}
static const FcChar8 *
-FcConfigGetAttribute (FcConfigParse *parse, char *attr)
+FcConfigGetAttribute (FcConfigParse *parse, const char *attr)
{
FcChar8 **attrs;
if (!parse->pstack)
@@ -1125,7 +1125,7 @@ FcStrtod (char *s, char **end)
int slen = strlen (s);
int dlen = strlen (locale_data->decimal_point);
- if (slen + dlen > sizeof (buf))
+ if (slen + dlen > (int) sizeof (buf))
{
if (end)
*end = s;
@@ -1591,7 +1591,7 @@ FcParseInclude (FcConfigParse *parse)
}
typedef struct _FcOpMap {
- char *name;
+ char name[16];
FcOp op;
} FcOpMap;
@@ -1617,7 +1617,7 @@ static const FcOpMap fcCompareOps[] = {
{ "not_contains", FcOpNotContains }
};
-#define NUM_COMPARE_OPS (sizeof fcCompareOps / sizeof fcCompareOps[0])
+#define NUM_COMPARE_OPS (int) (sizeof fcCompareOps / sizeof fcCompareOps[0])
static FcOp
FcConfigLexCompare (const FcChar8 *compare)
@@ -1717,7 +1717,7 @@ static const FcOpMap fcModeOps[] = {
{ "append_last", FcOpAppendLast },
};
-#define NUM_MODE_OPS (sizeof fcModeOps / sizeof fcModeOps[0])
+#define NUM_MODE_OPS (int) (sizeof fcModeOps / sizeof fcModeOps[0])
static FcOp
FcConfigLexMode (const FcChar8 *mode)
More information about the Fontconfig
mailing list