2002-07-07 01:21:37 +02:00
|
|
|
/*
|
2008-08-12 22:34:24 +02:00
|
|
|
* fontconfig/fc-lang/fc-lang.c
|
2002-07-07 01:21:37 +02:00
|
|
|
*
|
2004-12-07 02:14:46 +01:00
|
|
|
* Copyright © 2002 Keith Packard
|
2002-07-07 01:21:37 +02:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
* 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
|
2010-11-10 22:45:42 +01:00
|
|
|
* documentation, and that the name of the author(s) not be used in
|
2002-07-07 01:21:37 +02:00
|
|
|
* advertising or publicity pertaining to distribution of the software without
|
2010-11-10 22:45:42 +01:00
|
|
|
* specific, written prior permission. The authors make no
|
2002-07-07 01:21:37 +02:00
|
|
|
* representations about the suitability of this software for any purpose. It
|
|
|
|
* is provided "as is" without express or implied warranty.
|
|
|
|
*
|
2009-03-12 21:00:08 +01:00
|
|
|
* THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
2002-07-07 01:21:37 +02:00
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
2009-03-12 21:00:08 +01:00
|
|
|
* EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
2002-07-07 01:21:37 +02:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-02-06 18:46:06 +01:00
|
|
|
#include "fccharset.c"
|
|
|
|
#include "fcstr.c"
|
2006-08-30 13:24:03 +02:00
|
|
|
#include "fcserialize.c"
|
2002-07-07 01:21:37 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* fc-lang
|
|
|
|
*
|
|
|
|
* Read a set of language orthographies and build C declarations for
|
|
|
|
* charsets which can then be used to identify which languages are
|
2003-02-06 18:46:06 +01:00
|
|
|
* supported by a given font. Note that this uses some utilities
|
|
|
|
* from the fontconfig library, so the necessary file is simply
|
|
|
|
* included in this compilation. A couple of extra utility
|
|
|
|
* functions are also needed in slightly modified form
|
2002-07-07 01:21:37 +02:00
|
|
|
*/
|
|
|
|
|
2006-09-05 07:39:51 +02:00
|
|
|
FcPrivate void
|
2013-01-03 03:08:40 +01:00
|
|
|
FcCacheObjectReference (void *object FC_UNUSED)
|
2006-09-05 07:39:51 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FcPrivate void
|
2013-01-03 03:08:40 +01:00
|
|
|
FcCacheObjectDereference (void *object FC_UNUSED)
|
2006-09-05 07:39:51 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-29 13:25:20 +02:00
|
|
|
FcPrivate FcChar8 *
|
2013-01-03 03:08:40 +01:00
|
|
|
FcLangNormalize (const FcChar8 *lang FC_UNUSED)
|
2012-03-29 13:25:20 +02:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-09-01 10:49:47 +02:00
|
|
|
int FcDebugVal;
|
|
|
|
|
2003-03-02 20:12:23 +01:00
|
|
|
FcChar8 *
|
|
|
|
FcConfigHome (void)
|
|
|
|
{
|
2005-09-11 04:16:09 +02:00
|
|
|
return (FcChar8 *) getenv ("HOME");
|
2003-03-02 20:12:23 +01:00
|
|
|
}
|
|
|
|
|
2002-07-07 01:21:37 +02:00
|
|
|
static void
|
2005-09-23 01:45:53 +02:00
|
|
|
fatal (const char *file, int lineno, const char *msg)
|
2002-07-07 01:21:37 +02:00
|
|
|
{
|
2005-09-23 01:45:53 +02:00
|
|
|
if (lineno)
|
|
|
|
fprintf (stderr, "%s:%d: %s\n", file, lineno, msg);
|
|
|
|
else
|
2005-09-23 03:48:33 +02:00
|
|
|
fprintf (stderr, "%s: %s\n", file, msg);
|
2002-07-07 01:21:37 +02:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2010-09-21 19:14:55 +02:00
|
|
|
get_line (FILE *f, char *buf, int *lineno)
|
2002-07-07 01:21:37 +02:00
|
|
|
{
|
|
|
|
char *hash;
|
2010-09-21 19:14:55 +02:00
|
|
|
char *line;
|
2006-02-22 05:50:16 +01:00
|
|
|
int end;
|
2010-09-21 19:14:55 +02:00
|
|
|
|
|
|
|
next:
|
|
|
|
line = buf;
|
2002-07-07 01:21:37 +02:00
|
|
|
if (!fgets (line, 1024, f))
|
|
|
|
return 0;
|
|
|
|
++(*lineno);
|
|
|
|
hash = strchr (line, '#');
|
|
|
|
if (hash)
|
|
|
|
*hash = '\0';
|
2006-02-22 05:50:16 +01:00
|
|
|
|
2010-09-21 19:14:55 +02:00
|
|
|
while (line[0] && isspace (line[0]))
|
|
|
|
line++;
|
2006-02-22 05:50:16 +01:00
|
|
|
end = strlen (line);
|
|
|
|
while (end > 0 && isspace (line[end-1]))
|
|
|
|
line[--end] = '\0';
|
|
|
|
|
2010-09-21 19:14:55 +02:00
|
|
|
if (line[0] == '\0' || line[0] == '\n' || line[0] == '\r')
|
|
|
|
goto next;
|
|
|
|
|
2002-07-07 01:21:37 +02:00
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2006-04-06 06:33:11 +02:00
|
|
|
static char *dir = 0;
|
2003-10-27 07:30:29 +01:00
|
|
|
|
2004-04-14 20:08:41 +02:00
|
|
|
static FILE *
|
2003-10-27 07:30:29 +01:00
|
|
|
scanopen (char *file)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
f = fopen (file, "r");
|
|
|
|
if (!f && dir)
|
|
|
|
{
|
|
|
|
char path[1024];
|
|
|
|
|
|
|
|
strcpy (path, dir);
|
|
|
|
strcat (path, "/");
|
|
|
|
strcat (path, file);
|
|
|
|
f = fopen (path, "r");
|
|
|
|
}
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2002-07-07 01:21:37 +02:00
|
|
|
/*
|
|
|
|
* build a single charset from a source file
|
|
|
|
*
|
|
|
|
* The file format is quite simple, either
|
|
|
|
* a single hex value or a pair separated with a dash
|
|
|
|
*
|
|
|
|
* Comments begin with '#'
|
|
|
|
*/
|
|
|
|
|
2010-09-21 19:14:55 +02:00
|
|
|
static FcCharSet *
|
2006-09-01 10:49:47 +02:00
|
|
|
scan (FILE *f, char *file, FcCharSetFreezer *freezer)
|
2002-07-07 01:21:37 +02:00
|
|
|
{
|
2006-09-01 10:49:47 +02:00
|
|
|
FcCharSet *c = 0;
|
2009-03-19 00:28:52 +01:00
|
|
|
FcCharSet *n;
|
2010-09-21 19:14:55 +02:00
|
|
|
FcBool del;
|
2006-09-01 10:49:47 +02:00
|
|
|
int start, end, ucs4;
|
2010-09-21 19:14:55 +02:00
|
|
|
char buf[1024];
|
|
|
|
char *line;
|
2006-09-01 10:49:47 +02:00
|
|
|
int lineno = 0;
|
2002-07-07 01:21:37 +02:00
|
|
|
|
2010-09-21 19:14:55 +02:00
|
|
|
while ((line = get_line (f, buf, &lineno)))
|
2002-07-07 01:21:37 +02:00
|
|
|
{
|
|
|
|
if (!strncmp (line, "include", 7))
|
|
|
|
{
|
2009-03-02 10:55:37 +01:00
|
|
|
FILE *included_f;
|
|
|
|
char *included_file;
|
|
|
|
included_file = strchr (line, ' ');
|
|
|
|
if (!included_file)
|
|
|
|
fatal (file, lineno,
|
2006-04-11 16:20:59 +02:00
|
|
|
"invalid syntax, expected: include filename");
|
2009-03-02 10:55:37 +01:00
|
|
|
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;
|
2002-07-07 01:21:37 +02:00
|
|
|
}
|
2010-09-21 19:14:55 +02:00
|
|
|
del = FcFalse;
|
|
|
|
if (line[0] == '-')
|
|
|
|
{
|
|
|
|
del = FcTrue;
|
|
|
|
line++;
|
|
|
|
}
|
2002-07-07 01:21:37 +02:00
|
|
|
if (strchr (line, '-'))
|
|
|
|
{
|
|
|
|
if (sscanf (line, "%x-%x", &start, &end) != 2)
|
|
|
|
fatal (file, lineno, "parse error");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (sscanf (line, "%x", &start) != 1)
|
|
|
|
fatal (file, lineno, "parse error");
|
|
|
|
end = start;
|
|
|
|
}
|
|
|
|
if (!c)
|
|
|
|
c = FcCharSetCreate ();
|
|
|
|
for (ucs4 = start; ucs4 <= end; ucs4++)
|
|
|
|
{
|
2010-09-21 19:14:55 +02:00
|
|
|
if (!((del ? FcCharSetDelChar : FcCharSetAddChar) (c, ucs4)))
|
2002-07-07 01:21:37 +02:00
|
|
|
fatal (file, lineno, "out of memory");
|
|
|
|
}
|
|
|
|
}
|
2011-03-14 22:58:13 +01:00
|
|
|
n = (FcCharSet *) FcCharSetFreeze (freezer, c);
|
2002-07-07 01:21:37 +02:00
|
|
|
FcCharSetDestroy (c);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a file name into a name suitable for C declarations
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
get_name (char *file)
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
char *dot;
|
|
|
|
|
|
|
|
dot = strchr (file, '.');
|
|
|
|
if (!dot)
|
|
|
|
dot = file + strlen(file);
|
|
|
|
name = malloc (dot - file + 1);
|
|
|
|
strncpy (name, file, dot - file);
|
|
|
|
name[dot-file] = '\0';
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a C name into a language name
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
get_lang (char *name)
|
|
|
|
{
|
|
|
|
char *lang = malloc (strlen (name) + 1);
|
|
|
|
char *l = lang;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
while ((c = *name++))
|
|
|
|
{
|
2003-04-17 17:47:34 +02:00
|
|
|
if (isupper ((int) (unsigned char) c))
|
|
|
|
c = tolower ((int) (unsigned char) c);
|
2002-07-07 01:21:37 +02:00
|
|
|
if (c == '_')
|
|
|
|
c = '-';
|
|
|
|
if (c == ' ')
|
|
|
|
continue;
|
|
|
|
*l++ = c;
|
|
|
|
}
|
|
|
|
*l++ = '\0';
|
|
|
|
return lang;
|
|
|
|
}
|
|
|
|
|
2009-03-19 00:28:52 +01:00
|
|
|
typedef struct _Entry {
|
|
|
|
int id;
|
|
|
|
char *file;
|
|
|
|
} Entry;
|
|
|
|
|
2002-08-22 09:36:45 +02:00
|
|
|
static int compare (const void *a, const void *b)
|
|
|
|
{
|
2010-09-21 19:14:55 +02:00
|
|
|
const Entry *as = a, *bs = b;
|
|
|
|
return FcStrCmpIgnoreCase ((const FcChar8 *) as->file, (const FcChar8 *) bs->file);
|
2002-08-22 09:36:45 +02:00
|
|
|
}
|
|
|
|
|
2002-12-14 03:03:59 +01:00
|
|
|
#define MAX_LANG 1024
|
|
|
|
#define MAX_LANG_SET_MAP ((MAX_LANG + 31) / 32)
|
|
|
|
|
2009-03-19 00:28:52 +01:00
|
|
|
#define BitSet(map, i) ((map)[(entries[i].id)>>5] |= ((FcChar32) 1 << ((entries[i].id) & 0x1f)))
|
2002-12-14 03:03:59 +01:00
|
|
|
|
2002-07-07 01:21:37 +02:00
|
|
|
int
|
2013-01-03 03:08:40 +01:00
|
|
|
main (int argc FC_UNUSED, char **argv)
|
2002-07-07 01:21:37 +02:00
|
|
|
{
|
2013-11-02 18:23:55 +01:00
|
|
|
static Entry entries[MAX_LANG + 1];
|
2010-09-21 19:14:55 +02:00
|
|
|
static FcCharSet *sets[MAX_LANG];
|
2006-02-22 05:09:39 +01:00
|
|
|
static int duplicate[MAX_LANG];
|
|
|
|
static int country[MAX_LANG];
|
|
|
|
static char *names[MAX_LANG];
|
|
|
|
static char *langs[MAX_LANG];
|
2006-08-30 13:16:22 +02:00
|
|
|
static int off[MAX_LANG];
|
2002-07-07 01:21:37 +02:00
|
|
|
FILE *f;
|
2002-12-14 03:03:59 +01:00
|
|
|
int ncountry = 0;
|
2002-07-07 01:21:37 +02:00
|
|
|
int i = 0;
|
2006-08-30 13:16:22 +02:00
|
|
|
int nsets = 0;
|
2005-09-23 01:45:53 +02:00
|
|
|
int argi;
|
2005-06-28 05:41:02 +02:00
|
|
|
FcCharLeaf **leaves;
|
2002-07-07 01:21:37 +02:00
|
|
|
int total_leaves = 0;
|
2006-08-30 13:16:22 +02:00
|
|
|
int l, sl, tl, tn;
|
2006-02-22 05:09:39 +01:00
|
|
|
static char line[1024];
|
|
|
|
static FcChar32 map[MAX_LANG_SET_MAP];
|
2002-12-14 03:03:59 +01:00
|
|
|
int num_lang_set_map;
|
2003-03-05 06:48:53 +01:00
|
|
|
int setRangeStart[26];
|
|
|
|
int setRangeEnd[26];
|
|
|
|
FcChar8 setRangeChar;
|
2006-09-01 10:49:47 +02:00
|
|
|
FcCharSetFreezer *freezer;
|
2002-07-07 01:21:37 +02:00
|
|
|
|
2006-09-01 10:49:47 +02:00
|
|
|
freezer = FcCharSetFreezerCreate ();
|
|
|
|
if (!freezer)
|
|
|
|
fatal (argv[0], 0, "out of memory");
|
2005-09-23 01:45:53 +02:00
|
|
|
argi = 1;
|
|
|
|
while (argv[argi])
|
2002-12-14 03:03:59 +01:00
|
|
|
{
|
2005-09-23 01:45:53 +02:00
|
|
|
if (!strcmp (argv[argi], "-d"))
|
2003-10-27 07:30:29 +01:00
|
|
|
{
|
2005-09-23 01:45:53 +02:00
|
|
|
argi++;
|
|
|
|
dir = argv[argi++];
|
2003-10-27 07:30:29 +01:00
|
|
|
continue;
|
|
|
|
}
|
2002-12-14 03:03:59 +01:00
|
|
|
if (i == MAX_LANG)
|
2005-09-23 01:45:53 +02:00
|
|
|
fatal (argv[0], 0, "Too many languages");
|
2009-03-19 00:28:52 +01:00
|
|
|
entries[i].id = i;
|
|
|
|
entries[i].file = argv[argi++];
|
|
|
|
i++;
|
2002-12-14 03:03:59 +01:00
|
|
|
}
|
2009-03-19 00:28:52 +01:00
|
|
|
entries[i].file = 0;
|
|
|
|
qsort (entries, i, sizeof (Entry), compare);
|
2002-08-22 09:36:45 +02:00
|
|
|
i = 0;
|
2009-03-19 00:28:52 +01:00
|
|
|
while (entries[i].file)
|
2002-07-07 01:21:37 +02:00
|
|
|
{
|
2009-03-19 00:28:52 +01:00
|
|
|
f = scanopen (entries[i].file);
|
2002-07-07 01:21:37 +02:00
|
|
|
if (!f)
|
2009-03-19 00:28:52 +01:00
|
|
|
fatal (entries[i].file, 0, strerror (errno));
|
|
|
|
sets[i] = scan (f, entries[i].file, freezer);
|
|
|
|
names[i] = get_name (entries[i].file);
|
2002-12-14 03:03:59 +01:00
|
|
|
langs[i] = get_lang(names[i]);
|
|
|
|
if (strchr (langs[i], '-'))
|
|
|
|
country[ncountry++] = i;
|
|
|
|
|
2002-07-07 01:21:37 +02:00
|
|
|
total_leaves += sets[i]->num;
|
|
|
|
i++;
|
|
|
|
fclose (f);
|
|
|
|
}
|
2006-08-30 13:16:22 +02:00
|
|
|
nsets = i;
|
2002-07-07 01:21:37 +02:00
|
|
|
sets[i] = 0;
|
|
|
|
leaves = malloc (total_leaves * sizeof (FcCharLeaf *));
|
|
|
|
tl = 0;
|
|
|
|
/*
|
|
|
|
* Find unique leaves
|
|
|
|
*/
|
|
|
|
for (i = 0; sets[i]; i++)
|
|
|
|
{
|
|
|
|
for (sl = 0; sl < sets[i]->num; sl++)
|
|
|
|
{
|
|
|
|
for (l = 0; l < tl; l++)
|
2006-08-30 13:16:22 +02:00
|
|
|
if (leaves[l] == FcCharSetLeaf(sets[i], sl))
|
2002-07-07 01:21:37 +02:00
|
|
|
break;
|
|
|
|
if (l == tl)
|
2006-08-30 13:16:22 +02:00
|
|
|
leaves[tl++] = FcCharSetLeaf(sets[i], sl);
|
2002-07-07 01:21:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan the input until the marker is found
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (fgets (line, sizeof (line), stdin))
|
|
|
|
{
|
|
|
|
if (!strncmp (line, "@@@", 3))
|
|
|
|
break;
|
|
|
|
fputs (line, stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf ("/* total size: %d unique leaves: %d */\n\n",
|
|
|
|
total_leaves, tl);
|
2002-07-07 21:18:51 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find duplicate charsets
|
|
|
|
*/
|
|
|
|
duplicate[0] = -1;
|
|
|
|
for (i = 1; sets[i]; i++)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
|
|
|
duplicate[i] = -1;
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
if (sets[j] == sets[i])
|
|
|
|
{
|
|
|
|
duplicate[i] = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
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);
|
2010-06-03 04:38:19 +02:00
|
|
|
printf ("#define NUM0 (OFF0 + %d * sizeof (uintptr_t))\n", tn);
|
2006-08-30 13:16:22 +02:00
|
|
|
printf ("#define SET(n) (n * sizeof (FcLangCharSet) + offsetof (FcLangCharSet, charset))\n");
|
2010-06-03 04:38:19 +02:00
|
|
|
printf ("#define OFF(s,o) (OFF0 + o * sizeof (uintptr_t) - SET(s))\n");
|
2006-08-30 13:16:22 +02:00
|
|
|
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");
|
2009-03-19 00:28:52 +01:00
|
|
|
printf ("#define fcLangCharSetIndices (fcLangData.langIndices)\n");
|
2009-08-26 02:39:20 +02:00
|
|
|
printf ("#define fcLangCharSetIndicesInv (fcLangData.langIndicesInv)\n");
|
2006-08-30 13:16:22 +02:00
|
|
|
printf ("\n");
|
|
|
|
|
|
|
|
printf ("static const struct {\n"
|
|
|
|
" FcLangCharSet langCharSets[%d];\n"
|
|
|
|
" FcCharLeaf leaves[%d];\n"
|
2010-06-03 04:38:19 +02:00
|
|
|
" uintptr_t leaf_offsets[%d];\n"
|
2006-08-30 13:16:22 +02:00
|
|
|
" FcChar16 numbers[%d];\n"
|
2009-03-19 00:28:52 +01:00
|
|
|
" FcChar%s langIndices[%d];\n"
|
2009-08-26 02:39:20 +02:00
|
|
|
" FcChar%s langIndicesInv[%d];\n"
|
2006-08-30 13:16:22 +02:00
|
|
|
"} fcLangData = {\n",
|
2009-03-19 00:28:52 +01:00
|
|
|
nsets, tl, tn, tn,
|
2009-08-26 02:39:20 +02:00
|
|
|
nsets < 256 ? "8 " : "16", nsets, nsets < 256 ? "8 " : "16", nsets);
|
2006-08-30 13:16:22 +02:00
|
|
|
|
2003-03-05 06:48:53 +01:00
|
|
|
/*
|
2006-08-30 13:16:22 +02:00
|
|
|
* Dump sets
|
2003-03-05 06:48:53 +01:00
|
|
|
*/
|
2006-08-30 13:16:22 +02:00
|
|
|
|
|
|
|
printf ("{\n");
|
2003-03-05 06:48:53 +01:00
|
|
|
for (i = 0; sets[i]; i++)
|
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
int j = duplicate[i];
|
|
|
|
|
|
|
|
if (j < 0)
|
|
|
|
j = i;
|
|
|
|
|
2007-10-18 17:58:14 +02:00
|
|
|
printf (" { \"%s\", "
|
2006-08-30 13:16:22 +02:00
|
|
|
" { FC_REF_CONSTANT, %d, OFF(%d,%d), NUM(%d,%d) } }, /* %d */\n",
|
|
|
|
langs[i],
|
|
|
|
sets[j]->num, i, off[j], i, off[j], i);
|
2003-03-05 06:48:53 +01:00
|
|
|
}
|
2006-08-30 13:16:22 +02:00
|
|
|
printf ("},\n");
|
2003-03-05 06:48:53 +01:00
|
|
|
|
2002-07-07 01:21:37 +02:00
|
|
|
/*
|
2006-08-30 13:16:22 +02:00
|
|
|
* Dump leaves
|
2002-07-07 01:21:37 +02:00
|
|
|
*/
|
2006-08-30 13:16:22 +02:00
|
|
|
printf ("{\n");
|
|
|
|
for (l = 0; l < tl; l++)
|
2002-07-07 01:21:37 +02:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
printf (" { { /* %d */", l);
|
|
|
|
for (i = 0; i < 256/32; i++)
|
2005-11-04 20:31:26 +01:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
if (i % 4 == 0)
|
|
|
|
printf ("\n ");
|
|
|
|
printf (" 0x%08x,", leaves[l]->map[i]);
|
2005-11-04 20:31:26 +01:00
|
|
|
}
|
2006-08-30 13:16:22 +02:00
|
|
|
printf ("\n } },\n");
|
2005-11-04 20:31:26 +01:00
|
|
|
}
|
2006-08-30 13:16:22 +02:00
|
|
|
printf ("},\n");
|
2005-11-04 20:31:26 +01:00
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
/*
|
|
|
|
* Dump leaves
|
|
|
|
*/
|
|
|
|
printf ("{\n");
|
2005-11-04 20:31:26 +01:00
|
|
|
for (i = 0; sets[i]; i++)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (duplicate[i] >= 0)
|
|
|
|
continue;
|
2006-08-30 13:16:22 +02:00
|
|
|
printf (" /* %s */\n", names[i]);
|
2002-07-07 01:21:37 +02:00
|
|
|
for (n = 0; n < sets[i]->num; n++)
|
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
if (n % 4 == 0)
|
2002-07-07 01:21:37 +02:00
|
|
|
printf (" ");
|
|
|
|
for (l = 0; l < tl; l++)
|
2006-08-30 13:16:22 +02:00
|
|
|
if (leaves[l] == FcCharSetLeaf(sets[i], n))
|
2002-07-07 01:21:37 +02:00
|
|
|
break;
|
|
|
|
if (l == tl)
|
|
|
|
fatal (names[i], 0, "can't find leaf");
|
2006-08-30 13:16:22 +02:00
|
|
|
printf (" LEAF(%3d,%3d),", off[i], l);
|
|
|
|
if (n % 4 == 3)
|
2002-07-07 01:21:37 +02:00
|
|
|
printf ("\n");
|
|
|
|
}
|
2006-08-30 13:16:22 +02:00
|
|
|
if (n % 4 != 0)
|
2002-07-07 01:21:37 +02:00
|
|
|
printf ("\n");
|
2005-11-04 20:31:26 +01:00
|
|
|
}
|
2006-08-30 13:16:22 +02:00
|
|
|
printf ("},\n");
|
|
|
|
|
2005-11-04 20:31:26 +01:00
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
printf ("{\n");
|
2005-11-04 20:31:26 +01:00
|
|
|
for (i = 0; sets[i]; i++)
|
|
|
|
{
|
|
|
|
int n;
|
2006-08-30 13:16:22 +02:00
|
|
|
|
2005-11-19 17:24:53 +01:00
|
|
|
if (duplicate[i] >= 0)
|
|
|
|
continue;
|
2006-08-30 13:16:22 +02:00
|
|
|
printf (" /* %s */\n", names[i]);
|
2002-07-07 01:21:37 +02:00
|
|
|
for (n = 0; n < sets[i]->num; n++)
|
|
|
|
{
|
|
|
|
if (n % 8 == 0)
|
|
|
|
printf (" ");
|
2006-08-30 13:16:22 +02:00
|
|
|
printf (" 0x%04x,", FcCharSetNumbers (sets[i])[n]);
|
2002-07-07 01:21:37 +02:00
|
|
|
if (n % 8 == 7)
|
|
|
|
printf ("\n");
|
|
|
|
}
|
|
|
|
if (n % 8 != 0)
|
|
|
|
printf ("\n");
|
|
|
|
}
|
2009-03-19 00:28:52 +01:00
|
|
|
printf ("},\n");
|
|
|
|
|
2009-08-26 02:39:20 +02:00
|
|
|
/* langIndices */
|
2009-03-19 00:28:52 +01:00
|
|
|
printf ("{\n");
|
|
|
|
for (i = 0; sets[i]; i++)
|
|
|
|
{
|
|
|
|
printf (" %d, /* %s */\n", entries[i].id, names[i]);
|
|
|
|
}
|
2009-08-26 02:39:20 +02:00
|
|
|
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]]);
|
|
|
|
}
|
2006-08-30 13:16:22 +02:00
|
|
|
printf ("}\n");
|
2009-08-26 02:39:20 +02:00
|
|
|
|
2002-07-07 01:21:37 +02:00
|
|
|
printf ("};\n\n");
|
2009-08-26 02:39:20 +02:00
|
|
|
|
2002-12-14 03:03:59 +01:00
|
|
|
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);
|
|
|
|
/*
|
|
|
|
* Dump indices with country codes
|
|
|
|
*/
|
|
|
|
if (ncountry)
|
|
|
|
{
|
2006-04-06 06:33:11 +02:00
|
|
|
int c;
|
2002-12-14 03:03:59 +01:00
|
|
|
int ncountry_ent = 0;
|
|
|
|
printf ("\n");
|
|
|
|
printf ("static const FcChar32 fcLangCountrySets[][NUM_LANG_SET_MAP] = {\n");
|
|
|
|
for (c = 0; c < ncountry; c++)
|
|
|
|
{
|
|
|
|
i = country[c];
|
|
|
|
if (i >= 0)
|
|
|
|
{
|
2006-04-06 06:33:11 +02:00
|
|
|
int lang = strchr (langs[i], '-') - langs[i];
|
2002-12-14 03:03:59 +01:00
|
|
|
int d, k;
|
|
|
|
|
|
|
|
for (k = 0; k < num_lang_set_map; k++)
|
|
|
|
map[k] = 0;
|
|
|
|
|
|
|
|
BitSet (map, i);
|
|
|
|
for (d = c + 1; d < ncountry; d++)
|
|
|
|
{
|
|
|
|
int j = country[d];
|
2009-03-18 23:43:09 +01:00
|
|
|
if (j >= 0 && !strncmp (langs[j], langs[i], lang + 1))
|
2002-12-14 03:03:59 +01:00
|
|
|
{
|
|
|
|
BitSet(map, j);
|
|
|
|
country[d] = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf (" {");
|
|
|
|
for (k = 0; k < num_lang_set_map; k++)
|
|
|
|
printf (" 0x%08x,", map[k]);
|
|
|
|
printf (" }, /* %*.*s */\n",
|
2006-04-06 06:33:11 +02:00
|
|
|
lang, lang, langs[i]);
|
2002-12-14 03:03:59 +01:00
|
|
|
++ncountry_ent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf ("};\n\n");
|
|
|
|
printf ("#define NUM_COUNTRY_SET %d\n", ncountry_ent);
|
|
|
|
}
|
|
|
|
|
2003-03-05 06:48:53 +01:00
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
2017-06-06 11:10:18 +02:00
|
|
|
while (setRangeChar <= 'z') /* no language code starts with these letters */
|
|
|
|
setRangeStart[setRangeChar++ - 'a'] = i;
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
for (setRangeChar = 'a'; setRangeChar < 'z'; setRangeChar++)
|
|
|
|
setRangeEnd[setRangeChar - 'a'] = setRangeStart[setRangeChar+1-'a'] - 1;
|
|
|
|
setRangeEnd[setRangeChar - 'a'] = i - 1;
|
|
|
|
|
2003-03-05 06:48:53 +01:00
|
|
|
/*
|
|
|
|
* Dump sets start/finish for the fastpath
|
|
|
|
*/
|
2009-03-19 00:28:52 +01:00
|
|
|
printf ("\n");
|
2003-03-05 06:48:53 +01:00
|
|
|
printf ("static const FcLangCharSetRange fcLangCharSetRanges[] = {\n");
|
2009-03-19 00:28:52 +01:00
|
|
|
printf ("\n");
|
2003-03-05 06:48:53 +01:00
|
|
|
for (setRangeChar = 'a'; setRangeChar <= 'z' ; setRangeChar++)
|
|
|
|
{
|
|
|
|
printf (" { %d, %d }, /* %c */\n",
|
|
|
|
setRangeStart[setRangeChar - 'a'],
|
|
|
|
setRangeEnd[setRangeChar - 'a'], setRangeChar);
|
|
|
|
}
|
|
|
|
printf ("};\n\n");
|
|
|
|
|
2002-07-07 01:21:37 +02:00
|
|
|
while (fgets (line, sizeof (line), stdin))
|
|
|
|
fputs (line, stdout);
|
|
|
|
|
|
|
|
fflush (stdout);
|
|
|
|
exit (ferror (stdout));
|
|
|
|
}
|