X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgroff-font.c;h=9427089d3009f330e1e5997a6c59aab56583862e;hb=c434e369b6695f8135a2914e9a425edcdd09ef35;hp=d645b278433d52ad3a8b000eb0d30828ade274f4;hpb=d5d5ea4d068d9272c665358ed84a6297d5dec226;p=pspp diff --git a/src/groff-font.c b/src/groff-font.c index d645b27843..9427089d30 100644 --- a/src/groff-font.c +++ b/src/groff-font.c @@ -14,11 +14,12 @@ 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 -#include +#include "font.h" +#include "error.h" #include #include #include @@ -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, @@ -48,13 +48,7 @@ static void add_kern (struct font_desc * font, int ch1, int ch2, int adjust); /* 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 @@ -68,7 +62,7 @@ groff_init (void) /* 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) @@ -92,7 +86,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 +94,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 +349,7 @@ groff_read_font (const char *fn) goto file_lossage; } free (line); -#if unix +#ifdef unix free ((char *) fn); #endif @@ -381,7 +375,7 @@ lose: if (f != NULL) fclose (f); pool_destroy (font_pool); -#if unix +#ifdef unix free ((char *) fn); #endif err_pop_file_locator (&where); @@ -447,6 +441,20 @@ static struct } 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. */ @@ -600,23 +608,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 +972,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;