X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=fc-lang%2Ffc-lang.c;h=21d568d7e8d8e7bdcef48f6ba4fd4e4e77b5b86b;hb=2e44cbe1b9bf466718167e9e05077743df36ab21;hp=6a863e4e6dea689d1fbb01f5ccbfa5d3e08ff23d;hpb=67ed0b729718233662255a181bdcdb136c04dc5b;p=fontconfig.git diff --git a/fc-lang/fc-lang.c b/fc-lang/fc-lang.c index 6a863e4..21d568d 100644 --- a/fc-lang/fc-lang.c +++ b/fc-lang/fc-lang.c @@ -1,5 +1,5 @@ /* - * $RCSId: xc/lib/fontconfig/fc-lang/fc-lang.c,v 1.3 2002/08/22 07:36:43 keithp Exp $ + * fontconfig/fc-lang/fc-lang.c * * Copyright © 2002 Keith Packard * @@ -13,18 +13,18 @@ * 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 * PERFORMANCE OF THIS SOFTWARE. */ -#include "fcint.h" #include "fccharset.c" #include "fcstr.c" +#include "fcserialize.c" /* * fc-lang @@ -37,10 +37,6 @@ * functions are also needed in slightly modified form */ -const FcChar16 langBankNumbers[1]; /* place holders so that externs resolve */ -const FcCharLeaf langBankLeaves[1]; -const int langBankLeafIdx[1]; - void FcMemAlloc (int kind, int size) { @@ -51,18 +47,18 @@ FcMemFree (int kind, int size) { } -int* _fcBankId = 0; -int* _fcBankIdx = 0; -FcValueList ** _fcValueLists = 0; -FcPatternElt ** _fcPatternElts = 0; -int FcDebugVal = 0; +FcPrivate void +FcCacheObjectReference (void *object) +{ +} -int -FcCacheBankToIndexMTF (int bank) +FcPrivate void +FcCacheObjectDereference (void *object) { - return -1; } +int FcDebugVal; + FcChar8 * FcConfigHome (void) { @@ -129,28 +125,38 @@ scanopen (char *file) * Comments begin with '#' */ -static FcCharSet * -scan (FILE *f, char *file) +static const FcCharSet * +scan (FILE *f, char *file, FcCharSetFreezer *freezer) { - FcCharSet *c = 0; - FcCharSet *n; - int start, end, ucs4; - char line[1024]; - int lineno = 0; + FcCharSet *c = 0; + FcCharSet *n; + int start, end, ucs4; + char line[1024]; + int lineno = 0; while (get_line (f, line, &lineno)) { if (!strncmp (line, "include", 7)) { - file = strchr (line, ' '); - while (isspace(*file)) - file++; - f = scanopen (file); - if (!f) - fatal (file, 0, "can't open"); - c = scan (f, file); - fclose (f); - return c; + FILE *included_f; + char *included_file; + included_file = strchr (line, ' '); + if (!included_file) + fatal (file, lineno, + "invalid syntax, expected: include filename"); + while (isspace(*included_file)) + included_file++; + included_f = scanopen (included_file); + if (!included_f) + fatal (included_file, 0, "can't open"); + n = scan (included_f, included_file, freezer); + fclose (included_f); + if (!c) + c = FcCharSetCreate (); + if (!FcCharSetMerge (c, n, NULL)) + fatal (file, lineno, "out of memory"); + FcCharSetDestroy (n); + continue; } if (strchr (line, '-')) { @@ -171,7 +177,7 @@ scan (FILE *f, char *file) fatal (file, lineno, "out of memory"); } } - n = FcCharSetFreeze (c); + n = FcCharSetFreeze (freezer, c); FcCharSetDestroy (c); return n; } @@ -218,44 +224,52 @@ get_lang (char *name) return lang; } +typedef struct _Entry { + int id; + char *file; +} Entry; + static int compare (const void *a, const void *b) { - const FcChar8 *const *as = a, *const *bs = b; - return FcStrCmpIgnoreCase (*as, *bs); + const Entry const *as = a, *bs = b; + return FcStrCmpIgnoreCase (as->file, bs->file); } #define MAX_LANG 1024 #define MAX_LANG_SET_MAP ((MAX_LANG + 31) / 32) -#define BitSet(map, id) ((map)[(id)>>5] |= ((FcChar32) 1 << ((id) & 0x1f))) -#define BitGet(map, id) ((map)[(id)>>5] >> ((id) & 0x1f)) & 1) +#define BitSet(map, i) ((map)[(entries[i].id)>>5] |= ((FcChar32) 1 << ((entries[i].id) & 0x1f))) +#define BitGet(map, i) ((map)[(entries[i].id)>>5] >> ((entries[i].id) & 0x1f)) & 1) int main (int argc, char **argv) { - static char *files[MAX_LANG]; - static FcCharSet *sets[MAX_LANG]; + static Entry entries[MAX_LANG]; + static const FcCharSet *sets[MAX_LANG]; static int duplicate[MAX_LANG]; - static int offsets[MAX_LANG]; static int country[MAX_LANG]; static char *names[MAX_LANG]; static char *langs[MAX_LANG]; + static int off[MAX_LANG]; FILE *f; - int offset = 0; int ncountry = 0; int i = 0; + int nsets = 0; int argi; FcCharLeaf **leaves; int total_leaves = 0; - int offset_count = 0; - int l, sl, tl; + int l, sl, tl, tn; static char line[1024]; static FcChar32 map[MAX_LANG_SET_MAP]; int num_lang_set_map; int setRangeStart[26]; int setRangeEnd[26]; FcChar8 setRangeChar; + FcCharSetFreezer *freezer; + freezer = FcCharSetFreezerCreate (); + if (!freezer) + fatal (argv[0], 0, "out of memory"); argi = 1; while (argv[argi]) { @@ -267,18 +281,20 @@ main (int argc, char **argv) } if (i == MAX_LANG) fatal (argv[0], 0, "Too many languages"); - files[i++] = argv[argi++]; + entries[i].id = i; + entries[i].file = argv[argi++]; + i++; } - files[i] = 0; - qsort (files, i, sizeof (char *), compare); + entries[i].file = 0; + qsort (entries, i, sizeof (Entry), compare); i = 0; - while (files[i]) + while (entries[i].file) { - f = scanopen (files[i]); + f = scanopen (entries[i].file); if (!f) - fatal (files[i], 0, strerror (errno)); - sets[i] = scan (f, files[i]); - names[i] = get_name (files[i]); + fatal (entries[i].file, 0, strerror (errno)); + sets[i] = scan (f, entries[i].file, freezer); + names[i] = get_name (entries[i].file); langs[i] = get_lang(names[i]); if (strchr (langs[i], '-')) country[ncountry++] = i; @@ -287,6 +303,7 @@ main (int argc, char **argv) i++; fclose (f); } + nsets = i; sets[i] = 0; leaves = malloc (total_leaves * sizeof (FcCharLeaf *)); tl = 0; @@ -298,10 +315,10 @@ main (int argc, char **argv) for (sl = 0; sl < sets[i]->num; sl++) { for (l = 0; l < tl; l++) - if (leaves[l] == FcCharSetGetLeaf(sets[i], sl)) + if (leaves[l] == FcCharSetLeaf(sets[i], sl)) break; if (l == tl) - leaves[tl++] = FcCharSetGetLeaf(sets[i], sl); + leaves[tl++] = FcCharSetLeaf(sets[i], sl); } } @@ -318,22 +335,6 @@ main (int argc, char **argv) printf ("/* total size: %d unique leaves: %d */\n\n", total_leaves, tl); - /* - * Dump leaves - */ - printf ("const FcCharLeaf langBankLeaves[%d] = {\n", tl); - for (l = 0; l < tl; l++) - { - printf (" { { /* %d */", l); - for (i = 0; i < 256/32; i++) - { - if (i % 4 == 0) - printf ("\n "); - printf (" 0x%08x,", leaves[l]->map[i]); - } - printf ("\n } },\n"); - } - printf ("};\n\n"); /* * Find duplicate charsets @@ -352,111 +353,145 @@ main (int argc, char **argv) } } + tn = 0; + for (i = 0; sets[i]; i++) { + if (duplicate[i] >= 0) + continue; + off[i] = tn; + tn += sets[i]->num; + } + + printf ("#define LEAF0 (%d * sizeof (FcLangCharSet))\n", nsets); + printf ("#define OFF0 (LEAF0 + %d * sizeof (FcCharLeaf))\n", tl); + printf ("#define NUM0 (OFF0 + %d * sizeof (intptr_t))\n", tn); + printf ("#define SET(n) (n * sizeof (FcLangCharSet) + offsetof (FcLangCharSet, charset))\n"); + printf ("#define OFF(s,o) (OFF0 + o * sizeof (intptr_t) - SET(s))\n"); + printf ("#define NUM(s,n) (NUM0 + n * sizeof (FcChar16) - SET(s))\n"); + printf ("#define LEAF(o,l) (LEAF0 + l * sizeof (FcCharLeaf) - (OFF0 + o * sizeof (intptr_t)))\n"); + printf ("#define fcLangCharSets (fcLangData.langCharSets)\n"); + printf ("#define fcLangCharSetIndices (fcLangData.langIndices)\n"); + printf ("#define fcLangCharSetIndicesInv (fcLangData.langIndicesInv)\n"); + printf ("\n"); + + printf ("static const struct {\n" + " FcLangCharSet langCharSets[%d];\n" + " FcCharLeaf leaves[%d];\n" + " intptr_t leaf_offsets[%d];\n" + " FcChar16 numbers[%d];\n" + " FcChar%s langIndices[%d];\n" + " FcChar%s langIndicesInv[%d];\n" + "} fcLangData = {\n", + nsets, tl, tn, tn, + nsets < 256 ? "8 " : "16", nsets, nsets < 256 ? "8 " : "16", nsets); + /* - * Find ranges for each letter for faster searching + * Dump sets */ - setRangeChar = 'a'; + + printf ("{\n"); for (i = 0; sets[i]; i++) { - char c = names[i][0]; - - while (setRangeChar <= c && c <= 'z') - setRangeStart[setRangeChar++ - 'a'] = i; + int j = duplicate[i]; + + if (j < 0) + j = i; + + printf (" { \"%s\", " + " { FC_REF_CONSTANT, %d, OFF(%d,%d), NUM(%d,%d) } }, /* %d */\n", + langs[i], + sets[j]->num, i, off[j], i, off[j], i); } - for (setRangeChar = 'a'; setRangeChar < 'z'; setRangeChar++) - setRangeEnd[setRangeChar - 'a'] = setRangeStart[setRangeChar+1-'a'] - 1; - setRangeEnd[setRangeChar - 'a'] = i - 1; + printf ("},\n"); /* - * Dump arrays + * Dump leaves */ - for (i = 0; sets[i]; i++) + printf ("{\n"); + for (l = 0; l < tl; l++) { - int n; - - if (duplicate[i] >= 0) - continue; - - for (n = 0; n < sets[i]->num; n++) + printf (" { { /* %d */", l); + for (i = 0; i < 256/32; i++) { - for (l = 0; l < tl; l++) - if (leaves[l] == FcCharSetGetLeaf(sets[i], n)) - break; - if (l == tl) - fatal (names[i], 0, "can't find leaf"); - offset_count++; + if (i % 4 == 0) + printf ("\n "); + printf (" 0x%08x,", leaves[l]->map[i]); } - offsets[i] = offset; - offset += sets[i]->num; + printf ("\n } },\n"); } + printf ("},\n"); - printf ("const int langBankLeafIdx[%d] = {\n", - offset_count); + /* + * Dump leaves + */ + printf ("{\n"); for (i = 0; sets[i]; i++) { int n; if (duplicate[i] >= 0) continue; + printf (" /* %s */\n", names[i]); for (n = 0; n < sets[i]->num; n++) { - if (n % 8 == 0) + if (n % 4 == 0) printf (" "); for (l = 0; l < tl; l++) - if (leaves[l] == FcCharSetGetLeaf(sets[i], n)) + if (leaves[l] == FcCharSetLeaf(sets[i], n)) break; if (l == tl) fatal (names[i], 0, "can't find leaf"); - printf (" %3d,", l); - if (n % 8 == 7) + printf (" LEAF(%3d,%3d),", off[i], l); + if (n % 4 == 3) printf ("\n"); } - if (n % 8 != 0) + if (n % 4 != 0) printf ("\n"); } - printf ("};\n\n"); - - printf ("const FcChar16 langBankNumbers[%d] = {\n", - offset_count); + printf ("},\n"); + + printf ("{\n"); for (i = 0; sets[i]; i++) { int n; - + if (duplicate[i] >= 0) continue; + printf (" /* %s */\n", names[i]); for (n = 0; n < sets[i]->num; n++) { if (n % 8 == 0) printf (" "); - printf (" 0x%04x,", FcCharSetGetNumbers(sets[i])[n]); + printf (" 0x%04x,", FcCharSetNumbers (sets[i])[n]); if (n % 8 == 7) printf ("\n"); } if (n % 8 != 0) printf ("\n"); } - printf ("};\n\n"); - - /* - * Dump sets - */ + printf ("},\n"); - printf ("const FcLangCharSet fcLangCharSets[] = {\n"); + /* langIndices */ + printf ("{\n"); for (i = 0; sets[i]; i++) { - int j = duplicate[i]; - - if (j < 0) - j = i; + printf (" %d, /* %s */\n", entries[i].id, names[i]); + } + printf ("},\n"); - printf (" { (FcChar8 *) \"%s\",\n" - " { FC_REF_CONSTANT, %d, FC_BANK_LANGS, " - "{ { %d, %d } } } }, /* %d */\n", - langs[i], - sets[j]->num, offsets[j], offsets[j], j); + /* langIndicesInv */ + printf ("{\n"); + { + static int entries_inv[MAX_LANG]; + for (i = 0; sets[i]; i++) + entries_inv[entries[i].id] = i; + for (i = 0; sets[i]; i++) + printf (" %d, /* %s */\n", entries_inv[i], names[entries_inv[i]]); } + printf ("}\n"); + printf ("};\n\n"); + printf ("#define NUM_LANG_CHAR_SET %d\n", i); num_lang_set_map = (i + 31) / 32; printf ("#define NUM_LANG_SET_MAP %d\n", num_lang_set_map); @@ -484,7 +519,7 @@ main (int argc, char **argv) for (d = c + 1; d < ncountry; d++) { int j = country[d]; - if (j >= 0 && !strncmp (langs[j], langs[i], l)) + if (j >= 0 && !strncmp (langs[j], langs[i], lang + 1)) { BitSet(map, j); country[d] = -1; @@ -503,10 +538,29 @@ main (int argc, char **argv) } + /* + * Find ranges for each letter for faster searching + */ + setRangeChar = 'a'; + memset(setRangeStart, '\0', sizeof (setRangeStart)); + memset(setRangeEnd, '\0', sizeof (setRangeEnd)); + for (i = 0; sets[i]; i++) + { + char c = names[i][0]; + + while (setRangeChar <= c && c <= 'z') + setRangeStart[setRangeChar++ - 'a'] = i; + } + for (setRangeChar = 'a'; setRangeChar < 'z'; setRangeChar++) + setRangeEnd[setRangeChar - 'a'] = setRangeStart[setRangeChar+1-'a'] - 1; + setRangeEnd[setRangeChar - 'a'] = i - 1; + /* * Dump sets start/finish for the fastpath */ + printf ("\n"); printf ("static const FcLangCharSetRange fcLangCharSetRanges[] = {\n"); + printf ("\n"); for (setRangeChar = 'a'; setRangeChar <= 'z' ; setRangeChar++) { printf (" { %d, %d }, /* %c */\n",