]> git.donarmstrong.com Git - lilypond.git/commitdiff
* flower/memory-stream.cc (Memory_out_stream): remove fopencookie support.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 6 Jun 2005 14:27:42 +0000 (14:27 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 6 Jun 2005 14:27:42 +0000 (14:27 +0000)
* ttftool/ttfps.c: use lily_cookie functions everywhere.

* flower/include/file-cookie.hh: new file. lily_cookie extension

* flower/file-cookie.cc: new file. lily_cookie extension.

15 files changed:
ChangeLog
flower/file-cookie.cc [new file with mode: 0644]
flower/include/file-cookie.hh [new file with mode: 0644]
flower/include/libc-extension.hh
flower/include/memory-stream.hh
flower/libc-extension.cc
flower/memory-stream.cc
lily/GNUmakefile
lily/pfb.cc
scripts/midi2ly.py
ttftool/include/proto.h
ttftool/include/ttftool.h
ttftool/ps.c
ttftool/ttfps.c
ttftool/util.c

index 138faf9c01914c85c39d2b16eb8140f8e77105f7..114388c30023f21ed723bb6bd497833b5dff2b5e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2005-06-06  Han-Wen Nienhuys  <hanwen@xs4all.nl>
+
+       * flower/memory-stream.cc (Memory_out_stream): remove fopencookie support.
+
+       * ttftool/ttfps.c: use lily_cookie functions everywhere. 
+
+       * flower/include/file-cookie.hh: new file. lily_cookie extension 
+
+       * flower/file-cookie.cc: new file. lily_cookie extension.
+
 2005-06-06  Jan Nieuwenhuizen  <janneke@gnu.org>
 
        * scm/editor.scm (editor-command-template-alist): Add syn
@@ -28,7 +38,7 @@
 2005-06-03  Jan Nieuwenhuizen  <janneke@gnu.org>
 
        * scm/editor.scm (editor-command-template-alist): Start emacs if
-       emaclient fails.
+       emacslient fails.
 
        * lily/main.cc (setup_localisation): Listen to LILYPOND_LOCALEDIR.
 
diff --git a/flower/file-cookie.cc b/flower/file-cookie.cc
new file mode 100644 (file)
index 0000000..b216b8a
--- /dev/null
@@ -0,0 +1,58 @@
+
+#include <assert.h>
+#include <cstdio>
+
+#include "memory-stream.hh"
+
+extern "C" {
+
+  static bool
+  is_memory_stream (void *foo)
+  {
+    Memory_out_stream *cookie = (Memory_out_stream *) foo;
+    return dynamic_cast<Memory_out_stream *> (cookie);
+  }
+
+  void *
+  lily_fopencookie (void *cookie, char const *modes,
+                   lily_cookie_io_functions_t io_funcs)
+  {
+    (void) cookie;
+    (void) modes;
+    (void) io_funcs;
+    assert (is_memory_stream (cookie));
+    return (FILE *) cookie;
+  }
+
+  int
+  lily_cookie_fclose (void *file)
+  {
+    assert (is_memory_stream (file));
+    return Memory_out_stream::cleaner (file);
+  }
+
+  int
+  lily_cookie_fprintf (void *file, char const *format, ...)
+  {
+    assert (is_memory_stream (file));
+    va_list ap;
+    va_start (ap, format);
+
+    static char buf[65536];
+    int i = vsnprintf (buf, sizeof (buf), format, ap);
+    if (i == -1 || (unsigned) i > sizeof (buf))
+      assert (false);
+    va_end (ap);
+    return Memory_out_stream::writer (file, buf, i);
+  }
+
+  int
+  lily_cookie_putc (int c, void *file)
+  {
+    assert (is_memory_stream (file));
+    char buf[1];
+    buf[0] = (char) c;
+    return Memory_out_stream::writer (file, buf, 1);
+  }
+
+} /* extern C */
diff --git a/flower/include/file-cookie.hh b/flower/include/file-cookie.hh
new file mode 100644 (file)
index 0000000..f523c89
--- /dev/null
@@ -0,0 +1,31 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#include <stdio.h>
+#include <unistd.h>
+
+#if (! defined (__off64_t) && ! defined (__off64_t_defined)) || ! defined (__cplusplus)
+#define off64_t unsigned long long
+#endif
+  typedef struct
+  {
+    int (*read) (void *, char *, size_t);
+    int (*write) (void *, char const *, size_t);
+    int (*seek) (void *, off64_t *, int);
+    int (*close) (void *);
+  } lily_cookie_io_functions_t;
+
+
+  void *lily_fopencookie (void *cookie, char const *modes,
+                         lily_cookie_io_functions_t io_funcs);
+
+  int lily_cookie_fclose (void *);
+  int lily_cookie_fprintf (void *file, char const *format, ...);
+  int lily_cookie_putc (int c, void *file);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
index 3ee0fe426c09e6532dc27aced27900b02399fde9..470eff774acbf1a351194ab0b7d2473fad723450 100644 (file)
@@ -36,76 +36,6 @@ int isinf (double x);
 #endif
 #endif
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if ! HAVE_FOPENCOOKIE          /* GNU extension. */
-
-#include <stdio.h>
-#include <unistd.h>
-
-#if (! defined (__off64_t) && ! defined (__off64_t_defined)) || ! defined (__cplusplus)
-#define off64_t unsigned long long
-#endif
-
-#if HAVE_LIBIO_H
-#include <libio.h>
-#else
-
-#if 1 //! HAVE_FUNOPEN
-
-#define cookie_io_functions_t le_cookie_io_functions_t
-  typedef struct
-  {
-    ssize_t (*read) (void *, char *, size_t);
-    ssize_t (*write) (void *, char const *, size_t);
-    int (*seek) (void *, off64_t *, int);
-    int (*close) (void *);
-  } cookie_io_functions_t;
-
-#else
-
-  typedef struct
-  {
-    int (*read) (void *, char *, int);
-    int (*write) (void *, char const *, int);
-    fpos_t (*seek) (void *, fpos_t, int);
-    int (*close) (void *);
-  } cookie_io_functions_t;
-
-#endif /* ! HAVE_FUNOPEN */
-#endif /* ! HAVE_LIBIO_H */
-
-  FILE *fopencookie (void *cookie, char const *modes,
-                    cookie_io_functions_t io_funcs);
-
-#if ! HAVE_FUNOPEN
-
-  int handle_cookie_io_fclose (FILE *);
-  int handle_cookie_io_fprintf (FILE *file, char const *format, ...);
-  int handle_cookie_io_putc (int c, FILE *file);
-
-  /* FIXME: ttftool uses fclose fopencookie fprintf and putc only.  if
-     ALIAS_FILE_TO_FILECOOKIE, blondly redefine those functions
-     to wrappers that check for and handle Memory_out_stream.  */
-#ifdef ALIAS_FILE_TO_FILECOOKIE
-
-#define fclose handle_cookie_io_fclose
-#define fprintf handle_cookie_io_fprintf
-#ifdef putc
-#define std_putc putc
-#undef putc
-#endif
-#define putc handle_cookie_io_putc
-
-#endif /* ALIAS_FILE_TO_FILECOOKIE */
-#endif /* ! HAVE_FUNOPEN */
-#endif /* ! HAVE_FOPENCOOKIE */
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
 
 #if ! HAVE_MEMRCHR
 unsigned char *memrchr (unsigned char const *p, int n, char c);
index 12d2607a3727cee2443c1174a05e786e9d7da689..c082a2397249cd54a71dc223c5c8105a9dd26219 100644 (file)
@@ -13,6 +13,7 @@
 #include <unistd.h>
 
 #include "libc-extension.hh"
+#include "file-cookie.hh"
 
 class Memory_out_stream
 {
@@ -21,7 +22,7 @@ class Memory_out_stream
   int buffer_blocks_;
   FILE *file_;
 
-  static cookie_io_functions_t functions_;
+  static lily_cookie_io_functions_t functions_;
   static const int block_size_;
 
 public:
index dea40b6a108a36c3cd3b3e8e1dad269ff822344d..7b9b5d7821c265389a6a07e6ac793c65c376321a 100644 (file)
@@ -157,90 +157,3 @@ vsnprintf (char *str, size_t n, char const *format, va_list args)
 }
 #endif
 
-#include <assert.h>
-
-extern "C" {
-
-#if ! HAVE_FOPENCOOKIE
-#if HAVE_FUNOPEN
-
-  FILE *
-  fopencookie (void *cookie, char const *mode, cookie_io_functions_t fun)
-  {
-    (void) mode;
-#if 0
-    return funopen (cookie, fun.read, fun.write, fun.seek, fun.close);
-#else
-    return funopen (cookie,
-                   (int (*) (void *, char *, int)) fun.read,
-                   (int (*) (void *, char const *, int)) fun.write,
-                   (fpos_t (*) (void *, fpos_t, int)) fun.seek,
-                   (int (*) (void *)) fun.close);
-#endif
-  }
-
-#else /* ! HAVE_FUNOPEN */
-
-#include <cstdio>
-#include "memory-stream.hh"
-
-  static bool
-  is_memory_stream (void *foo)
-  {
-    Memory_out_stream *cookie = (Memory_out_stream *) foo;
-    return dynamic_cast<Memory_out_stream *> (cookie);
-  }
-
-  FILE *
-  fopencookie (void *cookie, char const *modes, cookie_io_functions_t io_funcs)
-  {
-    (void) cookie;
-    (void) modes;
-    (void) io_funcs;
-    if (is_memory_stream (cookie))
-      return (FILE *) cookie;
-    assert (false);
-    return 0;
-  }
-
-  int
-  handle_cookie_io_fclose (FILE *file)
-  {
-    if (is_memory_stream (file))
-      return Memory_out_stream::cleaner (file);
-    return fclose (file);
-  }
-
-  int
-  handle_cookie_io_fprintf (FILE *file, char const *format, ...)
-  {
-    va_list ap;
-    va_start (ap, format);
-    if (is_memory_stream (file))
-      {
-       static char buf[65536];
-       int i = vsnprintf (buf, sizeof (buf), format, ap);
-       if (i == -1 || (unsigned) i > sizeof (buf))
-         assert (false);
-       return Memory_out_stream::writer (file, buf, i);
-      }
-    int i = vfprintf (file, format, ap);
-    va_end (ap);
-    return i;
-  }
-
-  int
-  handle_cookie_io_putc (int c, FILE *file)
-  {
-    if (is_memory_stream (file))
-      {
-       char buf[1];
-       buf[0] = (char) c;
-       return Memory_out_stream::writer (file, buf, 1);
-      }
-    return putc (c, file);
-  }
-
-#endif /* ! HAVE_FUNOPEN */
-#endif /* ! HAVE_FOPENCOOKIE */
-} /* extern C */
index 3d29993486f8651f3a7a86f1c6a68174f7d6d2c1..f0302d81da067518b0e0c5bb493e5debac172bfd 100644 (file)
@@ -17,7 +17,7 @@
 */
 const int Memory_out_stream::block_size_ = 1024;
 
-cookie_io_functions_t
+lily_cookie_io_functions_t
 Memory_out_stream::functions_
 = {
   Memory_out_stream::reader,
@@ -40,7 +40,11 @@ Memory_out_stream::Memory_out_stream ()
   size_ = 0;
   buffer_ = 0;
   buffer_blocks_ = 0;
+  file_ = 0;
+
+#if 0
   file_ = fopencookie ((void *) this, "w", functions_);
+#endif
 }
 
 Memory_out_stream::~Memory_out_stream ()
index 9ecc8c3f589e45a4896b8895f9d14b8bd002e55e..e92486e321c638709c67ade3376c3bab7e63b26f 100644 (file)
@@ -4,7 +4,7 @@ depth = ..
 NAME = lilypond
 SUBDIRS = include
 
-MODULE_LIBS= $(depth)/flower  $(depth)/ttftool $(depth)/kpath-guile 
+MODULE_LIBS= $(depth)/ttftool $(depth)/flower   $(depth)/kpath-guile 
 MODULE_INCLUDES= $(depth)/flower/include $(depth)/ttftool/include 
 MODULE_CXXFLAGS=
 
index 449953b94c212df831b61e72ddda610668cc4091..7869d2ed1d25e887e8c306e23ae59209e1a6618b 100644 (file)
@@ -111,7 +111,7 @@ LY_DEFINE (ly_ttf_to_pfa, "ly:ttf->pfa",
   
   
   Memory_out_stream stream;
-  create_type42 (file_name.to_str0 (), stream.get_file ());
+  create_type42 (file_name.to_str0 (), (void*) &stream);
   SCM asscm = scm_from_locale_stringn (stream.get_string (),
                                       stream.get_length ());
 
index 2d7c22c37552a6b7def8274663fce6c3673794f3..8726c8d59f8231ac148ba1691e2b07e2af2f0186 100644 (file)
@@ -11,7 +11,6 @@
 '''
 TODO:
    * test on weird and unquantised midi input (lily-devel)
-   * drop c++ midi2ly
    * update doc and manpage
 
    * simply insert clef changes whenever too many ledger lines
index 68d6b1a407cdcc2de0c22baebd618e2c306247cd..841cdca1baa8d46c7064e3f1e467947c860414f2 100644 (file)
@@ -14,15 +14,16 @@ longHorMetric *readHmtxTable (int fd, int nummetrics);
 struct HheaTable *readHheaTable (int fd);
 int readKernTable (int fd, int **nke, struct KernEntry0 ***ke);
 
-void printPSFont (FILE * out, struct HeadTable *ht,
+void printPSFont (void * out, struct HeadTable *ht,
                  char **strings, int nglyphs, int postType,
                  struct PostTable *pt, struct GlyphName *gnt, int fd);
 
-void printPSHeader (FILE * out, struct HeadTable *ht,
+void printPSHeader (void * out, struct HeadTable *ht,
                    char **strings, struct PostTable *pt);
-void printPSData (FILE * out, int fd);
-void printPSTrailer (FILE * out, int nglyphs,
+void printPSData (void * out, int fd);
+void printPSTrailer (void * out, int nglyphs,
                     int postType, struct GlyphName *gnt);
+
 void printAFM (FILE * afm, struct HeadTable *ht,
               char **strings, int nglyphs, int postType,
               struct PostTable *pt, struct GlyphName *gnt,
@@ -53,7 +54,7 @@ void error (char *string);
 void syserror (char *string);
 ssize_t surely_read (int fildes, void *buf, size_t nbyte);
 char *unistrncpy (char *dst, char *str, size_t length);
-void fputpss (char *s, FILE * stream);
+void fputpss (char *s, void * stream);
 off_t surely_lseek (int fildes, off_t offset, int whence);
 unsigned hash (char *string);
 struct hashtable *make_hashtable (int size);
index c1884eddbee549dafd891d936153aa943a1445ea..7d5467f8345f771866d1e74ba930254d34fe8abf 100644 (file)
@@ -4,7 +4,7 @@ extern "C"
 #endif
 
 
-  void create_type42 (char const *, FILE *);
+  void create_type42 (char const *, void *);
 
 #ifdef __cplusplus
 }
index 13ee16a2dab5652e79f45202fa9b86f2e74c6e4a..4be735e46b5edec86f724cae6c56fc52b1150a13 100644 (file)
@@ -24,7 +24,7 @@
 
 
 void
-printPSFont (FILE * out, struct HeadTable *ht,
+printPSFont (void *out, struct HeadTable *ht,
             char **strings, int nglyphs, int postType,
             struct PostTable *pt, struct GlyphName *gnt, int fd)
 {
@@ -34,55 +34,55 @@ printPSFont (FILE * out, struct HeadTable *ht,
 }
 
 void
-printPSHeader (FILE * out, struct HeadTable *ht,
+printPSHeader (void *out, struct HeadTable *ht,
               char **strings, struct PostTable *pt)
 {
-  fprintf (out, "%%!PS-TrueTypeFont\n");
+  lily_cookie_fprintf (out, "%%!PS-TrueTypeFont\n");
   if (pt->maxMemType42)
-    fprintf (out, "%%%%VMUsage: %ld %ld\n", pt->minMemType42,
+    lily_cookie_fprintf (out, "%%%%VMUsage: %ld %ld\n", pt->minMemType42,
             pt->maxMemType42);
-  fprintf (out, "%d dict begin\n", 11);
-  fprintf (out, "/FontName /%s def\n", strings[6] ? strings[6] : "Unknown");
-  fprintf (out, "/Encoding StandardEncoding def\n");
-  fprintf (out, "/PaintType 0 def\n/FontMatrix [1 0 0 1 0 0] def\n");
-  fprintf (out, "/FontBBox [%ld %ld %ld %ld] def\n",
+  lily_cookie_fprintf (out, "%d dict begin\n", 11);
+  lily_cookie_fprintf (out, "/FontName /%s def\n", strings[6] ? strings[6] : "Unknown");
+  lily_cookie_fprintf (out, "/Encoding StandardEncoding def\n");
+  lily_cookie_fprintf (out, "/PaintType 0 def\n/FontMatrix [1 0 0 1 0 0] def\n");
+  lily_cookie_fprintf (out, "/FontBBox [%ld %ld %ld %ld] def\n",
           ht->xMin * 1000L / ht->unitsPerEm,
           ht->yMin * 1000L / ht->unitsPerEm,
           ht->xMax * 1000L / ht->unitsPerEm,
           ht->yMax * 1000L / ht->unitsPerEm);
-  fprintf (out, "/FontType 42 def\n");
-  fprintf (out, "/FontInfo 8 dict dup begin\n");
-  fprintf (out, "/version (%d.%d) def\n",
+  lily_cookie_fprintf (out, "/FontType 42 def\n");
+  lily_cookie_fprintf (out, "/FontInfo 8 dict dup begin\n");
+  lily_cookie_fprintf (out, "/version (%d.%d) def\n",
           ht->fontRevision.mantissa, ht->fontRevision.fraction);
   if (strings[0])
     {
-      fprintf (out, "/Notice (");
+      lily_cookie_fprintf (out, "/Notice (");
       fputpss (strings[0], out);
-      fprintf (out, ") def\n");
+      lily_cookie_fprintf (out, ") def\n");
     }
   if (strings[4])
     {
-      fprintf (out, "/FullName (");
+      lily_cookie_fprintf (out, "/FullName (");
       fputpss (strings[4], out);
-      fprintf (out, ") def\n");
+      lily_cookie_fprintf (out, ") def\n");
     }
   if (strings[1])
     {
-      fprintf (out, "/FamilyName (");
+      lily_cookie_fprintf (out, "/FamilyName (");
       fputpss (strings[1], out);
-      fprintf (out, ") def\n");
+      lily_cookie_fprintf (out, ") def\n");
     }
-  fprintf (out, "/isFixedPitch %s def\n",
+  lily_cookie_fprintf (out, "/isFixedPitch %s def\n",
           pt->isFixedPitch ? "true" : "false");
-  fprintf (out, "/UnderlinePosition %ld def\n",
+  lily_cookie_fprintf (out, "/UnderlinePosition %ld def\n",
           pt->underlinePosition * 1000L / ht->unitsPerEm);
-  fprintf (out, "/UnderlineThickness %ld def\n",
+  lily_cookie_fprintf (out, "/UnderlineThickness %ld def\n",
           pt->underlineThickness * 1000L / ht->unitsPerEm);
-  fprintf (out, "end readonly def\n");
+  lily_cookie_fprintf (out, "end readonly def\n");
 }
 
 void
-printPSData (FILE * out, int fd)
+printPSData (void *out, int fd)
 {
   static char xdigits[] = "0123456789ABCDEF";
 
@@ -93,47 +93,47 @@ printPSData (FILE * out, int fd)
 
   buffer = mymalloc (CHUNKSIZE);
 
-  fprintf (out, "/sfnts [");
+  lily_cookie_fprintf (out, "/sfnts [");
   for (;;)
     {
       i = read (fd, buffer, CHUNKSIZE);
       if (i == 0)
        break;
-      fprintf (out, "\n<");
+      lily_cookie_fprintf (out, "\n<");
       for (j = 0; j < i; j++)
        {
          if (j != 0 && j % 36 == 0)
-           putc ('\n', out);
-         /* fprintf(out,"%02X",(int)buffer[j]) is too slow */
-         putc (xdigits[(buffer[j] & 0xF0) >> 4], out);
-         putc (xdigits[buffer[j] & 0x0F], out);
+           lily_cookie_putc ('\n', out);
+         /* lily_cookie_fprintf (out,"%02X",(int)buffer[j]) is too slow */
+         lily_cookie_putc (xdigits[(buffer[j] & 0xF0) >> 4], out);
+         lily_cookie_putc (xdigits[buffer[j] & 0x0F], out);
        }
-      fprintf (out, "00>");    /* Adobe bug? */
+      lily_cookie_fprintf (out, "00>");        /* Adobe bug? */
       if (i < CHUNKSIZE)
        break;
     }
-  fprintf (out, "\n] def\n");
+  lily_cookie_fprintf (out, "\n] def\n");
   free (buffer);
 }
 
 void
-printPSTrailer (FILE * out, int nglyphs, int postType, struct GlyphName *gnt)
+printPSTrailer (void *out, int nglyphs, int postType, struct GlyphName *gnt)
 {
   int i, n;
   char *name;
 
-  fprintf (out, "/CharStrings %d dict dup begin\n", nglyphs);
+  lily_cookie_fprintf (out, "/CharStrings %d dict dup begin\n", nglyphs);
   switch (postType)
     {
     case 2:
       for (n = i = 0; i < nglyphs; i++)
        {
          if (n != 0 && n % 4 == 0)
-           fprintf (out, "\n");
+           lily_cookie_fprintf (out, "\n");
          name = NAMEOF (i);
          if (name)
            {
-             fprintf (out, "/%s %d def ", name, i);
+             lily_cookie_fprintf (out, "/%s %d def ", name, i);
              n++;
            }
        }
@@ -147,12 +147,12 @@ printPSTrailer (FILE * out, int nglyphs, int postType, struct GlyphName *gnt)
        }
       for (i = 0; i < 258 && i < nglyphs; i++)
        {
-         fprintf (out, "/%s %d def ", macGlyphEncoding[i], i);
+         lily_cookie_fprintf (out, "/%s %d def ", macGlyphEncoding[i], i);
          if (i != 0 && i % 4 == 0)
-           fprintf (out, "\n");
+           lily_cookie_fprintf (out, "\n");
        }
       break;
     }
-  fprintf (out, "end readonly def\n");
-  fprintf (out, "FontName currentdict end definefont pop\n");
+  lily_cookie_fprintf (out, "end readonly def\n");
+  lily_cookie_fprintf (out, "FontName currentdict end definefont pop\n");
 }
index 817477058120c04664a4d70613dc4bac7968b324..1af881909a4e5a98c9e67bcc5884f602e9ab2276 100644 (file)
@@ -8,16 +8,15 @@
 #include "types.h"
 #include "proto.h"
 
-#define ALIAS_FILE_TO_FILECOOKIE
-#include "libc-extension.hh"
-
+#include "file-cookie.hh"
 static void endianness_test (void);
 static void usage (char *);
 
 int verbosity = 0;
 
 void
-create_type42 (const char *infile, FILE * out)
+create_type42 (const char *infile, void *out)
 {
   int fd, i;
   struct OffsetTable ot;
@@ -118,7 +117,7 @@ create_type42 (const char *infile, FILE * out)
   if (verbosity >= 1)
     fprintf (stderr, "Generating PS file\n");
   printPSFont (out, ht, strings, nglyphs, postType, pt, gnt, fd);
-  fclose (out);
+  lily_cookie_fclose (out);
   if (verbosity >= 1)
     fprintf (stderr, "Done.\n");
   close (fd);
index 43db6d55ec58e7d5e80ad59f05656efd2adc00e7..cb396dbb9c9661491002e197ea958af2269a3c7b 100644 (file)
@@ -84,14 +84,14 @@ unistrncpy (char *dst, char *str, size_t length)
 }
 
 void
-fputpss (char *s, FILE * stream)
+fputpss (char *s, void *stream)
 {
   while (*s)
     {
       if ((*s & 0200) == 0 && *s >= 040 && *s != '(' && *s != ')')
-       putc (*s, stream);
+       lily_cookie_putc (*s, stream);
       else
-       fprintf (stream, "\\%03o", (unsigned char) *s);
+       lily_cookie_fprintf (stream, "\\%03o", (unsigned char) *s);
       s++;
     }
 }