X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=fc-lang%2Ffc-lang.c;h=a13d1bfe848e320cbf4e4dc7be1a4c294db9e3ca;hb=5aaf466d3899842763e746a9c2b745748eb34b48;hp=b0f1690e880533fc1823989148f2e9d3a0b1e500;hpb=bb36e67685dc4139fc4199c57c9d74d97f7923c8;p=fontconfig.git diff --git a/fc-lang/fc-lang.c b/fc-lang/fc-lang.c index b0f1690..a13d1bf 100644 --- a/fc-lang/fc-lang.c +++ b/fc-lang/fc-lang.c @@ -7,9 +7,9 @@ * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in + * documentation, and that the name of the author(s) not be used in * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no + * specific, written prior permission. The authors make no * representations about the suitability of this software for any purpose. It * is provided "as is" without express or implied warranty. * @@ -76,10 +76,14 @@ fatal (const char *file, int lineno, const char *msg) } static char * -get_line (FILE *f, char *line, int *lineno) +get_line (FILE *f, char *buf, int *lineno) { char *hash; + char *line; int end; + +next: + line = buf; if (!fgets (line, 1024, f)) return 0; ++(*lineno); @@ -87,12 +91,15 @@ get_line (FILE *f, char *line, int *lineno) if (hash) *hash = '\0'; + while (line[0] && isspace (line[0])) + line++; end = strlen (line); while (end > 0 && isspace (line[end-1])) line[--end] = '\0'; - if (line[0] == '\0' || line[0] == '\n' || line[0] == '\032' || line[0] == '\r') - return get_line (f, line, lineno); + if (line[0] == '\0' || line[0] == '\n' || line[0] == '\r') + goto next; + return line; } @@ -125,16 +132,18 @@ scanopen (char *file) * Comments begin with '#' */ -static const FcCharSet * +static FcCharSet * scan (FILE *f, char *file, FcCharSetFreezer *freezer) { FcCharSet *c = 0; - const FcCharSet *n; + FcCharSet *n; + FcBool del; int start, end, ucs4; - char line[1024]; + char buf[1024]; + char *line; int lineno = 0; - while (get_line (f, line, &lineno)) + while ((line = get_line (f, buf, &lineno))) { if (!strncmp (line, "include", 7)) { @@ -158,6 +167,12 @@ scan (FILE *f, char *file, FcCharSetFreezer *freezer) FcCharSetDestroy (n); continue; } + del = FcFalse; + if (line[0] == '-') + { + del = FcTrue; + line++; + } if (strchr (line, '-')) { if (sscanf (line, "%x-%x", &start, &end) != 2) @@ -173,7 +188,7 @@ scan (FILE *f, char *file, FcCharSetFreezer *freezer) c = FcCharSetCreate (); for (ucs4 = start; ucs4 <= end; ucs4++) { - if (!FcCharSetAddChar (c, ucs4)) + if (!((del ? FcCharSetDelChar : FcCharSetAddChar) (c, ucs4))) fatal (file, lineno, "out of memory"); } } @@ -224,23 +239,28 @@ 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 *as = a, *bs = b; + return FcStrCmpIgnoreCase ((const FcChar8 *) as->file, (const FcChar8 *) 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 const FcCharSet *sets[MAX_LANG]; + static Entry entries[MAX_LANG]; + static FcCharSet *sets[MAX_LANG]; static int duplicate[MAX_LANG]; static int country[MAX_LANG]; static char *names[MAX_LANG]; @@ -276,18 +296,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], freezer); - 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; @@ -356,21 +378,26 @@ main (int argc, char **argv) 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 NUM0 (OFF0 + %d * sizeof (uintptr_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 OFF(s,o) (OFF0 + o * sizeof (uintptr_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" + " uintptr_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, tl, tn, tn, + nsets < 256 ? "8 " : "16", nsets, nsets < 256 ? "8 " : "16", nsets); /* * Dump sets @@ -457,10 +484,29 @@ main (int argc, char **argv) if (n % 8 != 0) printf ("\n"); } + printf ("},\n"); + + /* langIndices */ + printf ("{\n"); + for (i = 0; sets[i]; i++) + { + printf (" %d, /* %s */\n", entries[i].id, names[i]); + } + printf ("},\n"); + + /* 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); @@ -527,7 +573,9 @@ main (int argc, char **argv) /* * 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",