-2005-02-25 Jan Nieuwenhuizen <janneke@gnu.org>
+2005-02-26 Jan Nieuwenhuizen <janneke@gnu.org>
- * 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.
/* 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
/* 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
#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
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`
if ! iscygwin; then
cd $build || exit 1
GUILE=1.6.5
- cat > guile-config <<EOF
-[ "\$1" == "--version" ] && echo "guile-config - Guile version $GUILE"
+ cat > i686-cygwin-guile-config <<EOF
+[ "\$1" == "--version" ] && echo "i686-cygwin-guile-config - Guile version $GUILE"
[ "\$1" == "compile" ] && echo "-I$cygwin_root/usr/include"
[ "\$1" == "link" ] && echo "-L$cygwin_root/usr/lib -lguile"
exit 0
EOF
- chmod 755 guile-config
+ chmod 755 i686-cygwin-guile-config
PATH=$(pwd):$PATH
fi
}
#ifndef LIBC_EXTENSION_HH
#define LIBC_EXTENSION_HH
-#include <cstddef>
-#include <cstdarg>
+#include <stddef.h>
+#include <stdarg.h>
#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 <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
+
+#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 */
#include <stdio.h>
#include <unistd.h>
+#include "libc-extension.hh"
+
class Memory_out_stream
{
char *buffer_;
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;
};
source file of the flowerlib
(c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
- Jan Nieuwenhuizen <janneke@gnu.org>
+ Jan Nieuwenhuizen <janneke@gnu.org>
*/
-#include "libc-extension.hh"
-
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cctype>
+#include "libc-extension.hh"
+
char*
strnlwr (char* start ,int n)
{
/*
There are some strange problems with round() on early glibcs.
- */
+*/
double
my_round (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;
}
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;
}
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;
}
return i;
}
#endif
+
+#include <assert.h>
+
+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 <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;
+ }
+
+#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 */
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_);
free (buffer_);
}
-FILE*
+FILE *
Memory_out_stream::get_file () const
{
return file_;
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;
}
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;
return size;
}
-
ssize_t
Memory_out_stream::reader (void *cookie,
char *buffer,
(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;
}
-/*
+/*
pfb.cc -- implement pfb conversion.
-
+
source file of the GNU LilyPond music typesetter
-
+
(c) 2004--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
-
*/
#include <cstdlib>
#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++;
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++);
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;
}
-
-
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])
#include "types.h"
#include "proto.h"
+#include "libc-extension.hh"
+
#define CHUNKSIZE 65534
#define NAMEOF(i) \
#include "types.h"
#include "proto.h"
+#include "libc-extension.hh"
+
static void endianness_test (void);
static void usage (char *);
#include "types.h"
#include "proto.h"
+#include "libc-extension.hh"
+
void *
mymalloc (size_t size)
{