You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA. */
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
#include <config.h>
-#include <assert.h>
+#include "font.h"
+#include "error.h"
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include "alloc.h"
#include "error.h"
#include "filename.h"
-#include "font.h"
+#include "getline.h"
#include "hash.h"
#include "pool.h"
#include "str.h"
#include "version.h"
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
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,
/* Typical whitespace characters for tokenizing. */
static const char whitespace[] = " \t\n\r\v";
-void
-groff_init (void)
-{
- space_index = font_char_name_to_index ("space");
-}
-
-/* Some notes on the groff_font(8) manpage:
+/* Some notes on the groff_font manpage:
DESC file format: A typical PostScript `res' would be 72000, with
`hor' and `vert' set to 1 to indicate that all those positions are
/* Reads a Groff font description file and converts it to a usable
binary format in memory. Installs the binary format in the global
- font table. See groff_font(8) for a description of the font
+ font table. See groff_font for a description of the font
description format supported. Returns nonzero on success. */
struct font_desc *
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;
/* Current location in file, used for error reporting. */
struct file_locator where;
-#if unix
+#ifdef unix
fn = fn_tilde_expand (fn);
#endif
goto file_lossage;
}
free (line);
-#if unix
+#ifdef unix
free ((char *) fn);
#endif
if (f != NULL)
fclose (f);
pool_destroy (font_pool);
-#if unix
+#ifdef unix
free ((char *) fn);
#endif
err_pop_file_locator (&where);
static int
font_msg (int class, const char *format,...)
{
+ struct error error;
va_list args;
+ error.class = class;
+ err_location (&error.where);
+ error.title = _("installation error: Groff font error: ");
+
va_start (args, format);
- tmsg (class, format, args, _("installation error: Groff font error: "));
+ err_vmsg (&error, format, args);
va_end (args);
return 0;
static void
scan_badchars (char *line, int len)
{
- unsigned char *cp = line;
+ char *cp = line;
/* Same bad characters as Groff. */
static unsigned char badchars[32] =
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
- for (; len--; cp++)
- if (badchars[*cp >> 3] & (1 << (*cp & 7)))
- {
- font_msg (SE, _("Bad character \\%3o."), *cp);
- *cp = ' ';
- }
+ for (; len--; cp++)
+ {
+ int c = (unsigned char) *cp;
+ if (badchars[c >> 3] & (1 << (c & 7)))
+ {
+ font_msg (SE, _("Bad character \\%3o."), *cp);
+ *cp = ' ';
+ }
+ }
}
\f
/* Character name hashing. */
}
hash;
+void
+groff_init (void)
+{
+ space_index = font_char_name_to_index ("space");
+}
+
+void
+groff_done (void)
+{
+ free (hash.tab) ;
+ pool_destroy(hash.ar);
+}
+
+
/* Searches for NAME in the global character code table, returns the
index if found; otherwise inserts NAME and returns the new
index. */
hash.size = 128;
hash.used = 0;
hash.next_index = 256;
- hash.tab = xmalloc (sizeof *hash.tab * hash.size);
+ hash.tab = xnmalloc (hash.size, sizeof *hash.tab);
hash.ar = pool_create ();
for (i = 0; i < hash.size; i++)
hash.tab[i].name = NULL;
int i, j;
hash.size *= 2;
- hash.tab = xmalloc (sizeof *hash.tab * hash.size);
+ hash.tab = xnmalloc (hash.size, sizeof *hash.tab);
for (i = 0; i < hash.size; i++)
hash.tab[i].name = NULL;
for (i = 0; i < old_size; i++)
font->deref_size = min_size + 16;
if (font->deref_size < 256)
font->deref_size = 256;
- font->deref = pool_realloc (font->owner, font->deref,
- sizeof *font->deref * font->deref_size);
+ font->deref = pool_nrealloc (font->owner, font->deref,
+ font->deref_size, sizeof *font->deref);
for (; i < font->deref_size; i++)
font->deref[i] = -1;
}
if (font->metric_used >= font->metric_size)
{
font->metric_size += 64;
- font->metric = pool_realloc (font->owner, font->metric,
- sizeof *font->metric * font->metric_size);
+ font->metric = pool_nrealloc (font->owner, font->metric,
+ font->metric_size, sizeof *font->metric);
}
font->metric[font->metric_used] = metrics;
font->deref[code] = font->metric_used++;
font->kern_size *= 2;
font->kern_max_used = font->kern_size / 2;
- font->kern = pool_malloc (font->owner,
- sizeof *font->kern * font->kern_size);
+ font->kern = pool_nmalloc (font->owner,
+ font->kern_size, sizeof *font->kern);
for (i = 0; i < font->kern_size; i++)
font->kern[i].ch1 = -1;
- 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];
- }
if (old_kern)
- pool_free (font->owner, 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;
if (dev->n_sizes + 2 >= m_sizes)
{
m_sizes += 1;
- dev->sizes = xrealloc (dev->sizes,
- m_sizes * sizeof *dev->sizes);
+ dev->sizes = xnrealloc (dev->sizes,
+ m_sizes, sizeof *dev->sizes);
}
dev->sizes[dev->n_sizes++][0] = lower;
dev->sizes[dev->n_sizes][1] = upper;
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;