CVSROOT:        /cvsroot/lilypond
Module name:    lilypond
Branch:         
Changes by:     Han-Wen Nienhuys <[EMAIL PROTECTED]>    05/06/12 16:33:21

Modified files:
        .              : ChangeLog 
        lily           : main.cc 
        ttftool        : parse.c ps.c ttfps.c util.c 
        ttftool/include: proto.h 
Added files:
        ttftool        : test.c 

Log message:
        * 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.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/ChangeLog.diff?tr1=1.3767&tr2=1.3768&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/main.cc.diff?tr1=1.262&tr2=1.263&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/ttftool/test.c?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/ttftool/parse.c.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/ttftool/ps.c.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/ttftool/ttfps.c.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/ttftool/util.c.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/ttftool/include/proto.h.diff?tr1=1.4&tr2=1.5&r1=text&r2=text

Patches:
Index: lilypond/ChangeLog
diff -u lilypond/ChangeLog:1.3767 lilypond/ChangeLog:1.3768
--- lilypond/ChangeLog:1.3767   Sun Jun 12 14:11:15 2005
+++ lilypond/ChangeLog  Sun Jun 12 16:33:20 2005
@@ -1,5 +1,10 @@
 2005-06-12  Han-Wen Nienhuys  <[EMAIL PROTECTED]>
 
+       * 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: lilypond/lily/main.cc
diff -u lilypond/lily/main.cc:1.262 lilypond/lily/main.cc:1.263
--- lilypond/lily/main.cc:1.262 Fri Jun 10 09:30:42 2005
+++ lilypond/lily/main.cc       Sun Jun 12 16:33:21 2005
@@ -5,7 +5,7 @@
 
   (c) 1997--2005 Han-Wen Nienhuys <[EMAIL PROTECTED]>
 */
-
+ 
 #include "main.hh"
 
 #include <cassert>
Index: lilypond/ttftool/include/proto.h
diff -u lilypond/ttftool/include/proto.h:1.4 
lilypond/ttftool/include/proto.h:1.5
--- lilypond/ttftool/include/proto.h:1.4        Thu Jun  9 16:45:47 2005
+++ lilypond/ttftool/include/proto.h    Sun Jun 12 16:33:21 2005
@@ -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 *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: lilypond/ttftool/parse.c
diff -u lilypond/ttftool/parse.c:1.7 lilypond/ttftool/parse.c:1.8
--- lilypond/ttftool/parse.c:1.7        Thu Jun  9 17:16:46 2005
+++ lilypond/ttftool/parse.c    Sun Jun 12 16:33:21 2005
@@ -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 @@
 }
 
 char **
-readNamingTable (int fd)
+readNamingTable (FILE *fd)
 {
   USHORT format;
   USHORT nrecords;
@@ -43,7 +43,7 @@
   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 @@
 }
 
 int
-readMaxpTable (int fd)
+readMaxpTable (FILE *fd)
 {
   struct
   {
@@ -131,7 +131,7 @@
 }
 
 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 @@
 }
 
 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 @@
  /*NOTREACHED*/}
 
 void *
-readLocaTable (int fd, int nglyphs, int format)
+readLocaTable (FILE *fd, int nglyphs, int format)
 {
   int i;
   switch (format)
@@ -255,13 +255,13 @@
  /*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 @@
 }
 
 longHorMetric *
-readHmtxTable (int fd, int nummetrics)
+readHmtxTable (FILE *fd, int nummetrics)
 {
   longHorMetric *metrics;
   int i;
@@ -293,7 +293,7 @@
 }
 
 struct HheaTable *
-readHheaTable (int fd)
+readHheaTable (FILE *fd)
 {
   struct HheaTable *hhea;
   hhea = mymalloc (sizeof (struct HheaTable));
@@ -308,7 +308,7 @@
 }
 
 int
-readKernTable (int fd, int **nkep, struct KernEntry0 ***kep)
+readKernTable (FILE *fd, int **nkep, struct KernEntry0 ***kep)
 {
   struct KernTable kt;
   struct KernSubTableHeader ksth;
Index: lilypond/ttftool/ps.c
diff -u lilypond/ttftool/ps.c:1.7 lilypond/ttftool/ps.c:1.8
--- lilypond/ttftool/ps.c:1.7   Thu Jun  9 16:45:47 2005
+++ lilypond/ttftool/ps.c       Sun Jun 12 16:33:21 2005
@@ -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 @@
 }
 
 void
-printPSData (void *out, int fd)
+printPSData (void *out, FILE *fd)
 {
   static char xdigits[] = "0123456789ABCDEF";
 
@@ -95,7 +95,7 @@
   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<");
Index: lilypond/ttftool/ttfps.c
diff -u lilypond/ttftool/ttfps.c:1.8 lilypond/ttftool/ttfps.c:1.9
--- lilypond/ttftool/ttfps.c:1.8        Thu Jun  9 16:45:47 2005
+++ lilypond/ttftool/ttfps.c    Sun Jun 12 16:33:21 2005
@@ -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 @@
 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 @@
 
   endianness_test ();
 
-  if ((fd = open (infile, O_RDONLY)) < 0)
+  if ((fd = fopen (infile, "rb")) == NULL)
     {
       syserror ("Error opening input file");
     }
@@ -122,7 +122,7 @@
   lily_cookie_fclose (out);
   if (ttf_verbosity >= 1)
     fprintf (stderr, "Done.\n");
-  close (fd);
+  fclose (fd);
 }
 
 
Index: lilypond/ttftool/util.c
diff -u lilypond/ttftool/util.c:1.11 lilypond/ttftool/util.c:1.12
--- lilypond/ttftool/util.c:1.11        Fri Jun 10 20:09:01 2005
+++ lilypond/ttftool/util.c     Sun Jun 12 16:33:21 2005
@@ -58,41 +58,39 @@
   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;
 }
 


_______________________________________________
Lilypond-cvs mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-cvs

Reply via email to