From: Han-Wen Nienhuys Date: Mon, 6 Jun 2005 14:27:42 +0000 (+0000) Subject: * flower/memory-stream.cc (Memory_out_stream): remove fopencookie support. X-Git-Tag: release/2.5.28~10 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=9087de1c637fc042ae3cbda8174a4ee9131cc523;p=lilypond.git * 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. --- diff --git a/ChangeLog b/ChangeLog index 138faf9c01..114388c300 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-06-06 Han-Wen Nienhuys + + * 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 * scm/editor.scm (editor-command-template-alist): Add syn @@ -28,7 +38,7 @@ 2005-06-03 Jan Nieuwenhuizen * 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 index 0000000000..b216b8a1e4 --- /dev/null +++ b/flower/file-cookie.cc @@ -0,0 +1,58 @@ + +#include +#include + +#include "memory-stream.hh" + +extern "C" { + + static bool + is_memory_stream (void *foo) + { + Memory_out_stream *cookie = (Memory_out_stream *) foo; + return dynamic_cast (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 index 0000000000..f523c897da --- /dev/null +++ b/flower/include/file-cookie.hh @@ -0,0 +1,31 @@ +#ifdef __cplusplus +extern "C" { +#endif + + +#include +#include + +#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 diff --git a/flower/include/libc-extension.hh b/flower/include/libc-extension.hh index 3ee0fe426c..470eff774a 100644 --- a/flower/include/libc-extension.hh +++ b/flower/include/libc-extension.hh @@ -36,76 +36,6 @@ int isinf (double x); #endif #endif -#ifdef __cplusplus -extern "C" { -#endif - -#if ! HAVE_FOPENCOOKIE /* GNU extension. */ - -#include -#include - -#if (! defined (__off64_t) && ! defined (__off64_t_defined)) || ! defined (__cplusplus) -#define off64_t unsigned long long -#endif - -#if HAVE_LIBIO_H -#include -#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); diff --git a/flower/include/memory-stream.hh b/flower/include/memory-stream.hh index 12d2607a37..c082a23972 100644 --- a/flower/include/memory-stream.hh +++ b/flower/include/memory-stream.hh @@ -13,6 +13,7 @@ #include #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: diff --git a/flower/libc-extension.cc b/flower/libc-extension.cc index dea40b6a10..7b9b5d7821 100644 --- a/flower/libc-extension.cc +++ b/flower/libc-extension.cc @@ -157,90 +157,3 @@ vsnprintf (char *str, size_t n, char const *format, va_list args) } #endif -#include - -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 -#include "memory-stream.hh" - - static bool - is_memory_stream (void *foo) - { - Memory_out_stream *cookie = (Memory_out_stream *) foo; - return dynamic_cast (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 */ diff --git a/flower/memory-stream.cc b/flower/memory-stream.cc index 3d29993486..f0302d81da 100644 --- a/flower/memory-stream.cc +++ b/flower/memory-stream.cc @@ -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 () diff --git a/lily/GNUmakefile b/lily/GNUmakefile index 9ecc8c3f58..e92486e321 100644 --- a/lily/GNUmakefile +++ b/lily/GNUmakefile @@ -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= diff --git a/lily/pfb.cc b/lily/pfb.cc index 449953b94c..7869d2ed1d 100644 --- a/lily/pfb.cc +++ b/lily/pfb.cc @@ -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 ()); diff --git a/scripts/midi2ly.py b/scripts/midi2ly.py index 2d7c22c375..8726c8d59f 100644 --- a/scripts/midi2ly.py +++ b/scripts/midi2ly.py @@ -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 diff --git a/ttftool/include/proto.h b/ttftool/include/proto.h index 68d6b1a407..841cdca1ba 100644 --- a/ttftool/include/proto.h +++ b/ttftool/include/proto.h @@ -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); diff --git a/ttftool/include/ttftool.h b/ttftool/include/ttftool.h index c1884eddbe..7d5467f834 100644 --- a/ttftool/include/ttftool.h +++ b/ttftool/include/ttftool.h @@ -4,7 +4,7 @@ extern "C" #endif - void create_type42 (char const *, FILE *); + void create_type42 (char const *, void *); #ifdef __cplusplus } diff --git a/ttftool/ps.c b/ttftool/ps.c index 13ee16a2da..4be735e46b 100644 --- a/ttftool/ps.c +++ b/ttftool/ps.c @@ -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"); } diff --git a/ttftool/ttfps.c b/ttftool/ttfps.c index 8174770581..1af881909a 100644 --- a/ttftool/ttfps.c +++ b/ttftool/ttfps.c @@ -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); diff --git a/ttftool/util.c b/ttftool/util.c index 43db6d55ec..cb396dbb9c 100644 --- a/ttftool/util.c +++ b/ttftool/util.c @@ -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++; } }