]> git.donarmstrong.com Git - lilypond.git/commitdiff
* ttftool/util.c (surely_lseek): use stdio FILE's for I/O
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 12 Jun 2005 16:33:21 +0000 (16:33 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 12 Jun 2005 16:33:21 +0000 (16:33 +0000)
* ttftool/test.c: new file. If compiled with -DTEST_TTFTOOL,
create a ttf2ps binary.

ChangeLog
lily/main.cc
ttftool/include/proto.h
ttftool/parse.c
ttftool/ps.c
ttftool/test.c [new file with mode: 0644]
ttftool/ttfps.c
ttftool/util.c

index 7800f284b87d860a235118bd0ae3e216e2bf07f1..632d44d2f7bbaadf05878f19a4c1d809ba2b314a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2005-06-12  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
+       * ttftool/util.c (surely_lseek): use stdio FILE's for I/O 
+
+       * ttftool/test.c: new file. If compiled with -DTEST_TTFTOOL,
+       create a ttf2ps binary.
+
        * scm/ps-to-png.scm (make-ps-images): fix rename-page-1 functionality.
 
        * scm/backend-library.scm (postscript->png): set rename-page-1 to
index 6ebaae182639d11120cd152b78e6fa8b4a680bdb..02d399aefe66c5b80ed01d83b7361d9676f9fc02 100644 (file)
@@ -5,7 +5,7 @@
 
   (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
-
 #include "main.hh"
 
 #include <cassert>
index a01f1e0651b8efe366e14764be54d6e560ec922a..d879f947c8a75f1c93721031f3b2668855db9234 100644 (file)
@@ -1,24 +1,24 @@
 /* Copyright (c) 1997-1998 by Juliusz Chroboczek */
 
-struct TableDirectoryEntry *readDirectory (int fd, struct OffsetTable *ot);
-char **readNamingTable (int fd);
-void readHeadTable (int fd, struct HeadTable *ht);
-int readPostTable (int fd, int nglyphs,
+struct TableDirectoryEntry *readDirectory (FILE *fd, struct OffsetTable *ot);
+char **readNamingTable (FILE *fd);
+void readHeadTable (FILE *fd, struct HeadTable *ht);
+int readPostTable (FILE *fd, int nglyphs,
                   struct PostTable *pt, struct GlyphName **gnt);
-int readMaxpTable (int fd);
-void *readLocaTable (int fd, int nglyphs, int format);
-struct Box *readGlyfTable (int fd, int nglyphs, int format, void *loca);
-longHorMetric *readHmtxTable (int fd, int nummetrics);
-struct HheaTable *readHheaTable (int fd);
-int readKernTable (int fd, int **nke, struct KernEntry0 ***ke);
+int readMaxpTable (FILE *fd);
+void *readLocaTable (FILE *fd, int nglyphs, int format);
+struct Box *readGlyfTable (FILE *fd, int nglyphs, int format, void *loca);
+longHorMetric *readHmtxTable (FILE *fd, int nummetrics);
+struct HheaTable *readHheaTable (FILE *fd);
+int readKernTable (FILE *fd, int **nke, struct KernEntry0 ***ke);
 
 void printPSFont (void * out, struct HeadTable *ht,
                  char **strings, int nglyphs, int postType,
-                 struct PostTable *pt, struct GlyphName *gnt, int fd);
+                 struct PostTable *pt, struct GlyphName *gnt, FILE *fd);
 
 void printPSHeader (void * out, struct HeadTable *ht,
                    char **strings, struct PostTable *pt);
-void printPSData (void * out, int fd);
+void printPSData (void * out, FILE *fd);
 void printPSTrailer (void * out, int nglyphs,
                     int postType, struct GlyphName *gnt);
 
@@ -50,11 +50,19 @@ void *mycalloc (size_t nelem, size_t elsize);
 void *myrealloc (void *ptr, size_t size);
 void ttf_error (char *string);
 void syserror (char *string);
-ssize_t surely_read (int fildes, void *buf, size_t nbyte);
+ssize_t surely_read (FILE *fildes, void *buf, size_t nbyte);
 char *unistrncpy (char *dst, char *str, size_t length);
 void fputpss (char *s, void * stream);
-off_t surely_lseek (int fildes, off_t offset, int whence);
+void surely_lseek (FILE *fildes, off_t offset, int whence);
 unsigned hash (char *string);
 struct hashtable *make_hashtable (int size);
 int puthash (struct hashtable *t, char *key, int value);
 int gethash (struct hashtable *t, char *key);
+
+#ifdef TEST_TTFTOOL
+#define lily_cookie_fclose fclose
+#define lily_cookie_fprintf fprintf
+#define lily_cookie_putc fputc
+#else
+#include "file-cookie.hh"
+#endif
index 95a605ee434bfc5df3003a443f118b36d96433fc..d198475c4b82e49eec511bc20e092722987e7b0b 100644 (file)
@@ -11,7 +11,7 @@
 #include "ttftool.h"
 
 struct TableDirectoryEntry *
-readDirectory (int fd, struct OffsetTable *ot)
+readDirectory (FILE *fd, struct OffsetTable *ot)
 {
   unsigned n;
   int i;
@@ -32,7 +32,7 @@ readDirectory (int fd, struct OffsetTable *ot)
 }
 
 char **
-readNamingTable (int fd)
+readNamingTable (FILE *fd)
 {
   USHORT format;
   USHORT nrecords;
@@ -43,7 +43,7 @@ readNamingTable (int fd)
   char *data;
   char **strings;
 
-  position = surely_lseek (fd, 0, SEEK_CUR);
+  position = ftell (fd);
 
   surely_read (fd, &format, sizeof (USHORT));
   FIX_UH (format);
@@ -114,7 +114,7 @@ readNamingTable (int fd)
 }
 
 int
-readMaxpTable (int fd)
+readMaxpTable (FILE *fd)
 {
   struct
   {
@@ -131,7 +131,7 @@ readMaxpTable (int fd)
 }
 
 void
-readHeadTable (int fd, struct HeadTable *ht)
+readHeadTable (FILE *fd, struct HeadTable *ht)
 {
   surely_read (fd, ht, sizeof (struct HeadTable));
   FIX_HeadTable (*ht);
@@ -149,7 +149,7 @@ readHeadTable (int fd, struct HeadTable *ht)
 }
 
 int
-readPostTable (int fd, int nglyphs, struct PostTable *pt,
+readPostTable (FILE *fd, int nglyphs, struct PostTable *pt,
               struct GlyphName **gt)
 {
   USHORT nglyphspost;
@@ -226,7 +226,7 @@ readPostTable (int fd, int nglyphs, struct PostTable *pt,
  /*NOTREACHED*/}
 
 void *
-readLocaTable (int fd, int nglyphs, int format)
+readLocaTable (FILE *fd, int nglyphs, int format)
 {
   int i;
   switch (format)
@@ -255,13 +255,13 @@ readLocaTable (int fd, int nglyphs, int format)
  /*NOTREACHED*/}
 
 struct Box *
-readGlyfTable (int fd, int nglyphs, int format, void *loca)
+readGlyfTable (FILE *fd, int nglyphs, int format, void *loca)
 {
   int i;
   struct Box *bbox;
   off_t base, offset;
 
-  base = surely_lseek (fd, 0, SEEK_CUR);
+  base = ftell (fd);
 
   bbox = mymalloc (nglyphs * sizeof (struct Box));
   for (i = 0; i < nglyphs; i++)
@@ -278,7 +278,7 @@ readGlyfTable (int fd, int nglyphs, int format, void *loca)
 }
 
 longHorMetric *
-readHmtxTable (int fd, int nummetrics)
+readHmtxTable (FILE *fd, int nummetrics)
 {
   longHorMetric *metrics;
   int i;
@@ -293,7 +293,7 @@ readHmtxTable (int fd, int nummetrics)
 }
 
 struct HheaTable *
-readHheaTable (int fd)
+readHheaTable (FILE *fd)
 {
   struct HheaTable *hhea;
   hhea = mymalloc (sizeof (struct HheaTable));
@@ -308,7 +308,7 @@ readHheaTable (int fd)
 }
 
 int
-readKernTable (int fd, int **nkep, struct KernEntry0 ***kep)
+readKernTable (FILE *fd, int **nkep, struct KernEntry0 ***kep)
 {
   struct KernTable kt;
   struct KernSubTableHeader ksth;
index d672f3b5f7d3b557de4958e1c94d9dd07064cbd2..94104d7bdc9f24f6ca382243488ac8583bab8a7c 100644 (file)
@@ -25,7 +25,7 @@
 void
 printPSFont (void *out, struct HeadTable *ht,
             char **strings, int nglyphs, int postType,
-            struct PostTable *pt, struct GlyphName *gnt, int fd)
+            struct PostTable *pt, struct GlyphName *gnt, FILE *fd)
 {
   printPSHeader (out, ht, strings, pt);
   printPSData (out, fd);
@@ -81,7 +81,7 @@ printPSHeader (void *out, struct HeadTable *ht,
 }
 
 void
-printPSData (void *out, int fd)
+printPSData (void *out, FILE *fd)
 {
   static char xdigits[] = "0123456789ABCDEF";
 
@@ -95,7 +95,7 @@ printPSData (void *out, int fd)
   lily_cookie_fprintf (out, "/sfnts [");
   for (;;)
     {
-      i = read (fd, buffer, CHUNKSIZE);
+      i = fread (buffer, 1, CHUNKSIZE, fd);
       if (i == 0)
        break;
       lily_cookie_fprintf (out, "\n<");
diff --git a/ttftool/test.c b/ttftool/test.c
new file mode 100644 (file)
index 0000000..76c18f5
--- /dev/null
@@ -0,0 +1,24 @@
+#ifdef TEST_TTFTOOL
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+#include "ttftool.h"
+
+
+main (int argc, char **argv)
+{
+  FILE *in, *out;
+  if (argc != 3)
+    {
+      fprintf (stderr, "test foo.ttf bar.pfa");
+      exit (2);
+    }
+
+  out = fopen (argv[2], "w");
+  assert(out);
+  create_type42 (argv[1], (void*) out);
+}
+
+#endif
index 8931949574844399a1b148efe24dc907980d2c32..2be555f5f0a35966e6863d555ccbbf728f4825b8 100644 (file)
@@ -8,8 +8,7 @@
 #include "types.h"
 #include "proto.h"
 
-#include "file-cookie.hh"
+
 static void endianness_test (void);
 static void usage (char *);
 
@@ -18,7 +17,8 @@ int ttf_verbosity = 0;
 void
 create_type42 (const char *infile, void *out)
 {
-  int fd, i;
+  FILE *fd = 0;
+  int  i;
   struct OffsetTable ot;
   struct HeadTable *ht;
   struct PostTable *pt;
@@ -41,7 +41,7 @@ create_type42 (const char *infile, void *out)
 
   endianness_test ();
 
-  if ((fd = open (infile, O_RDONLY)) < 0)
+  if ((fd = fopen (infile, "rb")) == NULL)
     {
       syserror ("Error opening input file");
     }
@@ -122,7 +122,7 @@ create_type42 (const char *infile, void *out)
   lily_cookie_fclose (out);
   if (ttf_verbosity >= 1)
     fprintf (stderr, "Done.\n");
-  close (fd);
+  fclose (fd);
 }
 
 
index ce794ba118578e451523ef18bd90c8a30516fdeb..12f29da1f99b6cf11fd2f35e7e0b21efd0b7af62 100644 (file)
@@ -58,41 +58,39 @@ myrealloc (void *ptr, size_t size)
   return p;
 }
 
-off_t
-surely_lseek (int fildes, off_t offset, int whence)
+void
+show_fpos (int fd)
+{
+  off_t here = lseek (fd, 0, SEEK_CUR);
+  off_t end = lseek (fd, 0, SEEK_END);
+  fprintf (stderr, "here %d end %d", here, end);
+  lseek (fd, here, SEEK_SET);
+}
+
+void
+surely_lseek (FILE *fildes, off_t offset, int whence)
 {
+  if (ttf_verbosity >= 3)
+    fprintf (stderr, "Seeking to %d %d\n", whence, offset);
+  
   off_t result;
-  if ((result = lseek (fildes, offset, whence)) < 0)
+  if ((result = fseek (fildes, (long) offset, whence)) < 0)
     {
       char s[100];
-      sprintf (s, "Cannot seek to %d %ld", whence, offset);
+      sprintf (s, "Cannot seek");
       syserror (s);
     }
-  return result;
 }
 
 ssize_t
-surely_read (int fildes, void *buf, size_t nbyte)
+surely_read (FILE *fildes, void *buf, size_t nbyte)
 {
   if (ttf_verbosity >= 3)
     fprintf (stderr, "Reading %d bytes\n", nbyte);
+  if (nbyte == 0)
+    return 0;
   
-  ssize_t n;
-  void *bufptr = buf;
-  while (nbyte > 0
-        && (n = read (fildes, bufptr, nbyte)) > 0)
-    {
-      bufptr += n;
-      nbyte -= n;
-    }
-
-  if (n < 0 || nbyte > 0)
-    {
-      char s[100];
-      sprintf (s, "error during read(), n = %d, nbyte = %d", n, nbyte);
-      syserror (s);
-    }
-  
+  int items = fread (buf, nbyte, 1,  fildes);
   return nbyte;
 }