From 94dfb814b6bcd17f05e3bb1ff61de9b9e526c3b7 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Fri, 25 Feb 2005 23:33:03 +0000 Subject: [PATCH] * ttftool/util.c: * ttftool/ttfps.c: * ttftool/ps.c: #include libc-extension.hh * flower/include/libc-extension.hh: * flower/libc-extension.cc (fopencookie)[!HAVE_FOPENCOOKIE]: Add wrapper using funopen. (fopencookie, handle_cookie_io_fclose, handle_cookie_io_fprintf, handle_cookie_io_fprintf): Add wrappers catching Memory_out_stream. * config.hh.in: * configure.in (AC_CHECK_FUNCS): Add fopencookie, funopen. (AC_CHECK_HEADERS): Add libio.h --- ChangeLog | 18 +++- config.hh.in | 17 +++- configure.in | 8 +- cygwin/mknetrel | 6 +- flower/include/libc-extension.hh | 79 ++++++++++++++--- flower/include/memory-stream.hh | 17 ++-- flower/libc-extension.cc | 148 ++++++++++++++++++++++++------- flower/memory-stream.cc | 25 +++--- lily/pfb.cc | 75 ++++++++-------- stepmake/aclocal.m4 | 4 +- ttftool/ps.c | 2 + ttftool/ttfps.c | 2 + ttftool/util.c | 2 + 13 files changed, 281 insertions(+), 122 deletions(-) diff --git a/ChangeLog b/ChangeLog index e4e4436b7d..0da093db45 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,20 @@ -2005-02-25 Jan Nieuwenhuizen +2005-02-26 Jan Nieuwenhuizen - * scripts/convert-ly.py: Uniformize, internalize. + * ttftool/util.c: + * ttftool/ttfps.c: + * ttftool/ps.c: #include libc-extension.hh + + * flower/include/libc-extension.hh: + * flower/libc-extension.cc (fopencookie)[!HAVE_FOPENCOOKIE]: Add + wrapper using funopen. + (fopencookie, handle_cookie_io_fclose, handle_cookie_io_fprintf, + handle_cookie_io_fprintf): Add wrappers catching Memory_out_stream. + + * config.hh.in: + * configure.in (AC_CHECK_FUNCS): Add fopencookie, funopen. + (AC_CHECK_HEADERS): Add libio.h + + * scripts/convert-ly.py: Uniformize, internationalize. (2.5.2): Remove fatal encoding rule. (2.5.13): Handle latin1 encoding gracefully. diff --git a/config.hh.in b/config.hh.in index cb6a64eafe..e04b6d163e 100644 --- a/config.hh.in +++ b/config.hh.in @@ -18,6 +18,15 @@ /* default lilypond locale dir */ #define LOCALEDIR "@LOCALEDIR@" +/* define if you have fopencookie */ +#define HAVE_FOPENCOOKIE 0 + +/* define if you have funopen */ +#define HAVE_FUNOPEN 0 + +/* define if you have gettext */ +#define HAVE_GETTEXT 0 + /* define if you have memmem */ #define HAVE_MEMMEM 0 @@ -30,9 +39,6 @@ /* define if you have yyFlexLexer.yy_current_buffer */ #undef HAVE_FLEXLEXER_YY_CURRENT_BUFFER -/* define if you have gettext */ -#define HAVE_GETTEXT 0 - /* define if you have isinf */ #define HAVE_ISINF 0 @@ -61,9 +67,12 @@ #define DIRSEP '@DIRSEP@' #define PATHSEP '@PATHSEP@' -/* define if you have assert */ +/* define if you have assert.h */ #define HAVE_ASSERT_H 0 +/* define if you have libio.h */ +#define HAVE_LIBIO_H 0 + /* define if you have sys/stat.h */ #define HAVE_SYS_STAT_H 0 diff --git a/configure.in b/configure.in index ae9ad055fc..cf7f736621 100644 --- a/configure.in +++ b/configure.in @@ -58,21 +58,17 @@ STEPMAKE_KPATHSEA STEPMAKE_MAKEINFO(REQUIRED) STEPMAKE_PYTHON_DEVEL(REQUIRED) -# mftrace for generating pfa's, pfb's STEPMAKE_PROGS(MFTRACE, mftrace, REQUIRED, 1.1.1) - -# mftrace for generating pfa's, pfb's STEPMAKE_PATH_PROG(FONTFORGE, fontforge, REQUIRED, 20041208) - -AC_CHECK_HEADERS([assert.h sys/stat.h]) +AC_CHECK_HEADERS([assert.h libio.h sys/stat.h]) AC_LANG_PUSH(C++) AC_CHECK_HEADERS([sstream]) AC_LANG_POP(C++) AC_HEADER_STAT AC_FUNC_MEMCMP AC_FUNC_VPRINTF -AC_CHECK_FUNCS([gettext isinf memmem snprintf vsnprintf gettext]) +AC_CHECK_FUNCS([fopencookie funopen gettext isinf memmem snprintf vsnprintf]) AC_MSG_CHECKING([for ec-fonts-mftraced]) ecb10=`kpsewhich ecb10.pfa 2>/dev/null` diff --git a/cygwin/mknetrel b/cygwin/mknetrel index 826f27ee87..c2889a92cd 100644 --- a/cygwin/mknetrel +++ b/cygwin/mknetrel @@ -90,13 +90,13 @@ preconfig () { if ! iscygwin; then cd $build || exit 1 GUILE=1.6.5 - cat > guile-config < i686-cygwin-guile-config < -#include +#include +#include #include "config.hh" -#include "flower-proto.hh" -char* strnlwr (char* start ,int n); -char* strnupr (char* start, int n); +char *strnlwr (char *start, int n); +char *strnupr (char *start, int n); -#if !HAVE_MEMMEM // GNU extension. -void *memmem (void const * haystack, int haystack_len, - void const *needle, int needle_len); +#if ! HAVE_MEMMEM /* GNU extension. */ +void *memmem (void const* haystack, int haystack_len, + void const *needle, int needle_len); #endif /* HAVE_MEMMEM */ -#if !HAVE_SNPRINTF // GNU extension. +#if ! HAVE_SNPRINTF /* GNU extension. */ int snprintf (char *str, size_t n, char const *format, ...); #endif -#if !HAVE_VSNPRINTF // GNU extension. +#if ! HAVE_VSNPRINTF /* GNU extension. */ int vsnprintf (char *str, size_t, char const *format, va_list args); #endif #ifndef isinf -#if !HAVE_ISINF // BSD extension +#if ! HAVE_ISINF /* BSD extension. */ 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 + +#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; + +#endif /* ! HAVE_LIBIO_H */ -Byte *memrchr (Byte const * p, int n, char c); -Byte *strrev (Byte* byte, int length_i); + 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... */ +#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 /* ! HAVE_FUNOPEN */ + +#endif /* ! HAVE_FOPENCOOKIE */ + +#ifdef __cplusplus +} /* extern "C" */ +#endif +unsigned char *memrchr (unsigned char const *p, int n, char c); +unsigned char *strrev (unsigned char *byte, int length_i); double my_round (double); -#endif // LIBC_EXTENSION_HH +#endif /* LIBC_EXTENSION_HH */ diff --git a/flower/include/memory-stream.hh b/flower/include/memory-stream.hh index e5077ffc43..f01c5f4d43 100644 --- a/flower/include/memory-stream.hh +++ b/flower/include/memory-stream.hh @@ -13,6 +13,8 @@ #include #include +#include "libc-extension.hh" + class Memory_out_stream { char *buffer_; @@ -23,17 +25,16 @@ class Memory_out_stream static cookie_io_functions_t functions_; static const int block_size_; - static ssize_t reader (void*, char*, size_t); - static ssize_t writer (void*, const char*, size_t); - static int seeker (void*, off64_t *, int whence); - static int cleaner (void*); - - public: - ~Memory_out_stream (); + static ssize_t reader (void *, char *, size_t); + static ssize_t writer (void *, char const *, size_t); + static int seeker (void *, off64_t *, int); + static int cleaner (void *); + Memory_out_stream (); + ~Memory_out_stream (); FILE *get_file () const; - char const *get_string() const; + char const *get_string () const; ssize_t get_length () const; }; diff --git a/flower/libc-extension.cc b/flower/libc-extension.cc index efa544be63..8ced60f22c 100644 --- a/flower/libc-extension.cc +++ b/flower/libc-extension.cc @@ -5,16 +5,16 @@ source file of the flowerlib (c) 1997--2005 Han-Wen Nienhuys - Jan Nieuwenhuizen + Jan Nieuwenhuizen */ -#include "libc-extension.hh" - #include #include #include #include +#include "libc-extension.hh" + char* strnlwr (char* start ,int n) { @@ -39,7 +39,7 @@ strnupr (char* start, int n) /* There are some strange problems with round() on early glibcs. - */ +*/ double my_round (double x) { @@ -59,32 +59,32 @@ isinf (double x) #if !HAVE_MEMMEM /** locate a substring. #memmem# finds the first occurrence of - #needle# in #haystack#. This is not ANSI-C. + #needle# in #haystack#. This is not ANSI-C. - The prototype is not in accordance with the Linux Programmer's - Manual v1.15, but it is with /usr/include/string.h */ + The prototype is not in accordance with the Linux Programmer's + Manual v1.15, but it is with /usr/include/string.h */ -Byte * -_memmem (Byte const *haystack, int haystack_len, - Byte const *needle,int needle_len) +unsigned char * +_memmem (unsigned char const *haystack, int haystack_len, + unsigned char const *needle,int needle_len) { - Byte const * end_haystack = haystack + haystack_len - needle_len + 1; - Byte const * end_needle = needle + needle_len ; + unsigned char const * end_haystack = haystack + haystack_len - needle_len + 1; + unsigned char const * end_needle = needle + needle_len ; /* Ahhh ... Some minimal lowlevel stuff. This *is* nice; Varation is the spice of life */ while (haystack < end_haystack) { - Byte const *subneedle = needle; - Byte const *subhaystack = haystack; + unsigned char const *subneedle = needle; + unsigned char const *subhaystack = haystack; while (subneedle < end_needle) if (*subneedle++ != *subhaystack++) goto next; /* Completed the needle. Gotcha. */ - return (Byte *) haystack; - next: - haystack++; + return (unsigned char *) haystack; + next: + haystack++; } return 0; } @@ -93,21 +93,21 @@ void * memmem (void const *haystack, int haystack_len, void const *needle,int needle_len) { - Byte const* haystack_byte_c = (Byte const*)haystack; - Byte const* needle_byte_c = (Byte const*)needle; + unsigned char const* haystack_byte_c = (unsigned char const*)haystack; + unsigned char const* needle_byte_c = (unsigned char const*)needle; return _memmem (haystack_byte_c, haystack_len, needle_byte_c, needle_len); } #endif -Byte * -memrchr (Byte const * p, int n, char c) +unsigned char * +memrchr (unsigned char const *p, int n, char c) { - const Byte * q = p+n; + const unsigned char *q = p + n; while (q > p) { if (*--q == c) - return (Byte*)q; + return (unsigned char*)q; } return 0; } @@ -122,18 +122,15 @@ my_swap (T &t1, T &t2, T &tmp) t2 = tmp; } -Byte* -strrev (Byte* byte, int length_i) +unsigned char * +strrev (unsigned char *byte, int length) { - Byte tmp_byte; - - Byte* left = byte; - Byte* right = byte + length_i; + unsigned char tmp_byte; + unsigned char *left = byte; + unsigned char *right = byte + length; while (right > left) - { - my_swap (*right-- , *left++ , tmp_byte); - } + my_swap (*right--, *left++ , tmp_byte); return byte; } @@ -157,3 +154,90 @@ vsnprintf (char *str, size_t, char const *format, va_list args) return i; } #endif + +#include + +extern "C" { + +#if ! HAVE_FOPENCOOKIE +#if HAVE_FUNOPEN + + FILE * + fopencookie (void *cookie, char const *mode, cookie_io_functions_t *fun) + { + return funopen (cookie, fun->read, fun->write, fun->seek, fun->close); + } + +#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; + } + +#undef fclose + int + handle_cookie_io_fclose (FILE *file) + { + if (is_memory_stream (file)) + return Memory_out_stream::cleaner (file); + return fclose (file); + } + +#undef fprintf + 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[1024]; + int i = vsnprintf (buf, sizeof (buf), format, ap); + if (i == -1) + assert (false); + return Memory_out_stream::writer (file, buf, i); + } + int i = vfprintf (file, format, ap); + va_end (ap); + return i; + } + +#ifdef std_putc +#define putc std_putc +#else +#undef putc +#endif + 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 9a9fbd4351..e33ed449e3 100644 --- a/flower/memory-stream.cc +++ b/flower/memory-stream.cc @@ -39,12 +39,13 @@ Memory_out_stream::cleaner (void *cookie) Memory_out_stream::Memory_out_stream () { size_ = 0; - buffer_ = 0; + buffer_ = 0; buffer_blocks_ = 0; file_ = fopencookie ((void*) this, "w", functions_); } -Memory_out_stream::~Memory_out_stream() +#undef fclose +Memory_out_stream::~Memory_out_stream () { if (file_) fclose (file_); @@ -52,7 +53,7 @@ Memory_out_stream::~Memory_out_stream() free (buffer_); } -FILE* +FILE * Memory_out_stream::get_file () const { return file_; @@ -70,14 +71,13 @@ Memory_out_stream::get_string () const return buffer_; } - ssize_t Memory_out_stream::writer (void *cookie, const char *buffer, size_t size) { - Memory_out_stream * stream = (Memory_out_stream*) cookie; - + Memory_out_stream *stream = (Memory_out_stream*) cookie; + ssize_t newsize = stream->size_ + size; bool change = false; @@ -89,7 +89,8 @@ Memory_out_stream::writer (void *cookie, } if (change) - stream->buffer_ = (char*) realloc (stream->buffer_, stream->buffer_blocks_ * block_size_); + stream->buffer_ = (char*) realloc (stream->buffer_, + stream->buffer_blocks_ * block_size_); memcpy (stream->buffer_ + stream->size_, buffer, size); stream->size_ = newsize; @@ -97,7 +98,6 @@ Memory_out_stream::writer (void *cookie, return size; } - ssize_t Memory_out_stream::reader (void *cookie, char *buffer, @@ -106,15 +106,16 @@ Memory_out_stream::reader (void *cookie, (void) cookie; (void) buffer; (void) size; - + assert (false); + return 0; } - int -Memory_out_stream::seeker (void*, off64_t *, int whence) +Memory_out_stream::seeker (void *, off64_t *, int whence) { + (void) whence; + assert (false); - (void)whence; return 0; } diff --git a/lily/pfb.cc b/lily/pfb.cc index 5ca2341a11..0be331868a 100644 --- a/lily/pfb.cc +++ b/lily/pfb.cc @@ -1,10 +1,9 @@ -/* +/* pfb.cc -- implement pfb conversion. - + source file of the GNU LilyPond music typesetter - + (c) 2004--2005 Han-Wen Nienhuys - */ #include @@ -16,15 +15,15 @@ #include "ttftool.h" char * -pfb2pfa (Byte const * pfb, int length) +pfb2pfa (Byte const *pfb, int length) { - char * out = new char[1]; + char *out = new char[1]; int olen = 0; - - Byte const * p = pfb; - while (p < pfb + length) + + Byte const *p = pfb; + while (p < pfb + length) { - if (*p++ != 128) + if (*p++ != 128) break; Byte type = *p++; @@ -39,18 +38,18 @@ pfb2pfa (Byte const * pfb, int length) if (type == 1) { out = (char*)realloc (out, olen + seglen + 1); - char* outp = out + olen ; + char *outp = out + olen ; memcpy (outp, p, seglen); - olen += seglen; + olen += seglen; p += seglen; } else if (type == 2) { - unsigned outlength = (seglen * 2) + (seglen / 32) + 2; + unsigned outlength = (seglen * 2) + (seglen / 32) + 2; out = (char*)realloc (out, olen + outlength + 1); - char * outp = out + olen; + char *outp = out + olen; for (int i = seglen; i--;) { sprintf (outp, "%02x", *p++); @@ -63,51 +62,47 @@ pfb2pfa (Byte const * pfb, int length) olen = outp - out; } - + } out[olen] = 0; return out; } -LY_DEFINE(ly_pfb_to_pfa, "ly:pfb->pfa", - 1, 0, 0, (SCM pfb_path), - "Convert the contents of a PFB file to PFA." - ) +LY_DEFINE (ly_pfb_to_pfa, "ly:pfb->pfa", + 1, 0, 0, (SCM pfb_file_name), + "Convert the contents of a PFB file to PFA." + ) { - SCM_ASSERT_TYPE(scm_is_string (pfb_path), pfb_path, - SCM_ARG1, __FUNCTION__, "string"); + SCM_ASSERT_TYPE (scm_is_string (pfb_file_name), pfb_file_name, + SCM_ARG1, __FUNCTION__, "string"); - String path = ly_scm2string (pfb_path); - int len ; - char *str = gulp_file (path, &len); + String file_name = ly_scm2string (pfb_file_name); + int len; + char *str = gulp_file (file_name, &len); char *pfa = pfb2pfa ((Byte*)str, len); - - SCM pfa_scm = scm_makfrom0str(pfa); + + SCM pfa_scm = scm_makfrom0str (pfa); free (pfa); delete str; return pfa_scm; } - -LY_DEFINE(ly_ttf_to_pfa, "ly:ttf->pfa", - 1, 0, 0, (SCM ttf_path), - "Convert the contents of a TTF file to Type42 PFA, returning it as " - " a string." - ) +LY_DEFINE (ly_ttf_to_pfa, "ly:ttf->pfa", + 1, 0, 0, (SCM ttf_file_name), + "Convert the contents of a TTF file to Type42 PFA, returning it as " + " a string." + ) { - SCM_ASSERT_TYPE(scm_is_string (ttf_path), ttf_path, - SCM_ARG1, __FUNCTION__, "string"); - - String path = ly_scm2string (ttf_path); + SCM_ASSERT_TYPE (scm_is_string (ttf_file_name), ttf_file_name, + SCM_ARG1, __FUNCTION__, "string"); + + String file_name = ly_scm2string (ttf_file_name); Memory_out_stream stream; - create_type42(path.to_str0 (), - stream.get_file()); + create_type42 (file_name.to_str0 (), stream.get_file ()); SCM asscm = scm_from_locale_stringn (stream.get_string (), stream.get_length ()); return asscm; } - - diff --git a/stepmake/aclocal.m4 b/stepmake/aclocal.m4 index 694d68ee1d..958b3a6e9a 100644 --- a/stepmake/aclocal.m4 +++ b/stepmake/aclocal.m4 @@ -491,8 +491,10 @@ AC_DEFUN([STEPMAKE_GUILE_FLAGS], [ AC_DEFUN(STEPMAKE_GUILE_DEVEL, [ ## First, let's just see if we can find Guile at all. + test -n "$target_alias" && target_guile_config=$target_alias-guile-config + test -n "$host_alias" && host_guile_config=$host_alias-guile-config AC_MSG_CHECKING([for guile-config]) - for guile_config in $GUILE_CONFIG guile-config $target-guile-config $build-guile-config; do + for guile_config in $GUILE_CONFIG $target_guile_config $host_guile_config $build_guile_config guile-config; do AC_MSG_RESULT([$guile_config]) if ! $guile_config --version > /dev/null 2>&1 ; then AC_MSG_WARN([cannot execute $guile_config]) diff --git a/ttftool/ps.c b/ttftool/ps.c index 3d8e786c74..6d75bbb40a 100644 --- a/ttftool/ps.c +++ b/ttftool/ps.c @@ -7,6 +7,8 @@ #include "types.h" #include "proto.h" +#include "libc-extension.hh" + #define CHUNKSIZE 65534 #define NAMEOF(i) \ diff --git a/ttftool/ttfps.c b/ttftool/ttfps.c index 88c6cff93f..6e8a0add73 100644 --- a/ttftool/ttfps.c +++ b/ttftool/ttfps.c @@ -8,6 +8,8 @@ #include "types.h" #include "proto.h" +#include "libc-extension.hh" + static void endianness_test (void); static void usage (char *); diff --git a/ttftool/util.c b/ttftool/util.c index 45244213a0..355d2b762f 100644 --- a/ttftool/util.c +++ b/ttftool/util.c @@ -9,6 +9,8 @@ #include "types.h" #include "proto.h" +#include "libc-extension.hh" + void * mymalloc (size_t size) { -- 2.39.5