Changed the definition of factors to be self referential.
[pspp-builds.git] / src / groff-font.c
index d645b278433d52ad3a8b000eb0d30828ade274f4..331da33d38dbd07ec4239f35e2a07b05cadc066a 100644 (file)
@@ -18,7 +18,8 @@
    02111-1307, USA. */
 
 #include <config.h>
-#include <assert.h>
+#include "font.h"
+#include "error.h"
 #include <stdio.h>
 #include <errno.h>
 #include <stdlib.h>
@@ -27,7 +28,6 @@
 #include "alloc.h"
 #include "error.h"
 #include "filename.h"
-#include "font.h"
 #include "hash.h"
 #include "pool.h"
 #include "str.h"
@@ -38,7 +38,7 @@ int font_number_to_index (int);
 int space_index;
 
 static int font_msg (int, const char *,...)
-     __attribute__ ((format (printf, 2, 3)));
+     PRINTF_FORMAT (2, 3);
 static void scan_badchars (char *, int);
 static void dup_char_metric (struct font_desc * font, int dest, int src);
 static void add_char_metric (struct font_desc * font, struct char_metrics *metrics,
@@ -92,7 +92,7 @@ groff_read_font (const char *fn)
   char *key;
 
   /* 0=kernpairs section, 1=charset section. */
-  int charset;
+  int charset = 0;
 
   /* Index for previous line. */
   int prev_index = -1;
@@ -100,7 +100,7 @@ groff_read_font (const char *fn)
   /* Current location in file, used for error reporting. */
   struct file_locator where;
 
-#if unix
+#ifdef unix
   fn = fn_tilde_expand (fn);
 #endif
 
@@ -355,7 +355,7 @@ groff_read_font (const char *fn)
       goto file_lossage;
     }
   free (line);
-#if unix
+#ifdef unix
   free ((char *) fn);
 #endif
 
@@ -381,7 +381,7 @@ lose:
   if (f != NULL)
     fclose (f);
   pool_destroy (font_pool);
-#if unix
+#ifdef unix
   free ((char *) fn);
 #endif
   err_pop_file_locator (&where);
@@ -600,23 +600,26 @@ add_kern (struct font_desc *font, int ch1, int ch2, int adjust)
       for (i = 0; i < font->kern_size; i++)
        font->kern[i].ch1 = -1;
 
-      if (old_kern) {
-       for (i = 0; i < old_kern_size; i++)
-         {
-           if (old_kern[i].ch1 == -1)
-             continue;
-
-           j = hash_kern (old_kern[i].ch1, old_kern[i].ch2) % font->kern_size;
-           while (font->kern[j].ch1 != -1)
-             if (0 == j--)
-               j = font->kern_size - 1;
-           font->kern[j] = old_kern[i];
-         }
-       pool_free (font->owner, old_kern);
-      }
+      if (old_kern)
+        {
+          for (i = 0; i < old_kern_size; i++)
+            {
+              if (old_kern[i].ch1 == -1)
+                continue;
+
+              j = (hash_kern (old_kern[i].ch1, old_kern[i].ch2)
+                   & (font->kern_size - 1));
+              while (font->kern[j].ch1 != -1)
+                if (0 == j--)
+                  j = font->kern_size - 1;
+              font->kern[j] = old_kern[i];
+            }
+          pool_free (font->owner, old_kern);
+        }
     }
 
-  for (i = hash_kern (ch1, ch2) % font->kern_size; font->kern[i].ch1 != -1;)
+  for (i = hash_kern (ch1, ch2) & (font->kern_size - 1);
+       font->kern[i].ch1 != -1; )
     if (0 == i--)
       i = font->kern_size - 1;
   font->kern[i].ch1 = ch1;
@@ -961,7 +964,8 @@ font_get_kern_adjust (const struct font_desc *font, int ch1, int ch2)
 
   if (!font->kern)
     return 0;
-  for (i = hash_kern (ch1, ch2) % font->kern_size; font->kern[i].ch1 != -1;)
+  for (i = hash_kern (ch1, ch2) & (font->kern_size - 1);
+       font->kern[i].ch1 != -1;)
     {
       if (font->kern[i].ch1 == ch1 && font->kern[i].ch2 == ch2)
        return font->kern[i].adjust;