]> git.wh0rd.org - fontconfig.git/blobdiff - fc-glyphname/fc-glyphname.c
Cleanup copyright notices to replace "Keith Packard" with "the author(s)"
[fontconfig.git] / fc-glyphname / fc-glyphname.c
index 2c69c2b407dbbbf1785cabcd5e58cba4f71657d7..b790d986fe455532323130e32501bf1835e16dbc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id$
+ * fontconfig/fc-glyphname/fc-glyphname.c
  *
  * Copyright © 2003 Keith Packard
  *
@@ -7,15 +7,15 @@
  * 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.
  *
- * 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
@@ -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 *name)
 }
 
 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);
 }
 
@@ -69,15 +73,15 @@ fatal (char *file, int lineno, char *msg)
 #define MAX_GLYPHNAME      10240
 #define MAX_NAMELEN        1024
 
-FcGlyphName *raw[MAX_GLYPHNAME];
-int        nraw;
-int        max_name_len;
-FcGlyphName *name_to_ucs[MAX_GLYPHNAME*2];
-FcGlyphName *ucs_to_name[MAX_GLYPHNAME*2];
-int        hash, rehash;
+static FcGlyphName *raw[MAX_GLYPHNAME];
+static int         nraw;
+static int         max_name_len;
+static FcGlyphName *name_to_ucs[MAX_GLYPHNAME*2];
+static FcGlyphName *ucs_to_name[MAX_GLYPHNAME*2];
+static unsigned int hash, rehash;
 
 static int
-rawindex (FcGlyphName *gn)
+rawindex (const FcGlyphName *gn)
 {
     int        i;
 
@@ -202,7 +206,7 @@ insert (FcGlyphName *gn, FcGlyphName **table, FcChar32 h)
     i = (int) (h % hash);
     while (table[i])
     {
-       if (!r) r = (int) (h % rehash);
+       if (!r) r = (int) (h % rehash + 1);
        i += r;
        if (i >= hash)
            i -= hash;
@@ -211,17 +215,17 @@ insert (FcGlyphName *gn, FcGlyphName **table, FcChar32 h)
 }
 
 static void
-dump (FcGlyphName **table, char *name)
+dump (FcGlyphName * const *table, const char *name)
 {
-    int        i;
+    int            i;
     
-    printf ("static FcGlyphName        *%s[%d] = {\n", name, hash);
+    printf ("static const FcGlyphId %s[%d] = {\n", name, hash);
 
     for (i = 0; i < hash; i++)
        if (table[i])
-           printf ("(FcGlyphName *) &glyph%d,\n", rawindex(table[i]));
+           printf ("    %d,\n", rawindex(table[i]));
        else
-           printf ("0,\n");
+           printf ("    -1,\n");
     
     printf ("};\n");
 }
@@ -233,13 +237,15 @@ main (int argc, char **argv)
     char       line[1024];
     FILE       *f;
     int                i;
+    char       *type;
     
     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);
@@ -278,27 +284,38 @@ main (int argc, char **argv)
     printf ("#define FC_GLYPHNAME_HASH %u\n", hash);
     printf ("#define FC_GLYPHNAME_REHASH %u\n", rehash);
     printf ("#define FC_GLYPHNAME_MAXLEN %d\n\n", max_name_len);
+    if (nraw < 128)
+       type = "int8_t";
+    else if (nraw < 32768)
+       type = "int16_t";
+    else
+       type = "int32_t";
+    
+    printf ("typedef %s FcGlyphId;\n\n", type);
     
     /*
      * Dump out entries
      */
     
+    printf ("static const struct { const FcChar32 ucs; const FcChar8 name[%d]; } _fc_glyph_names[%d] = {\n",
+           max_name_len + 1, nraw);
+    
     for (i = 0; i < nraw; i++)
-       printf ("static struct { FcChar32 ucs; FcChar8 name[%d]; }"
-               " glyph%d = { 0x%lx, \"%s\" };\n",
-               (int) strlen ((char *) raw[i]->name) + 1,
-               i, (unsigned long) raw[i]->ucs, raw[i]->name);
+       printf ("    { 0x%lx, \"%s\" },\n",
+               (unsigned long) raw[i]->ucs, raw[i]->name);
+
+    printf ("};\n");
 
     /*
      * Dump out name_to_ucs table
      */
 
-    dump (name_to_ucs, "name_to_ucs");
+    dump (name_to_ucs, "_fc_name_to_ucs");
     
     /*
      * Dump out ucs_to_name table
      */
-    dump (ucs_to_name, "ucs_to_name");
+    dump (ucs_to_name, "_fc_ucs_to_name");
 
     while (fgets (line, sizeof (line), stdin))
        fputs (line, stdout);