* 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 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
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.
--- /dev/null
+
+#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 */
--- /dev/null
+#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
#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);
#include <unistd.h>
#include "libc-extension.hh"
+#include "file-cookie.hh"
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:
}
#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 */
*/
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,
size_ = 0;
buffer_ = 0;
buffer_blocks_ = 0;
+ file_ = 0;
+
+#if 0
file_ = fopencookie ((void *) this, "w", functions_);
+#endif
}
Memory_out_stream::~Memory_out_stream ()
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=
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 ());
'''
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
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,
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);
#endif
- void create_type42 (char const *, FILE *);
+ void create_type42 (char const *, void *);
#ifdef __cplusplus
}
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)
{
}
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";
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++;
}
}
}
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");
}
#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;
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);
}
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++;
}
}