]> git.wh0rd.org - fontconfig.git/blobdiff - fc-lang/fc-lang.c
[fc-lang] Fix bug in country map generation
[fontconfig.git] / fc-lang / fc-lang.c
index 631411d1bb2d7f3bb0c41fa4b9289ab86c632d63..b0f1690e880533fc1823989148f2e9d3a0b1e500 100644 (file)
@@ -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
  *
  * 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
@@ -47,6 +47,18 @@ FcMemFree (int kind, int size)
 {
 }
 
+FcPrivate void
+FcCacheObjectReference (void *object)
+{
+}
+
+FcPrivate void
+FcCacheObjectDereference (void *object)
+{
+}
+
+int FcDebugVal;
+
 FcChar8 *
 FcConfigHome (void)
 {
@@ -113,31 +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;
+    const 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, ' ');
-            if (!file)
-                fatal (line, lineno, 
+           FILE *included_f;
+           char *included_file;
+           included_file = strchr (line, ' ');
+            if (!included_file)
+                fatal (file, lineno,
                        "invalid syntax, expected: include filename");
-           while (isspace(*file))
-               file++;
-           f = scanopen (file);
-           if (!f)
-               fatal (file, 0, "can't open");
-           c = scan (f, file);
-           fclose (f);
-           return c;
+           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, '-'))
        {
@@ -158,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;
 }
@@ -221,7 +240,7 @@ int
 main (int argc, char **argv)
 {
     static char                *files[MAX_LANG];
-    static FcCharSet   *sets[MAX_LANG];
+    static const FcCharSet     *sets[MAX_LANG];
     static int         duplicate[MAX_LANG];
     static int         country[MAX_LANG];
     static char                *names[MAX_LANG];
@@ -241,7 +260,11 @@ main (int argc, char **argv)
     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])
     {
@@ -263,7 +286,7 @@ main (int argc, char **argv)
        f = scanopen (files[i]);
        if (!f)
            fatal (files[i], 0, strerror (errno));
-       sets[i] = scan (f, files[i]);
+       sets[i] = scan (f, files[i], freezer);
        names[i] = get_name (files[i]);
        langs[i] = get_lang(names[i]);
        if (strchr (langs[i], '-'))
@@ -361,7 +384,7 @@ main (int argc, char **argv)
        if (j < 0)
            j = i;
 
-       printf ("    { (FcChar8 *) \"%s\", "
+       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);
@@ -465,7 +488,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;